コード例 #1
0
        public StratusOdinSerializedProperty(FieldInfo field, object target)
        {
            this.field        = field;
            this.type         = this.field.FieldType;
            this.propertyType = SerializedSystemObject.DeducePropertyType(this.field);
            this.displayName  = ObjectNames.NicifyVariableName(this.field.Name);
            this.target       = target;

            // Enum
            if (this.propertyType == SerializedPropertyType.Enum)
            {
                this.enumDisplayNames = StratusSearchableEnum.GetEnumDisplayNames(this.type);
            }

            // Array
            this.isArray = typeof(IList).IsAssignableFrom(this.type);
            if (this.isArray)
            {
                this.list            = this.field.GetValue(target) as IList;
                this.listElementType = Utilities.Reflection.GetIndexedType(list);
            }

            // Set the drawer
            this.drawer = SerializedSystemObject.GetObjectDrawer(this.isArray ? this.listElementType : this.type);
        }
コード例 #2
0
 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
 {
     label = EditorGUI.BeginProperty(position, label, property);
     {
         StratusSearchableEnum.EnumPopup(position, label, property);
     }
     EditorGUI.EndProperty();
 }
コード例 #3
0
        public static void Field(Rect position, FieldInfo field, object target)
        {
            StratusSerializedFieldType propertyType = SerializedFieldTypeExtensions.Deduce(field);
            string name  = ObjectNames.NicifyVariableName(field.Name);
            object value = null;

            switch (propertyType)
            {
            case StratusSerializedFieldType.ObjectReference:
                value = EditorGUI.ObjectField(position, name, (UnityEngine.Object)field.GetValue(target), field.FieldType, true);
                break;

            case StratusSerializedFieldType.Integer:
                value = EditorGUI.IntField(position, field.GetValue <int>(target));
                break;

            case StratusSerializedFieldType.Boolean:
                value = EditorGUI.Toggle(position, name, field.GetValue <bool>(target));
                break;

            case StratusSerializedFieldType.Float:
                value = EditorGUI.FloatField(position, field.GetValue <float>(target));
                break;

            case StratusSerializedFieldType.String:
                value = EditorGUI.TextField(position, name, field.GetValue <string>(target));
                break;

            case StratusSerializedFieldType.Color:
                value = EditorGUI.ColorField(position, name, field.GetValue <Color>(target));
                break;

            case StratusSerializedFieldType.Enum:
                StratusSearchableEnum.EnumPopup(position, name, field.GetValue <Enum>(target), (Enum selected) => field.SetValue(target, selected));
                break;

            case StratusSerializedFieldType.Vector2:
                value = EditorGUI.Vector2Field(position, name, field.GetValue <Vector2>(target));
                break;

            case StratusSerializedFieldType.Vector3:
                value = EditorGUI.Vector3Field(position, name, field.GetValue <Vector3>(target));
                break;

            case StratusSerializedFieldType.Vector4:
                value = EditorGUI.Vector4Field(position, name, field.GetValue <Vector4>(target));
                break;

            case StratusSerializedFieldType.Rect:
                value = EditorGUI.RectField(position, name, field.GetValue <Rect>(target));
                break;

            default:
                EditorGUI.LabelField(position, $"No supported drawer for type {field.FieldType.Name}!");
                break;
            }
        }
コード例 #4
0
        /// <summary>
        /// Draws a serialized property, saving any recorded changes
        /// </summary>
        /// <param name="property"></param>
        /// <returns>True if the property changed, false otherwise.</returns>

        public bool DrawSerializedProperty(SerializedProperty property, SerializedObject serializedObject)
        {
            EditorGUI.BeginChangeCheck();

            // If this property has been requested to be drawn in a custom manner
            if (propertyDrawOverrides.ContainsKey(property))
            {
                propertyDrawOverrides[property].Invoke(property);
            }
            else
            {
                // Arrays
                if (property.isArray && property.propertyType != SerializedPropertyType.String && drawReorderableLists)
                {
                    DrawReorderableList(property, property.displayName);
                }
                // Use normal drawers
                else
                {
                    bool overridden = false;
                    if (!overridden)
                    {
                        // Custom enum drawer, ho!
                        if (property.propertyType == SerializedPropertyType.Enum)
                        {
                            StratusSearchableEnum.EnumPopup(property);
                        }
                        else
                        {
                            EditorGUILayout.PropertyField(property, true);
                        }
                    }
                }
            }

            // If property was changed, save
            if (EditorGUI.EndChangeCheck())
            {
                // Record change
                Undo.RecordObject(target, property.name);

                // Apply the modified property
                serializedObject.ApplyModifiedProperties();

                // Inform that this property has been changed
                if (propertyChangeCallbacks.ContainsKey(property))
                {
                    propertyChangeCallbacks[property].Invoke();
                }
                return(true);
            }

            return(false);
        }
コード例 #5
0
        //------------------------------------------------------------------------/
        // Draw
        //------------------------------------------------------------------------/
        /// <summary>
        /// Draws a serialized property, saving any recorded changes
        /// </summary>
        /// <param name="property"></param>
        /// <returns>True if the property changed, false otherwise.</returns>

        public bool DrawSerializedProperty(SerializedProperty property, SerializedObject serializedObject)
        {
            EditorGUI.BeginChangeCheck();

            // If this property has been requested to be drawn in a custom manner
            if (this.propertyDrawOverrides.ContainsKey(property))
            {
                this.propertyDrawOverrides[property].Invoke(property);
            }
            else
            {
                // Arrays
                if (property.isArray && property.propertyType != SerializedPropertyType.String && this.drawReorderableLists)
                {
                    this.reorderableLists[this.unitySerializedPropertyModels[property]].DoLayoutList();
                    //this.DrawReorderableList(property, property.displayName);
                }
                else
                {
                    // Enums
                    if (property.propertyType == SerializedPropertyType.Enum && drawEnumPopup)
                    {
                        StratusSearchableEnum.EnumPopup(property);
                    }
                    else
                    {
                        EditorGUILayout.PropertyField(property, true);
                    }
                }
            }

            // If property was changed, save
            if (EditorGUI.EndChangeCheck())
            {
                //StratusDebug.Log($"Detected change on {property.displayName}");

                // Record change
                Undo.RecordObject(this.target, property.name);

                // Apply the modified property
                serializedObject.ApplyModifiedProperties();

                // Inform that this property has been changed
                if (this.propertyChangeCallbacks.ContainsKey(property))
                {
                    this.propertyChangeCallbacks[property].Invoke();
                }

                return(true);
            }

            return(false);
        }
コード例 #6
0
            //public static void FieldEditorGUILayout(FieldInfo field, SerializedPropertyType propertyType, string name, object target)
            //{
            //  switch (propertyType)
            //  {
            //    case SerializedPropertyType.ObjectReference:
            //      this.field.SetValue(target, UnityEditor.EditorGUILayout.ObjectField(name, this.GetValue<UnityEngine.Object>(target), type, true));
            //      break;
            //    case SerializedPropertyType.Integer:
            //      this.field.SetValue(target, UnityEditor.EditorGUILayout.IntField(name, this.GetValue<int>(target)));
            //      break;
            //    case SerializedPropertyType.Boolean:
            //      this.field.SetValue(target, UnityEditor.EditorGUILayout.Toggle(name, this.GetValue<bool>(target)));
            //      break;
            //    case SerializedPropertyType.Float:
            //      OnFloatEditorGUILayout(target);
            //      break;
            //    case SerializedPropertyType.String:
            //      this.field.SetValue(target, UnityEditor.EditorGUILayout.TextField(name, this.GetValue<string>(target)));
            //      break;
            //    case SerializedPropertyType.Color:
            //      this.field.SetValue(target, UnityEditor.EditorGUILayout.ColorField(name, this.GetValue<Color>(target)));
            //      break;
            //    case SerializedPropertyType.LayerMask:
            //      this.field.SetValue(target, UnityEditor.EditorGUILayout.LayerField(name, this.GetValue<LayerMask>(target)));
            //      break;
            //    case SerializedPropertyType.Enum:
            //      this.field.SetValue(target, UnityEditor.EditorGUILayout.EnumPopup(name, this.GetValue<Enum>(target)));
            //      break;
            //    case SerializedPropertyType.Vector2:
            //      this.field.SetValue(target, UnityEditor.EditorGUILayout.Vector2Field(name, this.GetValue<Vector2>(target)));
            //      break;
            //    case SerializedPropertyType.Vector3:
            //      this.field.SetValue(target, UnityEditor.EditorGUILayout.Vector3Field(name, this.GetValue<Vector3>(target)));
            //      break;
            //    case SerializedPropertyType.Vector4:
            //      this.field.SetValue(target, UnityEditor.EditorGUILayout.Vector4Field(name, this.GetValue<Vector4>(target)));
            //      break;
            //    case SerializedPropertyType.Rect:
            //      this.field.SetValue(target, UnityEditor.EditorGUILayout.RectField(name, this.GetValue<Rect>(target)));
            //      break;
            //    default:
            //      if (isArray)
            //      {
            //        EditorGUILayout.Space();
            //        StratusReorderableList.DrawCachedPolymorphicList(this.field, target);
            //      }
            //      else
            //      {
            //        UnityEditor.EditorGUILayout.LabelField($"No drawer implementation for {name} of type {type.Name}");
            //      }
            //      break;
            //  }
            //}

            public override bool DrawEditorGUI(Rect position, object target)
            {
                EditorGUI.BeginChangeCheck();
                object value = null;

                switch (propertyType)
                {
                case SerializedPropertyType.ObjectReference:
                    value = EditorGUI.ObjectField(position, name, GetValue <UnityEngine.Object>(target), type, true);
                    break;

                case SerializedPropertyType.Integer:
                    value = OnIntEditorGUI(position, target);
                    break;

                case SerializedPropertyType.Boolean:
                    value = EditorGUI.Toggle(position, name, GetValue <bool>(target));
                    break;

                case SerializedPropertyType.Float:
                    value = OnFloatEditorGUI(position, target);
                    break;

                case SerializedPropertyType.String:
                    value = EditorGUI.TextField(position, name, GetValue <string>(target));
                    break;

                case SerializedPropertyType.Color:
                    value = EditorGUI.ColorField(position, name, GetValue <Color>(target));
                    break;

                case SerializedPropertyType.LayerMask:
                    value = EditorGUI.LayerField(position, name, GetValue <LayerMask>(target));
                    break;

                case SerializedPropertyType.Enum:
                    StratusSearchableEnum.EnumPopup(position, name, GetValue <Enum>(target), (Enum selected) => SetValue(target, selected));
                    break;

                case SerializedPropertyType.Vector2:
                    value = EditorGUI.Vector2Field(position, name, GetValue <Vector2>(target));
                    break;

                case SerializedPropertyType.Vector3:
                    value = EditorGUI.Vector3Field(position, name, GetValue <Vector3>(target));
                    break;

                case SerializedPropertyType.Vector4:
                    value = EditorGUI.Vector4Field(position, name, GetValue <Vector4>(target));
                    break;

                case SerializedPropertyType.Rect:
                    value = EditorGUI.RectField(position, name, GetValue <Rect>(target));
                    break;

                default:
                    EditorGUI.LabelField(position, $"No supported drawer for type {type.Name}!");
                    break;
                }

                if (EditorGUI.EndChangeCheck())
                {
                    SetValue(target, value);
                    return(true);
                }

                return(false);
            }
コード例 #7
0
 public static void EnumToolbar <T>(ref T enumValue)
 {
     string[] options = StratusSearchableEnum.GetEnumDisplayNames((Enum)(object)enumValue);
     enumValue = (T)(object)GUILayout.Toolbar(Convert.ToInt32(enumValue), options, GUILayout.ExpandWidth(false));
 }