Esempio n. 1
0
        /// <summary>
        /// Removes the supplied variable from its blackboard.
        /// <param name="variable">The variable to be removed.</param>
        /// <summary>
        public static void RemoveVariable (Variable variable) {
            if (variable != null && variable.blackboard != null) {
                // Get the target blackboard
                InternalBlackboard blackboard = variable.blackboard;

                // Register undo
                #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
                Undo.RegisterUndo(blackboard, "Delete Variable");
                #else
                Undo.RecordObject(blackboard, "Delete Variable");
                #endif

                // Remove variable
                blackboard.RemoveVariable(variable);
                // Set dirty
                EditorUtility.SetDirty(blackboard);
            }
        }
Esempio n. 2
0
        /// <summary> 
        /// Draw a float variable.
        /// <param name="rect">The position to draw the variable.</param>
        /// <param name="fsmEvent">The float variable to be drawn.</param>
        /// </summary>
        static void DrawFsmEvent (Rect rect, FsmEvent fsmEvent) {
            rect.yMin += 3f;
            rect.yMax -= 2f;
            rect.xMin += 6f;
            rect.xMax -= 6f;

            bool oldGUIEnabled = GUI.enabled;
            GUI.enabled = !fsmEvent.isSystem;
            DrawName(new Rect (rect.x, rect.y, c_LargeNameWidth, rect.height), fsmEvent);
            GUI.enabled = oldGUIEnabled;

            rect.xMin += c_LargeNameWidth + c_Space;
            rect.xMax -= c_MinusButtonWidth + c_RightPadding;
            EditorGUI.SelectableLabel(rect, fsmEvent.id.ToString());

            rect.x += rect.width + 2f;
            rect.width = c_MinusButtonWidth;
            rect.yMin -= 2f;
            rect.yMax += 2f;
            oldGUIEnabled = GUI.enabled;
            GUI.enabled = !fsmEvent.isSystem;
            if (GUI.Button(rect, s_Styles.iconToolbarMinus, s_Styles.invisbleButton))
                s_VariableToRemove = fsmEvent;
            GUI.enabled = oldGUIEnabled;
        }
Esempio n. 3
0
        /// <summary> 
        /// Draw a dynamic list.
        /// <param name="rect">The position to draw the variable.</param>
        /// <param name="dynamicList">The dynamic list to be drawn.</param>
        /// </summary>
        static void DrawDynamicList (Rect rect, DynamicList dynamicList) {
            rect.yMin += 3f;
            rect.yMax -= 2f;
            rect.xMin += 6f;
            rect.xMax -= 6f;

            DrawName(new Rect (rect.x, rect.y, c_LargeNameWidth, rect.height), dynamicList);

            rect.xMin += c_LargeNameWidth + c_Space;
            rect.xMax -= c_MinusButtonWidth + c_RightPadding;
            EditorGUI.LabelField(rect, "[" + dynamicList.Count.ToString() + "]");

            rect.x += rect.width + 2f;
            rect.width = c_MinusButtonWidth;
            rect.yMin -= 2f;
            rect.yMax += 2f;
            if (GUI.Button(rect, s_Styles.iconToolbarMinus, s_Styles.invisbleButton))
                s_VariableToRemove = dynamicList;
        }
Esempio n. 4
0
        /// <summary> 
        /// Draw an object variable.
        /// <param name="rect">The position to draw the variable.</param>
        /// <param name="objectVar">The object variable to be drawn.</param>
        /// <param name="isAsset">The variable blackboard is an asset?</param>
        /// </summary>
        static void DrawObjectVar (Rect rect, ObjectVar objectVar, bool isAsset) {
            // Name
            rect.yMin += 3f;
            rect.yMax -= 2f;
            rect.xMin += 6f;
            rect.xMax -= 6f;
            rect.height -= c_TwoLinesHeight - c_OneLineHeight;
            DrawName(new Rect (rect.x, rect.y, c_SmallNameWidth, rect.height), objectVar);

            // Value
            rect.xMin += c_SmallNameWidth + c_Space;
            rect.xMax -= c_MinusButtonWidth + c_RightPadding;
            var objectType = objectVar.ObjectType;
            EditorGUI.BeginChangeCheck();
            var newValue = EditorGUI.ObjectField (rect, GUIContent.none, objectVar.Value, objectType, !isAsset);
            if (EditorGUI.EndChangeCheck() && newValue != objectVar.Value) {
                // Register undo
                if (objectVar.blackboard != null) { 
                    #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
                    Undo.RegisterUndo(objectVar.blackboard, "Variable Value");
                    #else
                    Undo.RecordObject(objectVar.blackboard, "Variable Value");
                    #endif
                }

                // Update variable value
                objectVar.Value = newValue;
                // Set blackboard dirty flag
                if (objectVar.blackboard != null) EditorUtility.SetDirty(objectVar.blackboard);
            }

            // Object Type
            rect.y += rect.height + 3f;
            var objectTypeAsString = objectType.ToString();
            if (GUI.Button(rect, objectTypeAsString, EditorStyles.popup)) {
                var menu = new GenericMenu();
                // Add None
                menu.AddItem(new GUIContent("None"), string.IsNullOrEmpty(objectTypeAsString), SetObjectType, new SetObjectVarType(objectVar, typeof(UnityEngine.Object)));

                // Add to menu all types that inherites from UnityEngine.Object
                var types = TypeUtility.GetDerivedTypes(typeof(UnityEngine.Object));
                for (int y = 0; y < types.Length; y++) { 
                    var typeAsString = types[y].ToString();
                    menu.AddItem(new GUIContent(typeAsString.Replace('.', '/')), objectTypeAsString == typeAsString, SetObjectType, new SetObjectVarType(objectVar, types[y]));
                }

                menu.ShowAsContext();
            }

            // Minus button
            rect.x += rect.width + 2f;
            rect.y -= rect.height + 3f;
            rect.width = c_MinusButtonWidth;
            rect.yMin -= 2f;
            rect.yMax += 2f;
            if (GUI.Button(rect, s_Styles.iconToolbarMinus, s_Styles.invisbleButton))
                s_VariableToRemove = objectVar;
        }
Esempio n. 5
0
        /// <summary> 
        /// Draw a material variable.
        /// <param name="rect">The position to draw the variable.</param>
        /// <param name="materialVar">The material variable to be drawn.</param>
        /// </summary>
        static void DrawMaterialVar (Rect rect, MaterialVar materialVar) {
            rect.yMin += 3f;
            rect.yMax -= 2f;
            rect.xMin += 6f;
            rect.xMax -= 6f;
            DrawName(new Rect (rect.x, rect.y, c_SmallNameWidth, rect.height), materialVar);

            rect.xMin += c_SmallNameWidth + c_Space;
            rect.xMax -= c_MinusButtonWidth + c_RightPadding;
            EditorGUI.BeginChangeCheck();
            var newValue = EditorGUI.ObjectField (rect, GUIContent.none, materialVar.Value, typeof(Material), true) as Material;
            if (EditorGUI.EndChangeCheck() && newValue != materialVar.Value) {
                // Register undo
                if (materialVar.blackboard != null) { 
                    #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
                    Undo.RegisterUndo(materialVar.blackboard, "Variable Value");
                    #else
                    Undo.RecordObject(materialVar.blackboard, "Variable Value");
                    #endif
                }

                // Update variable value
                materialVar.Value = newValue;
                // Set blackboard dirty flag
                if (materialVar.blackboard != null) EditorUtility.SetDirty(materialVar.blackboard);
            }

            rect.x += rect.width + 2f;
            rect.width = c_MinusButtonWidth;
            rect.yMin -= 2f;
            rect.yMax += 2f;
            if (GUI.Button(rect, s_Styles.iconToolbarMinus, s_Styles.invisbleButton))
                s_VariableToRemove = materialVar;
        }
Esempio n. 6
0
        /// <summary> 
        /// Draw a quaternion variable.
        /// <param name="rect">The position to draw the variable.</param>
        /// <param name="quaternionVar">The quaternion variable to be drawn.</param>
        /// </summary>
        static void DrawQuaternionVar (Rect rect, QuaternionVar quaternionVar) {
            rect.yMin += 3f;
            rect.yMax -= 2f;
            rect.xMin += 6f;
            rect.xMax -= 6f;
            DrawName(new Rect (rect.x, rect.y, c_SmallNameWidth, rect.height), quaternionVar);

            rect.xMin += c_SmallNameWidth + c_Space;
            rect.xMax -= c_MinusButtonWidth + c_RightPadding;
            #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
            rect.y -= 19f;
            #else
            rect.y -= 16f;
            #endif

            var q = quaternionVar.Value;
            var v4 = new Vector4(q[0], q[1], q[2], q[3]);
            EditorGUI.BeginChangeCheck();
            var newV4 = EditorGUI.Vector4Field (rect, string.Empty, v4);
            if (EditorGUI.EndChangeCheck() && v4 != newV4) {
                // Register undo
                if (quaternionVar.blackboard != null) { 
                    #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
                    Undo.RegisterUndo(quaternionVar.blackboard, "Variable Value");
                    #else
                    Undo.RecordObject(quaternionVar.blackboard, "Variable Value");
                    #endif
                }

                // Update variable value
                quaternionVar.Value = new Quaternion(newV4[0], newV4[1], newV4[2], newV4[3]);
                // Set blackboard dirty flag
                if (quaternionVar.blackboard != null) EditorUtility.SetDirty(quaternionVar.blackboard);
            }

            rect.x += rect.width + 2f;
            #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
            rect.y += 19f;
            #else
            rect.y += 16f;
            #endif

            rect.width = c_MinusButtonWidth;
            rect.yMin -= 2f;
            rect.yMax += 2f;
            if (GUI.Button(rect, s_Styles.iconToolbarMinus, s_Styles.invisbleButton))
                s_VariableToRemove = quaternionVar;
        }
Esempio n. 7
0
        /// <summary> 
        /// Draw a rect variable.
        /// <param name="rect">The position to draw the variable.</param>
        /// <param name="rectVar">The rect variable to be drawn.</param>
        /// </summary>
        static void DrawRectVar (Rect rect, RectVar rectVar) {
            rect.yMin += 3f;
            rect.yMax -= 2f;
            rect.xMin += 6f;
            rect.xMax -= 6f;

            DrawName(new Rect (rect.x, rect.y, c_SmallNameWidth, rect.height - (c_TwoLinesHeight - c_OneLineHeight)), rectVar);

            rect.xMin += c_SmallNameWidth + c_Space;
            rect.xMax -= c_MinusButtonWidth + c_RightPadding;
            #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
            rect.y -= 19f;
            #endif
            EditorGUI.BeginChangeCheck();
            var newValue = EditorGUI.RectField (rect, GUIContent.none, rectVar.Value);
            if (EditorGUI.EndChangeCheck() && newValue != rectVar.Value) {
                // Register undo
                if (rectVar.blackboard != null) { 
                    #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
                    Undo.RegisterUndo(rectVar.blackboard, "Variable Value");
                    #else
                    Undo.RecordObject(rectVar.blackboard, "Variable Value");
                    #endif
                }

                // Update variable value
                rectVar.Value = newValue;
                // Set blackboard dirty flag
                if (rectVar.blackboard != null) EditorUtility.SetDirty(rectVar.blackboard);
            }

            rect.x += rect.width + 2f;
            #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
            rect.y += 19f;
            #endif
            rect.height = c_OneLineHeight - 3f;
            rect.width = c_MinusButtonWidth;
            rect.yMin -= 2f;
            rect.yMax += 2f;
            if (GUI.Button(rect, s_Styles.iconToolbarMinus, s_Styles.invisbleButton))
                s_VariableToRemove = rectVar;
        }
Esempio n. 8
0
        /// <summary> 
        /// Draw the variables name.
        /// <param name="rect">The position to draw the variable name.</param>
        /// <param name="variable">The variable to be drawn.</param>
        /// </summary>
        static void DrawName (Rect rect, Variable variable) {
            EditorGUI.BeginChangeCheck();
            var newName = EditorGUI.TextField (rect, variable.name);
            if (EditorGUI.EndChangeCheck() && newName != variable.name) {
                // Register undo
                if (variable.blackboard != null) {
                    #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
                    Undo.RegisterUndo(variable.blackboard, "Variable Name");
                    #else
                    Undo.RecordObject(variable.blackboard, "Variable Name");
                    #endif
                }

                // Update variable name
                variable.name = newName;
                // Set blackboard dirty flag
                if (variable.blackboard != null) EditorUtility.SetDirty(variable.blackboard);
            }
        }
Esempio n. 9
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;
            }
        }
Esempio n. 10
0
		public override void Reset () {
			variable = new Variable();
			logType = Log.LogType.Log;
		}
Esempio n. 11
0
 public override void Reset () {
     list = new ConcreteDynamicList();
     variable = new Variable();
 }
Esempio n. 12
0
 public override void Reset () {
     list = new ConcreteDynamicList();
     storeIndex = new ConcreteIntVar();
     storeCurrentValue = new Variable();
     reverse = false;
 }
 static string GetVariableMember (Variable variable) {
     return "public static readonly int " + variable.name.Replace(" ", "_") + " = " + variable.id.ToString() + ";";
 }
Esempio n. 14
0
 /// <summary>
 /// Removes the supplied variable from the blackboard.
 /// <param name="variable">The variable to be removed.</param>
 /// </summary> 
 public void RemoveVariable (Variable variable) {
     if (variable != null && variable.blackboard == this) {
         // Float
         if (variable is ConcreteFloatVar) {
             // Searchs for the variable index
             for (int i = 0; i < m_FloatVars.Length; i++) {
                 // The variable has the current index?
                 if (m_FloatVars[i] == variable) {
                     // Remove variable
                     this.RemoveFloatVar(i);
                     break;
                 }
             }
         }
         // Int
         else if (variable is ConcreteIntVar) {
             // Searchs for the variable index
             for (int i = 0; i < m_IntVars.Length; i++) {
                 // The variable has the current index?
                 if (m_IntVars[i] == variable) {
                     // Remove variable
                     this.RemoveIntVar(i);
                     break;
                 }
             }
             return;
         }
         // Bool
         else if (variable is ConcreteBoolVar) {
             // Searchs for the variable index
             for (int i = 0; i < m_BoolVars.Length; i++) {
                 // The variable has the current index?
                 if (m_BoolVars[i] == variable) {
                     // Remove variable
                     this.RemoveBoolVar(i);
                     break;
                 }
             }
             return;
         }
         // String
         else if (variable is ConcreteStringVar) {
             // Searchs for the variable index
             for (int i = 0; i < m_StringVars.Length; i++) {
                 // The variable has the current index?
                 if (m_StringVars[i] == variable) {
                     // Remove variable
                     this.RemoveStringVar(i);
                     break;
                 }
             }
             return;
         }
         // Vector3
         else if (variable is ConcreteVector3Var) {
             // Searchs for the variable index
             for (int i = 0; i < m_Vector3Vars.Length; i++) {
                 // The variable has the current index?
                 if (m_Vector3Vars[i] == variable) {
                     // Remove variable
                     this.RemoveVector3Var(i);
                     break;
                 }
             }
             return;
         }
         // Rect
         else if (variable is ConcreteRectVar) {
             // Searchs for the variable index
             for (int i = 0; i < m_RectVars.Length; i++) {
                 // The variable has the current index?
                 if (m_RectVars[i] == variable) {
                     // Remove variable
                     this.RemoveRectVar(i);
                     break;
                 }
             }
             return;
         }
         // Color
         else if (variable is ConcreteColorVar) {
             // Searchs for the variable index
             for (int i = 0; i < m_ColorVars.Length; i++) {
                 // The variable has the current index?
                 if (m_ColorVars[i] == variable) {
                     // Remove variable
                     this.RemoveColorVar(i);
                     break;
                 }
             }
             return;
         }
         // Quaternion
         else if (variable is ConcreteQuaternionVar) {
             // Searchs for the variable index
             for (int i = 0; i < m_QuaternionVars.Length; i++) {
                 // The variable has the current index?
                 if (m_QuaternionVars[i] == variable) {
                     // Remove variable
                     this.RemoveQuaternionVar(i);
                     break;
                 }
             }
             return;
         }
         // GameObject
         else if (variable is ConcreteGameObjectVar) {
             // Searchs for the variable index
             for (int i = 0; i < m_GameObjectVars.Length; i++) {
                 // The variable has the current index?
                 if (m_GameObjectVars[i] == variable) {
                     // Remove variable
                     this.RemoveGameObjectVar(i);
                     break;
                 }
             }
             return;
         }
         // Texture
         else if (variable is ConcreteTextureVar) {
             // Searchs for the variable index
             for (int i = 0; i < m_TextureVars.Length; i++) {
                 // The variable has the current index?
                 if (m_TextureVars[i] == variable) {
                     // Remove variable
                     this.RemoveTextureVar(i);
                     break;
                 }
             }
             return;
         }
         // Material
         else if (variable is ConcreteMaterialVar) {
             // Searchs for the variable index
             for (int i = 0; i < m_MaterialVars.Length; i++) {
                 // The variable has the current index?
                 if (m_MaterialVars[i] == variable) {
                     // Remove variable
                     this.RemoveMaterialVar(i);
                     break;
                 }
             }
             return;
         }
         // Object
         else if (variable is ConcreteObjectVar) {
             // Searchs for the variable index
             for (int i = 0; i < m_ObjectVars.Length; i++) {
                 // The variable has the current index?
                 if (m_ObjectVars[i] == variable) {
                     // Remove variable
                     this.RemoveObjectVar(i);
                     break;
                 }
             }
             return;
         }
         // DynamicList
         else if (variable is ConcreteDynamicList) {
             // Searchs for the variable index
             for (int i = 0; i < m_DynamicLists.Length; i++) {
                 // The variable has the current index?
                 if (m_DynamicLists[i] == variable) {
                     // Remove variable
                     this.RemoveDynamicList(i);
                     break;
                 }
             }
             return;
         }
         // FsmEvent
         else if (variable is FsmEvent) {
             // Searchs for the variable index
             for (int i = 0; i < m_ConcreteFsmEvents.Length; i++) {
                 // The variable has the current index?
                 if (m_ConcreteFsmEvents[i] == variable) {
                     // Remove variable
                     this.RemoveFsmEvent(i);
                     break;
                 }
             }
             return;
         }
     }
 }
Esempio n. 15
0
 public override void Reset () {
     list = new ConcreteDynamicList();
     storeCurrentValue = new Variable();
 }
Esempio n. 16
0
 public override void Reset () {
     list = new ConcreteDynamicList();
     variable = new Variable();
     storeIndex = new ConcreteIntVar();
 }