Ejemplo n.º 1
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;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Behaviour Machine callback called whenever the active node changes.
        /// </summary>
        private void ActiveNodeChanged()
        {
            // Get the active node
            ActionNode activeNode = this.GetActiveNode();

            if (activeNode != null)
            {
                // Create an editor node for the active node
                m_NodeEditor = activeNode == null ? null : NodeEditor.CreateEditor(activeNode.GetType());
            }

            // Repaint this inspector
            this.Repaint();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reset the supplied node properties.
        /// <param name="node">The node to be reseted.</param>
        /// </summary>
        public static void ResetNode(ActionNode node)
        {
            // Get the owner as an Uniyt object
            var ownerUnityObj = node != null ? node.owner as UnityEngine.Object : null;

            // Validate parameters
            if (ownerUnityObj != null)
            {
                // Register Undo
                #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
                Undo.RegisterUndo(ownerUnityObj, "Reset Node");
                #else
                Undo.RecordObject(ownerUnityObj, "Reset Node");
                #endif

                node.name = node.GetType().Name;
                node.Reset();
                node.OnValidate();
                StateUtility.SetDirty(node.owner);
            }
        }
Ejemplo n.º 4
0
        public static NodeLinkedList compile(LinkedListNode <Token> firstToken)
        {
            CompiledStatement cs = CompilerFactory.Instance.CreateCompiledStatement(firstToken);

            Compiled = cs.compile(ref firstToken);
            while (firstToken != null)
            {
                cs = CompilerFactory.Instance.CreateCompiledStatement(firstToken);
                NodeLinkedList nll = cs.compile(ref firstToken);
                Compiled.Add(nll);
            }
            ActionNode a = Compiled.First;

            while (a != null)
            {
                Console.WriteLine(a.GetType());
                a = a.Next;
            }

            return(Compiled);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Updates the active node data.
        /// <param name="activeNode">The active node.</param>
        /// </summary>
        void UpdateActiveNode(ActionNode activeNode)
        {
            var activeNodeType = activeNode != null?activeNode.GetType() : null;

            // The active node type has changed?
            if (activeNodeType != m_ActiveNodeType)
            {
                if (activeNode == null)
                {
                    m_ActiveNodeType     = null;
                    m_ActiveNodeInfo     = null;
                    m_ActiveNodeIcon     = null;
                    m_ActiveNodeTypeName = string.Empty;
                    return;
                }
                else
                {
                    m_ActiveNodeType     = activeNodeType;
                    m_ActiveNodeInfo     = AttributeUtility.GetAttribute <NodeInfoAttribute>(m_ActiveNodeType, true) ?? new NodeInfoAttribute();
                    m_ActiveNodeIcon     = IconUtility.GetIcon(m_ActiveNodeType);
                    m_ActiveNodeTypeName = " (" + m_ActiveNodeType.Name + ")";
                }
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Class constructor. Create SerializedNode for inspected object.
 /// <param name="target">The node to get the be inspected.</param>
 /// </summary>
 public SerializedNode(ActionNode target)
 {
     m_Target       = target;
     m_Type         = m_Target.GetType();
     m_RecreateData = true;
 }
Ejemplo n.º 7
0
        //
        // Methods
        //



        /// <summary>
        /// Handles the onGUI event.
        /// </summary>
        /// <param name="property">Property.</param>
        /// <param name="node">Node.</param>
        /// <param name="guiContent">GUI content.</param>
        public override void OnGUI(SerializedNodeProperty property, ActionNode node, GUIContent guiContent)
        {
            //if (animatorSerialized == null || aniController == null) {
            if (aniController == null)
            {
                //!!! Serialization never serialized Animator cos its initialized in Reset after
//								NodePropertyIterator iter= property.serializedNode.GetIterator();
//								iter.Find(attribute.animatorFieldName);
//								 animatorSerialized=iter.current;
                //				//								if(animatorSerialized==null || animatorSerialized.value==null){
                //										Debug.LogError("AnimatorStateNodePropertyDrawer> No Animator component set on node parent GameObject");
                //									return;
                //								}

                //runtimeContoller =( (Animator)animatorSerialized.value).runtimeAnimatorController;
                Animator animator = node.GetType().GetField(attribute.animatorFieldName).GetValue(node) as Animator;



                RuntimeAnimatorController runtimeContoller;


                runtimeContoller = animator.runtimeAnimatorController;

                if (runtimeContoller is AnimatorOverrideController)
                {
                    aniController = ((AnimatorOverrideController)runtimeContoller).runtimeAnimatorController as UnityEditor.Animations.AnimatorController;
                }
                else
                {
                    aniController = runtimeContoller as UnityEditor.Animations.AnimatorController;
                }
            }



            animatorStateDisplayOptions = MecanimUtility.GetDisplayOptions(aniController);
            animatorStateValues         = MecanimUtility.GetAnimatorStates(aniController);



            if (property.value != null)
            {
                if (animatorStateValues.Length > 0)
                {
                    animatorStateSelectedPrev = animatorStateSelected = animatorStateValues.FirstOrDefault((itm) => itm.nameHash == ((ws.winx.unity.AnimatorState)property.value).nameHash);
                }
            }


            animatorStateSelected = EditorGUILayoutEx.CustomObjectPopup(guiContent, animatorStateSelected, animatorStateDisplayOptions, animatorStateValues);                                     //,compare);



            //TODO try Begin/End Check
            if (animatorStateSelectedPrev != animatorStateSelected)
            {
                NodePropertyIterator iter = property.serializedNode.GetIterator();
                iter.Find(attribute.layerIndexFieldName);
                SerializedNodeProperty layerIndexSerialized = iter.current;

                layerIndexSerialized.value = MecanimUtility.GetLayerIndex(aniController, animatorStateSelected);
                layerIndexSerialized.ApplyModifiedValue();



                ws.winx.unity.AnimatorState state = property.value as ws.winx.unity.AnimatorState;
                if (state == null)
                {
                    state = ScriptableObject.CreateInstance <ws.winx.unity.AnimatorState>();
                }

                state.motion   = animatorStateSelected.motion;
                state.nameHash = animatorStateSelected.nameHash;
                state.layer    = (int)layerIndexSerialized.value;

                if (state.motion is UnityEditor.Animations.BlendTree)
                {
                    BlendTree tree           = (BlendTree)state.motion;
                    int       blendParamsNum = tree.GetRecursiveBlendParamCount();

                    state.blendParamsHashes = new int[blendParamsNum];

                    for (int i = 0; i < blendParamsNum; i++)
                    {
                        state.blendParamsHashes[i] = Animator.StringToHash(tree.GetRecursiveBlendParam(i));
                    }
                }
                else
                {
                    state.blendParamsHashes = null;
                }

                //property.value=state;
                property.ValueChanged();


                property.ApplyModifiedValue();

                animatorStateSelectedPrev = animatorStateSelected;
            }



            if (animatorStateSelected.motion == null)
            {
                Debug.LogError("Selected state doesn't have Motion set");
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Draw a node.
        /// <param name="rect">The rect to draw the node.</param>
        /// <param name="index">The index of the node to be drawn.</param>
        /// <param name="selected">The node is selected?</param>
        /// <param name="focused">The node is being focused?</param>
        /// </summary>
        private void DrawNode(Rect rect, int index, bool selected, bool focused)
        {
            ActionNode[] nodes = m_ActionState.GetNodes();

            if (index < 0 || index >= nodes.Length)
            {
                return;
            }

            // Get the node
            ActionNode node = nodes[index];

            Event current = Event.current;

            switch (current.type)
            {
            case EventType.Repaint:
                // Get the node id
                int nodeId = node.instanceID;
                // Create the gui content
                var guiContent = new GUIContent(node.name, IconUtility.GetIcon(node.GetType()));
                // Get the guiStyle
                var guiStyle = InternalActionStateEditor.s_Styles.label;

                // Set style color
                if (node is ConditionNode)
                {
                    guiStyle.normal.textColor  = TreeGUI.Yellow;
                    guiStyle.focused.textColor = TreeGUI.Yellow;
                }
                else if (node is MissingNode)
                {
                    guiStyle.normal.textColor  = TreeGUI.Red;
                    guiStyle.focused.textColor = TreeGUI.Red;
                }
                else if (node is BranchNode)
                {
                    guiStyle.normal.textColor  = s_Styles.textColor;
                    guiStyle.focused.textColor = s_Styles.textColor;
                }
                // else if (node is ICallbackNode) {
                //     guiStyle.normal.textColor = TreeGUI.Blue;
                //     guiStyle.focused.textColor = TreeGUI.Blue;
                // }
                else
                {
                    guiStyle.normal.textColor  = TreeGUI.Green;
                    guiStyle.focused.textColor = TreeGUI.Green;
                }

                // Draw the node name and icon
                Rect nodeRect = rect;
                nodeRect.yMin += 1;
                nodeRect.yMax -= 4;
                guiStyle.Draw(nodeRect, guiContent, focused, focused, selected, focused);

                // Draw visual debugging?
                if (Application.isPlaying && m_NodeStatusTime.ContainsKey(nodeId))
                {
                    var pingStyle = InternalActionStateEditor.s_Styles.ping;
                    var pingRect  = nodeRect;
                    pingRect.xMax  = pingStyle.CalcSize(guiContent).x + (guiContent.image.height > 16f ? 0f : 28f);
                    pingRect.xMin -= 8f;
                    pingRect.yMin += 1f;
                    pingRect.yMax -= 1f;
                    // pingRect.y += 1f;
                    // pingRect.height -= 2f;

                    // Get the delta time
                    var dt = (float)(EditorApplication.timeSinceStartup - m_NodeStatusTime[nodeId].time);

                    // Set gui color
                    Color oldColor = GUI.color;
                    switch (m_NodeStatusTime[nodeId].status)
                    {
                    case Status.Success:
                        GUI.color = new Color(0f, .8f, 0f, 1f - dt);            // green
                        break;

                    case Status.Failure:
                        GUI.color = new Color(.8f, .8f, 0f, 1f - dt);           // yellow
                        break;

                    case Status.Error:
                        GUI.color = new Color(.8f, 0f, 0f, 1f - dt);            // red
                        break;

                    case Status.Running:
                        GUI.color = new Color(0f, 0f, 1f, .6f - dt);            // blue
                        break;
                    }

                    // Draw ping for one second
                    if (dt >= 1f)
                    {
                        m_NodeStatusTime.Remove(nodeId);
                    }

                    // Draw ping
                    pingStyle.Draw(pingRect, guiContent, false, false, false, false);
                    // Restore old gui color
                    GUI.color = oldColor;
                }
                break;

            case EventType.MouseDown:
                if (current.button == 1 && rect.Contains(current.mousePosition))
                {
                    NodeContextMenu(node);
                    current.Use();
                }
                break;
            }
        }