void Start ()
    {
        grid = GetComponent<Grid>();
        requestManager = GetComponent<PathRequestManager>();
        consumePathQ = new Queue<Stack<Node>>();
        TrafficIntensityTimer.gameTime = GameObject.Find("HUDGameTime").GetComponent<GameTime>();
        poison = false;

        ModifiedBFS();
        initProducer();
        initConsumers();
    }
Пример #2
0
 public void ReCalcPath()
 {
     PathRequestManager.RequestPath(transform.position, target.position, OnPathFound);
 }
Пример #3
0
 public void FindPath(IGrid grid, Vector3 start, Vector3 target, PathRequestManager requestManager)
 {
     StartCoroutine(CalculatePath(grid, start, target, requestManager));
 }
Пример #4
0
 // Use this for initialization
 void Start()
 {
     PathRequestManager.RequestPath(transform.position, target.position, OnPathFound);
 }
Пример #5
0
 void Awake()
 {
     requestManager = GetComponent<PathRequestManager> ();
     grid = GetComponent<Grid> ();
 }
Пример #6
0
    /// <summary>
    /// Awake this instance.  Gets a PathRequestManager component
    /// as well as a Grid component.
    /// </summary>
    void Awake()
    {
        requestManager = GetComponent<PathRequestManager>();
        grid=GetComponent<Grid>();

        TestFileRecord.CreateFile(String.Format("{0:yyy-MM-dd HH.mm.ss}__{1}.txt", DateTime.Now, "TestFile"));
    }
Пример #7
0
 void Awake()
 {
     grid = ResourceGrid.Grid;
     requestManager = GetComponent<PathRequestManager>();
 }
Пример #8
0
 void Awake()
 {
     pInstance    = this;
     mPathfinding = GetComponent <Pathfinding>();
 }
Пример #9
0
 // Start is called before the first frame update
 void Start()
 {
     StartCoroutine(UpdatePath());
     PathRequestManager.RequestPath(new PathRequest(transform.position, target.position, OnPathFound));
 }
 void Move()
 {
     PathRequestManager.RequestPath(transform.position, target, OnPathFound);
 }
Пример #11
0
 private void Awake()
 {
     requestManager = GetComponent <PathRequestManager>();
     grid           = GameObject.FindGameObjectWithTag("Grid").GetComponent <Grid>();
 }
Пример #12
0
    public override IEnumerator Update()
    {
        // 적을 찾는다.
        List <Unit> enemies = FindEnemiesWithTag();

        // 조건. 적이 없다면.
        if (enemies.Count <= 0)
        {
            yield return(new WaitForSeconds(sc.GetRandomDelay()));

            yield break;
        }

        // 가장 가까운 적을 찾는다.
        Unit target = GetClosest(enemies);

        sc.target = target;

        // 조건. 사거리 내에 있는지 확인한다.
        // 사거리 내에 있다면, 상태를 변경한다.
        if (IsInAttackrange())
        {
            // 왼쪽이 0
            int dir = (sc.target.transform.position.x - controller.Position.x < 0) ? 0 : 1;
            controller.modelTr.rotation = Quaternion.Euler(new Vector3(0, 180 * dir, 0));

            sc.ChangeState(sc.attackState);
            yield break;
        }

        // 사거리내에 없다면.
        // 사이에 장애물이 있는지 확인한다.
        if (CheckAround())
        {
            PathRequestManager.RequestPath(new PathRequest(controller.Position, target.transform.position, OnPathFound));
        }

        else
        {
            if (follow != null)
            {
                controller.StopCoroutine(follow);
                follow = null;
            }
            follow = sc.StartCoroutine(this.FollowTarget());
        }
        var range = UnityEngine.Random.Range(0, 100);

        if (range <= 10)
        {
            if (YellowBean.SoundManager.Instance != null)
            {
                if (sc.tag.CompareTo("Yellow") == 0)
                {
                    YellowBean.SoundManager.Instance.PlaySFX(string.Format("y_battle{0}", UnityEngine.Random.Range(0, 7)));
                }
                else
                {
                    YellowBean.SoundManager.Instance.PlaySFX(string.Format("g_battle{0}", UnityEngine.Random.Range(0, 9)));
                }
            }
        }

        yield return(new WaitForSeconds(sc.GetRandomDelay()));

        sc.ChangeState(sc.chaseSate);
    }
Пример #13
0
 void Awake()
 {
     map = GetComponent<AStarMap>();
     requestManager = GetComponent<PathRequestManager>();
 }
Пример #14
0
 // Script must be on the same gameobject to work
 void Awake()
 {
     // make reference
     requestManager = GetComponent<PathRequestManager>();
     grid = GetComponent<Grid>();
 }
Пример #15
0
    Grid grid;//get grid script
    //Scripts


    void Awake() {
		requestManager = GetComponent<PathRequestManager>();
		grid = GetComponent<Grid>();//gets the grit info
    }
Пример #16
0
	void Awake(){
		heatmanager = GetComponent<HeatMapManager>();
		grid = GetComponentInParent<Grid>();
		pathManager = GetComponent<PathRequestManager>();
	}
Пример #17
0
 private void Awake()
 {
     m_grid           = GetComponent <Grid> ();
     m_requestManager = GetComponent <PathRequestManager> ();
 }
Пример #18
0
 // Use this for initialization
 void Awake()
 {
     NodeGrid = GetComponent<Grid>();
     RequestManager = GetComponent<PathRequestManager>();
 }
Пример #19
0
 private void Awake()
 {
     requestManager = GetComponent <PathRequestManager>();
     grid           = GetComponent <NodeGraph>();
 }
 void Awake()
 {
     instance = this;
     pathFinding = GetComponent<FindPath>();
 }
Пример #21
0
 private void Awake()
 {
     this.requestManager = this.GetComponent <PathRequestManager>();
     this.grid           = this.GetComponent <NavGrid>();
 }
Пример #22
0
 void Start()
 {
     grid = Grid.Instance;
     requestManager = GetComponent<PathRequestManager>();
 }
Пример #23
0
 void Awake()
 {
     grid           = GetComponent <Graph> ();
     requestManager = GetComponent <PathRequestManager> ();
 }
Пример #24
0
	void Awake(){
		manager = this;
		pathFinding = GetComponent<PathFinding>(); 
	}
Пример #25
0
 public void RequestPathInstantly()
 {
     PathRequestManager.RequestPath(transform.position, player.position, OnPathFound);
 }
Пример #26
0
 public void findPlayer()
 {
     PathRequestManager.RequestPath(transform.position, target.position, OnPathFound);
 }
Пример #27
0
 private void Awake()
 {
     instance    = this;
     pathfinding = GetComponent <Astar>();
 }
Пример #28
0
        public IEnumerator CalculatePath(IGrid grid, Vector3 startPos, Vector3 targetPos, PathRequestManager requestManager)
        {
            if (grid == null)
            {
                yield break;
            }

            Vector3[] waypoints = new Vector3[0];
            bool      pathFound = false;

            INode startNode  = grid.NodeFromWorldPosition(startPos);
            INode targetNode = grid.NodeFromWorldPosition(targetPos);

            var openSet   = new Heap <INode>(grid.NodeCount);
            var closedSet = new HashSet <INode>();

            openSet.Add(startNode);

            while (openSet.Count > 0)
            {
                INode currentNode = openSet.Unshift();
                closedSet.Add(currentNode);

                if (currentNode == targetNode)
                {
                    pathFound = true;
                    break;
                }

                AnalyzeNeighbourNodes(grid, currentNode, targetNode, openSet, closedSet);
            }

            yield return(null);

            if (pathFound)
            {
                waypoints = RetracePath(startNode, targetNode);
            }

            if (requestManager != null)
            {
                requestManager.OnProcessingFinished(waypoints, pathFound);
            }
        }
Пример #29
0
 void Awake() {
     navigationGrid = GetComponent<NavigationGridMap>();
     requestManager = GetComponent<PathRequestManager>();
 }
Пример #30
0
    private void OnTriggerEnter(Collider collision)
    {
        if (collision.gameObject.name.Contains("Rock") || collision.gameObject.name.Contains("Cube"))
        {
            UnityEngine.Debug.Log("i hit a rock");
            avoided = true;
            if (collision.gameObject.transform.position.x < transform.position.x)
            {
                walkLeft = true;
            }
            else
            {
                walkLeft = false;
            }

            myNode    = Grid.instance.NodeFromWorldPoint(transform.position);
            previousX = myNode.gridX;
            previousY = myNode.gridY;

            int targetX = (walkLeft == false) ? myNode.gridX - 1 : myNode.gridX + 1;
            int targetY = myNode.gridY - 1;

            if (targetX >= Grid.instance.GridSizeX)
            {
                targetY -= 1;
            }
            else if (targetX < 0)
            {
                targetX = 0;
            }

            targetNode       = Grid.instance.NodeFromXY(targetX, targetY);
            targetPosition   = targetNode.worldPosition;
            targetPosition.y = transform.position.y;
            yChangedCount   += 1;
        }



        if (collision.gameObject.name.Contains("Sawmill"))
        {
            UnityEngine.Debug.Log("i hit a Sawmill");
            millPos   = Grid.instance.NodeFromWorldPoint(collision.gameObject.transform.position).worldPosition;
            millPos.y = transform.position.y;
            foundMill = true;

            Grid.instance.DiscoveredNode(myId, Grid.instance.NodeFromWorldPoint(collision.gameObject.transform.position).gridX, Grid.instance.NodeFromWorldPoint(collision.gameObject.transform.position).gridY);
            Grid.instance.DiscoveredNodes(myId, Grid.instance.NodeFromWorldPoint(collision.gameObject.transform.position));

            if (foundMill == true && foundTree == true)
            {
                if (treeCut == false)
                {
                    PathRequestManager.RequestPath(myId, transform.position, treePos, OnPathFound);
                    searching = false;
                    UnityEngine.Debug.Log("done2");
                    action = 1;
                }
                else
                {
                    sw.Stop();
                    UnityEngine.Debug.Log("done by " + myId);
                    print("Task Complete: " + sw.ElapsedMilliseconds + " ms");
                    UnityEngine.Debug.Log("TREEE IS GONE N");
                    action = 2;
                }
            }
        }


        if (collision.gameObject.name.Contains("Tree"))
        {
            UnityEngine.Debug.Log("i hit a Tree");
            treePos   = Grid.instance.NodeFromWorldPoint(collision.gameObject.transform.position).worldPosition;
            treePos.y = transform.position.y;
            foundTree = true;
            Grid.instance.DiscoveredNode(myId, Grid.instance.NodeFromWorldPoint(collision.gameObject.transform.position).gridX, Grid.instance.NodeFromWorldPoint(collision.gameObject.transform.position).gridY);
            Grid.instance.DiscoveredNodes(myId, Grid.instance.NodeFromWorldPoint(collision.gameObject.transform.position));

            if (foundMill == true && foundTree == true)
            {
                if (treeCut == false)
                {
                    collision.gameObject.SetActive(false);
                    searching = false;
                    treeCut   = true;
                    UnityEngine.Debug.Log("cutting tree");
                    action = 1;
                    PathRequestManager.RequestPath(myId, transform.position, millPos, OnPathFound);
                }
            }
        }

        if (collision.gameObject.tag == "Player")
        {
            UnityEngine.Debug.Log("sharing knowledge");
            Node[,] mygrid    = Grid.instance.GetGridFromID(this.gameObject.GetInstanceID());
            Node[,] othergrid = Grid.instance.GetGridFromID(collision.gameObject.GetInstanceID());

            for (int x = 0; x < mygrid.GetLength(0); x++)
            {
                for (int y = 0; y < mygrid.GetLength(1); y++)
                {
                    if (mygrid[x, y].discovered)
                    {
                        Grid.instance.DiscoveredNode(collision.gameObject.GetInstanceID(), x, y, mygrid[x, y].walkable);
                        UnityEngine.Debug.Log("knowledge shared 1");
                    }
                    else if (othergrid[x, y].discovered)
                    {
                        UnityEngine.Debug.Log("knowledge shared 2");
                        Grid.instance.DiscoveredNode(myId, x, y, mygrid[x, y].walkable);
                    }
                }
            }
        }
    }
Пример #31
0
 void Awake()
 {
     _instance    = this;
     _pathFinding = GetComponent <PathFinding>();
 }
Пример #32
0
 void Awake()
 {
     requestManager = GetComponent <PathRequestManager>();
     grid           = GetComponent <Grid>();
 }
    void Awake()
    {
        requestManager = GetComponent <PathRequestManager> ();
//		grid = GetComponent<Grid> ();
//		grid = GetComponent<MapGenerator> ().MapGrid;
    }
Пример #34
0
 void Awake()
 {
     // class is an instance of itself
     instance    = this;
     pathFinding = GetComponent <Pathfinding>();
 }
Пример #35
0
 void Awake()
 {
     grid           = GetComponent <Grid>();
     requestManager = GetComponent <PathRequestManager>();
     drawThis       = true;
 }
Пример #36
0
 void Awake()
 {
     instance    = this;
     pathfinding = GetComponent <Pathfinding>();
 }
Пример #37
0
    /// <summary>
    /// Update del jugador en cada frame, si es su turno
    /// </summary>
    public void UpdatePlayer()
    {
        Ray        cameraRay = Camera.main.ScreenPointToRay(Input.mousePosition); // posición del raycast donde está el mouse
        RaycastHit hit;
        GridNode   selectedNode = null;

        if (Physics.Raycast(cameraRay, out hit, 100f, _groundMask))
        {
            selectedNode = PathRequestManager.RequestNodeFromWorldPosition(hit.point); // obtiene el nodo de la grid bajo el mouse
        }
        if (type == PlayerType.User)                                                   // Update del equipo del jugador
        {
            if (selectedNode != null && Input.GetMouseButtonDown(0))
            {
                OnPlayerLeftClick(selectedNode); //Comprobar  input del jugador
            }
        }
        else // Update del equipo controlado por la IA
        {
            Unit chip = team.units[_enemyIndex];

            if (chip != _selectedUnit)
            {
                GridNode selectedNodeChip = chip.GetGridNode(); // obtiene el nodo de la grid bajo de la ficha
                UnitSelection(chip);                            // _selectedUnit pasa a ser chip y se muestrean las casillas accesibles

                _enemyTimer = 0;
                _movida     = false;
            }
            else if (_enemyTimer >= _hoverTime * 1.5)
            {
                if (!_movida)
                {
                    GridNode newNode;
                    newNode = BestNodeSelection(chip); // devuelve la mejor casilla accesible

                    if (newNode == null)
                    {
                        chip.EnableUnit(false);                 // si no hay buenos resultados, no hacer nada
                    }
                    else
                    {
                        OnSelectedUnit(newNode);  // se mueve al nodo elegido y lo deselecciona
                    }
                    _movida = true;
                }
                _enemyIndex++;
            }
            else
            {
                _enemyTimer += Time.deltaTime;
            }
        }

        //Si el mouse del jugador simplemente se encuentra encima de una casilla no vacia
        if (selectedNode != null)
        {
            //Comprobar si esta ocupada por una unidad
            if (selectedNode.isOccupied != null && selectedNode.isOccupied.tag == "Unit")
            {
                Unit unit = (Unit)selectedNode.isOccupied;

                if (unit != _hoveredUnit) //Comprobar si es una unidad diferente
                {
                    UnitInfoManager.instance.HideLevelInfo();
                    UnitInfoManager.instance.HideAdvantageInfo();

                    _hoverTimer  = 0;
                    _hoveredUnit = unit;
                }
                else //Si es el mismo
                {
                    if (_hoverTimer >= _hoverTime) //Ha pasado el tiempo minimo para que
                    {
                        UnitInfoManager.instance.ShowLevelInfo(_hoveredUnit);                         //Mostrar nivel

                        if (_selectedUnit != null && _selectedUnit.unitTeam != _hoveredUnit.unitTeam) //Si tenemos otra unidad seleccionada y sobre la que  estamos es de otro equipo
                        {
                            UnitInfoManager.instance.ShowAdvantageInfo(_selectedUnit, _hoveredUnit);  //Mostrar ventaja en combate
                        }
                    }
                    else
                    {
                        _hoverTimer += Time.deltaTime;
                    }
                }
            }
            else
            {
                UnitInfoManager.instance.HideAdvantageInfo();
                UnitInfoManager.instance.HideLevelInfo();
            }
        }
    }
Пример #38
0
 public void Awake()
 {
     requestManager = GetComponent<PathRequestManager>();
 }
Пример #39
0
 private void Awake()
 {
     instance         = this;
     pathfinding      = GetComponent <Pathfinding>();
     pathRequestQueue = new Queue <PathRequest>();
 }
Пример #40
0
 void Start() {
     managerContext = this;
     targetFinder = GetComponent<PathFinding>();
 }
Пример #41
0
    Pathfinding pathfinding;            // Reference to the pathfinding script



    // Executes at the start of a game
    private void Awake()
    {
        instance    = this;                         // Makes sure there is only one instance of the class ?
        pathfinding = GetComponent <Pathfinding>(); // Loads the pathfinding functions
    }
Пример #42
0
 void Awake()
 {
     requestManager = GetComponent <PathRequestManager>();
     grid           = GetComponent <QuadTree>();
 }
 void RequestPathToTarget(Transform target)
 {
     PathRequestManager.RequestPath(new PathRequest(entity.transform.position, target.position, OnPathFound));
 }
Пример #44
0
 void Awake()
 {
     instance = this;
     PathFinder = GetComponent<PathFinding>();
 }
 void RequestPathToTarget(Vector3 target)
 {
     PathRequestManager.RequestPath(new PathRequest(entity.transform.position, target, OnPathFound));
     //Debug.Log("Target: " + target);
     lineOnScreen(target);
 }
Пример #46
0
 void Awake()
 {
     requestManager = GetComponent<PathRequestManager>();
     grid = GetComponent<QuadTree>();
 }
Пример #47
0
 private void Awake()
 {
     requestManger = GetComponent <PathRequestManager>();
     grid          = this.GetComponent <NodeGrid>();
 }
 void Awake()
 {
     instance = this;
     pathfinding = GetComponent<Pathfinding> ();
 }
	void Awake()
	{
		requestManager = GetComponent<PathRequestManager>();
		sphericalGrid = GetComponent<SphericalGrid>();
	}