diff --git a/Packages/uGUI-Skinner/Editor/SkinPartsInspector/ScriptableLogicInspector.cs b/Packages/uGUI-Skinner/Editor/SkinPartsInspector/ScriptableLogicInspector.cs index df0c3b3..b2d5f7f 100644 --- a/Packages/uGUI-Skinner/Editor/SkinPartsInspector/ScriptableLogicInspector.cs +++ b/Packages/uGUI-Skinner/Editor/SkinPartsInspector/ScriptableLogicInspector.cs @@ -79,6 +79,7 @@ public void DrawInspector(EditorSkinPartsPropertry property) SkinnerEditorUtility.ResetArray(property.objectReferenceValues, ScriptableLogic.RequiredObjectLength, false); var logicProperty = property.objectReferenceValues.GetArrayElementAtIndex(ScriptableLogic.LogicIndex); + var preSelectLogic = logicProperty.objectReferenceValue as UserLogic; SkinnerEditorGUILayout.ObjectField(SkinContent.Logic, logicProperty, typeof(UserLogic)); ; if (logicProperty.hasMultipleDifferentValues) return; @@ -91,6 +92,14 @@ public void DrawInspector(EditorSkinPartsPropertry property) SkinnerEditorUtility.ResetArray(property.floatValues, current.FloatArrayCount); SkinnerEditorUtility.ResetArray(property.vector4Values, current.Vector4ArrayCount); SkinnerEditorUtility.ResetArray(property.stringValues, current.StringArrayCount); + + logicProperty.objectReferenceValue = userLogic; + + if (preSelectLogic != userLogic) + { + InitializeFields(property); + } + for (int i = 0; i < current.VariableDisplayDatas.Count; i++) { var v = current.VariableDisplayDatas[i]; @@ -231,6 +240,57 @@ public void DrawInspector(EditorSkinPartsPropertry property) } } + /// + /// 表示データを元にフィールドを全て初期化する + /// + /// property + private void InitializeFields(EditorSkinPartsPropertry property) + { + for (int i = 0; i < current.VariableDisplayDatas.Count; i++) + { + var v = current.VariableDisplayDatas[i]; + + SerializedProperty element = null; + switch (v.PropertyType) + { + case SerializedPropertyType.ObjectReference: + { + element = property.objectReferenceValues.GetArrayElementAtIndex(v.FieldIndex + ScriptableLogic.RequiredObjectLength); + } + break; + case SerializedPropertyType.Float: + case SerializedPropertyType.Boolean: + case SerializedPropertyType.Integer: + case SerializedPropertyType.LayerMask: + case SerializedPropertyType.Enum: + { + element = property.floatValues.GetArrayElementAtIndex(v.FieldIndex); + } + break; + case SerializedPropertyType.Vector2: + case SerializedPropertyType.Vector3: + case SerializedPropertyType.Vector4: + case SerializedPropertyType.Color: + case SerializedPropertyType.Rect: + { + element = property.vector4Values.GetArrayElementAtIndex(v.FieldIndex); + } + break; + case SerializedPropertyType.Character: + case SerializedPropertyType.String: + { + element = property.stringValues.GetArrayElementAtIndex(v.FieldIndex); + } + break; + } + + if (element != null) + { + SkinnerEditorUtility.FieldClean(element, v.VariableData.DefaultValue); + } + } + } + /// /// インスペクター用表示データを生成して初期化する /// diff --git a/Packages/uGUI-Skinner/Editor/SkinnerEditorUtility.cs b/Packages/uGUI-Skinner/Editor/SkinnerEditorUtility.cs index 883e71f..228f565 100644 --- a/Packages/uGUI-Skinner/Editor/SkinnerEditorUtility.cs +++ b/Packages/uGUI-Skinner/Editor/SkinnerEditorUtility.cs @@ -79,7 +79,7 @@ private static bool IsDefinedDisallowMultiplyComponent(Type type) #endregion - private static void FieldClean(SerializedProperty arrayObj, object defaultValue) + public static void FieldClean(SerializedProperty arrayObj, object defaultValue) { bool hasDefaultValue = defaultValue != null; switch (arrayObj.propertyType) diff --git a/Packages/uGUI-Skinner/Runtime/UserLogic.cs b/Packages/uGUI-Skinner/Runtime/UserLogic.cs index 3a57666..83d2efb 100644 --- a/Packages/uGUI-Skinner/Runtime/UserLogic.cs +++ b/Packages/uGUI-Skinner/Runtime/UserLogic.cs @@ -111,6 +111,11 @@ public sealed class UserLogicVariable /// public string FieldDisplayName; + /// + /// 初期値 + /// + public object DefaultValue; + /// /// カスタムプロパティ ///