2026-05-07 10:14:44 +02:00

60 lines
1.7 KiB
C#

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Wing.Gizmos
{
public class GizmosAxis : MonoBehaviour
{
private GizmosBase _coordinate;
private int m_iLayer;
private bool mSelected = false;
// Use this for initialization
void Awake()
{
_coordinate = transform.parent.parent.GetComponent<GizmosBase>();
m_iLayer = LayerMask.NameToLayer(Settings.GizmosLayerName);
gameObject.layer = m_iLayer;
}
// Update is called once per frame
void Update()
{
if (mSelected)
{
if (!Input.GetMouseButton(0))
{
mSelected = false;
StartCoroutine(delayRelease());
}
else
{
_coordinate.OnMouseDrag(gameObject);
}
}
else if(Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 1000, 1 << m_iLayer))
{
if (hit.collider.gameObject == gameObject)
{
_coordinate.OnMouseEnter(gameObject);
_coordinate.OnMouseDown(gameObject);
mSelected = true;
}
}
}
}
IEnumerator delayRelease()
{
yield return new WaitForEndOfFrame();
_coordinate.OnMouseExit(gameObject);
_coordinate.OnMouseUp(gameObject);
}
}
}