Beispiel #1
0
        public override void OnGUI(SerializedProperty property, GUIContent label)
        {
            if (property.objectReferenceValue == null)
            {
                CreateVariable(property);
            }
            if (property.objectReferenceValue == null)
            {
                return;
            }
            SerializedObject serializedObject = new SerializedObject(property.objectReferenceValue);

            serializedObject.Update();
            GUILayout.BeginHorizontal();

            SerializedProperty nameProperty   = serializedObject.FindProperty("name");
            SerializedProperty valueProperty  = serializedObject.FindProperty("value");
            SerializedProperty sharedProperty = serializedObject.FindProperty("isShared");

            if (EditorUtility.IsPersistent(property.objectReferenceValue) && fieldInfo.HasAttribute(typeof(SharedPersistentAttribute)) || fieldInfo.FieldType == typeof(FsmArray))
            {
                sharedProperty.boolValue = true;
            }

            Color    color = GUI.backgroundColor;
            FsmError error = ErrorChecker.GetError(property.objectReferenceValue);

            if (error != null)
            {
                GUI.backgroundColor = Color.red;
            }

            int variableIndex = -1;

            if (sharedProperty.boolValue)
            {
                variableIndex = DrawSharedVariable(label, nameProperty);
            }
            else
            {
                OnPropertyField(valueProperty, label);
            }
            GUI.backgroundColor = color;

            if (DoSharedToggle(property))
            {
                DrawSharedToggle(sharedProperty);
            }
            GUILayout.EndHorizontal();
            if (variableIndex == 0)
            {
                nameProperty.stringValue = "None";
                Color color1 = GUI.backgroundColor;
                GUI.backgroundColor = (EditorGUIUtility.isProSkin?new Color(0f, 0f, 0f, 0.6f):new Color(0f, 0f, 0f, 0.2f));
                GUIStyle style = new GUIStyle("box");
                style.normal.textColor = new Color(0f, 0f, 0f, 0.7f);
                if (GUILayout.Button("Click to create a new variable [" + fieldInfo.FieldType.Name + "]", style, GUILayout.ExpandWidth(true)))
                {
                    CreateVariable(property.objectReferenceValue.GetType(), fieldInfo.Name);
                    nameProperty.stringValue = fieldInfo.Name;
                }
                GUI.backgroundColor = color1;
            }
            serializedObject.ApplyModifiedProperties();
        }