Skip to content

Commit

Permalink
feat: ScriptableLogic フィールド初期値に対応
Browse files Browse the repository at this point in the history
  • Loading branch information
pspkurara committed Nov 6, 2020
1 parent 477b0d4 commit 4c33f1f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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];
Expand Down Expand Up @@ -231,6 +240,57 @@ public void DrawInspector(EditorSkinPartsPropertry property)
}
}

/// <summary>
/// 表示データを元にフィールドを全て初期化する
/// </summary>
/// <param name="property">property</param>
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);
}
}
}

/// <summary>
/// インスペクター用表示データを生成して初期化する
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Packages/uGUI-Skinner/Editor/SkinnerEditorUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions Packages/uGUI-Skinner/Runtime/UserLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ public sealed class UserLogicVariable
/// </summary>
public string FieldDisplayName;

/// <summary>
/// 初期値
/// </summary>
public object DefaultValue;

/// <summary>
/// カスタムプロパティ
/// </summary>
Expand Down

0 comments on commit 4c33f1f

Please sign in to comment.