Exemplo n.º 1
0
        public void Serialize(object value, Type type)
        {
            var wrapper = EditorSerializedFieldUtilities.GetWrapperForType(type);

            if (wrapper != null)
            {
//                if (type.IsEnum)
//                    value = Enum.ToObject(type, value);
                Serialize(wrapper, value);
                return;
            }

            if (type.GetCustomAttribute(typeof(SerializableAttribute), true) == null)
            {
                return;
            }

            wrapper = EditorSerializedFieldUtilities.GetWrapperForType(typeof(bool));
            wrapper.SetValue(MightyGUIUtilities.GetFoldout(m_fileName));

            WriteFile(m_path, wrapper);

            foreach (var field in type.GetSerializableFields())
            {
                EditorFieldsDatabase.GetEditorField(m_fileName).Serialize(field.GetValue(value), field.FieldType);
            }
        }
Exemplo n.º 2
0
        public void DrawLayerField(Rect position, SerializedProperty property, LayerFieldAttribute attribute, GUIContent label = null)
        {
            if (property.propertyType != SerializedPropertyType.Integer)
            {
                position = MightyGUIUtilities.DrawPropertyField(position, property);
                MightyGUIUtilities.DrawHelpBox(position, $"\"{property.displayName}\" should be of type int");
                return;
            }

            int layer;

            if (attribute.Options.Contains(FieldOption.HideLabel))
            {
                layer = EditorGUI.LayerField(position, property.intValue);
            }
            else if (attribute.Options.Contains(FieldOption.BoldLabel))
            {
                layer = EditorGUI.LayerField(position, label ?? EditorGUIUtility.TrTextContent(property.displayName), property.intValue,
                                             EditorStyles.boldLabel);
            }
            else
            {
                layer = EditorGUI.LayerField(position, label ?? EditorGUIUtility.TrTextContent(property.displayName), property.intValue);
            }

            property.intValue = layer;
        }
Exemplo n.º 3
0
        public static void DrawTagField(SerializedProperty property, FieldOption options, GUIContent label = null)
        {
            if (property.propertyType != SerializedPropertyType.String)
            {
                MightyGUIUtilities.DrawPropertyField(property, label);
                MightyGUIUtilities.DrawHelpBox($"\"{property.displayName}\" should be of type string");
                return;
            }

            string tag;

            if (options.Contains(FieldOption.HideLabel))
            {
                tag = EditorGUILayout.TagField(property.stringValue);
            }
            else if (options.Contains(FieldOption.BoldLabel))
            {
                tag = EditorGUILayout.TagField(label ?? EditorGUIUtility.TrTextContent(property.displayName), property.stringValue,
                                               EditorStyles.boldLabel);
            }
            else
            {
                tag = EditorGUILayout.TagField(label ?? EditorGUIUtility.TrTextContent(property.displayName), property.stringValue);
            }

            property.stringValue = tag;
        }
Exemplo n.º 4
0
        public static void DrawTagField(Rect position, SerializedProperty property, FieldOption options)
        {
            if (property.propertyType != SerializedPropertyType.String)
            {
                position = MightyGUIUtilities.DrawPropertyField(position, property);
                MightyGUIUtilities.DrawHelpBox(position, $"\"{property.displayName}\" should be of type string");
                return;
            }

            string tag;

            if (options.Contains(FieldOption.HideLabel))
            {
                tag = EditorGUI.TagField(position, property.stringValue);
            }
            else if (options.Contains(FieldOption.BoldLabel))
            {
                tag = EditorGUI.TagField(position, property.displayName, property.stringValue, EditorStyles.boldLabel);
            }
            else
            {
                tag = EditorGUI.TagField(position, property.displayName, property.stringValue);
            }

            property.stringValue = tag;
        }
Exemplo n.º 5
0
        public virtual void EndDrawMember(MightySerializedField serializedField, T attribute,
                                          MightyDrawer.PropertyDrawCallback propertyDrawCallback, BasePropertyDrawerAttribute drawerAttribute = null)
        {
            var property = serializedField.Property;

            if (!property.IsCollection())
            {
                EndDraw(serializedField, attribute);
                return;
            }

            if (!property.isExpanded)
            {
                return;
            }

            MightyGUIUtilities.DrawArrayBody(property, index =>
            {
                BeginDrawElement(serializedField, index, attribute);
                propertyDrawCallback?.Invoke(serializedField, property.GetArrayElementAtIndex(index), drawerAttribute);
                EndDrawElement(serializedField, index, attribute);
            });

            EditorGUI.indentLevel--;

            EndDrawArray(serializedField, attribute);
        }
Exemplo n.º 6
0
        protected override void InvokeMethod(MightyMethod mightyMethod, T attribute)
        {
            var methodInfo = mightyMethod.MemberInfo;

            if (!m_methodCache.Contains(mightyMethod))
            {
                EnableDrawer(mightyMethod, attribute);
            }

            if (m_methodCache[mightyMethod])
            {
                var label      = attribute.Label;
                var buttonText = string.IsNullOrEmpty(label) ? methodInfo.Name.GetPrettyName() : label;

                var enabled = GUI.enabled;

                GUI.enabled = enabled && (attribute.ExecuteInPlayMode || !EditorApplication.isPlaying);

                if (DrawButton(attribute, buttonText, methodInfo.Name))
                {
                    methodInfo.Invoke(mightyMethod.Context.Target, null);
                    OnFunctionHasBeenCalled();
                }

                GUI.enabled = enabled;
            }
            else
            {
                MightyGUIUtilities.DrawHelpBox($"{attribute.GetType().Name} works only on methods with no parameters");
            }
        }
Exemplo n.º 7
0
        protected virtual void BeginDrawMember(MightySerializedField serializedField, T attribute,
                                               MightyDrawer.PropertyDrawCallback propertyDrawCallback = null, BasePropertyDrawerAttribute drawerAttribute = null)
        {
            var property = serializedField.Property;

            if (!property.IsCollection())
            {
                BeginDraw(serializedField, attribute);

                propertyDrawCallback?.Invoke(serializedField, property, drawerAttribute);
                return;
            }

            BeginDrawArray(serializedField, attribute);
            BeginDrawHeader(serializedField, attribute);

            if (!MightyGUIUtilities.DrawFoldout(property))
            {
                EndDrawHeader(serializedField, attribute);
                EndDrawArray(serializedField, attribute);
                return;
            }

            EditorGUI.indentLevel++;
            MightyGUIUtilities.DrawArraySizeField(property);

            EndDrawHeader(serializedField, attribute);
        }
Exemplo n.º 8
0
        protected override void ValidateProperty(MightySerializedField serializedField, MaxValueAttribute attribute)
        {
            var property = serializedField.Property;

            switch (property.propertyType)
            {
            case SerializedPropertyType.Integer:
                if (property.intValue > attribute.MaxValue)
                {
                    property.intValue = (int)attribute.MaxValue;
                }
                break;

            case SerializedPropertyType.Float:
                if (property.floatValue > attribute.MaxValue)
                {
                    property.floatValue = attribute.MaxValue;
                }
                break;

            default:
                MightyGUIUtilities.DrawHelpBox($"{nameof(MaxValueAttribute)} can be used only on int or float fields");
                break;
            }
        }
Exemplo n.º 9
0
        protected override void DrawProperty(MightySerializedField mightyMember, SerializedProperty property, T attribute)
        {
            if (property.propertyType != SerializedPropertyType.String)
            {
                MightyGUIUtilities.DrawPropertyField(property);
                MightyGUIUtilities.DrawHelpBox($"{attribute.GetType()} can be used only on string fields");
                return;
            }

            if (!m_pathCache.Contains(mightyMember))
            {
                EnableDrawer(mightyMember, attribute);
            }
            var defaultPath = m_pathCache[mightyMember].Value;

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.PropertyField(property);
            if (MightyGUIUtilities.DrawButton("...", GUILayout.Width(35)))
            {
                var value = property.stringValue;

                value = DisplayPanel(property.displayName, !string.IsNullOrWhiteSpace(value)
                    ? FileUtilities.GetDirectoryPath(value) ?? value
                    : defaultPath, mightyMember, attribute);

                if (!string.IsNullOrWhiteSpace(value))
                {
                    property.stringValue = value;
                }
            }

            EditorGUILayout.EndHorizontal();
        }
Exemplo n.º 10
0
        public void DrawField(string fieldName, Object context, object target)
        {
            var field     = target.GetField(fieldName);
            var attribute = field.GetCustomAttribute <EditorSerializeAttribute>();

            if (attribute.PreviousName != null)
            {
                EditorFieldsDatabase.RenameField(context, attribute.PreviousName, field.Name);
            }

            var editorField = EditorFieldsDatabase.GetEditorField(context, field.Name);

            if (editorField == null)
            {
                return;
            }

            var value = field.GetValue(target);

            Deserialize(editorField, target, field, ref value);

            EditorGUI.BeginChangeCheck();

            value = MightyGUIUtilities.DrawLayoutField(field, context, target, value,
                                                       !attribute.Options.Contains(EditorFieldOption.DontFold), attribute.Options.Contains(EditorFieldOption.Asset));

            if (EditorGUI.EndChangeCheck())
            {
                Serialize(attribute, editorField, value, field.FieldType);
            }
        }
Exemplo n.º 11
0
        private static bool DrawActivateButton()
        {
            Space();
            GUILayout.BeginHorizontal(GUILayout.Height(30));
            GUILayout.FlexibleSpace();

            var activated = MightySettingsServices.Activated;

            var color = GUI.color;

            GUI.enabled = !activated;

            GUI.color = new Color(1, 1, 1, 2);

            activated = MightyGUIUtilities.DrawToggleButton(activated, "ON",
                                                            new Color(0.27f, 0.89f, 0.09f), GUILayout.Width(100), GUILayout.Height(30));

            GUI.enabled = activated;

            activated = !MightyGUIUtilities.DrawToggleButton(!activated, "OFF",
                                                             new Color(0.84f, 0.15f, 0.13f), GUILayout.Width(100), GUILayout.Height(30));

            GUI.color = color;

            MightySettingsServices.Activated = activated;

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUI.enabled = true;

            return(activated);
        }
Exemplo n.º 12
0
        protected override void DrawProperty(MightySerializedField mightyMember, SerializedProperty property,
                                             GetComponentButtonAttribute attribute)
        {
            if (property.propertyType != SerializedPropertyType.ObjectReference ||
                !mightyMember.PropertyType.IsSubclassOf(typeof(Component)))
            {
                MightyGUIUtilities.DrawHelpBox($"{nameof(GetComponentButtonAttribute)} can be used only on Components fields");
                return;
            }

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.ObjectField(property, !attribute.Options.Contains(FieldOption.HideLabel)
                ? EditorGUIUtility.TrTextContent(property.displayName)
                : GUIContent.none);

            if (GUILayout.Button("Get Component", GUILayout.Width(100)))
            {
                var component = property.GetGameObject().GetComponent(mightyMember.PropertyType);
                if (component != null)
                {
                    property.objectReferenceValue = component;
                }
            }

            EditorGUILayout.EndHorizontal();
        }
Exemplo n.º 13
0
        public bool BeginFoldout(bool foldout, string label, int indentLevel, bool drawLine, ColorValue lineColor)
        {
            var backgroundColor = GUI.backgroundColor;
            var contentColor    = GUI.contentColor;

            GUI.backgroundColor = foldout ? backgroundColor : MightyColorUtilities.DarkenColor(backgroundColor, .3f);
            GUI.contentColor    = foldout ? contentColor : MightyColorUtilities.DarkenColor(contentColor, .25f);

            GUILayout.BeginVertical(MightyStyleUtilities.GetFoldAreaHeader(indentLevel));
            EditorGUI.indentLevel = 1;

            GUILayout.BeginVertical(MightyStyles.FoldBoxHeaderContent);
            foldout = MightyGUIUtilities.DrawFoldout(foldout, label, MightyStyles.FoldAreaLabel);
            GUILayout.EndVertical();

            if (!foldout)
            {
                EditorGUI.indentLevel = indentLevel;
                GUILayout.EndVertical();
            }
            else if (drawLine)
            {
                DrawLine(lineColor);
            }

            GUI.backgroundColor = backgroundColor;
            GUI.contentColor    = contentColor;

            return(foldout);
        }
Exemplo n.º 14
0
 private void OnEnable()
 {
     m_darkBox    = MightyDrawersDatabase.GetDrawer <DarkBoxGrouper>();
     titleContent = new GUIContent(MightyGUIUtilities.DrawIcon(IconName.HELP))
     {
         text = TITLE_TEXT,
     };
 }
Exemplo n.º 15
0
        public float GetElementHeight(MightySerializedField serializedField, int index, BasePropertyDrawerAttribute baseAttribute)
        {
            var element = serializedField.GetElement(index);

            return(element.propertyType != SerializedPropertyType.String
                ? MightyGUIUtilities.WARNING_HEIGHT
                : MightyGUIUtilities.TextHeight(element.stringValue, 3) + MightyGUIUtilities.FIELD_HEIGHT +
                   MightyGUIUtilities.FIELD_SPACING * 2);
        }
Exemplo n.º 16
0
 private object InvokeDrawer(Rect position, MightyMethod <object> drawerMethod, string signature, params object[] parameters)
 {
     if (drawerMethod != null)
     {
         return(drawerMethod.Invoke(parameters));
     }
     MightyGUIUtilities.DrawHelpBox(position, $"The drawer callback is invalid, it should be like this: \"{signature}\"");
     return(null);
 }
Exemplo n.º 17
0
        protected override void DrawDecorator(BaseMightyMember mightyMember, TitleAttribute attribute)
        {
            if (!m_headerCache.Contains(mightyMember))
            {
                EnableDrawer(mightyMember, attribute);
            }

            MightyGUIUtilities.DrawTitle(m_headerCache[mightyMember].Value);
        }
Exemplo n.º 18
0
        protected override void DrawProperty(MightySerializedField mightyMember, SerializedProperty property, Rotation2DAttribute attribute)
        {
            if (property.IsCollection())
            {
                MightyGUIUtilities.DrawArray(property, index => DrawElement(mightyMember, index, attribute));
                return;
            }

            DrawRotation2D(property, attribute);
        }
Exemplo n.º 19
0
        public void DrawSlider(SerializedProperty property, PercentSliderAttribute attribute, GUIContent label = null)
        {
            switch (property.propertyType)
            {
            case SerializedPropertyType.Integer:
                GUILayout.BeginHorizontal();

                if (attribute.Options.Contains(FieldOption.HideLabel))
                {
                    property.intValue = EditorGUILayout.IntSlider(property.intValue, 0, 100);
                }
                else if (label != null)
                {
                    property.intValue = EditorGUILayout.IntSlider(label, property.intValue, 0, 100);
                }
                else
                {
                    property.intValue = EditorGUILayout.IntSlider(property.displayName, property.intValue, 0, 100);
                }

                GUILayout.Label("%", GUILayout.Width(15));
                GUILayout.EndHorizontal();
                break;

            case SerializedPropertyType.Float:
                GUILayout.BeginHorizontal();

                var value = attribute.Between01 ? property.floatValue * 100 : property.floatValue;

                if (attribute.Options.Contains(FieldOption.HideLabel))
                {
                    value = EditorGUILayout.Slider(value, 0, 100);
                }
                else if (label != null)
                {
                    value = EditorGUILayout.Slider(label, value, 0, 100);
                }
                else
                {
                    value = EditorGUILayout.Slider(property.displayName, value, 0, 100);
                }

                property.floatValue = attribute.Between01 ? value / 100 : value;

                GUILayout.Label("%", GUILayout.Width(15));
                GUILayout.EndHorizontal();
                break;

            default:
                MightyGUIUtilities.DrawPropertyField(property, label);
                MightyGUIUtilities.DrawHelpBox($"{nameof(PercentSliderAttribute)} can be used only on int and float fields");
                break;
            }
        }
Exemplo n.º 20
0
        private static Texture2D GetTexture(BaseMightyMember mightyMember, object target, ScriptIconAttribute attribute)
        {
            var path = attribute.IconPath;

            if (attribute.PathAsCallback && mightyMember.GetValueFromMember(target, attribute.IconPath, out string pathValue))
            {
                path = pathValue;
            }

            return(MightyGUIUtilities.GetTexture(path));
        }
Exemplo n.º 21
0
        protected override void DrawProperty(MightySerializedField serializedField, SerializedProperty property,
                                             AssetOnlyAttribute attribute)
        {
            if (property.IsCollection())
            {
                MightyGUIUtilities.DrawArray(property, index => DrawElement(serializedField, index, attribute));
                return;
            }

            DrawAssetField(property, attribute);
        }
Exemplo n.º 22
0
        private void OnGUI()
        {
            minSize  = maxSize = new Vector2(400, 90);
            position = new Rect(new Vector2((float)Screen.currentResolution.width / 2 - minSize.x / 2,
                                            (float)Screen.currentResolution.height / 2 - minSize.y / 2), minSize);

            GUI.color = MightyColorUtilities.Brighter;

            GUILayout.BeginVertical(MightyStyles.White);
            GUILayout.BeginVertical(MightyStyles.SimpleDarkBox);
            GUILayout.FlexibleSpace();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            GUILayout.BeginVertical();
            GUILayout.FlexibleSpace();
            GUI.color = Color.white;
            GUILayout.Box(MightyGUIUtilities.DrawIcon(IconName.Loading(m_iconIndex)));
            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();

            GUILayout.Space(10);

            GUILayout.BeginVertical();
            GUILayout.FlexibleSpace();

            GUI.color = MightyColorUtilities.Yellow;
            GUILayout.Label(APPLYING_VALUES, MightyStyles.BigBoldLabelStyle);
            GUI.color = Color.white;
            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUI.color = Color.white;
            GUILayout.Label(m_infoLabel, MightyStyles.InfoLabelStyle);
            GUILayout.Label(m_indexLabel, MightyStyles.InfoLabelStyle);
            if (m_displayProgression)
            {
                GUILayout.Label(SLASH, MightyStyles.InfoLabelStyle);
                GUILayout.Label(m_countLabel, MightyStyles.InfoLabelStyle);
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();
            GUILayout.EndVertical();
        }
Exemplo n.º 23
0
        private float[] DrawMultiField(Rect position, GUIContent label, float[] values, FieldOption options)
        {
            if (!DrawLabel(ref position, null, options, label))
            {
                position.width -= MightyGUIUtilities.FIELD_SPACING * (Columns - 1);
            }

            MightyGUIUtilities.MultiFloatField(position, GetLabelContents(), values, GetLabelWidths(), Orientation);

            return(values);
        }
Exemplo n.º 24
0
        protected override void DrawProperty(MightySerializedField mightyMember, SerializedProperty property,
                                             ResizableTextAreaAttribute attribute)
        {
            if (property.IsCollection())
            {
                MightyGUIUtilities.DrawArray(property, index => DrawElement(mightyMember, index, attribute));
                return;
            }

            DrawTextArea(property, attribute.Options);
        }
Exemplo n.º 25
0
        private static bool Button(string label)
        {
            var previousColor = GUI.backgroundColor;

            GUI.backgroundColor = Color.white;

            var pressed = MightyGUIUtilities.DrawButton(label, 25);

            GUI.backgroundColor = previousColor;

            return(pressed);
        }
Exemplo n.º 26
0
 protected override void DrawLabel(BaseMightyMember mightyMember, LargeLabelAttribute attribute, string prefix, string label)
 {
     if (string.IsNullOrEmpty(prefix))
     {
         EditorGUILayout.LabelField(label, EditorStyles.largeLabel, GUILayout.Height(20),
                                    GUILayout.Width(MightyGUIUtilities.TextWidth(label) + MightyGUIUtilities.TAB_SIZE));
     }
     else
     {
         EditorGUILayout.LabelField(prefix, label, EditorStyles.largeLabel, GUILayout.Height(20));
     }
 }
Exemplo n.º 27
0
        private void Serialize(BaseEditorFieldWrapper wrapper, object value)
        {
            wrapper.SetValue(value);
            if (!(wrapper is BaseArrayFieldWrapper arrayWrapper))
            {
                WriteFile(m_path, wrapper);
                return;
            }

            arrayWrapper.foldout = MightyGUIUtilities.GetFoldout(m_fileName);
            WriteFile(m_path, arrayWrapper);
        }
Exemplo n.º 28
0
        private void DrawAssetField(Rect position, SerializedProperty property, AssetOnlyAttribute attribute)
        {
            if (property.propertyType != SerializedPropertyType.ObjectReference)
            {
                position = MightyGUIUtilities.DrawPropertyField(position, property);
                MightyGUIUtilities.DrawHelpBox(position, $"{property.name} should be of type UnityEngine.Object");
                return;
            }

            property.objectReferenceValue = attribute.Options.Contains(FieldOption.HideLabel)
                ? EditorGUI.ObjectField(position, property.objectReferenceValue, property.GetSystemType(), false)
                : EditorGUI.ObjectField(position, property.displayName, property.objectReferenceValue, property.GetSystemType(), false);
        }
Exemplo n.º 29
0
        public void DrawTextArea(Rect position, SerializedProperty property, FieldOption options, GUIContent label = null)
        {
            if (property.propertyType != SerializedPropertyType.String)
            {
                position = MightyGUIUtilities.DrawPropertyField(position, property);
                MightyGUIUtilities.DrawHelpBox(position, $"{nameof(ResizableTextAreaAttribute)} can only be used on string fields");
                return;
            }

            DrawLabel(ref position, property, options, label);

            position.height      = MightyGUIUtilities.TextHeight(property.stringValue, 3);
            property.stringValue = EditorGUI.TextArea(position, property.stringValue);
        }
Exemplo n.º 30
0
        private void DrawAssetField(SerializedProperty property, AssetOnlyAttribute attribute, GUIContent label = null)
        {
            if (property.propertyType != SerializedPropertyType.ObjectReference)
            {
                MightyGUIUtilities.DrawPropertyField(property, label);
                MightyGUIUtilities.DrawHelpBox($"{property.name} should be of type UnityEngine.Object");
                return;
            }

            property.objectReferenceValue = attribute.Options.Contains(FieldOption.HideLabel)
                ? EditorGUILayout.ObjectField(property.objectReferenceValue, property.GetSystemType(), false)
                : EditorGUILayout.ObjectField(label ?? EditorGUIUtility.TrTextContent(property.displayName),
                                              property.objectReferenceValue, property.GetSystemType(), false);
        }