123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- /*************************************************************************
- * Copyright © 2017-2018 Mogoson. All rights reserved.
- *------------------------------------------------------------------------
- * File : AroundCameraEditor.cs
- * Description : Custom editor for AroundCamera.
- *------------------------------------------------------------------------
- * Author : Mogoson
- * Version : 0.1.0
- * Date : 4/9/2018
- * Description : Initial development version.
- *
- * Author : Mogoson
- * Version : 0.1.1
- * Date : 6/27/2018
- * Description : Optimize display of node.
- *************************************************************************/
- using Mogoson.UEditor;
- using UnityEditor;
- using UnityEngine;
- namespace AIPagedLod
- {
- [CustomEditor(typeof(AroundCamera), true)]
- [CanEditMultipleObjects]
- public class AroundCameraEditor : GenericEditor
- {
- #region Field and Property
- protected AroundCamera Target { get { return target as AroundCamera; } }
- protected Vector2 angles;
- protected float distance;
- #endregion
- #region Protected Method
- protected virtual void OnEnable()
- {
- if (Target.target == null)
- {
- return;
- }
- angles = Target.transform.eulerAngles;
- distance = Vector3.Distance(Target.transform.position, Target.target.position);
- }
- protected virtual void OnSceneGUI()
- {
- if (Target.target == null)
- {
- return;
- }
- if (!Application.isPlaying)
- {
- Target.transform.rotation = Quaternion.Euler(angles);
- Target.transform.position = Target.target.position - Target.transform.forward * distance;
- }
- DrawSceneGizmos();
- DrawSceneGUI();
- }
- protected void DrawSceneGizmos()
- {
- Handles.color = Blue;
- DrawAdaptiveSphereCap(Target.target.position, Quaternion.identity, NodeSize);
- var direction = Target.transform.position - Target.target.position;
- DrawSphereArrow(Target.target.position, Target.transform.position, NodeSize);
- DrawSphereArrow(Target.target.position, direction, Target.distanceRange.min, NodeSize, "Min");
- DrawSphereArrow(Target.target.position, direction, Target.distanceRange.max, NodeSize, "Max");
- Handles.Label(Target.target.position, "Target");
- }
- public override void OnInspectorGUI()
- {
- base.OnInspectorGUI();
- Vector2 angleValue = EditorGUILayout.Vector2Field("相机角度:", angles);
- if (angleValue != angles)
- {
- angles = angleValue;
- if (!Application.isPlaying)
- {
- Target.transform.rotation = Quaternion.Euler(angles);
- MarkSceneDirty();
- }
- }
- float distanceValue = EditorGUILayout.FloatField("相机距离:", distance);
- if ( Mathf.Abs(distanceValue - distance) > 0.1f)
- {
- distance = distanceValue;
- if (!Application.isPlaying)
- {
- Target.transform.position = Target.target.position - Target.transform.forward * distance;
- MarkSceneDirty();
- }
- }
- }
- protected void DrawSceneGUI()
- {
- return;
- var rect = new Rect(10, Screen.height - 125, 225, 75);
- GUI.color = Color.white;
- Handles.BeginGUI();
- GUILayout.BeginArea(rect, "Current Around", "Window");
- if (Application.isPlaying)
- {
- EditorGUILayout.Vector2Field("Angles", Target.CurrentAngles);
- EditorGUILayout.FloatField("Distance", Target.CurrentDistance);
- }
- else
- {
- EditorGUI.BeginChangeCheck();
- angles = EditorGUILayout.Vector2Field("Angles", angles);
- distance = EditorGUILayout.FloatField("Distance", distance);
- if (EditorGUI.EndChangeCheck())
- {
- MarkSceneDirty();
- }
- }
- GUILayout.EndArea();
- Handles.EndGUI();
- }
- #endregion
- }
- }
|