public override void Clear(bool destroyNodes) { base.Clear(destroyNodes); this.m_ParameterValues.Clear(); this.m_RootBlendTree = null; this.m_RootNode = null; }
public override void DoBackgroundClickAction() { base.selection.Clear(); UnityEditor.Graphs.AnimationBlendTree.Node rootNode = (base.graph as UnityEditor.Graphs.AnimationBlendTree.Graph).rootNode; base.selection.Add(rootNode); Selection.activeObject = rootNode.motion; }
private void ArrangeNodeRecursive(UnityEditor.Graphs.AnimationBlendTree.Node node, int depth) { if (node.isLeaf && (node.parent != null)) { Rect position = node.position; position.y = this.m_VerticalLeafOffset; position.x = (depth * 270f) + 70f; position.x += Mathf.PingPong((node.childIndex + 0.5f) / ((float)node.parent.children.Count), 0.5f) * 20f; node.position = position; this.m_VerticalLeafOffset += position.height + 5f; } else if (node.children.Count != 0) { float verticalLeafOffset = this.m_VerticalLeafOffset; float positiveInfinity = float.PositiveInfinity; float negativeInfinity = float.NegativeInfinity; foreach (UnityEditor.Graphs.AnimationBlendTree.Node node2 in node.children) { this.ArrangeNodeRecursive(node2, depth + 1); positiveInfinity = Mathf.Min(positiveInfinity, node2.position.y); negativeInfinity = Mathf.Max(negativeInfinity, node2.position.y); } Rect rect2 = node.position; rect2.y = (positiveInfinity + negativeInfinity) * 0.5f; rect2.x = (depth * 270f) + 70f; node.position = rect2; this.m_VerticalLeafOffset = Mathf.Max((float)(15f + this.m_VerticalLeafOffset), (float)((verticalLeafOffset + rect2.height) + 15f)); } }
private void CreateNodeFromAnimationClip(AnimationClip clip, UnityEditor.Graphs.AnimationBlendTree.Node parentNode) { UnityEditor.Graphs.AnimationBlendTree.Node node = this.CreateNode(clip, clip.name); node.parent = parentNode; Slot fromSlot = parentNode.AddOutputSlot(clip.name); Slot toSlot = node.AddInputSlot((parentNode.motion as BlendTree).name); this.Connect(fromSlot, toSlot); }
private void DeleteNodeCallback(object obj) { UnityEditor.Graphs.AnimationBlendTree.Node node = obj as UnityEditor.Graphs.AnimationBlendTree.Node; if (node != null) { string[] toDelete = new string[] { node.motion.name }; if (DeleteNodeDialog(toDelete)) { UnityEditor.Graphs.AnimationBlendTree.Node[] nodes = new UnityEditor.Graphs.AnimationBlendTree.Node[] { node }; this.blendTreeGraph.RemoveNodeMotions(nodes); this.blendTreeGraph.BuildFromBlendTree(this.blendTreeGraph.rootBlendTree); } } }
private UnityEditor.Graphs.AnimationBlendTree.Node CreateNode(Motion motion, string name) { UnityEditor.Graphs.AnimationBlendTree.Node node = UnityEditor.Graphs.Node.Instance <UnityEditor.Graphs.AnimationBlendTree.Node>(); node.hideFlags = HideFlags.HideAndDontSave; node.name = name; node.motion = motion; BlendTree tree = motion as BlendTree; float num = 0f; if (tree != null) { num = tree.recursiveBlendParameterCount * 20f; } node.position = new Rect(0f, 0f, 200f, 50f + num); this.AddNode(node); return(node); }
private void HandleNodeInput(UnityEditor.Graphs.AnimationBlendTree.Node node) { Event current = Event.current; if ((current.type == EventType.MouseDown) && (current.button == 0)) { base.selection.Clear(); base.selection.Add(node); Selection.activeObject = node.motion; UnityEditor.Graphs.AnimationBlendTree.Node rootNode = this.blendTreeGraph.rootNode; if (((current.clickCount == 2) && (node.motion is UnityEditor.Animations.BlendTree)) && (rootNode != node.motion)) { base.selection.Clear(); Stack <UnityEditor.Graphs.AnimationBlendTree.Node> stack = new Stack <UnityEditor.Graphs.AnimationBlendTree.Node>(); for (UnityEditor.Graphs.AnimationBlendTree.Node node3 = node; (node3.motion is UnityEditor.Animations.BlendTree) && (node3 != rootNode); node3 = node3.parent) { stack.Push(node3); } foreach (UnityEditor.Graphs.AnimationBlendTree.Node node4 in stack) { this.m_Tool.AddBreadCrumb(node4.motion); } } current.Use(); } if ((current.type == EventType.MouseDown) && (current.button == 1)) { GenericMenu menu = new GenericMenu(); UnityEditor.Animations.BlendTree motion = node.motion as UnityEditor.Animations.BlendTree; if (motion != null) { menu.AddItem(new GUIContent("Add Motion"), false, new GenericMenu.MenuFunction2(this.CreateMotionCallback), motion); menu.AddItem(new GUIContent("Add Blend Tree"), false, new GenericMenu.MenuFunction2(this.CreateBlendTreeCallback), motion); } if (node != this.blendTreeGraph.rootNode) { menu.AddItem(new GUIContent("Delete"), false, new GenericMenu.MenuFunction2(this.DeleteNodeCallback), node); } menu.ShowAsContext(); Event.current.Use(); } }
private void CreateNodeFromBlendTreeRecursive(BlendTree blendTree, UnityEditor.Graphs.AnimationBlendTree.Node parentNode) { UnityEditor.Graphs.AnimationBlendTree.Node node = this.CreateNode(blendTree, blendTree.name); if (parentNode != null) { node.parent = parentNode; Slot fromSlot = parentNode.AddOutputSlot(blendTree.name); Slot toSlot = node.AddInputSlot((parentNode.motion as BlendTree).name); this.Connect(fromSlot, toSlot); } else { this.m_RootBlendTree = blendTree; this.m_RootNode = node; } int childCount = blendTree.GetChildCount(); for (int i = 0; i < childCount; i++) { Motion childMotion = blendTree.GetChildMotion(i); if (childMotion == null) { this.CreateEmptySlot(node); } else if (childMotion is BlendTree) { this.CreateNodeFromBlendTreeRecursive(childMotion as BlendTree, node); } else { if (!(childMotion is AnimationClip)) { throw new NotImplementedException("Unknown Motion type:" + childMotion.GetType()); } this.CreateNodeFromAnimationClip(childMotion as AnimationClip, node); } } }
private void CreateEmptySlot(UnityEditor.Graphs.AnimationBlendTree.Node parentNode) { parentNode.AddOutputSlot(""); }
public override void NodeGUI(UnityEditor.Graphs.Node n) { UnityEditor.Graphs.AnimationBlendTree.Node node = n as UnityEditor.Graphs.AnimationBlendTree.Node; UnityEditor.Animations.BlendTree motion = node.motion as UnityEditor.Animations.BlendTree; GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(200f) }; GUILayout.BeginVertical(options); foreach (Slot slot in n.inputSlots) { base.LayoutSlot(slot, this.LimitStringWidth(slot.title, 180f, UnityEditor.Graphs.Styles.varPinIn), false, false, false, UnityEditor.Graphs.Styles.varPinIn); } foreach (Slot slot2 in n.outputSlots) { base.LayoutSlot(slot2, this.LimitStringWidth(slot2.title, 180f, UnityEditor.Graphs.Styles.varPinOut), false, false, false, UnityEditor.Graphs.Styles.varPinOut); } n.NodeUI(this); EditorGUIUtility.labelWidth = 50f; if (motion != null) { if (motion.recursiveBlendParameterCount > 0) { for (int i = 0; i < motion.recursiveBlendParameterCount; i++) { string recursiveBlendParameter = motion.GetRecursiveBlendParameter(i); float recursiveBlendParameterMin = motion.GetRecursiveBlendParameterMin(i); float recursiveBlendParameterMax = motion.GetRecursiveBlendParameterMax(i); EventType type = Event.current.type; if ((Event.current.button != 0) && Event.current.isMouse) { Event.current.type = EventType.Ignore; } if (Mathf.Approximately(recursiveBlendParameterMax, recursiveBlendParameterMin)) { recursiveBlendParameterMax = recursiveBlendParameterMin + 1f; } EditorGUI.BeginChangeCheck(); float parameterValue = EditorGUILayout.Slider(GUIContent.Temp(recursiveBlendParameter, recursiveBlendParameter), this.blendTreeGraph.GetParameterValue(recursiveBlendParameter), recursiveBlendParameterMin, recursiveBlendParameterMax, new GUILayoutOption[0]); if (EditorGUI.EndChangeCheck()) { this.blendTreeGraph.SetParameterValue(recursiveBlendParameter, parameterValue); InspectorWindow.RepaintAllInspectors(); } if (Event.current.button != 0) { Event.current.type = type; } } } else { EditorGUILayout.LabelField("No blend parameter to display", new GUILayoutOption[0]); } if (node.animator != null) { List <UnityEditor.Graphs.Edge> list = new List <UnityEditor.Graphs.Edge>(n.outputEdges); node.UpdateAnimator(); if (this.m_Weights.Length != list.Count) { this.m_Weights = new float[list.Count]; } BlendTreePreviewUtility.GetRootBlendTreeChildWeights(node.animator, 0, node.animator.GetCurrentAnimatorStateInfo(0).fullPathHash, this.m_Weights); for (int j = 0; j < list.Count; j++) { UnityEditor.Graphs.AnimationBlendTree.Node node2 = list[j].toSlot.node as UnityEditor.Graphs.AnimationBlendTree.Node; node2.weight = node.weight * this.m_Weights[j]; list[j].color = node2.weightEdgeColor; } } } GUILayout.EndVertical(); this.HandleNodeInput(n as UnityEditor.Graphs.AnimationBlendTree.Node); }