AroundCameraEditor.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*************************************************************************
  2. * Copyright © 2017-2018 Mogoson. All rights reserved.
  3. *------------------------------------------------------------------------
  4. * File : AroundCameraEditor.cs
  5. * Description : Custom editor for AroundCamera.
  6. *------------------------------------------------------------------------
  7. * Author : Mogoson
  8. * Version : 0.1.0
  9. * Date : 4/9/2018
  10. * Description : Initial development version.
  11. *
  12. * Author : Mogoson
  13. * Version : 0.1.1
  14. * Date : 6/27/2018
  15. * Description : Optimize display of node.
  16. *************************************************************************/
  17. using Mogoson.UEditor;
  18. using UnityEditor;
  19. using UnityEngine;
  20. namespace AIPagedLod
  21. {
  22. [CustomEditor(typeof(AroundCamera), true)]
  23. [CanEditMultipleObjects]
  24. public class AroundCameraEditor : GenericEditor
  25. {
  26. #region Field and Property
  27. protected AroundCamera Target { get { return target as AroundCamera; } }
  28. protected Vector2 angles;
  29. protected float distance;
  30. #endregion
  31. #region Protected Method
  32. protected virtual void OnEnable()
  33. {
  34. if (Target.target == null)
  35. {
  36. return;
  37. }
  38. angles = Target.transform.eulerAngles;
  39. distance = Vector3.Distance(Target.transform.position, Target.target.position);
  40. }
  41. protected virtual void OnSceneGUI()
  42. {
  43. if (Target.target == null)
  44. {
  45. return;
  46. }
  47. if (!Application.isPlaying)
  48. {
  49. Target.transform.rotation = Quaternion.Euler(angles);
  50. Target.transform.position = Target.target.position - Target.transform.forward * distance;
  51. }
  52. DrawSceneGizmos();
  53. DrawSceneGUI();
  54. }
  55. protected void DrawSceneGizmos()
  56. {
  57. Handles.color = Blue;
  58. DrawAdaptiveSphereCap(Target.target.position, Quaternion.identity, NodeSize);
  59. var direction = Target.transform.position - Target.target.position;
  60. DrawSphereArrow(Target.target.position, Target.transform.position, NodeSize);
  61. DrawSphereArrow(Target.target.position, direction, Target.distanceRange.min, NodeSize, "Min");
  62. DrawSphereArrow(Target.target.position, direction, Target.distanceRange.max, NodeSize, "Max");
  63. Handles.Label(Target.target.position, "Target");
  64. }
  65. public override void OnInspectorGUI()
  66. {
  67. base.OnInspectorGUI();
  68. Vector2 angleValue = EditorGUILayout.Vector2Field("相机角度:", angles);
  69. if (angleValue != angles)
  70. {
  71. angles = angleValue;
  72. if (!Application.isPlaying)
  73. {
  74. Target.transform.rotation = Quaternion.Euler(angles);
  75. MarkSceneDirty();
  76. }
  77. }
  78. float distanceValue = EditorGUILayout.FloatField("相机距离:", distance);
  79. if ( Mathf.Abs(distanceValue - distance) > 0.1f)
  80. {
  81. distance = distanceValue;
  82. if (!Application.isPlaying)
  83. {
  84. Target.transform.position = Target.target.position - Target.transform.forward * distance;
  85. MarkSceneDirty();
  86. }
  87. }
  88. }
  89. protected void DrawSceneGUI()
  90. {
  91. return;
  92. var rect = new Rect(10, Screen.height - 125, 225, 75);
  93. GUI.color = Color.white;
  94. Handles.BeginGUI();
  95. GUILayout.BeginArea(rect, "Current Around", "Window");
  96. if (Application.isPlaying)
  97. {
  98. EditorGUILayout.Vector2Field("Angles", Target.CurrentAngles);
  99. EditorGUILayout.FloatField("Distance", Target.CurrentDistance);
  100. }
  101. else
  102. {
  103. EditorGUI.BeginChangeCheck();
  104. angles = EditorGUILayout.Vector2Field("Angles", angles);
  105. distance = EditorGUILayout.FloatField("Distance", distance);
  106. if (EditorGUI.EndChangeCheck())
  107. {
  108. MarkSceneDirty();
  109. }
  110. }
  111. GUILayout.EndArea();
  112. Handles.EndGUI();
  113. }
  114. #endregion
  115. }
  116. }