public void SetParent(AT_ContainerNode node) { // Ensure we're not parenting the node to itself if (node != this) { #if UNITY_EDITOR SetDirty(); #endif // If the node has a parent if (Parent != null) { // Remove the node from the parent Parent.RemoveChild(this); } // Set the new parent in the tree Parent = node; // Set the gameObject's parent to maintain the Unity heirarchy gameObject.transform.parent = node.gameObject.transform; } else { Debug.LogWarning("AT_Node: Failed to parent node because node and parent are the same node"); } }
public void Init( EditorWindow window ) { // Load in texture resources m_lineTexture = ( Texture2D )Resources.Load( "Line Texture 2" ); m_arrowTexture = ( Texture2D )Resources.Load( "ArrowHead" ); m_icons = new Texture2D[6]; m_icons[0] = (Texture2D)Resources.Load("Icon - StateMachine"); m_icons[1] = (Texture2D)Resources.Load("Icon - BlendGraph"); m_icons[2] = (Texture2D)Resources.Load("Icon - Animation"); m_icons[3] = (Texture2D)Resources.Load("Icon - Blend"); m_icons[4] = (Texture2D)Resources.Load("Icon - AddBlend"); m_icons[5] = (Texture2D)Resources.Load("Icon - Pose"); // Init editor to safe state m_editorWindow = window; m_selectedAnimationTree = null; m_Windows.Clear(); m_activeContainer = null; ActiveWindow = null; Dragging = false; ConnectionStart = null; ConnectionEnd = null; m_camerScaleAmount = new Vector2(1, 1); // Find all the enabled animation trees m_activeAnimationTrees = GameObject.FindObjectsOfType(typeof(AnimationTree)) as AnimationTree[]; }
public void Update() { if ( m_selectedAnimationTree != null && m_selectedAnimationTree.IsDirty ) { CheckForDirtyNodes(m_selectedAnimationTree.Root); m_selectedAnimationTree.IsDirty = false; } if ( Selection.activeGameObject != null ) { // Get the current selection from Unity GameObject go = Selection.activeGameObject; // Get the tree the current selection belongs to AnimationTree currentTree = GetAnimationTree( go ); // If a child of an animation tree is currently selected... if (currentTree != null) { GameObject firstChild = go; // Make sure the firstChild points to an AT_Node not the AnimationTree base object if (currentTree.gameObject == go ) { firstChild = currentTree.Root.gameObject; } m_currentNode = firstChild.GetComponent<AT_Node>(); AT_ContainerNode contParent; // If the root is not selected, find the closest container node to the selected node if (firstChild != currentTree.Root.gameObject) { if (m_currentNode != null && m_currentNode.Parent != null) { contParent = FindNextContainerNode(m_currentNode.Parent.gameObject); } else { contParent = FindNextContainerNode(firstChild.transform.parent.gameObject); } } else { // If the root is selected, it is the active container contParent = firstChild.GetComponent<AT_ContainerNode>(); } // Change the control variables node's parent to the currently selected container. // This allows us to view and select the control variables node while inside any // container node without altering what the active container node is if (m_selectedAnimationTree != null && m_activeContainer != null) { m_selectedAnimationTree.m_controlVarsNode.Parent = m_activeContainer; } // If we've selected a new container node, rebuild the tree graph if ( contParent != m_activeContainer ) { m_activeContainer = contParent; RebuildTreeGraph(); } // If the control variables window doesn't exist, create it if (m_controlVarsWindow == null) { RefreshVariablesWindow(); } } m_selectedAnimationTree = currentTree; } else { m_selectedAnimationTree = null; } }
// Draw the GUI used for selecting animation trees void DrawAnimTreeSelectionGUI() { EditorGUIUtility.LookLikeControls (); string[] trees = new string[m_activeAnimationTrees.Length + 2]; trees[0] = "None"; trees[1] = ""; int counter = 2; int selected = 0; foreach (AnimationTree tree in m_activeAnimationTrees) { if (tree != null) { trees[counter] = tree.name; if (m_selectedAnimationTree == tree) { selected = counter; } counter++; } } GUILayout.Label("Animation Tree:", GUILayout.ExpandWidth(false)); int newSel = EditorGUILayout.Popup(selected, trees, GUILayout.ExpandWidth(false)); if (newSel != selected) { if (newSel <= 1) { Selection.activeGameObject = null; } else { Selection.activeGameObject = m_activeAnimationTrees[newSel-2].gameObject; } m_controlVarsWindow = null; m_activeContainer = null; m_selectedAnimationTree = null; m_Windows.Clear(); } }