using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEngine; using VketCloudGUITools.Runtime; namespace VketCloudGUITools.Editor { /// /// IVCGUIItem用のInspector用便利関数 /// 継承でUI処理使いまわせないので所属にする /// public class VCGUIItemInspectorHelper { // Interfaceなので内部変数名が一致するとは限らない // いちおうデフォルトによく使う値をいれるが、適時カスタマイズが必要 public string propertyNameScript = "m_Script"; public string propertyNameVcguiTransform = "_vcTransform"; public string propertyNameCanvas = "_parentLayer"; public string propertyNameVisible = "_visible"; public SerializedObject serializedObject; public IVCGUIItem item; public SerializedProperty scriptProperty; public SerializedProperty vcTransformProperty; public SerializedProperty parentLayerProperty; public SerializedProperty visibleProperty; public void OnEnable(SerializedObject serializedObject, IVCGUIItem item) { this.serializedObject = serializedObject; this.item = item; RefleshSerializedProperty(); } private void RefleshSerializedProperty() { scriptProperty = serializedObject.FindProperty(propertyNameScript); vcTransformProperty = serializedObject.FindProperty(propertyNameVcguiTransform); parentLayerProperty = serializedObject.FindProperty(propertyNameCanvas); visibleProperty = serializedObject.FindProperty(propertyNameVisible); } private VCTransform GetVcguiTransform(IVCGUIItem targetItem) { IHasVCTransform hasTransform = targetItem as IHasVCTransform; if (hasTransform != null) { return hasTransform.VcTransform; } return null; } private GameObject GetGameObject(IVCGUIItem targetItem) { MonoBehaviour mono = targetItem as MonoBehaviour; if (mono != null) { return mono.gameObject; } return null; } public void DrawPropertyScript() { EditorGUILayout.PropertyField(scriptProperty); } public void DrawPropertyVcTransform() { EditorGUILayout.PropertyField(vcTransformProperty); } public void DrawPropertyParentLayer() { EditorGUILayout.PropertyField(parentLayerProperty); } public void DrawPropertyVisible() { EditorGUILayout.Toggle(nameof(IVCGUIItem.Visible), item.Visible); } public void DrawPropertyShow() { var gameObject = GetGameObject(item); EditorGUI.BeginChangeCheck(); var newShow = EditorGUILayout.Toggle(nameof(IVCGUIItem.Show), item.Show); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(gameObject, "VCGUI Item"); item.Show = newShow; } } public void DrawPropertyPos() { var vcguiTransform = GetVcguiTransform(item); EditorGUI.BeginChangeCheck(); var newPos = EditorGUILayout.Vector2IntField(nameof(IVCGUIItem.Pos), item.Pos); if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(new Object[] { vcguiTransform.transform, vcguiTransform }, "VCGUI Item"); item.Pos = newPos; } } public void DrawPropertySize() { var vcguiTransform = GetVcguiTransform(item); EditorGUI.BeginChangeCheck(); var newSize = EditorGUILayout.Vector2IntField(nameof(IVCGUIItem.Size), item.Size); if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(new Object[] { vcguiTransform.transform, vcguiTransform }, "VCGUI Item"); item.Size = newSize; } } public void DrawPropertyZ() { var vcguiTransform = GetVcguiTransform(item); EditorGUI.BeginChangeCheck(); var newZ = EditorGUILayout.IntField(nameof(IVCGUIItem.Z), item.Z); if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(new Object[] { vcguiTransform.transform, vcguiTransform }, "VCGUI Item"); item.Z = newZ; } } } }