Exemplo n.º 1
0
 /// <summary> 
 /// Register undo before add a new variable.
 /// <param name="blackboard">The blackboard to register undo.</param> 
 /// <param name="name">The name of the undo.</param> 
 /// </summary>
 private static void RegisterVariableUndo (InternalBlackboard blackboard, string name) {
     #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
     Undo.RegisterUndo(blackboard, name);
     #else
     Undo.RecordObject(blackboard, name);
     #endif
 }
 /// <summary> 
 /// Unity callback called when the object is loaded.
 /// </summary>
 void OnEnable () {
     if (target != null) {
         m_SerialObj = new SerializedObject(target);
         m_ScriptProperty = m_SerialObj.FindProperty("m_Script");
         m_Blackboard = target as InternalBlackboard;
         m_VariableEditor = new VariableEditor(m_Blackboard);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Update the hideFlag of all states on the same GameObject as the supplied blackboard.
 /// <param name ="blackboard">The target blackboard.</param>
 /// </summary>
 static void OnBlackboardHideFlag (InternalBlackboard blackboard) {
     // It's a blackboard?
     if (blackboard != null) {
         // Get the prefab type
         var prefabType = UnityEditor.PrefabUtility.GetPrefabType(blackboard.gameObject);
         // Its an instance of a prefab?
         if (prefabType != UnityEditor.PrefabType.None) {
             // Get all states in the blackboard
             InternalStateBehaviour[] states = blackboard.GetComponents<InternalStateBehaviour>();
             for (int i = 0; i < states.Length; i++)
                 OnStateHideFlag(states[i]);
         }
         
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Class constructor.
        /// <param name="stateTransition">The target transition.</param>
        /// <param name="destination">The target destination.</param>
        /// <param name="index">The transition index.</param>
        /// <param name="blackboard">The state blackboard.</param>
        /// </summary>
        public TransitionGUI (StateTransition stateTransition, InternalStateBehaviour destination, int index, InternalBlackboard blackboard) {
            m_Transition = stateTransition;
            m_Destination = destination;

            // It's a global event?
            if (m_Transition.eventID < 0) {
                 if (InternalGlobalBlackboard.Instance != null)
                     m_FsmEvent = InternalGlobalBlackboard.Instance.GetFsmEvent(m_Transition.eventID);
            }
            // It's a local variable and the blackboard is not null?
            else if (m_Transition.eventID > 0 && blackboard != null)
                m_FsmEvent = blackboard.GetFsmEvent(m_Transition.eventID);

            // Get the transition arrow vertical offset
            m_VerticalOffset = StateGUI.defaultHeight + TransitionGUI.defaultHeight * (index + .35f);
        }
Exemplo n.º 5
0
        static void EnabledStatesNameGizmo (InternalBlackboard blackboard, GizmoType gizmoType) {
            //  Is in playmode?
            if (EditorApplication.isPlaying && BehaviourMachinePrefs.enabledStateName) {
                // The styles is null?
                if (s_Styles == null)
                    s_Styles = new GizmoDrawer.Styles();

                // Get root parents
                var rootParents = blackboard.GetEnabledRootParents();
                Camera currentCamera = Camera.current;

                // There is at least one fsm enabled?
                if (rootParents.Length <= 0 || currentCamera == null)
                    return;

                // The object is visible by the camera?
                Vector3 position = blackboard.transform.position;
                Vector3 viewportPoint = currentCamera.WorldToViewportPoint(position);
                if (viewportPoint.z <= 0 || !(new Rect(0, 0, 1, 1)).Contains(viewportPoint))
                    return;

                // Get enabled state names
                string names = rootParents[0].GetEnabledStateName();
                for (int i = 1; i < rootParents.Length; i++)
                    names += "\n" + rootParents[i].GetEnabledStateName();

                // Handles.Label has an offset bug when working with styles that are not MiddleLeft, bellow is a workaround to center the text.
                GUIContent nameContent = new GUIContent(names);
                Vector2 size = s_Styles.enabledStateName.CalcSize(nameContent);
                Vector3 screenPoint = currentCamera.WorldToScreenPoint(position);
                position = currentCamera.ScreenToWorldPoint(new Vector3(screenPoint.x - size.x * .5f, screenPoint.y, - screenPoint.z));

                // Draw enabled states name
                Handles.Label(position, nameContent, s_Styles.enabledStateName);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Constructor for DynamicList variables that will be added to a blackboard.
 /// <param name="name">The name of the variable.</param>
 /// <param name="blackboard">The variable blackboard.</param>
 /// <param name="id">The unique id of the variable</param>
 /// </summary>
 public DynamicList (string name, InternalBlackboard blackboard, int id) : base (name, blackboard, id) {}
Exemplo n.º 7
0
 /// <summary>
 /// Constructor for none variables.
 /// </summary>
 public Variable () {
     m_Blackboard = null;
     m_IsConstant = false;
     m_Name = " ";
 }
Exemplo n.º 8
0
 /// <summary>
 /// Constructor for Object variables that will be added to a blackboard.
 /// <param name="name">The name of the variable.</param>
 /// <param name="blackboard">The variable blackboard.</param>
 /// <param name="id">The unique id of the variable</param>
 /// </summary>
 public ObjectVar (string name, InternalBlackboard blackboard, int id) : base (name, blackboard, id) {}
Exemplo n.º 9
0
 /// <summary>
 /// Constructor for Material variables that will be added to a blackboard.
 /// <param name="name">The name of the variable.</param>
 /// <param name="blackboard">The variable blackboard.</param>
 /// <param name="id">The unique id of the variable</param>
 /// </summary>
 public MaterialVar (string name, InternalBlackboard blackboard, int id) : base (name, blackboard, id) {}
Exemplo n.º 10
0
 /// <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;
 }
Exemplo n.º 11
0
 /// <summary>
 /// Constructor for ConcreteFsmEvent that will be added to a blackboard.
 /// <param name="name">The name of the variable.</param>
 /// <param name="blackboard">The variable blackboard.</param>
 /// <param name="id">The unique id of the variable</param>
 /// <param name="isSystem">Returns true if this is a system event; otherwise false.</param>
 /// </summary>
 public ConcreteFsmEvent (string name, InternalBlackboard blackboard, int id, bool isSystem) : base (name, blackboard, id, isSystem) {}
Exemplo n.º 12
0
 /// <summary>
 /// Constructor for string variables that will be added to a blackboard.
 /// <param name="name">The name of the variable.</param>
 /// <param name="blackboard">The variable blackboard.</param>
 /// <param name="id">The unique id of the variable</param>
 /// </summary>
 public StringVar (string name, InternalBlackboard blackboard, int id) : base (name, blackboard, id) {Value = string.Empty;}
Exemplo n.º 13
0
 /// <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;
 }
Exemplo n.º 14
0
 /// <summary>
 /// After call this function the variable will be none and should not be in the blackboard.
 /// </summary>
 public void SetAsNone () {
     m_Blackboard = null;
     m_IsConstant = false;
     m_Name = " ";
 }
Exemplo n.º 15
0
 /// <summary>
 /// After call this function the variable will be invalid and should be recreated.
 /// </summary>
 public void SetAsInvalid () {
     m_Blackboard = null;
     m_IsConstant = false;
     m_Name = "Invalid";
 }
Exemplo n.º 16
0
        /// <summary>
		/// After call this function the variable will be a constant and should not be in the blackboard.
        /// </summary>
        public void SetAsConstant () {
            m_Blackboard = null;
            m_IsConstant = true;
            m_Name = " ";
        }
Exemplo n.º 17
0
        public static MonoScript CreateOrEditCustomBlackboard (string path, InternalBlackboard blackboard) {
            try {
                // opens the file if it allready exists, creates it otherwise
                using (FileStream stream = File.Open(path, FileMode.Create, FileAccess.Write)) {
                    // Create the string builder
                    var code = new CodeBuilder();
                    // Has Namespace
                    bool hasNamespace = !string.IsNullOrEmpty(blackboard.Namespace);

                    // Add header
                    code.AppendLine(BlackboardCodeGenerator.GetHeader());
                    // Add namespaces
                    code.AppendLine("using UnityEngine;");
                    code.AppendLine("using BehaviourMachine;");
                    code.AppendLine();

                    // Add namespace?
                    if (hasNamespace) {
                        code.AppendLine("namespace " + blackboard.Namespace + " {");
                        // Add more one tab
                        code.tabSize += 1;  
                    }

                    // It is the GlobalBlackboard?
                    if (blackboard.GetType().Name == "GlobalBlackboard") {
                        // Add Componente Menu
                        code.AppendLine("[AddComponentMenu(\"\")]");
                        // Add class
                        code.AppendLine("public class " + BlackboardCodeGenerator.GetClassName(path) + " : InternalGlobalBlackboard {");
                        // Add more one tab
                        code.tabSize += 1;

                        // Add Instance property
                        code.AppendLine("/// <summary>");
                        code.AppendLine("/// The GlobalBlackboard instance.");
                        code.AppendLine("/// </summary>");
                        code.AppendLine("public static new GlobalBlackboard Instance {get {return InternalGlobalBlackboard.Instance as GlobalBlackboard;}}");
                        code.AppendLine();
                    }
                    else {
                        // Add class
                        code.AppendLine("public class " + BlackboardCodeGenerator.GetClassName(path) + " : Blackboard {");
                        // Add more one tab
                        code.tabSize += 1;
                    }

                    // FloatVar
                    FloatVar[] floatVars = blackboard.floatVars;
                    if (floatVars.Length > 0) {
                        code.AppendLine("// FloatVars");
                        for (int i = 0; i < floatVars.Length; i++)
                            code.AppendLine(BlackboardCodeGenerator.GetVariableMember(floatVars[i]));
                    }

                    // IntVar
                    IntVar[] intVars = blackboard.intVars;
                    if (intVars.Length > 0) {
                        code.AppendLine("// IntVars");
                        for (int i = 0; i < intVars.Length; i++)
                            code.AppendLine(BlackboardCodeGenerator.GetVariableMember(intVars[i]));
                    }

                    // BoolVar
                    BoolVar[] boolVars = blackboard.boolVars;
                    if (boolVars.Length > 0) {
                        code.AppendLine("// BoolVars");
                        for (int i = 0; i < boolVars.Length; i++)
                            code.AppendLine(BlackboardCodeGenerator.GetVariableMember(boolVars[i]));
                    }

                    // StringVar
                    StringVar[] stringVars = blackboard.stringVars;
                    if (stringVars.Length > 0) {
                        code.AppendLine("// StringVars");
                        for (int i = 0; i < stringVars.Length; i++)
                            code.AppendLine(BlackboardCodeGenerator.GetVariableMember(stringVars[i]));
                    }

                    // Vector3Var
                    Vector3Var[] vector3Vars = blackboard.vector3Vars;
                    if (vector3Vars.Length > 0) {
                        code.AppendLine("// Vector3Vars");
                        for (int i = 0; i < vector3Vars.Length; i++)
                            code.AppendLine(BlackboardCodeGenerator.GetVariableMember(vector3Vars[i]));
                    }

                    // RectVar
                    RectVar[] rectVars = blackboard.rectVars;
                    if (rectVars.Length > 0) {
                        code.AppendLine("// RectVars");
                        for (int i = 0; i < rectVars.Length; i++)
                            code.AppendLine(BlackboardCodeGenerator.GetVariableMember(rectVars[i]));
                    }

                    // ColorVar
                    ColorVar[] colorVars = blackboard.colorVars;
                    if (colorVars.Length > 0) {
                        code.AppendLine("// ColorVars");
                        for (int i = 0; i < colorVars.Length; i++)
                            code.AppendLine(BlackboardCodeGenerator.GetVariableMember(colorVars[i]));
                    }

                    // QuaternionVar
                    QuaternionVar[] quaternionVars = blackboard.quaternionVars;
                    if (quaternionVars.Length > 0) {
                        code.AppendLine("// QuaternionVars");
                        for (int i = 0; i < quaternionVars.Length; i++)
                            code.AppendLine(BlackboardCodeGenerator.GetVariableMember(quaternionVars[i]));
                    }

                    // GameObjectVar
                    GameObjectVar[] gameObjectVars = blackboard.gameObjectVars;
                    if (gameObjectVars.Length > 0) {
                        code.AppendLine("// GameObjectVars");
                        for (int i = 0; i < gameObjectVars.Length; i++)
                            code.AppendLine(BlackboardCodeGenerator.GetVariableMember(gameObjectVars[i]));
                    }

                    // TextureVar
                    TextureVar[] textureVars = blackboard.textureVars;
                    if (textureVars.Length > 0) {
                        code.AppendLine("// TextureVars");
                        for (int i = 0; i < textureVars.Length; i++)
                            code.AppendLine(BlackboardCodeGenerator.GetVariableMember(textureVars[i]));
                    }

                    // MaterialVar
                    MaterialVar[] materialVars = blackboard.materialVars;
                    if (materialVars.Length > 0) {
                        code.AppendLine("// MaterialVars");
                        for (int i = 0; i < materialVars.Length; i++)
                            code.AppendLine(BlackboardCodeGenerator.GetVariableMember(materialVars[i]));
                    }

                    // ObjectVar
                    ObjectVar[] objectVars = blackboard.objectVars;
                    if (objectVars.Length > 0) {
                        code.AppendLine("// ObjectVars");
                        for (int i = 0; i < objectVars.Length; i++)
                            code.AppendLine(BlackboardCodeGenerator.GetVariableMember(objectVars[i]));
                    }

                    // FsmEvents
                    FsmEvent[] fsmEvents = blackboard.fsmEvents;
                    if (fsmEvents.Length > 0) {
                        code.AppendLine("// FsmEvents");
                        for (int i = 0; i < fsmEvents.Length; i++)
                            code.AppendLine(BlackboardCodeGenerator.GetVariableMember(fsmEvents[i]));
                    }

                    // Remove one tab
                    code.tabSize -= 1;

                    // Close class brackets
                    code.AppendLine("}");

                    // Close namespace brackets
                    if (hasNamespace) {
                        // Remove one tab
                        code.tabSize -= 1;
                        // Close brackets
                        code.AppendLine("}");
                    }

                    // Write data on file
                    using(StreamWriter writer = new StreamWriter(stream)) {
                        writer.Write(code.ToString());
                    }
                }

                AssetDatabase.Refresh();
                return AssetDatabase.LoadAssetAtPath(path, typeof(MonoScript)) as MonoScript;
            }
            catch(System.Exception e) {
                Debug.LogException(e);
                return null;
            }
        }
Exemplo n.º 18
0
        static void FsmEvent2ConcreteFsmEvent (InternalBlackboard blackboard, bool isPrefab) {
            // Get the target serialized object
            var serializedBlackboard = new SerializedObject(blackboard);
            // Get the m_FsmEvents property
            var fsmEventProperty = serializedBlackboard.FindProperty("m_FsmEvents");
            // Get the m_ConcreteFsmEvents property
            var concreteFsmEventProperty = serializedBlackboard.FindProperty("m_ConcreteFsmEvents");

            // Copy data
            if (fsmEventProperty != null && concreteFsmEventProperty != null && (isPrefab || !fsmEventProperty.isInstantiatedPrefab || fsmEventProperty.prefabOverride)) {

                for (int i = 0; i < fsmEventProperty.arraySize; i++) {
                    // Add new FsmEvent
                    concreteFsmEventProperty.InsertArrayElementAtIndex(i);
                    // Get the new FsmEvent
                    SerializedProperty newFsmProperty = concreteFsmEventProperty.GetArrayElementAtIndex(i);
                    // Get the old FsmEvent
                    SerializedProperty oldFsmProperty = fsmEventProperty.GetArrayElementAtIndex(i);

                    // Update the new FsmEvent properties
                    newFsmProperty.FindPropertyRelative("m_ID").intValue = oldFsmProperty.FindPropertyRelative("m_ID").intValue;
                    newFsmProperty.FindPropertyRelative("m_Name").stringValue = oldFsmProperty.FindPropertyRelative("m_Name").stringValue;
                    newFsmProperty.FindPropertyRelative("m_Blackboard").objectReferenceValue = oldFsmProperty.FindPropertyRelative("m_Blackboard").objectReferenceValue;
                    newFsmProperty.FindPropertyRelative("m_IsConstant").boolValue = oldFsmProperty.FindPropertyRelative("m_IsConstant").boolValue;
                    newFsmProperty.FindPropertyRelative("m_EventId").intValue = oldFsmProperty.FindPropertyRelative("m_EventId").intValue;
                    newFsmProperty.FindPropertyRelative("m_IsSystem").boolValue = oldFsmProperty.FindPropertyRelative("m_IsSystem").boolValue;
                }

                // Clear the fsmEvent event property
                fsmEventProperty.ClearArray();
            }

            // Dispose properties
            fsmEventProperty.Dispose();
            concreteFsmEventProperty.Dispose();
            // Update serialized data
            serializedBlackboard.ApplyModifiedProperties();
        }
Exemplo n.º 19
0
 /// <summary>
 /// Constructor for FsmEvent that will be added to a blackboard.
 /// <param name="name">The name of the variable.</param>
 /// <param name="blackboard">The variable blackboard.</param>
 /// <param name="id">The unique id of the variable</param>
 /// <param name="isSystem">Returns true if this is a system event; otherwise false.</param>
 /// </summary>
 public FsmEvent (string name, InternalBlackboard blackboard, int id, bool isSystem) : base (name, blackboard, id) {
     m_IsSystem = isSystem;
 }
Exemplo n.º 20
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();
        }
Exemplo n.º 21
0
 /// <summary>
 /// Constructor for variables that will be added to a .
 /// <param name="name">The name of the variable.</param>
 /// <param name="blackboard">The variable blackboard.</param>
 /// <param name="id">The unique id of the variable</param>
 /// </summary>
 public Variable (string name, InternalBlackboard blackboard, int id) {
     m_Blackboard = blackboard;
     m_IsConstant = false;
     m_ID = id;
     this.name = name;
 }
Exemplo n.º 22
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;
            }
        }
Exemplo n.º 23
0
 /// <summary>
 /// Constructor for Vector3 variables that will be added to a blackboard.
 /// <param name="name">The name of the variable.</param>
 /// <param name="blackboard">The variable blackboard.</param>
 /// <param name="id">The unique id of the variable</param>
 /// </summary>
 public Vector3Var (string name, InternalBlackboard blackboard, int id) : base (name, blackboard, id) {}
Exemplo n.º 24
0
 /// <summary>
 /// Constructor for float variables that will be added to a blackboard.
 /// <param name="name">The name of the variable.</param>
 /// <param name="blackboard">The variable blackboard.</param>
 /// <param name="id">The unique id of the variable</param>
 /// </summary>
 public ConcreteFloatVar (string name, InternalBlackboard blackboard, int id) : base (name, blackboard, id) {}
Exemplo n.º 25
0
 /// <summary> 
 /// Register undo before add a new variable.
 /// <param name="userData">The blackboard to register undo.</param> 
 /// </summary>
 static void RegisterVariableUndo (InternalBlackboard blackboard) {
     #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
     Undo.RegisterUndo(blackboard, "Add Variable");
     #else
     Undo.RecordObject(blackboard, "Add Variable");
     #endif
 }
Exemplo n.º 26
0
 /// <summary>
 /// Constructor for Color variables that will be added to a blackboard.
 /// <param name="name">The name of the variable.</param>
 /// <param name="blackboard">The variable blackboard.</param>
 /// <param name="id">The unique id of the variable</param>
 /// </summary>
 public ColorVar (string name, InternalBlackboard blackboard, int id) : base (name, blackboard, id) {}
Exemplo n.º 27
0
        /// <summary> 
        /// Returns the total height to draw the blackboard variables.
        /// <param name="blackboard">The target blackboard to calculate the height.</param> 
        /// <returns>The required height to draw all variables in the blackboard.</returns> 
        /// </summary>
        public static float GetHeight (InternalBlackboard blackboard) {
            if (blackboard == null)
                return 0f;

            float height =    blackboard.GetFloatsSize() * c_OneLineHeight 
                            + blackboard.GetIntsSize() * c_OneLineHeight
                            + blackboard.GetBoolsSize() * c_OneLineHeight
                            + blackboard.GetStringsSize() * c_OneLineHeight
                            + blackboard.GetVector3sSize() * c_OneLineHeight
                            + blackboard.GetRectsSize() * c_TwoLinesHeight
                            + blackboard.GetColorsSize() * c_OneLineHeight
                            + blackboard.GetQuaternionsSize() * c_OneLineHeight
                            + blackboard.GetGameObjectsSize() * c_OneLineHeight
                            + blackboard.GetTexturesSize() * c_OneLineHeight
                            + blackboard.GetMaterialsSize() * c_OneLineHeight
                            + blackboard.GetObjectsSize() * c_TwoLinesHeight
                            + blackboard.GetDynamicListsSize() * c_OneLineHeight
                            + blackboard.GetFsmEventsSize() * c_OneLineHeight;
            return height;
        }
Exemplo n.º 28
0
 /// <summary>
 /// Constructor for Quaternion variables that will be added to a blackboard.
 /// <param name="name">The name of the variable.</param>
 /// <param name="blackboard">The variable blackboard.</param>
 /// <param name="id">The unique id of the variable</param>
 /// </summary>
 public QuaternionVar (string name, InternalBlackboard blackboard, int id) : base (name, blackboard, id) {}
Exemplo n.º 29
0
        /// <summary>
        /// Draw the blackboard view.
        /// <param name="rect">The position to draw the variables.</param>
        /// <param name="blackboard">The blackboard to be drawn.</param>
        /// <param name="blackboardHeight">The size needed to show all variables in the blackboard.</param>
        /// </summary>
        void DrawBlackboardView (Rect rect, InternalBlackboard blackboard, float blackboardHeight) {
            // Draw header
            Rect headerRect = new Rect (rect.x, rect.y, rect.width, blackboardHeaderHeight);
            if (GUI.Button(headerRect, new GUIContent( "Variables [" + blackboard.GetSize().ToString() + "]","Click to expand/collapse"), s_Styles.blackboardHeader)) {
                if (Event.current.mousePosition.x >= headerRect.xMax - c_BlackboardHeaderButtonWidth) {
                    BlackboardGUIUtility.OnAddContextMenu(blackboard);
                    m_BlackboardViewIsExpanded = true;
                }
                else
                    m_BlackboardViewIsExpanded = !m_BlackboardViewIsExpanded;
            }

            // Draw plus button
            headerRect.y += 2f;
            headerRect.xMin = headerRect.width - c_BlackboardHeaderButtonWidth;
            GUI.Label(headerRect, s_Styles.iconToolbarPlus);

            // The blackboard is expanded
            if (m_BlackboardViewIsExpanded && rect.height - headerRect.height > 0f) {
                rect.yMin += headerRect.height;

                // Draw background
                if (Event.current.type == EventType.Repaint)
                    s_Styles.blackboardBox.Draw(rect, false, false, false, false);

                // Do scroll bar?
                bool doScroll = blackboardHeight > rect.height;

                // Scroll bar logic
                if (doScroll) {
                    // Create a gui group
                    rect.yMin += 2f;
                    rect.yMax -= 2f;
                    GUI.BeginGroup(rect);
                    rect.y = rect.x = 0f;

                    // Get scroll event
                    if (Event.current.type == EventType.ScrollWheel) {
                        m_BlackboardScroll += Event.current.delta.y * 10f;
                        Event.current.Use();
                    }
                    
                    // Update rect
                    rect.y -= m_BlackboardScroll;
                    rect.width -= 12f;
                }

                // Draw variables
                BlackboardGUIUtility.DrawVariables(rect, blackboard);

                // Draw scroll bar
                if (doScroll) {
                    rect.y += m_BlackboardScroll;
                    rect.width += 12f;
                    var scrollPosition = new Rect (rect.x + rect.width - 16f, rect.y, 16f, rect.height);
                    m_BlackboardScroll = GUI.VerticalScrollbar(scrollPosition, m_BlackboardScroll, rect.height, 0f, blackboardHeight);
                    GUI.EndGroup();
                }
            }
        }
Exemplo n.º 30
0
 /// <summary>
 /// Constructor for Texture variables that will be added to a blackboard.
 /// <param name="name">The name of the variable.</param>
 /// <param name="blackboard">The variable blackboard.</param>
 /// <param name="id">The unique id of the variable</param>
 /// </summary>
 public TextureVar (string name, InternalBlackboard blackboard, int id) : base (name, blackboard, id) {}