コード例 #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
        private void TransitionList()
        {
            Reo_List_Transitions = new ReorderableList(serializedObject, transitions, true, true, true, true)
            {
                drawElementCallback = (rect, index, isActive, isFocused) =>
                {
                    var r1 = new Rect(rect)
                    {
                        y = rect.y + 2, height = EditorGUIUtility.singleLineHeight
                    };
                    var r2 = new Rect(r1);
                    var r3 = new Rect(r2);

                    var element = transitions.GetArrayElementAtIndex(index);

                    var decision   = element.FindPropertyRelative("decision");
                    var TrueState  = element.FindPropertyRelative("trueState");
                    var FalseState = element.FindPropertyRelative("falseState");


                    var empty = decision.objectReferenceValue == null;
                    if (empty)
                    {
                        r1.width -= 30;
                    }

                    EditorGUI.PropertyField(r1, decision, new GUIContent("[" + index + "] Decision", "If the Decision is true it will go to the True State, else it will go to the False state"));

                    if (empty)
                    {
                        var AddButtonRect = new Rect(r1)
                        {
                            x = rect.width + 12, width = 25, height = EditorGUIUtility.singleLineHeight
                        };

                        if (GUI.Button(AddButtonRect, "+"))
                        {
                            // OnAddCallback_Decision(index);
                            MTools.AddScriptableAssetContextMenu(decision, typeof(MAIDecision), MTools.GetSelectedPathOrFallback());
                        }
                    }



                    empty = TrueState.objectReferenceValue == null;

                    if (empty)
                    {
                        r2.width -= 30;
                    }

                    r2.y += EditorGUIUtility.singleLineHeight + 3;
                    EditorGUI.PropertyField(r2, TrueState, new GUIContent("True" + (empty ? " (Do Nothing)" : ""), "If the Decision is TRUE, It will execute this state. if is Empty, it will do nothing"));


                    if (empty)
                    {
                        var AddButtonRect = new Rect(r2)
                        {
                            x = rect.width + 12, width = 25, height = EditorGUIUtility.singleLineHeight
                        };
                        if (GUI.Button(AddButtonRect, "+"))
                        {
                            MTools.CreateScriptableAsset(TrueState, typeof(MAIState), MTools.GetSelectedPathOrFallback());
                        }
                    }



                    empty = FalseState.objectReferenceValue == null;
                    if (empty)
                    {
                        r3.width -= 30;
                    }
                    r3.y += (EditorGUIUtility.singleLineHeight + 3) * 2;


                    EditorGUI.PropertyField(r3, FalseState, new GUIContent("False" + (empty ? " (Do Nothing)" : ""), "If the Decision is FALSE, It will execute this state. if is Empty, it will do nothing"));

                    if (empty)
                    {
                        var AddButtonRect = new Rect(r3)
                        {
                            x = rect.width + 12, width = 25, height = EditorGUIUtility.singleLineHeight
                        };
                        if (GUI.Button(AddButtonRect, "+"))
                        {
                            MTools.CreateScriptableAsset(FalseState, typeof(MAIState), MTools.GetSelectedPathOrFallback());
                        }
                    }
                },

                drawHeaderCallback = rect => EditorGUI.LabelField(rect, new GUIContent("   Decisions", "Transitions for other States")),

                onAddCallback = list => OnAddCallback_Decision(),


                onRemoveCallback = list =>
                {
                    var decision = m.transitions[list.index].decision;

                    string Path = AssetDatabase.GetAssetPath(decision);

                    if (Path == AssetDatabase.GetAssetPath(target))        //mean it was created inside the AI STATE
                    {
                        DestroyImmediate(decision, true);                  //Delete the internal asset!
                        transitions.DeleteArrayElementAtIndex(list.index); // Removed double //HACK HACK
                        AssetDatabase.SaveAssets();
                    }
                    else
                    {
                        transitions.DeleteArrayElementAtIndex(list.index);
                    }

                    CheckListIndex(list);

                    EditorUtility.SetDirty(target);
                },
                elementHeightCallback = (index) =>
                {
                    var DefaultHeight = EditorGUIUtility.singleLineHeight + 5;

                    //if (Reo_List_Transitions.index == index)
                    return(DefaultHeight * 3);
                    //else
                    //    return DefaultHeight;
                },
            };
        }
コード例 #3
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();
        }
コード例 #4
0
 private void CreateBoolVar() => Bool = (BoolVar)MTools.CreateScriptableAsset(typeof(BoolVar));
コード例 #5
0
 private void CreateFloat() => Float = (FloatVar)MTools.CreateScriptableAsset(typeof(FloatVar));
コード例 #6
0
 private void CreateIntVar() => Int = (IntVar)MTools.CreateScriptableAsset(typeof(IntVar));