ElectricityBusinessHall_Dig.../Assets/Resources/Scripts/Function/Space3DIcon.cs

53 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class Space3DIcon : MonoBehaviour
{
private GameObject icon;
// Start is called before the first frame update
void Start()
{
icon=transform.GetChild(0).gameObject;
icon.transform.DOLocalMoveY(3, 0.8f).SetLoops(-1, LoopType.Yoyo);
if(!icon.GetComponent<UI3DEventTrigger>())
icon.AddComponent<UI3DEventTrigger>();
icon.GetComponent<UI3DEventTrigger>().onClick= ViewCenter;
}
// Update is called once per frame
void Update()
{
}
/// <summary>
/// ÊӽǾÓÖÐ
/// </summary>
public void ViewCenter() {
Quaternion angle= Quaternion.LookRotation(-transform.forward);
Vector3 endpos= transform.position + transform.forward * 5;
Main.intance.CameraMoveTarget(endpos, angle);
}
/// <summary>
/// ¸øUIÌí¼ÓÅöײÌå
/// </summary>
/// <param name="uiobj"></param>
void AddUICollider(GameObject uiobj)
{
if (!uiobj.GetComponent<BoxCollider>())
{
uiobj.AddComponent<BoxCollider>();
Vector2 pivot = uiobj.GetComponent<RectTransform>().pivot;
Vector3 center = new Vector3(uiobj.GetComponent<RectTransform>().sizeDelta.x * (0.5f - pivot.x), uiobj.GetComponent<RectTransform>().sizeDelta.x * (0.5f - pivot.y));
uiobj.GetComponent<BoxCollider>().size = uiobj.GetComponent<RectTransform>().sizeDelta;
uiobj.GetComponent<BoxCollider>().center = center;
}
}
}