Skip to content

Commit

Permalink
feat: ScriptableLogic プロパティドローAttributeに対応
Browse files Browse the repository at this point in the history
Range、ColorUsage、TextArea属性が使えるようにした
  • Loading branch information
pspkurara committed Nov 6, 2020
1 parent 740f1c7 commit a26aeff
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal sealed class UserLogicVariableDisplayData
public UserLogicVariable VariableData;
public int FieldIndex;
public string[] PopupDisplayName;
public Dictionary<Type, PropertyAttribute> FieldDefinedAttributes;
public List<Type> PropertyTypeDefinedAttributes;
public List<Attribute> PropertyTypeAttributes;
public int[] PopupValue;
Expand Down Expand Up @@ -111,18 +112,43 @@ public void DrawInspector(EditorSkinPartsPropertry property)
{
var element = property.vector4Values.GetArrayElementAtIndex(v.FieldIndex);
SkinnerEditorGUILayout.ColorField(v.DisplayName, element);
if (v.FieldDefinedAttributes.ContainsKey(typeof(ColorUsageAttribute)))
{
var colorUsageData = v.FieldDefinedAttributes[typeof(ColorUsageAttribute)] as ColorUsageAttribute;
SkinnerEditorGUILayout.ColorField(v.DisplayName, element, false, colorUsageData.showAlpha, colorUsageData.hdr);
}
else
{
SkinnerEditorGUILayout.ColorField(v.DisplayName, element);
}
}
break;
case SerializedPropertyType.Float:
{
var element = property.floatValues.GetArrayElementAtIndex(v.FieldIndex);
SkinnerEditorGUILayout.FloatField(v.DisplayName, element);
if (v.FieldDefinedAttributes.ContainsKey(typeof(RangeAttribute)))
{
var rangeData = v.FieldDefinedAttributes[typeof(RangeAttribute)] as RangeAttribute;
SkinnerEditorGUILayout.Slider(v.DisplayName, element, rangeData.min, rangeData.max);
}
else
{
SkinnerEditorGUILayout.FloatField(v.DisplayName, element);
}
}
break;
case SerializedPropertyType.Integer:
{
var element = property.floatValues.GetArrayElementAtIndex(v.FieldIndex);
SkinnerEditorGUILayout.IntField(v.DisplayName, element);
if (v.FieldDefinedAttributes.ContainsKey(typeof(RangeAttribute)))
{
var rangeData = v.FieldDefinedAttributes[typeof(RangeAttribute)] as RangeAttribute;
SkinnerEditorGUILayout.IntSlider(v.DisplayName, element, rangeData.min.ToInt(), rangeData.max.ToInt());
}
else
{
SkinnerEditorGUILayout.IntField(v.DisplayName, element);
}
}
break;
case SerializedPropertyType.Enum:
Expand Down Expand Up @@ -165,7 +191,19 @@ public void DrawInspector(EditorSkinPartsPropertry property)
case SerializedPropertyType.String:
{
var element = property.stringValues.GetArrayElementAtIndex(v.FieldIndex);
SkinnerEditorGUILayout.TextField(v.DisplayName, element);
if (v.FieldDefinedAttributes.ContainsKey(typeof(TextAreaAttribute)))
{
var textAreaData = v.FieldDefinedAttributes[typeof(TextAreaAttribute)] as TextAreaAttribute;
EditorGUILayout.LabelField(v.DisplayName);
int lineCount = element.stringValue.Count(c => c == '\n');
lineCount = Mathf.Clamp(lineCount, textAreaData.minLines, textAreaData.maxLines);
SkinnerEditorGUILayout.TextArea(element,
GUILayout.Height(lineCount * EditorGUIUtility.singleLineHeight));
}
else
{
SkinnerEditorGUILayout.TextField(v.DisplayName, element);
}
}
break;
}
Expand Down Expand Up @@ -218,6 +256,7 @@ private bool CreateDisplayData(UserLogic userLogic)
var floatArrayCount = 0;
var vector4ArrayCount = 0;
var stringArrayCount = 0;
var fieldAttributes = new List<Attribute>();
foreach (var v in userLogic.variables)
{
bool isUnCorrect = false;
Expand Down Expand Up @@ -304,6 +343,14 @@ private bool CreateDisplayData(UserLogic userLogic)
var displayName = v.FieldDisplayName == null ? SkinnerEditorUtility.GetEditorName(v.FieldType.Name) : v.FieldDisplayName;
data.DisplayName = new GUIContent(displayName);
data.VariableData = v;
if (v.PropertyAttributes != null)
{
data.FieldDefinedAttributes = v.PropertyAttributes.ToDictionary(a => a.GetType(), a => a);
}
else
{
data.FieldDefinedAttributes = new Dictionary<Type, PropertyAttribute>();
}
data.PropertyTypeAttributes = v.FieldType.GetCustomAttributesWithBaseType().ToList();
data.PropertyTypeDefinedAttributes = data.PropertyTypeAttributes.Select(a => a.GetType()).ToList();
userLogicVariableDisplayDatas.Add(data);
Expand Down
84 changes: 82 additions & 2 deletions Packages/uGUI-Skinner/Editor/SkinnerEditorGUILayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void ObjectField(GUIContent label, SerializedProperty property, Sy
if (showComponentIndex)
{
objectFieldRect.width -= EditorConst.ComponentIndexFieldWidth + EditorGUIUtility.standardVerticalSpacing;
}
}

var result = EditorGUI.ObjectField(objectFieldRect, label, property.objectReferenceValue, type, componentInfo.isComponent || isGameObject);

Expand Down Expand Up @@ -126,6 +126,29 @@ public static void FloatField(GUIContent label, SerializedProperty property, par
EditorGUI.showMixedValue = showMixedValue;
}

/// <summary>
/// <see cref="EditorGUILayout.Slider"/>を表示
/// </summary>
/// <param name="label">ラベル</param>
/// <param name="property">プロパティ</param>
/// <param name="leftValue">左の値</param>
/// <param name="rightValue">右の値</param>
/// <param name="options">レイアウト設定</param>
public static void Slider(GUIContent label, SerializedProperty property, float leftValue, float rightValue, params GUILayoutOption[] options)
{
bool showMixedValue = EditorGUI.showMixedValue;
if (property.hasMultipleDifferentValues)
{
EditorGUI.showMixedValue = true;
}
var result = EditorGUILayout.Slider(label, property.floatValue, leftValue, rightValue, options);
if (!Mathf.Approximately(result, property.floatValue))
{
property.floatValue = result;
}
EditorGUI.showMixedValue = showMixedValue;
}

/// <summary>
/// <see cref="EditorGUILayout.IntField"/>を表示
/// </summary>
Expand All @@ -147,6 +170,29 @@ public static void IntField(GUIContent label, SerializedProperty property, param
EditorGUI.showMixedValue = showMixedValue;
}

/// <summary>
/// <see cref="EditorGUILayout.IntSlider"/>を表示
/// </summary>
/// <param name="label">ラベル</param>
/// <param name="property">プロパティ</param>
/// <param name="leftValue">左の値</param>
/// <param name="rightValue">右の値</param>
/// <param name="options">レイアウト設定</param>
public static void IntSlider(GUIContent label, SerializedProperty property, int leftValue, int rightValue, params GUILayoutOption[] options)
{
bool showMixedValue = EditorGUI.showMixedValue;
if (property.hasMultipleDifferentValues)
{
EditorGUI.showMixedValue = true;
}
var result = EditorGUILayout.IntSlider(label, property.floatValue.ToInt(), leftValue, rightValue, options);
if (!Mathf.Approximately(result, property.floatValue))
{
property.floatValue = result;
}
EditorGUI.showMixedValue = showMixedValue;
}

/// <summary>
/// <see cref="EditorGUILayout.Toggle"/>を表示
/// </summary>
Expand Down Expand Up @@ -237,13 +283,27 @@ public static void MaskField(GUIContent label, SerializedProperty property, stri
/// <param name="property">プロパティ</param>
/// <param name="options">レイアウト設定</param>
public static void ColorField(GUIContent label, SerializedProperty property, params GUILayoutOption[] options)
{
ColorField(label, property, false, true, false, options);
}

/// <summary>
/// <see cref="EditorGUILayout.ColorField"/>を表示
/// </summary>
/// <param name="label">ラベル</param>
/// <param name="property">プロパティ</param>
/// <param name="showEyedropper">Eyedropperの表示を有効</param>
/// <param name="showAlpha">アルファの表示を有効</param>
/// <param name="hdr">HDR表示を有効</param>
/// <param name="options">レイアウト設定</param>
public static void ColorField(GUIContent label, SerializedProperty property, bool showEyedropper, bool showAlpha, bool hdr, params GUILayoutOption[] options)
{
bool showMixedValue = EditorGUI.showMixedValue;
if (property.hasMultipleDifferentValues)
{
EditorGUI.showMixedValue = true;
}
Vector4 result = EditorGUILayout.ColorField(label, property.vector4Value.ToColor(), options).ToVector();
Vector4 result = EditorGUILayout.ColorField(label, property.vector4Value.ToColor(), showEyedropper, showAlpha, hdr, options).ToVector();
if (result != property.vector4Value)
{
property.vector4Value = result;
Expand Down Expand Up @@ -339,6 +399,26 @@ public static void TextField(GUIContent label, SerializedProperty property, para
EditorGUI.showMixedValue = showMixedValue;
}

/// <summary>
/// <see cref="EditorGUILayout.TextArea"/>を表示
/// </summary>
/// <param name="property">プロパティ</param>
/// <param name="options">レイアウト設定</param>
public static void TextArea(SerializedProperty property, params GUILayoutOption[] options)
{
bool showMixedValue = EditorGUI.showMixedValue;
if (property.hasMultipleDifferentValues)
{
EditorGUI.showMixedValue = true;
}
var result = EditorGUILayout.TextArea(property.stringValue, options);
if (result != property.stringValue)
{
property.stringValue = result;
}
EditorGUI.showMixedValue = showMixedValue;
}

/// <summary>
/// <see cref="EditorGUILayout.TextField"/>をChar用モードで表示
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions Packages/uGUI-Skinner/Runtime/UserLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Runtime.CompilerServices;
using UnityEngine;
using Type = System.Type;
using Attribute = System.Attribute;

namespace Pspkurara.UI.Skinner
{
Expand Down Expand Up @@ -110,6 +111,11 @@ public sealed class UserLogicVariable
/// </summary>
public string FieldDisplayName;

/// <summary>
/// カスタムプロパティ
/// </summary>
public PropertyAttribute[] PropertyAttributes;

}

}

0 comments on commit a26aeff

Please sign in to comment.