/// <summary>
        /// Class constructor.
        /// <param name="target">The target object (node, variable or generic object).</param>
        /// <param name="serializedNode">The target serialized node.</param>
        /// <param name="path">The property path.</param>
        /// <param name="type">The type of the property.</param>
        /// <param name="propertyType">The property type.</param>
        /// <param name="array">The array that the element belongs to.</param>
        /// <param name="index">The element index.</param>
        /// <param name="variableInfo">A variable info if the serialized property is a variable; null otherwise.</param>
        /// </summary>
        public SerializedArrayElement (object target, SerializedNode serializedNode, string path, System.Type type, NodePropertyType propertyType, Array array, int index, VariableInfoAttribute variableInfo) : base (target, serializedNode, path, type, propertyType) {
            m_Array = array;
            m_Index = index;
            m_VariableInfo = variableInfo;
            this.label = "Element " + index.ToString();

            // Its a variable type?
            if (propertyType == NodePropertyType.Variable) {
                // Update label
                this.tooltip = (type.Name + ": " + this.tooltip).Replace("Var", string.Empty);

                // Set concreteVariable
                var variable = m_Array.GetValue(m_Index) as BehaviourMachine.Variable;
                System.Type variableType = variable != null ? variable.GetType() : null;
                m_IsConcreteVariable = variableType != null && TypeUtility.GetConcreteType(variableType) == variableType;
            }
        }
        /// <summary>
        /// Constructor.
        /// <param name="serializedNode">The target serialized node.</param>
        /// <param name="path">The property path.</param>
        /// <param name="propertyType">The serialize property type.</param>
        /// <param name="target">The object that owns the serialized field.</param>
        /// <param name="fieldInfo">The field info of the property.</param>
        /// </summary>
        public SerializedNodeField (SerializedNode serializedNode, string path, NodePropertyType propertyType, object target, FieldInfo fieldInfo) : base (target, serializedNode, path, fieldInfo.FieldType, propertyType) {
            m_FieldInfo = fieldInfo;
            this.hideInInspector = AttributeUtility.GetAttribute<HideInInspector>(fieldInfo, true) != null;

            // Variable?
            if (propertyType == NodePropertyType.Variable) {
                this.label = StringHelper.SplitCamelCase(fieldInfo.Name);
                m_VariableInfo = AttributeUtility.GetAttribute<VariableInfoAttribute>(fieldInfo, true) ?? new VariableInfoAttribute();

                var variable = m_FieldInfo.GetValue(m_Target) as BehaviourMachine.Variable;
                System.Type variableType = variable != null ? variable.GetType() : null; 

                m_IsConcreteVariable = variableType != null && TypeUtility.GetConcreteType(variableType) == variableType;
                this.tooltip = (fieldInfo.FieldType.Name + ": " + m_VariableInfo.tooltip).Replace("Var", string.Empty);
            }
            else {
                this.label = StringHelper.SplitCamelCase(fieldInfo.Name);
                var tooltip = AttributeUtility.GetAttribute<BehaviourMachine.TooltipAttribute>(fieldInfo, true);
                if (tooltip != null)
                    m_Tooltip = tooltip.tooltip;
            }
        }
 /// <summary>
 /// Class constructor.
 /// <param name="target">The target object (node, variable or a generic object).</param>
 /// <param name="serializedNode">The target serialized node.</param>
 /// <param name="path">The property path.</param>
 /// <param name="type">The type of the property.</param>
 /// <param name="propertyType">The property type.</param>
 /// </summary>
 public SerializedNodeProperty (object target, SerializedNode serializedNode, string path, Type type, NodePropertyType propertyType) {
     m_Target = target;
     m_SerializedNode = serializedNode;
     m_Path = path;
     m_PropertyType = propertyType;
     m_Type = type;
 }
Beispiel #4
0
        /// <summary>
        /// Returns a set of serialized properties in an object.
        /// <param name="serializedNode">The target serialized node.</param>
        /// <param name="target">The object to get the properties.</param>
        /// <param name="targetType">The target object type.</param>
        /// <param name="currentPath">The property path of the target.</param>
        /// <returns>The serialized properties in the target object.</returns>
        /// </summary>
        static SerializedNodeProperty[] GetPropertiesData (SerializedNode serializedNode, object target, Type targetType, string currentPath = "") {
            // Create the property data list
            var propertyData = new List<SerializedNodeProperty>();
            // Get serialized fields for the target type
            FieldInfo[] serializedFields = NodeSerialization.GetSerializedFields(targetType);

            for (int i = 0; i < serializedFields.Length; i++) {
                // Get field
                FieldInfo field = serializedFields[i];
                // Get field type
                var fieldType = field.FieldType;
                // Get the field property attribute
                var propertyAttr = AttributeUtility.GetAttribute<PropertyAttribute>(field, true);
                // Get the property type
                var propertyType = SerializedNode.GetPropertyType(fieldType);
                // Create the property data
                var currentSerializedField = new SerializedNodeField(serializedNode, currentPath + field.Name, propertyType, target, field);
                propertyData.Add(currentSerializedField);

                // Variable?
                if (propertyType == NodePropertyType.Variable) {
                    // Get the field value
                    object fieldValue = target != null ? field.GetValue(target) : null;

                    // Get the children fields
                    SerializedNodeProperty[] children = SerializedNode.GetPropertiesData(serializedNode, fieldValue, fieldValue != null ? fieldValue.GetType() : fieldType, currentPath + field.Name + ".");

                    // Create the property drawer for the "Value" child property
                    if (propertyAttr != null && currentSerializedField.isConcreteVariable) {
                        foreach (var child in children) {
                            // It is the "Value" property?
                            if (child.label == "Value")
                                child.customDrawer = NodePropertyDrawer.GetDrawer(propertyAttr);
                        }
                    }

                    // Set children
                    currentSerializedField.SetChildren(children);
                }
                // Array?
                else if (propertyType == NodePropertyType.Array) {
                    // Get the array value
                    Array array = target != null ? field.GetValue(target) as Array : null;
                    // Get array element type
                    var elementType = fieldType.GetElementType();
                    // Create the array children list
                    var childrenList = new List<SerializedNodeProperty>();

                    // Create the array size
                    childrenList.Add(new SerializedArraySize(target, serializedNode, currentSerializedField.path + ".size", currentSerializedField, array, elementType));

                    // Create children
                    var variableInfo = AttributeUtility.GetAttribute<VariableInfoAttribute>(field, true) ?? new VariableInfoAttribute();
                    childrenList.AddRange(SerializedNode.GetPropertiesData(serializedNode, target, array, elementType, currentSerializedField.path + ".", variableInfo, propertyAttr));

                    // Set array data children
                    currentSerializedField.SetChildren(childrenList.ToArray());
                }
                // Get the property drawer
                else if (propertyAttr != null)
                    currentSerializedField.customDrawer = NodePropertyDrawer.GetDrawer(propertyAttr);
            }

            return propertyData.ToArray();
        }
Beispiel #5
0
        /// <summary>
        /// Returns a set of serialized properties in an array.
        /// <param name="serializedNode">The target serialized node.</param>
        /// <param name="target">The target object (node, variable or generic object).</param>
        /// <param name="targetArray">The target array.</param>
        /// <param name="type">The elements type in the array.</param>
        /// <param name="currentPath">The property path of the target array.</param>
        /// <param name="variableInfo">The variable info in the array or null.</param>
        /// <param name="propertyAttr">The property attribute in the array.</param>
        /// <returns>The serialized properties in the array.</returns>
        /// </summary>
        static SerializedNodeProperty[] GetPropertiesData (SerializedNode serializedNode, object target, Array targetArray, Type type, string currentPath, VariableInfoAttribute variableInfo, PropertyAttribute propertyAttr) {
            // Create the property data list
            var propertyData = new List<SerializedNodeProperty>();
            // Get the property type
            var propertyType = SerializedNode.GetPropertyType(type);

            if (targetArray != null) {
                // Variable?
                if (propertyType == NodePropertyType.Variable) {
                    for (int i = 0; i < targetArray.Length; i++) {
                        // Get the field value
                        object elementValue = targetArray.GetValue(i);
                        // Create the variable data
                        var variableData = new SerializedArrayElement(target, serializedNode, currentPath + "data[" + i.ToString() + "]", type, propertyType, targetArray, i, variableInfo);

                        // Create the variable children
                        SerializedNodeProperty[] children = SerializedNode.GetPropertiesData(serializedNode, elementValue, elementValue != null ? elementValue.GetType() : type, variableData.path + ".");

                        // Create the property drawer for the "Value" child property
                        if (propertyAttr != null && variableData.isConcreteVariable) {
                            foreach (var child in children) {
                                // It is the "Value" property?
                                if (child.label == "Value")
                                    child.customDrawer = NodePropertyDrawer.GetDrawer(propertyAttr);
                            }
                        }

                        // Set children
                        variableData.SetChildren(children);

                        // Add the variable data to the list
                        propertyData.Add(variableData);
                    }
                }
               // Array?
                else if (propertyType == NodePropertyType.Array) {
                    for (int i = 0; i < targetArray.Length; i++) {
                        // Create the current property data
                        var currentPropertyData = new SerializedArrayElement(target, serializedNode, currentPath + "data[" + i.ToString() + "]" , type, propertyType, targetArray, i, variableInfo);
                        // Get the array value
                        var array = targetArray.GetValue(i) as Array;
                        // Get array element type
                        var elementType = type.GetElementType();
                        // Create the array children list
                        var childrenList = new List<SerializedNodeProperty>();

                        // Create the array size
                        childrenList.Add(new SerializedArraySize(target, serializedNode, currentPropertyData.path + ".size", currentPropertyData, array, elementType));
                        // Create array children
                        childrenList.AddRange(SerializedNode.GetPropertiesData(serializedNode, target, array, elementType, currentPropertyData.path + ".", variableInfo, propertyAttr));

                        // Set array data children
                        currentPropertyData.SetChildren(childrenList.ToArray());

                        // Add to list
                        propertyData.Add(currentPropertyData);
                    }
                }
                else {
                    for (int i = 0; i < targetArray.Length; i++) {
                        // Create the current property data
                        var currentPropertyData = new SerializedArrayElement(target, serializedNode, currentPath + "data[" + i.ToString() + "]" , type, propertyType, targetArray, i, variableInfo);
                        // Try to get a property drawer
                        if (propertyAttr != null)
                            currentPropertyData.customDrawer = NodePropertyDrawer.GetDrawer(propertyAttr);
                        // Add to list
                        propertyData.Add(currentPropertyData);
                    }
                }
            }

            return propertyData.ToArray();
        }
 /// <summary>
 /// Class constructor.
 /// <param name="target">The target object (node, variable or generic object).</param>
 /// <param name="serializedNode">The target serialized node.</param>
 /// <param name="path">The property path.</param>
 /// <param name="arrayData">The serialize property of the target array.</param>
 /// <param name="array">The target array.</param>
 /// <param name="elementType">The array element type.</param>
 /// </summary>
 public SerializedArraySize (object target, SerializedNode serializedNode, string path, SerializedNodeProperty arrayData, Array array, Type elementType) : base (target, serializedNode, path, typeof(int), NodePropertyType.ArraySize) {
     m_ArrayData = arrayData;
     m_Array = array;
     m_ElementType = elementType;
     this.label = "Size";
 }
Beispiel #7
0
        /// <summary>
        /// Shows the node generic menu.
        /// </summary>
        void ShowNodeContextMenu()
        {
            var menu = new GenericMenu();

            menu.AddItem(new GUIContent("Reset"), false, delegate { StateUtility.ResetNode(target); m_SerializedNode = new SerializedNode(target); m_SerializedNode.Update(); });
            menu.AddSeparator(string.Empty);
            menu.AddItem(new GUIContent("Copy"), false, delegate { BehaviourTreeUtility.nodeToPaste = target; });
            menu.AddSeparator(string.Empty);
            if (target != null)
            {
                menu.AddItem(new GUIContent("Find Script"), false, delegate {
                    MonoScript script = BehaviourTreeUtility.GetNodeScript(target.GetType());
                    if (script != null)
                    {
                        EditorGUIUtility.PingObject(script);
                    }
                });
                menu.AddItem(new GUIContent("Edit Script"), false, delegate {
                    MonoScript script = BehaviourTreeUtility.GetNodeScript(target.GetType());
                    if (script != null)
                    {
                        AssetDatabase.OpenAsset(script);
                    }
                });
            }
            else
            {
                menu.AddDisabledItem(new GUIContent("Find Script"));
                menu.AddDisabledItem(new GUIContent("Edit Script"));
            }

            menu.ShowAsContext();
        }
        /// <summary>
        /// Show the specified space, clip, node and position.
        /// </summary>
        /// <param name="space">Space.</param>
        /// <param name="clip">Clip.</param>
        /// <param name="node">Node.</param>
        /// <param name="position">Position.</param>
        public static void Show(GameObject space,AnimationClip clip, SerializedNode node, Rect? position)
        {
            MecanimNodeEditorWindow.__spaceGameObject = space;//in this case is character
                        MecanimNodeEditorWindow.__spaceGameObjectAnimationClip = clip;
                        MecanimNodeEditorWindow.__serializedNode = node;

                        ///////   ACCESS SERIALIZED DATA /////////
                        NodePropertyIterator iterator = node.GetIterator ();

                        __isPlaying = false;
                        __isRecording = false;
                        __variableSelected = null;
                        __timeNormalized = 0f;
                        __timeNormalizedUpdate = false;
                        __timeCurrent = 0f;

                        AnimationMode.StopAnimationMode ();
                        Undo.postprocessModifications -= PostprocessAnimationRecordingModifications;

                        SceneView.onSceneGUIDelegate += OnSceneGUI;

                        if (iterator.Find ("clipBindings"))
                                clipBindingsSerialized = iterator.current;

                        if (__mecanimNodeClipBinding == null)
                                __mecanimNodeClipBinding = ScriptableObject.CreateInstance<EditorClipBinding> ();

                        __mecanimNodeClipBinding.gameObject = __spaceGameObject;
                        __mecanimNodeClipBinding.clip = __spaceGameObjectAnimationClip;

                        /////// INIT SERIALIZED NODE PROPERTIES - CURVES, COLORS, VARIABLES //////

                        if (iterator.Find ("curves"))
                                curvesSerialized = iterator.current;
                        else
                                Debug.LogError ("MecananimNode should have public field 'curves'");

                        if (iterator.Find ("curvesColors"))
                                curvesColorsSerialized = iterator.current;
                        else
                                Debug.LogError ("MecananimNode should have public field 'curvesColors'");

                        if (iterator.Find ("variablesBindedToCurves"))
                                variablesBindedToCurvesSerialized = iterator.current;
                        else
                                Debug.LogError ("MecananimNode should have public field 'variablesBindedToCurves'");

                        curves = (AnimationCurve[])curvesSerialized.value;
                        curveColors = (Color[])curvesColorsSerialized.value;
                        variablesBindedToCurves = (UnityVariable[])variablesBindedToCurvesSerialized.value;

                        AnimationModeUtility.ResetBindingsTransformPropertyModification (clipBindingsSerialized.value as EditorClipBinding[]);
                        AnimationModeUtility.ResetBindingTransformPropertyModification (__mecanimNodeClipBinding);

                        keyframeTimeValues = new float[0];
                        eventTimeValuesPrev = new float[0];

                        keyframeTimeValuesSelected = new bool[0];
                        keyframesDisplayNames = new string[0];

                        ///////////// create Reordable list of gameObject-animationClip //////////////////

                        __gameObjectClipList = new ReorderableList (clipBindingsSerialized.value as IList, typeof(EditorClipBinding), true, true, true, true);
                        __gameObjectClipList.drawElementCallback = onDrawElement;

                        __gameObjectClipList.drawHeaderCallback = onDrawHeaderElement;

                        __gameObjectClipList.onRemoveCallback = onRemoveCallback;
                        __gameObjectClipList.onAddCallback = onAddCallback;
                        __gameObjectClipList.onSelectCallback = onSelectCallback;

                        //__gameObjectClipList.elementHeight = 32f;

                        if (MecanimNodeEditorWindow.__window != null)//restore last
                                position = __window.position;

                        MecanimNodeEditorWindow.__window = (MecanimNodeEditorWindow)EditorWindow.GetWindow (typeof(MecanimNodeEditorWindow));

                        if (position.HasValue)
                                MecanimNodeEditorWindow.__window.position = position.Value;

                        MecanimNodeEditorWindow.__window.Show ();
        }
Beispiel #9
0
        /// <summary>
        /// Draws the node inspector.
        /// <param name="target">The node that is being inspected.</param>
        /// </summary>
        public void DrawNode (ActionNode target) {
            // Create style?
            if (s_Styles == null)
                s_Styles = new NodeEditor.Styles();

            if (target == null) {
                m_SerializedNode = null;
                m_Target = null;
                m_TargetContent = GUIContent.none;
                m_TargetIconContent = GUIContent.none;
                m_TargetType = string.Empty;
            }
            // The target node has changed?
            else if (m_SerializedNode == null || m_SerializedNode.target != target) {
                m_SerializedNode = new SerializedNode(target);
                m_Target = target;

                Type targetType = m_Target.GetType();
                m_TargetType = " (" + targetType.Name + ")";
                var nodeInfo = AttributeUtility.GetAttribute<NodeInfoAttribute>(targetType, false) ?? new NodeInfoAttribute();
                m_TargetContent = new GUIContent(target.name + m_TargetType, null, nodeInfo.description);
                m_TargetIconContent = new GUIContent(IconUtility.GetIcon(targetType));

                // Update Values
                m_SerializedNode.Update();
            }

            // The serialized node is not null?
            if (m_SerializedNode != null) {
                // Draw node title
                this.DrawTitle();

                if (m_Target != null && BehaviourWindow.IsVisible(m_Target.instanceID)) {
                    // Draw node properties
                    this.OnInspectorGUI();

                    // Update target content?
                    if (Event.current.type == EventType.Used && m_Target != null) {
                        m_TargetContent.text = m_Target.name + m_TargetType;
                    }
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Shows the node generic menu.
        /// </summary>
        void ShowNodeContextMenu () {
            var menu = new GenericMenu();

            menu.AddItem(new GUIContent("Reset"), false, delegate {StateUtility.ResetNode(target); m_SerializedNode = new SerializedNode(target); m_SerializedNode.Update();});
            menu.AddSeparator(string.Empty);
            menu.AddItem(new GUIContent("Copy"), false, delegate {BehaviourTreeUtility.nodeToPaste = target;});
            menu.AddSeparator(string.Empty);
            if (target != null) {
                menu.AddItem(new GUIContent("Find Script"), false, delegate {
                    MonoScript script = BehaviourTreeUtility.GetNodeScript(target.GetType());
                    if (script != null)
                        EditorGUIUtility.PingObject(script);
                });
                menu.AddItem(new GUIContent("Edit Script"), false, delegate {
                    MonoScript script = BehaviourTreeUtility.GetNodeScript(target.GetType());
                    if (script != null)
                        AssetDatabase.OpenAsset(script);
                });
            }
            else {
                menu.AddDisabledItem(new GUIContent("Find Script"));
                menu.AddDisabledItem(new GUIContent("Edit Script"));
            }

            menu.ShowAsContext();
        }