Beispiel #1
0
        void DrawAttributes()
        {
            try
            {
                GUILayout.BeginVertical("box");
                GUILayout.Box("Attributes", GUILayout.ExpandWidth(true));
                EditorGUILayout.Space();
                if (!inAddAttribute && GUILayout.Button("Add Attribute", EditorStyles.miniButton))
                {
                    inAddAttribute = true;
                }
                if (inAddAttribute)
                {
                    GUILayout.BeginHorizontal("box");
                    attribute = (vItemAttributes)EditorGUILayout.EnumPopup(attribute);
                    EditorGUILayout.LabelField("Value", GUILayout.MinWidth(60));
                    attributeValue = EditorGUILayout.IntField(attributeValue);
                    GUILayout.EndHorizontal();
                    if (item.attributes != null && item.attributes.Contains(attribute))
                    {
                        EditorGUILayout.HelpBox("This attribute already exist ", MessageType.Error);
                        if (GUILayout.Button("Cancel", EditorStyles.miniButton, GUILayout.MinWidth(60)))
                        {
                            inAddAttribute = false;
                        }
                    }
                    else
                    {
                        GUILayout.BeginHorizontal("box");
                        if (GUILayout.Button("Add", EditorStyles.miniButton, GUILayout.MinWidth(60)))
                        {
                            item.attributes.Add(new vItemAttribute(attribute, attributeValue));

                            attributeValue = 0;
                            inAddAttribute = false;
                        }
                        if (GUILayout.Button("Cancel", EditorStyles.miniButton, GUILayout.MinWidth(60)))
                        {
                            attributeValue = 0;
                            inAddAttribute = false;
                        }
                        GUILayout.EndHorizontal();
                    }
                }
                EditorGUILayout.Space();
                for (int i = 0; i < item.attributes.Count; i++)
                {
                    GUILayout.BeginHorizontal("box");
                    EditorGUILayout.LabelField(item.attributes[i].name.ToString(), GUILayout.MinWidth(60));
                    item.attributes[i].value = EditorGUILayout.IntField(item.attributes[i].value);

                    EditorGUILayout.Space();
                    if (GUILayout.Button("x", GUILayout.MaxWidth(30)))
                    {
                        item.attributes.RemoveAt(i);
                        GUILayout.EndHorizontal();
                        break;
                    }
                    GUILayout.EndHorizontal();
                }

                GUILayout.EndVertical();
            }
            catch { }
        }
Beispiel #2
0
        void DrawAttributes()
        {
            try
            {
                GUILayout.BeginVertical("box");
                GUILayout.Box("Attributes", GUILayout.ExpandWidth(true));
                EditorGUILayout.Space();
                if (!inAddAttribute && GUILayout.Button("Add Attribute", EditorStyles.miniButton))
                {
                    inAddAttribute = true;
                }
                if (inAddAttribute)
                {
                    GUILayout.BeginHorizontal("box");
                    attribute = (vItemAttributes)EditorGUILayout.EnumPopup(attribute);
                    EditorGUILayout.LabelField("Value", GUILayout.MinWidth(60));
                    attributeValue = EditorGUILayout.IntField(attributeValue);
                    GUILayout.EndHorizontal();
                    if (item.attributes != null && item.attributes.Contains(attribute))
                    {
                        EditorGUILayout.HelpBox("This attribute already exist ", MessageType.Error);
                        if (GUILayout.Button("Cancel", EditorStyles.miniButton, GUILayout.MinWidth(60)))
                        {
                            inAddAttribute = false;
                        }
                    }
                    else
                    {
                        GUILayout.BeginHorizontal("box");
                        if (GUILayout.Button("Add", EditorStyles.miniButton, GUILayout.MinWidth(60)))
                        {
                            item.attributes.Add(new vItemAttribute(attribute, attributeValue));

                            attributeValue = 0;
                            inAddAttribute = false;
                        }
                        if (GUILayout.Button("Cancel", EditorStyles.miniButton, GUILayout.MinWidth(60)))
                        {
                            attributeValue = 0;
                            inAddAttribute = false;
                        }
                        GUILayout.EndHorizontal();
                    }
                }
                EditorGUILayout.Space();
                var attributesProp = serializedObject.FindProperty("attributes");
                for (int i = 0; i < item.attributes.Count; i++)
                {
                    GUILayout.BeginHorizontal("box");
                    var attributeValue = attributesProp.GetArrayElementAtIndex(i).FindPropertyRelative("value");
                    attributeValue.serializedObject.Update();
                    EditorGUILayout.LabelField(item.attributes[i].name.ToString(), GUILayout.MinWidth(60));
                    EditorGUILayout.PropertyField(attributeValue, new GUIContent(""));
                    //item.attributes[i].value = EditorGUILayout.IntField(item.attributes[i].value);

                    EditorGUILayout.Space();
                    if (GUILayout.Button("x", GUILayout.MaxWidth(30)))
                    {
                        item.attributes.RemoveAt(i);
                        GUILayout.EndHorizontal();

                        break;
                    }
                    attributeValue.serializedObject.ApplyModifiedProperties();
                    GUILayout.EndHorizontal();
                }

                GUILayout.EndVertical();
            }
            catch { }
        }