Exemplo n.º 1
0
        public override void OnGUI
            (Rect rect, SerializedProperty prop, GUIContent label)
        {
            rect.height = EditorGUIUtility.singleLineHeight;
            var typeLabel  = new GUIContent(label.text + " Type");
            var valueLabel = new GUIContent(label.text + " Value");

            var typeStr = prop.FindPropertyRelative("typeStr");
            var type    = Type.GetType(typeStr.stringValue);

            EditorGUI.PropertyField(rect, typeStr, typeLabel);

            rect.y += EditorGUIUtility.singleLineHeight
                      + EditorGUIUtility.standardVerticalSpacing;

            if (type != null)
            {
                if (typeof(UnityEngine.Object).IsAssignableFrom(type))
                {
                    var obj = prop.FindPropertyRelative("obj");
                    EditorGUI.ObjectField(rect, obj, type);
                }
                else
                {
                    var strProp  = prop.FindPropertyRelative("str");
                    var str      = strProp.stringValue;
                    var oldValue = DynamicValue.DeserializeValue(str, type);
                    var newValue = GUIExtension.DrawField(rect, oldValue, type, valueLabel, true);

                    if (newValue != oldValue)
                    {
                        strProp.stringValue = DynamicValue.SerializeValue(newValue);
                    }
                }
            }
            else
            {
                GUI.enabled = false;
                EditorGUI.TextField(rect, valueLabel, "Unknown Type");
                GUI.enabled = true;
            }

            prop.serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 2
0
        public bool Add(string name, DynamicValue value)
        {
            InitCache();

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if (cache.ContainsKey(name))
            {
                return(false);
            }

            variables.Add(new Variable(name, value));
            cache.Add(name, value);
            return(true);
        }
Exemplo n.º 3
0
        void OnGUI()
        {
            if (list == null || list.Equals(null))
            {
                Close();
                return;
            }

            XGUI.ResetToStyle(null);
            XGUI.BeginVertical();

            XGUI.ResetToStyle(GUI.skin.textField);

            XGUI.LabelWidth = 40;
            varName         = XGUI.TextField("Name", varName);
            typeStr         = XGUI.TextField("Type", typeStr);

            XGUI.ResetToStyle(null);
            XGUI.BeginHorizontal();

            XGUI.ResetToStyle(GUI.skin.button);
            if (XGUI.Button("Cancel"))
            {
                Close();
                return;
            }

            XGUI.Enabled = IsValid();
            if (XGUI.Button("Create"))
            {
                var value = new DynamicValue();
                value.TypeString = typeStr;
                list.list.Add(new Variable(varName, value));
                editor.SaveList();
                Close();
                return;
            }

            XGUI.EndHorizontal();

            if (!IsNameValid())
            {
                EditorGUILayout.HelpBox(
                    "Variable name is empty!",
                    MessageType.Warning);
            }
            else if (!IsNameUnique())
            {
                EditorGUILayout.HelpBox(
                    "Variable name is the same as an existing variable!",
                    MessageType.Warning);
            }
            else if (!IsTypeValid())
            {
                EditorGUILayout.HelpBox(
                    "Variable type does not exist!",
                    MessageType.Warning);
            }

            XGUI.EndVertical();
        }
Exemplo n.º 4
0
 public Variable(string name, DynamicValue value)
 {
     this.name  = name;
     this.value = value;
 }