Example #1
0
        /// <summary>
        /// Displays a context menu to add variables to a blackboard.
        /// <param name="blackboard">The target blackboard to add a new variable.</param>
        /// </summary>
        public static void OnAddContextMenu(InternalBlackboard blackboard)
        {
            GUIUtility.hotControl      = 0;
            GUIUtility.keyboardControl = 0;

            var menu = new GenericMenu();

            menu.AddItem(new GUIContent("Float"), false, delegate() { BlackboardUtility.AddFloatVar(blackboard); });
            menu.AddItem(new GUIContent("Int"), false, delegate() { BlackboardUtility.AddIntVar(blackboard); });
            menu.AddItem(new GUIContent("Bool"), false, delegate() { BlackboardUtility.AddBoolVar(blackboard); });
            menu.AddItem(new GUIContent("String"), false, delegate() { BlackboardUtility.AddStringVar(blackboard); });
            menu.AddItem(new GUIContent("Vector3"), false, delegate() { BlackboardUtility.AddVector3Var(blackboard); });
            menu.AddItem(new GUIContent("Rect"), false, delegate() { BlackboardUtility.AddRectVar(blackboard); });
            menu.AddItem(new GUIContent("Color"), false, delegate() { BlackboardUtility.AddColorVar(blackboard); });
            menu.AddItem(new GUIContent("Quaternion"), false, delegate() { BlackboardUtility.AddQuaternionVar(blackboard); });
            menu.AddItem(new GUIContent("GameObject"), false, delegate() { BlackboardUtility.AddGameObjectVar(blackboard); });
            menu.AddItem(new GUIContent("Texture"), false, delegate() { BlackboardUtility.AddTextureVar(blackboard); });
            menu.AddItem(new GUIContent("Material"), false, delegate() { BlackboardUtility.AddMaterialVar(blackboard); });
            menu.AddItem(new GUIContent("Object"), false, delegate() { BlackboardUtility.AddObjectVar(blackboard); });
            menu.AddItem(new GUIContent("DynamicList"), false, delegate() { BlackboardUtility.AddDynamicList(blackboard); });
            menu.AddItem(new GUIContent("FsmEvent"), false, delegate() { BlackboardUtility.AddFsmEvent(blackboard); });

            if (!(blackboard is InternalGlobalBlackboard))
            {
                menu.AddSeparator("");
                menu.AddItem(new GUIContent("Global Blackboard"), false, delegate() { EditorApplication.ExecuteMenuItem("Tools/BehaviourMachine/Global Blackboard"); });
            }

            menu.ShowAsContext();
        }
        /// <summary>
        /// Adds a new bool var to the supplied blackboard.
        /// Automatically handles undo.
        /// <param name="blackboard">The blackboard to add a new BoolVar.</param>
        /// <returns>The new variable.</returns>
        /// </summary>
        public static BoolVar AddBoolVar(InternalBlackboard blackboard)
        {
            BlackboardUtility.RegisterVariableUndo(blackboard, "Add Bool Variable");
            var newVariable = blackboard.AddBoolVar();

            EditorUtility.SetDirty(blackboard);
            return(newVariable);
        }
        /// <summary>
        /// Adds a new FsmEvent var to the supplied blackboard.
        /// Automatically handles undo.
        /// <param name="blackboard">The blackboard to add a new FsmEventVar.</param>
        /// <returns>The new variable.</returns>
        /// </summary>
        public static FsmEvent AddFsmEvent(InternalBlackboard blackboard)
        {
            BlackboardUtility.RegisterVariableUndo(blackboard, "Add FsmEvent");
            var newVariable = blackboard.AddFsmEvent();

            EditorUtility.SetDirty(blackboard);
            return(newVariable);
        }
Example #4
0
        /// <summary>
        /// Draw the variables of a blackboard in the GUI.
        /// <param name="position">The position in the GUI to draw the variables.</param>
        /// <param name="blackboard">The blackboard to be drawn.</param>
        /// </summary>
        public static void DrawVariables(Rect position, InternalBlackboard blackboard)
        {
            if (blackboard == null)
            {
                return;
            }

            // Create styles
            if (s_Styles == null)
            {
                s_Styles = new BlackboardGUIUtility.Styles();
            }

            // Update variable to remove
            s_VariableToRemove = null;

            // Is asset?
            bool isAsset = AssetDatabase.Contains(blackboard.gameObject);

            // Save GUI.changed
            EditorGUI.BeginChangeCheck();

            // FloatVar
            position.height = c_OneLineHeight;
            foreach (var floatVar in blackboard.floatVars)
            {
                DrawFloatVar(position, floatVar);
                position.y += position.height;
            }
            // IntVar
            foreach (var intVar in blackboard.intVars)
            {
                DrawIntVar(position, intVar);
                position.y += position.height;
            }
            // BoolVar
            foreach (var boolVar in blackboard.boolVars)
            {
                DrawBoolVar(position, boolVar);
                position.y += position.height;
            }
            // StringVar
            foreach (var stringVar in blackboard.stringVars)
            {
                DrawStringVar(position, stringVar);
                position.y += position.height;
            }
            // Vector3Var
            foreach (var vector3Var in blackboard.vector3Vars)
            {
                DrawVector3Var(position, vector3Var);
                position.y += position.height;
            }
            // positionVar
            position.height = c_TwoLinesHeight;
            foreach (var rectVar in blackboard.rectVars)
            {
                DrawRectVar(position, rectVar);
                position.y += position.height;
            }
            // ColorVar
            position.height = c_OneLineHeight;
            foreach (var colorVar in blackboard.colorVars)
            {
                DrawColorVar(position, colorVar);
                position.y += position.height;
            }
            // QuaternionVar
            foreach (var quaternionVar in blackboard.quaternionVars)
            {
                DrawQuaternionVar(position, quaternionVar);
                position.y += position.height;
            }
            // GameObjectVar
            foreach (var gameObjectVar in blackboard.gameObjectVars)
            {
                DrawGameObjectVar(position, gameObjectVar, isAsset);
                position.y += position.height;
            }
            // TextureVar
            foreach (var textureVar in blackboard.textureVars)
            {
                DrawTextureVar(position, textureVar);
                position.y += position.height;
            }
            // MaterialVar
            foreach (var materialVar in blackboard.materialVars)
            {
                DrawMaterialVar(position, materialVar);
                position.y += position.height;
            }
            // ObjectVar
            position.height = c_TwoLinesHeight;
            foreach (var objectVar in blackboard.objectVars)
            {
                DrawObjectVar(position, objectVar, isAsset);
                position.y += position.height;
            }
            // DynamicList
            position.height = c_OneLineHeight;
            foreach (var dynamicList in blackboard.dynamicLists)
            {
                DrawDynamicList(position, dynamicList);
                position.y += position.height;
            }
            // FsmEvent
            foreach (var fsmEvent in blackboard.fsmEvents)
            {
                DrawFsmEvent(position, fsmEvent);
                position.y += position.height;
            }

            // Restore old GUI.changed
            EditorGUI.EndChangeCheck();

            // Delete variable?
            if (s_VariableToRemove != null)
            {
                GUIUtility.hotControl      = 0;
                GUIUtility.keyboardControl = 0;

                BlackboardUtility.RemoveVariable(s_VariableToRemove);
                s_VariableToRemove = null;
            }
        }