public void SetPedestrianNode(Tooltip a_tooltip, PedestrianNode a_obj, bool a_show = true) { switch (a_tooltip) { case Tooltip.ANCHOR: { AnchorNode = a_obj; if (a_obj) { PreviousAnchorNode = a_obj; } if (AnchorNode) { ShowTooltip(Tooltip.ANCHOR, a_show); PositionTooltip(Tooltip.ANCHOR, AnchorNode.gameObject); } } break; case Tooltip.EDIT: { EditNode = a_obj; if (a_obj) { PreviousEditNode = a_obj; } if (EditNode) { ShowTooltip(Tooltip.EDIT, a_show); PositionTooltip(Tooltip.EDIT, EditNode.gameObject); } } break; } }
public void AddNode( PedestrianNode a_node ) { if(NodeExists(a_node)) return; m_nodes.Add( a_node ); }
public bool NodeExists( PedestrianNode a_node ) { for(int nIndex = 0; nIndex < m_nodes.Count; nIndex++) { if(m_nodes[nIndex] == a_node) return true; } return false; }
public bool HasVisitedNode( PedestrianNode a_node ) { for(int nIndex = 0; nIndex < m_prevPedestrianNodes.Length; nIndex++) { if(m_prevPedestrianNodes[nIndex] == a_node) return true; } return false; }
void Awake() { if(!m_node && GetComponent<PedestrianNode>()) m_node = GetComponent<PedestrianNode>(); if(GetComponent<Rigidbody>()) GetComponent<Rigidbody>().useGravity = false; if(GetComponent<Collider>()) GetComponent<Collider>().isTrigger = true; }
void Awake() { PedestrianNode = (PedestrianNode)target; PedestrianNode.CleanupNodes(); }
public void RemoveNode( PedestrianNode a_node ) { m_nodes.Remove( a_node ); }
public void SetPedestrianNode( Tooltip a_tooltip, PedestrianNode a_obj, bool a_show = true ) { switch(a_tooltip) { case Tooltip.ANCHOR: { AnchorNode = a_obj; if(a_obj) PreviousAnchorNode = a_obj; if(AnchorNode) { ShowTooltip(Tooltip.ANCHOR, a_show); PositionTooltip(Tooltip.ANCHOR, AnchorNode.gameObject); } } break; case Tooltip.EDIT: { EditNode = a_obj; if(a_obj) PreviousEditNode = a_obj; if(EditNode) { ShowTooltip(Tooltip.EDIT, a_show); PositionTooltip(Tooltip.EDIT, EditNode.gameObject); } } break; } }
void SetPedestrianNode( PedestrianSystem.Tooltip a_tooltip, PedestrianNode a_obj ) { switch(a_tooltip) { case PedestrianSystem.Tooltip.ANCHOR: { AnchorNode = a_obj; if(PedestrianSystem.Instance && AnchorNode) { //PedestrianSystem.Instance.AnchorNode = AnchorNode; PedestrianSystem.Instance.PositionTooltip(a_tooltip, AnchorNode.gameObject); } } break; case PedestrianSystem.Tooltip.EDIT: { EditNode = a_obj; if(PedestrianSystem.Instance && EditNode) { ///PedestrianSystem.Instance.EditNode = EditNode; PedestrianSystem.Instance.PositionTooltip(a_tooltip, EditNode.gameObject); } } break; } }
public void SetPedestrianNode( PedestrianNode a_piece ) { EditNode = a_piece; AnchorNode = a_piece; }
public void Spawn( Vector3 a_pos, PedestrianNode a_startNode ) { transform.position = a_pos - m_offsetPosVal; m_currentNode = a_startNode; }
void Update() { if(!m_currentNode) { DetermineSpeed( 0.0f, true ); // idle animation as we are not walking anywhere return; } Vector3 dir = m_currentNode.transform.position; dir.x += m_lanePosXVariation; dir.z += m_lanePosZVariation; dir = dir - (transform.position + m_offsetPosVal); // find the direction to the next node Vector3 speed = dir.normalized * m_currentSpeed; // work out how fast we should travel in the desired directoin if(ThresholdReached) { if(m_currentNode.m_waitAtNode) { if(m_speed != 0.0f) m_speedStoredWhileWaiting = m_speed; DetermineSpeed( 0.0f, true ); } else { if(m_speedStoredWhileWaiting != 0.0f) { DetermineSpeed(m_speedStoredWhileWaiting); m_speedStoredWhileWaiting = 0.0f; } m_prevPedestrianNodes[m_nodeVisitIndex] = m_currentNode; m_nodeVisitIndex++; if(m_nodeVisitIndex >= m_prevPedestrianNodes.Length) m_nodeVisitIndex = 0; m_currentNode = m_currentNode.NextNode( this ); // find another node or do something else ThresholdReached = false; } } else if(dir.magnitude > m_nodeThreshold) { if(GetComponent<Rigidbody>()) // if we have a rigidbody, use the following code to move us { GetComponent<Rigidbody>().velocity = speed; // set our rigidbody to this speed to move us by the determined speed if(m_lookAtNode) transform.forward = Vector3.Slerp( transform.forward, dir.normalized, m_rotationSpeed * Time.deltaTime ); // rotate our forward directoin over time to face the node we are moving towards } else // no rigidbody then use the following code to move us { if(GetComponent<Collider>()) // it generally is a bad idea to move something with a collider, so we should tell someone about it if this is happening. See Unity Docs for more info: http://docs.unity3d.com/ScriptReference/Collider.html Debug.LogWarning("Pedestrian System Warning -> Object has a collider. You should think about moving the object with a rigidbody instead."); transform.position += speed * Time.deltaTime; // move us by the determined speed if(m_lookAtNode) transform.forward = Vector3.Slerp( transform.forward, dir.normalized, m_rotationSpeed * Time.deltaTime ); // rotate our forward directoin over time to face the node we are moving towards } if(m_onlyRotYAxis) transform.rotation = Quaternion.Euler(new Vector3(0.0f, transform.eulerAngles.y, 0.0f)); // only rotate around the Y axis. } else ThresholdReached = true; }