public void RemoveElement(PuzzleElement element) { PuzzleContainer container = puzzle.GetElementContainer(element); ContainerFront containerFront = null; foreach (ContainerFront current in nodes) { if (current.container == container) { containerFront = current; } } foreach (ContainerFront current in edges) { if (current.container == container) { containerFront = current; } } if (containerFront == null) { return; } containerFront.SetElement(null); }
private void SetState(PuzzleStateNode newState, bool animate) { PuzzleStateNode lastState = state; m_State = newState; stateChangeTime = Time.time; if (animate) { itemChangeTime = stateChangeTime + itemDelay; doneTime = stateChangeTime; } else { itemChangeTime = stateChangeTime; doneTime = stateChangeTime; } bool itemChange = false; foreach (var element in puzzle.dynamicElements) { object oldVal = puzzle.GetElementValue(lastState.state, element); object newVal = puzzle.GetElementValue(newState.state, element); if (!newVal.Equals(oldVal)) { PuzzleContainer container = puzzle.GetElementContainer(element); ContainerFront front = GetContainer(container); StartCoroutine(front.AnimateValue((bool)oldVal, (bool)newVal, animate)); itemChange = true; } } if (itemChange && animate) { doneTime += itemAndEffectDuration; } bool movement = false; foreach (var item in puzzle.items) { PuzzleNode oldNode = puzzle.GetItemNode(lastState.state, item); PuzzleNode newNode = puzzle.GetItemNode(newState.state, item); if (newNode != oldNode) { movement = true; } ItemFront front = GetItem(item); // Animate regardless of whether old and new node are the same. // Movement of other items may cause static item to change offset. StartCoroutine(front.AnimateNode(oldNode, newNode, state, animate)); } if (movement && animate) { itemChangeTime += moveDuration; doneTime += moveDuration; } }
public void OnContainerMouseExit(ContainerFront container) { if (playing) { return; } if (s_Hovered == container) { s_Hovered = null; } }
public void OnContainerMouseEnter(ContainerFront container) { if (playing) { return; } if (IsValidHover(container)) { s_Hovered = container; } }
public void UpdateReceiver(PuzzleReceiverElement receiver) { PuzzleContainer c = puzzle.puzzle.GetElementContainer(receiver); ContainerFront containerFront = puzzle.GetContainer(c); if (containerFront == null) { return; } Vector3 end = containerFront.GetElementPosition(); LineRenderer line = m_Lines[receiver]; UpdateReceiver(line, end, false); }
public void Reset() { undoStack.Clear(); m_State = puzzle.startNode; foreach (var element in puzzle.dynamicElements) { PuzzleContainer container = puzzle.GetElementContainer(element); ContainerFront front = GetContainer(container); front.SetElement(element); } foreach (var item in puzzle.items) { PuzzleNode newNode = item.defaultNode; ItemFront front = GetItem(item); front.SetNodePos(newNode, state); } }
public void OnContainerMouseDown(ContainerFront container) { if (playing) { return; } s_Selected = container; s_MouseDownWorldPos = GetMousePos(); s_MouseDownNodePos = container.transform.position; s_DraggingThresholdPassed = false; NodeFront nodeFront = container as NodeFront; if (tool == MouseTool.Move) { s_DragStartNode = nodeFront; } if (tool == MouseTool.Connect) { if (nodeFront != null) { s_DragStartNode = nodeFront; s_TempDragEdge.gameObject.SetActive(true); s_TempDragEdge.transform.position = container.transform.position; s_TempDragEdge.transform.localScale = new Vector3(0.1f, 1, 1); } } if (tool == MouseTool.Trigger) { if (nodeFront != null && (nodeFront.container.element as PuzzleTriggerElement) != null) { s_DragStartNode = nodeFront; nodeFront.AddReceiver(s_TempDragReceiver); } } }
bool IsValidHover(ContainerFront container) { if (playing) { return(false); } if (s_DragStartNode == null) { return(true); } if (tool == MouseTool.Move) { return(false); } if (tool == MouseTool.Connect) { return(container is NodeFront && container != selected); } if (tool == MouseTool.Trigger) { return((container.container.element as PuzzleReceiverElement) != null); } return(false); }
public void OnContainerMouseUp(ContainerFront container) { }
public void OnContainerMouseOver(ContainerFront container) { }
void HandleEdgeDrag() { if (Input.GetMouseButtonUp(0)) { s_TempDragEdge.gameObject.SetActive(false); if (hovered is NodeFront && hovered != s_DragStartNode) { NodeFront hoveredNode = (hovered as NodeFront); // Add new node and edge to it. if (hovered == s_TempDragNode) { PuzzleNode newNode = new PuzzleNode(); newNode.SetPosition(VectorToPoint(Snap(hoveredNode.transform.position))); puzzle.AddNode(newNode); foreach (NodeFront node in nodes) { if (node.node == newNode) { s_Selected = node; } } PuzzleEdge edge = new PuzzleEdge(s_DragStartNode.node, newNode); puzzle.AddEdge(edge); } // Add edge to existing node. else { PuzzleEdge edge = new PuzzleEdge(s_DragStartNode.node, hoveredNode.node); puzzle.AddEdge(edge); foreach (EdgeFront edgeFront in edges) { if (edgeFront.edge == edge) { s_Selected = edgeFront; } } } } s_DragStartNode = null; s_TempDragNode.gameObject.SetActive(false); } else { Vector2 pos = GetMousePos(); if (hovered is NodeFront) { pos = hovered.transform.position; } s_TempDragEdge.SetPositions(s_TempDragEdge.transform.position, pos); Vector2 snapped = Snap(pos); Point position = VectorToPoint(snapped); bool validNew = true; if (Vector2.Distance(snapped, pos * 0.5f) > 0.25f) { validNew = false; } else { foreach (PuzzleNode node in puzzle.nodes) { if (node.position == position) { validNew = false; break; } } } s_TempDragNode.gameObject.SetActive(validNew); s_TempDragNode.SetPoint(position); } }