Пример #1
0
 public PathNode(Vector3 position, Grid.Node node)
 {
     this.position = position;
     this.node     = node;
     speedCost     = 0;
     carCost       = 0;
 }
Пример #2
0
        public static PathFinder CreateInstance()
        {
            instance         = new PathFinder();
            instance.manager = GameplayManager.Instance.GetManager <Grid.Manager>();
            instance.nodes   = new PathNode[instance.manager.SizeX, instance.manager.SizeZ];

            Vector3 posNode = Vector3.up;

            for (int z = 0; z < instance.manager.SizeZ; ++z)
            {
                posNode.z = z;
                for (int x = 0; x < instance.manager.SizeX; ++x)
                {
                    posNode.x = x;
                    Grid.Node node = instance.manager.GetNode(posNode);
                    if (node)
                    {
                        PathNode n = new PathNode(posNode, node);
                        instance.nodes[x, z] = n;
                    }
                }
            }

            return(instance);
        }
Пример #3
0
        public void Initialize()
        {
            Grid.Manager grid = GameplayManager.Instance.GetManager <Grid.Manager>();
            districts = new List <Grid.Node>();
            Vector3 nodePosition = new Vector3();

            for (int z = 0; z < grid.SizeZ; ++z)
            {
                nodePosition.z = z;
                for (int x = 0; x < grid.SizeX; ++x)
                {
                    nodePosition.x = x;
                    Grid.Node node = grid.GetNode(nodePosition);
                    if (node)
                    {
                        node.AddOnChangeType(AddDestination);
                    }
                }
            }

            for (int i = 0; i < carPrefab.Length; ++i)
            {
                carPrefab[i].poolCar = new List <Driver>();
            }
        }
Пример #4
0
 private void AddDestination(Grid.Node node)
 {
     if (node.NodeType != Grid.ENodeType.District)
     {
         districts.Remove(node);
     }
     else
     {
         districts.Add(node);
     }
 }
Пример #5
0
        private Grid.Node GetDestination(Grid.Node node)
        {
            int index = Random.Range(0, districts.Count);

            while (districts[index] == node)
            {
                index = Random.Range(0, districts.Count);
            }

            return(districts[index]);
        }
Пример #6
0
        /*public Driver Spawn(Grid.Node node)
         * {
         *      int index = Random.Range(0, carPrefab.Length);
         *      Grid.Node destination = GetDestination(node);
         *      Driver obj = carPrefab[index].CreateCar(node.GetPosition() + Vector3.up * .51f);
         *      Grid.Node[] p = Pathfinding.PathFinder.GetPath(node.GetPosition(), destination.GetPosition());
         *
         *      obj.SetPath(p);
         *
         *      InvokeOnSpawn(obj);
         *
         *      return obj;
         * }*/

        public Driver Spawn(Grid.Node node, Grid.Node destination)
        {
            int index = Random.Range(0, carPrefab.Length);
            //Grid.Node newDestination = destination;
            Driver obj = carPrefab[index].CreateCar(node.GetPosition() + Vector3.up * .51f);

            Grid.Node[] p = Pathfinding.PathFinder.GetPath(node.GetPosition(), destination.GetPosition());

            obj.SetPath(p);

            InvokeOnSpawn(obj);
            VictoryConditions.Instance.allCars.Add(obj);

            return(obj);
        }
Пример #7
0
 private void Patience()
 {
     if (pathTween.IsPlaying())
     {
         return;
     }
     isStopped = true;
     timer    += Time.deltaTime;
     if (timer > 2.5f)
     {
         //gameObject.SetActive(false);
         node = null;
         pathTween.Play();
         isStopped = false;
     }
 }
Пример #8
0
 private bool MoveOnIntersection()
 {
     if (node.CanDrive(this))
     {
         if (!pathTween.IsPlaying())
         {
             pathTween.Play();
         }
         node = null;
     }
     else if (pathTween.IsPlaying())
     {
         pathTween.Pause();
     }
     return(pathTween.IsPlaying());
 }
Пример #9
0
 private void TouchDown(SInputTouch touch)
 {
     if (touch.overGUI)
     {
         return;
     }
     if (touch.gameObject == null)
     {
         typeSelectionTransform.gameObject.SetActive(false);
     }
     else
     {
         gridNodeSelected = touch.gameObject.GetComponent <Grid.Node>();
         if (gridNodeSelected)
         {
             typeSelectionTransform.gameObject.SetActive(gridNodeSelected.NodeType == Grid.ENodeType.Intersection);
             //typeSelectionTransform.position = Camera.main.WorldToScreenPoint(gridNodeSelected.GetPosition() + Vector3.up * .5f);
         }
     }
     InvokeOnOpenSelection(gameObject.activeInHierarchy);
 }
Пример #10
0
        private void NextNode()
        {
            if (indexNodePath == nodePath.Length)
            {
                gameObject.SetActive(false);
                return;
            }

            Vector3 previousDirection = nodePath[indexNodePath - 1].GetPosition();
            Vector3 nextDirection     = indexNodePath + 1 < nodePath.Length ? nodePath[indexNodePath + 1].GetPosition() : transform.position;

            Vector3[] waypoints = nodePath[indexNodePath].GetWaypoint(previousDirection, nextDirection);

            node = nodePath[indexNodePath++];
            if (waypoints == null)
            {
                Debug.LogWarning("No Path on Node : " + nodePath[indexNodePath - 1]);
                return;
            }
            TweenParams tParam = new TweenParams().SetSpeedBased(true).SetEase(Ease.Linear);

            tParam.OnComplete(NextNode);
            pathTween = transform.DOPath(waypoints, speed, PathType.CatmullRom).SetLookAt(0f).SetAs(tParam);
        }