using Neatly.UI; using UnityEngine; using UnityEditor; using UnityEditor.UI; using UnityEngine.UI; namespace NeatlyEditor.UI { [CustomEditor(typeof(EffectImage), true)] [CanEditMultipleObjects] public class EffectImageEditor : ImageEditor { SerializedProperty m_TargetPosition; SerializedProperty m_PosTimeTotal; SerializedProperty m_TargetRotate; SerializedProperty m_RotateTimeTotal; SerializedProperty m_TargetColor; SerializedProperty m_ColorTimeTotal; SerializedProperty m_TargetScale; SerializedProperty m_ScaleTimeTotal; SerializedProperty m_LoopMode; GUIContent m_TargetPositionContent; GUIContent m_PosTimeTotalContent; GUIContent m_TargetRotateContent; GUIContent m_RotateTimeContent; GUIContent m_TargetColorContent; GUIContent m_ColorTimeTotalContent; GUIContent m_TargetScaleContent; GUIContent m_ScaleTimeTotalContent; GUIContent m_LoopModeContent; protected override void OnEnable() { base.OnEnable(); m_TargetPositionContent = new GUIContent("目标:"); m_PosTimeTotalContent = new GUIContent("时间:"); m_TargetRotateContent = new GUIContent("目标:"); m_RotateTimeContent = new GUIContent("时间:"); m_TargetColorContent = new GUIContent("目标:"); m_ColorTimeTotalContent = new GUIContent("时间:"); m_TargetScaleContent = new GUIContent("目标:"); m_ScaleTimeTotalContent = new GUIContent("时间:"); m_LoopModeContent = new GUIContent("循环模式"); // m_Sprite = serializedObject.FindProperty("m_Sprite"); m_TargetPosition = serializedObject.FindProperty("m_TargetPosition"); m_PosTimeTotal = serializedObject.FindProperty("m_PosTimeTotal"); m_TargetRotate = serializedObject.FindProperty("m_TargetRotate"); m_RotateTimeTotal = serializedObject.FindProperty("m_RotateTimeTotal"); m_TargetColor = serializedObject.FindProperty("m_TargetColor"); m_ColorTimeTotal = serializedObject.FindProperty("m_ColorTimeTotal"); m_TargetScale = serializedObject.FindProperty("m_TargetScale"); m_ScaleTimeTotal = serializedObject.FindProperty("m_ScaleTimeTotal"); m_LoopMode = serializedObject.FindProperty("m_LoopMode"); } public override void OnInspectorGUI() { base.OnInspectorGUI(); serializedObject.Update(); EffectGUI(); serializedObject.ApplyModifiedProperties(); } private void EffectGUI() { EffectImage effectImage = target as EffectImage; InspectorHelper.BeginGroup(); effectImage.positionEnable = InspectorHelper.Toggle("位置", effectImage.positionEnable, true); if (effectImage.positionEnable) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(m_TargetPosition, m_TargetPositionContent); EditorGUILayout.PropertyField(m_PosTimeTotal, m_PosTimeTotalContent); EditorGUI.indentLevel--; } InspectorHelper.EndGroup(); InspectorHelper.BeginGroup(); effectImage.rotateEnable = InspectorHelper.Toggle("旋转", effectImage.rotateEnable, true); if (effectImage.rotateEnable) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(m_TargetRotate, m_TargetRotateContent); EditorGUILayout.PropertyField(m_RotateTimeTotal, m_RotateTimeContent); EditorGUI.indentLevel--; } InspectorHelper.EndGroup(); InspectorHelper.BeginGroup(); effectImage.colorEnable = InspectorHelper.Toggle("色彩", effectImage.colorEnable, true); if (effectImage.colorEnable) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(m_TargetColor, m_TargetColorContent); EditorGUILayout.PropertyField(m_ColorTimeTotal, m_ColorTimeTotalContent); EditorGUI.indentLevel--; } InspectorHelper.EndGroup(); InspectorHelper.BeginGroup(); effectImage.scaleEnable = InspectorHelper.Toggle("缩放", effectImage.scaleEnable, true); if (effectImage.scaleEnable) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(m_TargetScale, m_TargetScaleContent); EditorGUILayout.PropertyField(m_ScaleTimeTotal, m_ScaleTimeTotalContent); EditorGUI.indentLevel--; } InspectorHelper.EndGroup(); InspectorHelper.BeginGroup(); effectImage.useLoop = InspectorHelper.Toggle("UseLoop", effectImage.useLoop, true); if (effectImage.useLoop) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(m_LoopMode, m_LoopModeContent); EditorGUI.indentLevel--; } InspectorHelper.EndGroup(); } public override bool HasPreviewGUI() { return true; } public override string GetInfoString() { Image image = target as Image; Sprite sprite = image.sprite; int x = (sprite != null) ? Mathf.RoundToInt(sprite.rect.width) : 0; int y = (sprite != null) ? Mathf.RoundToInt(sprite.rect.height) : 0; return string.Format("Image Size: {0}x{1}", x, y); } } }