Пример #1
0
    // Start is called before the first frame update
    void Start()
    {
        currentIndex = 0;
        nextIndex    = 1;
        isMoving     = true;
        timer        = 0.0f;

        if (!setCustomPath)
        {
            pathToTake = AllNodes.AStar(startingPoint.GetComponent <Node>(), endingPoint.GetComponent <Node>());
        }
        pathToTake[nextIndex].isOccupied = true;
    }
Пример #2
0
    void CheckInput()
    {
        if (Input.touchCount == 1)
        {
            Touch touch = Input.GetTouch(0);
            if (touch.phase == TouchPhase.Began)
            {
                heldDowntimer = Time.time;

                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, 100.0f))
                {
                    if (hit.transform.tag == "Nodes" || hit.transform.tag == "HorizontalTouchMove" || hit.transform.tag == "VerticalMovers")
                    {
                        //transform.GetChild(0).GetComponent<Highlight>().isVisible = false;
                        destinationNode = hit.transform.GetComponent <Node>();
                    }
                }
            }
            else if (touch.phase == TouchPhase.Ended)
            {
                heldDowntimer = Time.time - heldDowntimer;

                if (heldDowntimer < 0.16f && destinationNode)
                {
                    TouchDecal.AddTouchAnimation(destinationNode.transform);
                    List <Node> tempPath = AllNodes.AStar(currentNode, destinationNode);

                    //Edge cases
                    if (tempPath.Count > 0 && tempPath[0].isOccupied)
                    {
                        if (isMoving)
                        {
                            //Occupancy set by the player
                            if (tempPath[0] != pathToDestination[0])
                            {
                                Node onlyRemainingNode = pathToDestination[0];
                                pathToDestination.Clear();
                                pathToDestination.Add(onlyRemainingNode);
                                return;
                            }
                        }
                        else
                        {
                            destinationNode = null;
                            return;
                        }
                    }

                    //If already moving, adjust
                    if (pathToDestination.Count > 0)
                    {
                        if (pathToDestination[0] != tempPath[0])
                        {
                            tempPath.Insert(0, currentNode);
                            tempPath.Insert(0, pathToDestination[0]);
                        }
                    }

                    //Set occupancy
                    pathToDestination = tempPath;
                    if (pathToDestination.Count > 0)
                    {
                        if (!isMoving)
                        {
                            currentNode.isOccupied = false;
                            isMoving = true;
                        }
                        pathToDestination[0].isOccupied = true;
                    }
                }
                else
                {
                    destinationNode = null;
                }
            }
        }
    }