using Unity.Mathematics; using UnityEditor; using UnityEditorInternal; using UnityEngine; using UnityEngine.UIElements; using static Codice.Client.Commands.WkTree.WorkspaceTreeNode; namespace X.Rendering.Scene { [CustomEditor(typeof(SceneEffect))] public class SceneEffectEditorBase : Editor { ReorderableList lightList; Transform transform; int selectIndex = -1; public override VisualElement CreateInspectorGUI() { transform = (target as MonoBehaviour).transform; lightList = new ReorderableList(serializedObject, serializedObject.FindProperty("capsuleLights"), true, true, true, true); lightList.onSelectCallback += (_) => { Debug.Log($"{lightList.index}"); selectIndex = lightList.index; }; lightList.drawHeaderCallback = DrawHeader; lightList.drawElementCallback = DrawListItems; return base.CreateInspectorGUI(); } private void DrawListItems(Rect rect, int index, bool isActive, bool isFocused) { SerializedProperty element = lightList.serializedProperty.GetArrayElementAtIndex(index); EditorGUI.LabelField(new Rect(rect.x, rect.y, 200, EditorGUIUtility.singleLineHeight), $"{element.vector4Value}"); } private void DrawHeader(Rect rect) { string name = "光照方向"; EditorGUI.LabelField(rect, name); } public override void OnInspectorGUI() { serializedObject.Update(); //base.OnInspectorGUI(); lightList.DoLayoutList(); serializedObject.ApplyModifiedProperties(); } public void OnSceneGUI() { if(selectIndex == -1 || selectIndex >= lightList.serializedProperty.arraySize) { return; } SerializedProperty element = lightList.serializedProperty.GetArrayElementAtIndex(selectIndex); var rot = new float4(element.vector4Value).xyz; rot += DrawRotationHandle(element.vector4Value); element.vector4Value = new float4(rot, element.vector4Value.w); serializedObject.ApplyModifiedProperties(); } protected float3 DrawRotationHandle(Vector3 rotation) { EditorGUI.BeginChangeCheck(); var newRot = Handles.PositionHandle(rotation, Quaternion.identity); EditorGUI.EndChangeCheck(); Debug.Log((newRot - transform.position).normalized); Handles.ConeHandleCap(0, transform.position, Quaternion.EulerRotation(math.degrees((newRot-transform.position).normalized)), HandleUtility.GetHandleSize(transform.position), EventType.Repaint); float3 delta; if (newRot != rotation) { Undo.RecordObject(target, "Rotate Handle"); // Perform the handle move and update the serialized data delta = newRot - rotation; } else { delta = float3.zero; } return delta; } private Vector3 CalculateTargetPosition() { Vector3 handlePosition; //if (transform.parent != null) //{ // handlePosition = transform.parent.TransformPoint(tweenPosition.TargetPosition); //} //else { handlePosition = transform.position; } return handlePosition; } } [CustomEditor(typeof(CapsuleShadowAreaEffect))] public class MyClaCapsuleShadowAreaEffectsEditor : SceneEffectEditorBase { } }