private NpcNode GetNearesstNpcNode() { var angle = 360f; NpcNode node = null; var o = _power > powerThrold ? _pointDataDelta.x : GetAngleWithCamera(_lastFocusNode); foreach (var n in NpcNode.nodeList) { if (n == _lastFocusNode) { continue; } var a = GetAngleWithCamera(n); if (a * o > 0) { continue; } a = Mathf.Abs(a); if (a < angle) { angle = a; node = n; } } return(node); }
public void FocusNpcNode(NpcNode rNode, float rTime = 1) { if (null == rNode || currentFocusNode == rNode) { enabled = true; return; } //自动聚焦后需要把惯性去掉 _controlRemember.Clear(); currentFocusNode?.OnLoseFocus(); currentFocusNode = rNode; RecordBackCameraData(); var autoFocus = gameObject.GetComponentDefault <CameraAutoFocus>(); autoFocus.onFocusFinish.RemoveAllListeners(); autoFocus.onFocusFinish.AddListener(() => { enabled = true; controlType = ControlType.Focus; currentFocusNode.OnGetFocus(); }); autoFocus.StartFocus(_camera, _originData, rTime); }
public void SetNode(NpcNode node) { ClearAnswers(); textDialog.text = node.content; GameObject answer; List <Node> nextNodes = board.GetNextNodes(node); if (nextNodes.Count > 0) { foreach (NpcNode n in nextNodes) { answer = Instantiate(answerTemplate, answerTransform); answer.GetComponentInChildren <Text>().text = n.choiceString; answer.GetComponent <Button>().onClick.AddListener(() => { SetNode(n); }); answer.SetActive(true); } } else { answer = Instantiate(answerTemplate, answerTransform); answer.GetComponentInChildren <Text>().text = "Leave"; answer.GetComponent <Button>().onClick.AddListener(() => { HideWindow(); }); answer.SetActive(true); } }
/// <summary> /// 相机与目标之间的Y轴角度 /// </summary> /// <param name="rNode"></param> /// <returns></returns> private float GetAngleWithCamera(NpcNode rNode) { var dir = rNode.transform.position - _camera.transform.position; var q = Quaternion.Euler(new Vector3(0, -focusAngleOffset, 0)); var r = Quaternion.LookRotation(dir) * q; var a = r.eulerAngles.y - _camera.transform.eulerAngles.y; a = Mathf.Repeat(a + 180, 360) - 180; return(a); }
private void Awake() { node = GetComponentInParent <NpcNode>(); }
/// <summary> /// Gets a start or end NpcNode Node. Returns null if a problem. If random then will use source node as starting point for separation calc, if source node null then will choose any random node /// sourceNode is only used for randomClose/Med/Long calc's, ignored for all other /// </summary> /// <param name="npcNode"></param> /// <returns></returns> private Node GetNpcNode(NpcNode npcNode, Node sourceNode = null) { Node node = null; int nodeID = -1; switch (npcNode.name) { case "Airport": nodeID = GameManager.i.cityScript.airportDistrictID; node = GameManager.i.dataScript.GetNode(nodeID); if (node == null) { Debug.LogWarningFormat("Invalid Airport node (Null) for nodeID {0}", nodeID); } break; case "Harbour": nodeID = GameManager.i.cityScript.harbourDistrictID; if (nodeID > -1) { node = GameManager.i.dataScript.GetNode(nodeID); } else { Debug.LogWarning("No Harbour district present (nodeID -1)"); if (sourceNode != null) { node = GameManager.i.dataScript.GetRandomNodeExclude(sourceNode); } else { node = GameManager.i.dataScript.GetRandomNode(); } } if (node == null) { Debug.LogWarningFormat("Invalid Harbour node (Null) for nodeID {0}", nodeID); } break; case "CityHall": nodeID = GameManager.i.cityScript.cityHallDistrictID; node = GameManager.i.dataScript.GetNode(nodeID); if (node == null) { Debug.LogWarningFormat("Invalid City Hall node (Null) for nodeID {0}", nodeID); } break; case "Icon": nodeID = GameManager.i.cityScript.iconDistrictID; if (nodeID > -1) { node = GameManager.i.dataScript.GetNode(nodeID); } else { Debug.LogWarning("No Icon district present (nodeID -1)"); if (sourceNode != null) { node = GameManager.i.dataScript.GetRandomNodeExclude(sourceNode); } else { node = GameManager.i.dataScript.GetRandomNode(); } } if (node == null) { Debug.LogWarningFormat("Invalid Icon node (Null) for nodeID {0}", nodeID); } break; case "arcCORPORATE": case "arcGATED": case "arcGOVERNMENT": case "arcINDUSTRIAL": case "arcRESEARCH": case "arcSPRAWL": case "arcUTILITY": NodeArc arc = npcNode.nodeArc; if (arc != null) { if (sourceNode != null) { node = GameManager.i.dataScript.GetRandomNode(arc.nodeArcID, sourceNode.nodeID); } else { node = GameManager.i.dataScript.GetRandomNode(arc.nodeArcID); } if (node == null) { Debug.LogWarningFormat("Invalid node (Null) for \"{0}\"", npcNode.name); } } else { Debug.LogWarningFormat("Invalid nodeArc (Null) for \"{0}\"", npcNode.name); } break; case "RandomClose": case "RandomMedium": case "RandomLong": if (sourceNode == null) { sourceNode = GameManager.i.dataScript.GetRandomNode(); } else { int distance = 0; switch (npcNode.name) { case "RandomClose": distance = randomClose; break; case "RandomMedium": distance = randomMedium; break; case "RandomLong": distance = randomLong; break; } //valid source node, get path data node = GameManager.i.dijkstraScript.GetRandomNodeAtDistance(sourceNode, distance); if (node == null) { Debug.LogWarningFormat("Invalid Random node (Null) for SourceNodeID {0}, distance {1}", sourceNode.nodeID, distance); } } break; default: Debug.LogWarningFormat("Unrecognised NpcNode \"{0}\"", npcNode.name); break; } return(node); }