using UnityEditor; using System.Collections.Generic; using UnityEngine; using VketCloudGUITools.Runtime; namespace VketCloudGUITools.Editor { [CustomEditor(typeof(VCImage))] public class VCImageInspector : VCGUIItemBehaviourInspector { [SerializeField] private SerializedProperty unityImageProperty; [SerializeField] private SerializedProperty toggleListProperty; private bool showAdvancedOptions = false; protected override void OnEnable() { base.OnEnable(); unityImageProperty = serializedObject.FindProperty("_unityImage"); toggleListProperty = serializedObject.FindProperty("_toggleList"); } public override void OnInspectorGUI() { serializedObject.Update(); DrawPropertyScript(); DrawPropertyVcTransform(); DrawPropertyParentLayer(); DrawPropertyUnityImage(); DrawPropertyVisible(); DrawPropertyToggleList(toggleListProperty); DrawPropertyShow(); DrawPropertyPos(); DrawPropertySize(); DrawPropertyZ(); showAdvancedOptions = EditorGUILayout.Foldout(showAdvancedOptions, "Advanced Options"); if (showAdvancedOptions) { var image = target as VCImage; if (image.UVArea == null || image.UVArea.Count != 4) { if (image.UVAreaRate == null || image.UVAreaRate.Count != 4) { GUILayout.Label("UVArea"); if (GUILayout.Button("New")) { Undo.RecordObject(target, "Create UVArea"); image.UVArea = new List { 0, 0, image.Sprite.texture.width, image.Sprite.texture.height }; Repaint(); } } } else { GUILayout.Label("UVArea"); if (GUILayout.Button("Delete")) { Undo.RecordObject(target, "Delete UVArea"); image.UVArea = null; Repaint(); } else { EditorGUI.BeginChangeCheck(); var x = EditorGUILayout.IntField("X", image.UVArea[0]); var y = EditorGUILayout.IntField("Y", image.UVArea[1]); var width = EditorGUILayout.IntField("Width", image.UVArea[2]); var height = EditorGUILayout.IntField("Height", image.UVArea[3]); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Change UVArea"); image.UVArea = new List { x, y, width, height }; } } } if (image.UVAreaRate == null || image.UVAreaRate.Count != 4) { if (image.UVArea == null || image.UVArea.Count != 4) { GUILayout.Label("UVAreaRate"); if (GUILayout.Button("New")) { Undo.RecordObject(target, "Create UVAreaRate"); image.UVAreaRate = new List { 0, 0, 1, 1 }; Repaint(); } } } else { GUILayout.Label("UVAreaRate"); if (GUILayout.Button("Delete")) { Undo.RecordObject(target, "Delete UVAreaRate"); image.UVAreaRate = null; Repaint(); } else { EditorGUI.BeginChangeCheck(); var x = EditorGUILayout.FloatField("X", image.UVAreaRate[0]); var y = EditorGUILayout.FloatField("Y", image.UVAreaRate[1]); var width = EditorGUILayout.FloatField("Width", image.UVAreaRate[2]); var height = EditorGUILayout.FloatField("Height", image.UVAreaRate[3]); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Change UVAreaRate"); image.UVAreaRate = new List { x, y, width, height }; } } } } serializedObject.ApplyModifiedProperties(); } private void DrawPropertyUnityImage() { EditorGUILayout.PropertyField(unityImageProperty); } } }