コード例 #1
0
ファイル: NodeMap.cs プロジェクト: substence/DinerDash
    //This probably shouldn't do any rendering changes, perhaps NodeRenderer?
    private void UpdateOccupant(Node node, NodeOccupant occupant)
    {
        //Calculate path to target
        Node targetNode = occupant.target;

        if (targetNode != null && occupant.isPathingDirty)
        {
            occupant.path           = NodePathing.GetPath(nodes, node, targetNode, occupant);
            occupant.isPathingDirty = false;//perhaps the setter for 'path' should do this automatically?
        }

        //Move towards next node
        Node nextNode = occupant.GetNextNode();

        if (nextNode != null)
        {
            Vector3 currentPosition = occupant.graphic.transform.position;
            Vector3 targetPosition  = GetWorldPositionOfNode(nextNode);

            occupant.graphic.transform.position = Vector3.Lerp(currentPosition, targetPosition, 5f * Time.deltaTime);

            //if close enough to target node, update path
            if (Vector3.Distance(currentPosition, targetPosition) < 0.1f)
            {
                occupant.path.RemoveAt(0);
                node.occupant = null;
                SetNodeOccupant(nextNode, occupant);
            }
        }
        else
        {
            occupant.graphic.transform.position = GetWorldPositionOfNode(node);
        }
    }
コード例 #2
0
ファイル: NodeMap.cs プロジェクト: substence/DinerDash
    private void ValidateNode(Node node)
    {
        NodeOccupant occupant = node.GetFirstOccupant();

        if (!node.isPathable && occupant != null)
        {
            Node validNode = NodePathing.FindClosestPathableNode(this, node);
            if (validNode != null)
            {
                node.occupant = null;
                SetNodeOccupant(validNode, occupant);
            }
        }
    }