示例#1
0
        // private Color color = new Color(1,0.4f,0.4f,1);

        public override void OnGUI(Rect position, UnityEditor.SerializedProperty property, GUIContent label)
        {
            var element = property.objectReferenceValue;

            var attr = attribute as CreateScriptableAssetAttribute;

            if (element == null)
            {
                position.width -= 22;

                //var oldColor = GUI.color;
                //GUI.color = color;
                UnityEditor.EditorGUI.PropertyField(position, property);
                // GUI.color = oldColor;
                var AddButtonRect = new Rect(position)
                {
                    x = position.width + position.x + 2, width = 20
                };

                if (GUI.Button(AddButtonRect, "+"))
                {
                    if (attr.isAsset)
                    {
                        MTools.CreateScriptableAsset(property, MTools.Get_Type(property), MTools.GetSelectedPathOrFallback());
                    }
                    else
                    {
                        MTools.CreateScriptableAssetInternal(property, MTools.Get_Type(property));
                    }
                }
            }
            else
            {
                UnityEditor.EditorGUI.PropertyField(position, property);
            }

            if (property.isArray)
            {
            }
        }
示例#2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (popupStyle == null)
            {
                popupStyle = new GUIStyle(GUI.skin.GetStyle("PaneOptions"))
                {
                    imagePosition = ImagePosition.ImageOnly
                }
            }
            ;

            if (AddStyle == null)
            {
                AddStyle = new GUIStyle(GUI.skin.GetStyle("PaneOptions"))
                {
                    imagePosition = ImagePosition.ImageOnly
                }
            }
            ;

            position.y -= 0;

            label = EditorGUI.BeginProperty(position, label, property);
            Rect variableRect = new Rect(position);

            position = EditorGUI.PrefixLabel(position, label);
            EditorGUI.BeginChangeCheck();

            float height = EditorGUIUtility.singleLineHeight;

            // Get properties
            SerializedProperty useConstant   = property.FindPropertyRelative("UseConstant");
            SerializedProperty constantValue = property.FindPropertyRelative("ConstantValue");
            SerializedProperty variable      = property.FindPropertyRelative("Variable");

            Rect prop = new Rect(position)
            {
                height = height
            };
            // Calculate rect for configuration button
            Rect buttonRect = new Rect(position);

            buttonRect.yMin  += popupStyle.margin.top;
            buttonRect.width  = popupStyle.fixedWidth + popupStyle.margin.right;
            buttonRect.x     -= 20;
            buttonRect.height = height;

            position.xMin = buttonRect.xMax;


            var AddButtonRect = new Rect(prop)
            {
                x = prop.width + prop.x - 20, width = 22
            };


            // Store old indent level and set it to 0, the PrefixLabel takes care of it
            int indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            int result = EditorGUI.Popup(buttonRect, useConstant.boolValue ? 0 : 1, popupOptions, popupStyle);

            useConstant.boolValue = (result == 0);

            bool varIsEmpty = variable.objectReferenceValue == null;

            if (varIsEmpty && !useConstant.boolValue)
            {
                prop.width -= 22;
            }


            EditorGUI.PropertyField(prop, useConstant.boolValue ? constantValue : variable, GUIContent.none, false);

            if (varIsEmpty && !useConstant.boolValue)
            {
                if (GUI.Button(AddButtonRect, new GUIContent("+", "Create")))
                {
                    MTools.CreateScriptableAsset(variable, MTools.Get_Type(variable), MTools.GetSelectedPathOrFallback());
                }
            }

            //  ShowScriptVar(variableRect, height, useConstant, variable);

            if (EditorGUI.EndChangeCheck())
            {
                property.serializedObject.ApplyModifiedProperties();
            }

            EditorGUI.indentLevel = indent;
            EditorGUI.EndProperty();
        }