public void OnArrowClicked(Arrow_CellEditor _arrow) { if (_arrow == arrowUp) { CreateAndAttachChildNode(ENodePosition.EAbove); } else if (_arrow == arrowDown) { CreateAndAttachChildNode(ENodePosition.EBelow); } else if (_arrow == arrowRight) { CreateAndAttachChildNode(ENodePosition.ERight); } else if (_arrow == arrowLeft) { CreateAndAttachChildNode(ENodePosition.ELeft); } else { Debug.Log("ERROR : OnArrowClicked received arrow that doesn't belong to node"); } }
private void InstantiateArrows() { GameObject arr; switch (eType) { case ENodeType.EBase: if (childAbove == null) { arr = InstantiateArrow(new Vector3(0, 0, 1.5f), Quaternion.Euler(90, 0, 0)); arrowUp = arr.GetComponent <Arrow_CellEditor>(); } if (childBelow == null) { arr = InstantiateArrow(new Vector3(0, 0, -1.5f), Quaternion.Euler(-90, 0, 0)); arrowDown = arr.GetComponent <Arrow_CellEditor>(); } if (childLeft == null) { arr = InstantiateArrow(new Vector3(-1.5f, 0, 0), Quaternion.Euler(0, 0, 90)); arrowLeft = arr.GetComponent <Arrow_CellEditor>(); } if (childRight == null) { arr = InstantiateArrow(new Vector3(1.5f, 0, 0), Quaternion.Euler(0, 0, -90)); arrowRight = arr.GetComponent <Arrow_CellEditor>(); } break; case ENodeType.ESplit: case ENodeType.ENormal: if (childAbove == null && ePositionToParent != ENodePosition.EBelow) { arr = InstantiateArrow(transform.position + new Vector3(0, 0, 1.5f), Quaternion.Euler(90, 0, 0)); arrowUp = arr.GetComponent <Arrow_CellEditor>(); } if (childBelow == null && ePositionToParent != ENodePosition.EAbove) { arr = InstantiateArrow(transform.position + new Vector3(0, 0, -1.5f), Quaternion.Euler(-90, 0, 0)); arrowDown = arr.GetComponent <Arrow_CellEditor>(); } if (childLeft == null && ePositionToParent != ENodePosition.ERight) { arr = InstantiateArrow(transform.position + new Vector3(-1.5f, 0, 0), Quaternion.Euler(0, 0, 90)); arrowLeft = arr.GetComponent <Arrow_CellEditor>(); } if (childRight == null && ePositionToParent != ENodePosition.ELeft) { arr = InstantiateArrow(transform.position + new Vector3(1.5f, 0, 0), Quaternion.Euler(0, 0, -90)); arrowRight = arr.GetComponent <Arrow_CellEditor>(); } break; case ENodeType.ESingle: if (ePositionToParent == ENodePosition.EAbove && childAbove == null) { arr = InstantiateArrow(transform.position + new Vector3(0, 0, 1.5f), Quaternion.Euler(90, 0, 0)); arrowUp = arr.GetComponent <Arrow_CellEditor>(); } else if (ePositionToParent == ENodePosition.EBelow && childBelow == null) { arr = InstantiateArrow(transform.position + new Vector3(0, 0, -1.5f), Quaternion.Euler(-90, 0, 0)); arrowDown = arr.GetComponent <Arrow_CellEditor>(); } else if (childLeft == null && ePositionToParent == ENodePosition.ELeft) { arr = InstantiateArrow(transform.position + new Vector3(-1.5f, 0, 0), Quaternion.Euler(0, 0, 90)); arrowLeft = arr.GetComponent <Arrow_CellEditor>(); } else if (childRight == null && ePositionToParent == ENodePosition.ERight) { arr = InstantiateArrow(transform.position + new Vector3(1.5f, 0, 0), Quaternion.Euler(0, 0, -90)); arrowRight = arr.GetComponent <Arrow_CellEditor>(); } break; case ENodeType.EEnd: break; default: Debug.Log("FATAL ERROR : Node has unknown type when instantiating arrows"); break; } }
public void CreateAndAttachChildNode(ENodePosition _ePosition) { Vector3 childPos = Vector3.zero; Quaternion childRot = Quaternion.Euler(Vector3.zero); ENodeType eChildType = ENodeType.ENormal; if (eType != ENodeType.EBase) { List <Node_CellEditor> armNodes = GetAllNodesOfArm(); //this node is also in there as the last node so we have to take the node at index lenth -2 Node_CellEditor parentNode = armNodes[armNodes.Count - 2]; if (parentNode != null) { Vector3 pos = transform.position; Vector3 parPos = parentNode.transform.position; Vector3 dir = (pos - parPos).normalized; childPos = dir * DISTANCE_AVERAGE; float rot = StaticMaths.FindLookAtAngle2D(pos, parPos); //maybe pos and childPos or parPos and childPos childRot = Quaternion.Euler(0f, rot, 0f); //childRot = gameObject.transform.rotation; if ((ePositionToParent == ENodePosition.ERight && _ePosition == ENodePosition.EAbove) || (ePositionToParent == ENodePosition.ELeft && _ePosition == ENodePosition.EBelow)) { childPos = new Vector3(-childPos.z, childPos.y, childPos.x); } else if ((ePositionToParent == ENodePosition.EAbove && _ePosition == ENodePosition.ELeft) || (ePositionToParent == ENodePosition.EBelow && _ePosition == ENodePosition.ERight)) { childPos = new Vector3(-childPos.z, childPos.y, childPos.x); } else if ((ePositionToParent == ENodePosition.ERight && _ePosition == ENodePosition.EBelow) || (ePositionToParent == ENodePosition.ELeft && _ePosition == ENodePosition.EAbove)) { childPos = new Vector3(childPos.z, childPos.y, -childPos.x); } else if ((ePositionToParent == ENodePosition.EAbove && _ePosition == ENodePosition.ERight) || (ePositionToParent == ENodePosition.EBelow && _ePosition == ENodePosition.ELeft)) { childPos = new Vector3(childPos.z, childPos.y, -childPos.x); } } else { Debug.Log("FATAL ERROR : non-base node doesn't have parent node. "); } } else { childPos = transform.position; eChildType = ENodeType.ESingle; switch (_ePosition) { case ENodePosition.EAbove: childPos.z += DISTANCE_AVERAGE; break; case ENodePosition.EBelow: childPos.z -= DISTANCE_AVERAGE; break; case ENodePosition.ERight: childPos.x += DISTANCE_AVERAGE; break; case ENodePosition.ELeft: childPos.x -= DISTANCE_AVERAGE; break; } } childPos += transform.position; //These ifs make sure that you can't create a child node on the socket where a parent node is attached if (_ePosition == ENodePosition.EAbove && ePositionToParent != ENodePosition.EBelow) { GameObject chA = Instantiate(NODE_TEMPLATE, childPos, childRot); chA.transform.parent = transform; childAbove = chA.GetComponent <Node_CellEditor>(); childAbove.PostConstructor(eChildType, _ePosition, this); if (arrowUp != null) { Destroy(arrowUp.gameObject); arrowUp = null; } } else if (_ePosition == ENodePosition.ERight && ePositionToParent != ENodePosition.ELeft) { GameObject chR = Instantiate(NODE_TEMPLATE, childPos, childRot); chR.transform.parent = transform; childRight = chR.GetComponent <Node_CellEditor>(); childRight.PostConstructor(eChildType, _ePosition, this); if (arrowRight != null) { Destroy(arrowRight.gameObject); arrowRight = null; } } else if (_ePosition == ENodePosition.EBelow && ePositionToParent != ENodePosition.EAbove) { GameObject chB = Instantiate(NODE_TEMPLATE, childPos, childRot); chB.transform.parent = transform; childBelow = chB.GetComponent <Node_CellEditor>(); childBelow.PostConstructor(eChildType, _ePosition, this); if (arrowDown != null) { Destroy(arrowDown.gameObject); arrowDown = null; } } else if (_ePosition == ENodePosition.ELeft && ePositionToParent != ENodePosition.ERight) { GameObject chL = Instantiate(NODE_TEMPLATE, childPos, childRot); chL.transform.parent = transform; childLeft = chL.GetComponent <Node_CellEditor>(); childLeft.PostConstructor(eChildType, _ePosition, this); if (arrowLeft != null) { Destroy(arrowLeft.gameObject); arrowLeft = null; } } if (eType != ENodeType.EBase) { parentNode.UpdateNodeType(); } else { UpdateNodeType(); } }