63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class RuntimeGizmo
|
|
{
|
|
public GameObject gizmo;
|
|
protected GameObject prefab;
|
|
public bool enabled = false;
|
|
|
|
protected GameObject target;
|
|
|
|
protected List<string> handleNames;
|
|
|
|
protected float scaleRate = 1.0f;
|
|
|
|
public virtual void Initialize() { }
|
|
|
|
public virtual List<GameObject> RegisterObjectsToSelectDetector() { return null; } //这样可以让Gizmo的指定组件可以使用TransformGizmo的操纵
|
|
|
|
public virtual void Update() { }
|
|
|
|
protected virtual void RenderUpdate()
|
|
{
|
|
//Gizmo Scale Update
|
|
Vector3 cameraPosition = Camera.main.transform.position;
|
|
Vector3 gizmoPosition = gizmo.transform.position;
|
|
float distance = (cameraPosition - gizmoPosition).magnitude;
|
|
gizmo.GetComponent<Transform>().localScale = new Vector3(distance, distance, distance);
|
|
}
|
|
|
|
protected virtual void FollowUpdate() { }
|
|
|
|
protected void HideBeindCamera()
|
|
{
|
|
if (gizmo.activeSelf) { gizmo.SetActive(false); }
|
|
gizmo.GetComponent<Transform>().position = Camera.main.transform.position - Camera.main.transform.forward * 10;
|
|
}
|
|
|
|
public virtual void EnableGizmo(GameObject target)
|
|
{
|
|
enabled = true;
|
|
this.target = target;
|
|
if (!gizmo.activeSelf) { gizmo.SetActive(true); }
|
|
gizmo.GetComponent<Transform>().position = target.transform.position;
|
|
gizmo.GetComponent<Transform>().rotation = target.transform.rotation;
|
|
}
|
|
|
|
public virtual void DisableGizmo()
|
|
{
|
|
enabled = false;
|
|
this.target = null;
|
|
HideBeindCamera();
|
|
}
|
|
public virtual void OnSelect(string handleName) { }
|
|
|
|
public virtual void OnUnSelect() { }
|
|
protected virtual void OnSelecting() { }
|
|
|
|
protected virtual void ChangeRenderOnSelect() { }
|
|
protected virtual void ChangeRenderOnUnSelect() { }
|
|
}
|