private void ClicOnEmptyField(Vector2 mousePos) { selectedTransition = null; selectedNode = null; selectedNodesID.Clear(); StartSelectingMultipleNodes(mousePos); }
private bool IsNodeSelected(MotionMatchingNode node) { if (selectedNode != null) { if (selectedNode.ID == node.ID) { return(true); } } if (selectedNodesID.Contains(node.ID)) { return(true); } return(false); }
private void RemoveNode(MotionMatchingNode node) { switch (node.nodeType) { case MotionMatchingNodeType.State: selectedLayer.RemoveState(node.stateIndex); break; case MotionMatchingNodeType.Portal: selectedLayer.RemovePortal(node.ID); break; case MotionMatchingNodeType.Contact: selectedLayer.RemoveState(node.stateIndex); break; } }
private bool SelectOutput(Vector2 mousePos) { for (int i = 0; i < selectedLayer.nodes.Count; i++) { if (selectedLayer.nodes[i].output.Contains(mousePos)) { selectedNodesID.Clear(); selectedNode = null; selectedInputNode = null; selectedTransition = null; drawTransitionToMousePos = true; selectedOutputNode = i; return(true); } } return(false); }
private bool SelectTransition(Vector2 mousePos) { foreach (MotionMatchingState s in selectedLayer.states) { foreach (Transition t in s.transitions) { if (t.transitionRect.Contains(mousePos)) { selectedNodesID.Clear(); selectedNode = null; selectedOutputNode = null; selectedInputNode = null; selectedTransition = t; return(true); } } } return(false); }
private bool SelectNode(Vector2 mousePos) { for (int i = 0; i < selectedLayer.nodes.Count; i++) { if (selectedLayer.nodes[i].rect.Contains(mousePos)) { if (!selectedNodesID.Contains(selectedLayer.nodes[i].ID)) { selectedNodesID.Clear(); } selectedTransition = null; selectedOutputNode = null; selectedInputNode = null; moveNodes = true; startMouseDownPosition = mousePos; selectedNode = selectedLayer.nodes[i]; selectedLayer.MoveNodeOnTop(i); return(true); } } return(false); }
private void MakingTransition(Vector2 mousePos) { if (drawTransitionToMousePos) { for (int i = 0; i < selectedLayer.nodes.Count; i++) { MotionMatchingNode n = selectedLayer.nodes[i]; if (n.nodeType == MotionMatchingNodeType.State) { if (n.rect.Contains(mousePos) || n.input.Contains(mousePos) || n.output.Contains(mousePos)) { if (selectedInputNode != null) { selectedLayer.MakeTransition( n.stateIndex, selectedLayer.nodes[(int)selectedInputNode].stateIndex, selectedLayer.nodes[(int)selectedInputNode].ID, selectedLayer.nodes[(int)selectedInputNode].nodeType == MotionMatchingNodeType.Portal ); break; } else if (selectedOutputNode != null) { selectedLayer.MakeTransition( selectedLayer.nodes[(int)selectedOutputNode].stateIndex, n.stateIndex, n.ID, n.nodeType == MotionMatchingNodeType.Portal ); break; } } } else if (n.nodeType == MotionMatchingNodeType.Portal) { if (n.rect.Contains(mousePos) || n.input.Contains(mousePos)) { if (selectedOutputNode != null) { selectedLayer.MakeTransition( selectedLayer.nodes[(int)selectedOutputNode].stateIndex, n.stateIndex, n.ID, n.nodeType == MotionMatchingNodeType.Portal ); break; } } } else if (n.nodeType == MotionMatchingNodeType.Contact) { if (n.rect.Contains(mousePos) || n.output.Contains(mousePos)) { if (selectedInputNode != null) { selectedLayer.MakeTransition( n.stateIndex, selectedLayer.nodes[(int)selectedInputNode].stateIndex, selectedLayer.nodes[(int)selectedInputNode].ID, selectedLayer.nodes[(int)selectedInputNode].nodeType == MotionMatchingNodeType.Portal ); break; } } } } } }
private bool SelectingElements(Vector2 mousePos) { for (int i = 0; i < selectedLayer.nodes.Count; i++) { if (selectedLayer.nodes[i].input.Contains(mousePos) && selectedLayer.nodes[i].nodeType != MotionMatchingNodeType.Contact) { selectedNodesID.Clear(); //selectedNode = null; //selectedTransition = null; selectedOutputNode = null; drawTransitionToMousePos = true; selectedInputNode = i; return(true); } if (selectedLayer.nodes[i].output.Contains(mousePos) && selectedLayer.nodes[i].nodeType != MotionMatchingNodeType.Portal) { selectedNodesID.Clear(); //selectedNode = null; //selectedTransition = null; selectedInputNode = null; drawTransitionToMousePos = true; selectedOutputNode = i; return(true); } if (selectedLayer.nodes[i].nodeType != MotionMatchingNodeType.Portal) { foreach (Transition t in selectedLayer.states[selectedLayer.nodes[i].stateIndex].transitions) { if (t.transitionRect.Contains(mousePos)) { selectedNodesID.Clear(); selectedNode = null; selectedOutputNode = null; selectedInputNode = null; if (selectedTransition == t) { selectedTransition = null; } else { selectedTransition = t; } return(true); } } } int nodeIndex = selectedLayer.nodes.Count - 1 - i; if (selectedLayer.nodes[nodeIndex].rect.Contains(mousePos)) { if (!selectedNodesID.Contains(selectedLayer.nodes[nodeIndex].ID)) { selectedNodesID.Clear(); } selectedTransition = null; selectedOutputNode = null; selectedInputNode = null; moveNodes = true; startMouseDownPosition = mousePos; selectedNode = selectedLayer.nodes[nodeIndex]; selectedLayer.MoveNodeOnTop(nodeIndex); return(true); } } return(false); }
private void GenericMenuCallback(object action) { switch (action) { case GraphGenericMenuActions.AddMotionMatchingState: selectedLayer.AddState( "New State", MotionMatchingStateType.MotionMatching, GetNewStateID(), mousePosition ); break; case GraphGenericMenuActions.AddSingleAnimationState: selectedLayer.AddState( "New State", MotionMatchingStateType.SingleAnimation, GetNewStateID(), mousePosition ); break; case GraphGenericMenuActions.AddContactState: selectedLayer.AddState( "New State", MotionMatchingStateType.ContactAnimationState, GetNewStateID(), mousePosition ); break; case GraphGenericMenuActions.RemoveState: if (selectedNode != null) { RemoveNode(selectedNode); selectedNode = null; } if (selectedNodesID.Count > 0) { for (int i = 0; i < selectedLayer.nodes.Count; i++) { if (selectedNodesID.Contains(selectedLayer.nodes[i].ID)) { selectedNodesID.Remove(selectedLayer.nodes[i].ID); RemoveNode(selectedLayer.nodes[i]); i--; } } selectedNodesID.Clear(); } break; case GraphGenericMenuActions.RemoveTransition: foreach (MotionMatchingState s in selectedLayer.states) { for (int i = 0; i < s.transitions.Count; i++) { if (s.transitions[i].transitionRect == selectedTransition.transitionRect) { s.RemoveTransition(selectedTransition.nextStateIndex); selectedTransition = null; return; } } } break; case GraphGenericMenuActions.SetAsStartState: selectedLayer.SetStartState(selectedNode.stateIndex); break; case GraphGenericMenuActions.ShowNodes: Vector2 delta = Vector3.zero; foreach (MotionMatchingNode n in selectedLayer.nodes) { delta += n.rect.center; } delta /= selectedLayer.nodes.Count; delta = rectCentre - delta; foreach (MotionMatchingNode n in selectedLayer.nodes) { n.Move(delta); } break; case GraphGenericMenuActions.AddPortalToState: selectedLayer.AddPortal(mousePosition, GetNewStateID()); break; case GraphGenericMenuActions.ShowOriginalNode: Vector2 delta_2 = Vector2.zero; foreach (MotionMatchingNode n in selectedLayer.nodes) { if (n.nodeType == MotionMatchingNodeType.State && n.stateIndex == selectedNode.stateIndex) { delta_2 = rectCentre - n.rect.center; } } foreach (MotionMatchingNode n in selectedLayer.nodes) { n.Move(delta_2); } break; } }