コード例 #1
0
    // Move to the given object
    // Check all the paths leading to tile neibourgh from this object
    // Choose the shorten path
    // if no path exist, return false
    public bool MoveToObject(GameObject targetObj)
    {
        if (targetObj == null)
        {
            Debug.Log("Error target object null");
            return(false);
        }
        pathFindingManager.grid.ScanObstacles(); // important to check where the colliders are
        List <Node> potentialNodes = pathFindingManager.grid.GetFreeNeighbours(targetObj);
        string      str            = "";

        foreach (Node node in potentialNodes)
        {
            str += " " + node.ToString();
        }
        Debug.Log("Free nodes at:" + str);
        Queue <Node> pathToFollow = GetShortestPathToTargets(potentialNodes);

        if (pathToFollow != null && pathToFollow.Count > 0)
        {
            StartFollowingPath(PathFindingManager.ConvertPathToWorldCoord(pathToFollow));
            return(true);
        }
        else
        {
            return(false);
        }
    }
コード例 #2
0
 public override bool AButton()
 {
     return(Parent.ParentController.ParentShip.FreezeTime > -1 || DodgeBullet != null ||
            (AttackTarget != null && Vector2.Distance(Parent.ParentController.ParentShip.Position.get(), AttackTarget.Position.get()) > 300 &&
             PathFindingManager.CollisionLine(Parent.ParentController.ParentShip.Position.get(), AttackTarget.Position.get()) ||
             (isPathfinding && PathFindingManager.CollisionLine(Parent.ParentController.ParentShip.Position.get(), PathfindingTarget))));
 }
コード例 #3
0
    public void MoveTo(Vector2 newPosition)
    {
        Vector2      startPos = new Vector2(transform.position.x, transform.position.y);
        Queue <Node> nodePath = pathFindingManager.GetPathWithAStarAlgo(startPos, newPosition);

        StartFollowingPath(PathFindingManager.ConvertPathToWorldCoord(nodePath));
    }
コード例 #4
0
 void Awake()
 {
     pathFinding = GetComponent <PathFindingManager>();
     motor       = GetComponent <CharacterMotor>();
     gun         = GetComponentInChildren <ProjectileLauncher>();
     team        = GetComponent <TeamController>();
     health      = GetComponent <HealthController>();
 }
コード例 #5
0
        public override bool RightTrigger()
        {
            if (Parent.ParentController.ParentShip.FreezeTime < 1 &&
                PathFindingManager.GetAttackValue(Parent.ParentController.ParentShip.Position.get()) >
                PathFindingManager.StartingCell - 50 && WaveManager.CurrentWave > 3 && FactionManager.UnitCount > 20)
            {
                return(true);
            }

            return(base.RightTrigger());
        }
コード例 #6
0
        public override void Enter()
        {
            FactionManager.NeutralUnitCount = 0;

            MaxTimer = 500;

            do
            {
                if (WaveManager.CurrentTeamCount != -1)
                {
                    BarTeam TopBar = OverTeamBar.BarTeams[0];
                    TopBar.ListTargetPosition = FactionManager.TeamCount - 1;
                    for (int i = 1; i < OverTeamBar.BarTeams.Count; i++)
                    {
                        OverTeamBar.BarTeams[i - 1] = OverTeamBar.BarTeams[i];
                        OverTeamBar.BarTeams[i].ListTargetPosition--;
                    }
                    OverTeamBar.BarTeams[OverTeamBar.BarTeams.Count - 1] = TopBar;
                }
                WaveManager.ActiveTeam = OverTeamBar.BarTeams[0].Team;
            }while (FactionManager.TeamDead.ContainsKey(WaveManager.ActiveTeam) && FactionManager.TeamDead[WaveManager.ActiveTeam]);

            WaveManager.CurrentTeamCount++;

            if (!FactionManager.TeamStreak.ContainsKey(WaveManager.ActiveTeam))
            {
                FactionManager.TeamStreak.Add(WaveManager.ActiveTeam, 0);
            }
            else
            {
                FactionManager.TeamStreak[WaveManager.ActiveTeam]++;
            }

            if (WaveManager.CurrentTeamCount > FactionManager.TeamCount - 1)
            {
                WaveManager.CurrentTeamCount  = 0;
                WaveManager.CurrentWaveEvent += WaveManager.GameSpeed;

                if (WaveManager.CurrentWaveEvent > 1)
                {
                    WaveManager.NewWave(GameManager.GetLevel().getCurrentScene());
                    WaveManager.CurrentWaveEvent = 0;
                }
            }

            Timer    = 0;
            MaxTimer = 2000;

            PathFindingManager.Rebuild();

            base.Enter();
        }
コード例 #7
0
        private void ResetDefenseTarget()
        {
            Dictionary <MiningPlatform, float> PlatformScores = new Dictionary <MiningPlatform, float>();

            foreach (UnitBasic u in FactionManager.SortedUnits[Parent.ParentController.ParentShip.GetTeam()])
            {
                if (u.GetType().IsSubclassOf(typeof(MiningPlatform)))
                {
                    MiningPlatform m = (MiningPlatform)u;
                    if (!PlatformScores.ContainsKey(m))
                    {
                        PlatformScores.Add(m, 0);

                        foreach (UnitBasic u2 in FactionManager.SortedUnits[Parent.ParentController.ParentShip.GetTeam()])
                        {
                            if (u2.GetType().IsSubclassOf(typeof(UnitTurret)))
                            {
                                UnitTurret t2 = (UnitTurret)u2;
                                if (t2.IsAlly(Parent.ParentController.ParentShip) && !t2.Dead)
                                {
                                    PlatformScores[m] += Vector2.Distance(t2.Position.get(), m.Position.get());
                                }
                            }
                        }
                    }
                }
            }

            MiningPlatform forwardPlatform = PathFindingManager.TraceToMiningPlatform(NeutralManager.GetSpawnPosition(),
                                                                                      Parent.ParentController.ParentShip.GetTeam());

            if (forwardPlatform != null && PlatformScores.ContainsKey(forwardPlatform))
            {
                PlatformScores[forwardPlatform] *= 2;
            }

            float BestScore = 0;

            foreach (MiningPlatform m in PlatformScores.Keys)
            {
                if (PlatformScores[m] > BestScore)
                {
                    CurrentDefenseTarget = m;
                    BestScore            = PlatformScores[m];
                }
            }

            DefenseLocation = PathFindingManager.TraceCellPoint(CurrentDefenseTarget.Position.get(), 10);
        }
コード例 #8
0
    private void Awake()
    {
        S = this;

        shortestPath  = new List <Node>();
        priorityQueue = new PriorityQueue <Node>();

        startNode        = null;
        targetNode       = null;
        isStartPosSelect = true;

        searchWithAstar = false;
        searchSpeed     = 0;
        requestFrom     = null;
    }
コード例 #9
0
    private void Awake()
    {
        GridMap.SetNodeSize(1, 1);
        TSRandom.Init();
        _pfm = new PathFindingManager(1);
        //_pm = PathManager.Instance;
        _gridGraph._mapSizeX = 50;
        _gridGraph._mapSizeZ = 50;
        _gridGraph._startPos = TSVector.zero;
        _gridGraph.SetUpMap();

        _map = _gridGraph._map;    //GridMapManager.Instance.CreateGridMap(50, 50, TSVector.zero, 0, this.IsTileUnWalkable);
        PathFindingAgentBehaviour.C_DESIRED_DELTATIME = 18;
        s_AstarAgent = new SingleObjectPool <PathFindingAgentBehaviour>(10);
    }
コード例 #10
0
    private void Awake()
    {
        gameManager         = FindObjectOfType <GameManager>();
        pathFindingManager  = FindObjectOfType <PathFindingManager>();
        playerTransform     = gameManager.GetPlayerTranform();
        patrolPathGenerator = FindObjectOfType <PatrolPathGenerator>();
        foesManager         = FindObjectOfType <FoesManager>();
        avoidanceBehavior   = GetComponentInChildren <AvoidanceBehavior>();
        rigid    = GetComponent <Rigidbody2D>();
        collider = GetComponent <BoxCollider2D>();
        animator = GetComponent <Animator>();
        renderer = GetComponent <SpriteRenderer>();

        // Spawn a wandering point
        wanderingPoint = Instantiate(wanderingPointPrefab, Vector3.zero, Quaternion.identity);
    }
コード例 #11
0
        /// <summary>
        ///     The mod entry point, called after the mod is first loaded.
        /// </summary>
        /// <param name="helper">Provides simplified APIs for writing mods.</param>
        public override void Entry(IModHelper helper)
        {
            ClickToMoveHelper.Init(this.Monitor, this.Helper.Reflection);

            this.pathFindingManager = new PathFindingManager(helper);

            // Hook events.
            helper.Events.Display.RenderedWorld += this.OnRenderedWorld;

            // Add patches.
            HarmonyInstance.DEBUG = true;
            HarmonyInstance harmony = HarmonyInstance.Create(this.ModManifest.UniqueID);

            ClickToMovePatcher.Hook(harmony, helper, this.Monitor, this.pathFindingManager);

            // Log info
            this.Monitor.VerboseLog("Initialized.");
        }
コード例 #12
0
        public override void Update(GameTime gameTime)
        {
            if (DodgeBullet != null && DodgeBullet.TimeAlive >= DodgeBullet.LifeTime)
            {
                DodgeBullet = null;
            }

            SearchTime += gameTime.ElapsedGameTime.Milliseconds;
            if (SearchTime > MaxSearchTime || (AttackTarget != null && !AttackTarget.CanBeTargeted()))
            {
                SearchTime = 0;
                SearchForEnemies();
            }

            if (AttackTarget == null || AttackTarget.GetType().IsSubclassOf(typeof(UnitTurret)))
            {
                UnitTurret u = (UnitTurret)AttackTarget;
                if (AttackTarget == null || (u.MyCard == null && NeutralManager.MyPattern.CurrentCard.Type.Equals("Heavy") ||
                                             (u.MyCard != null && NeutralManager.MyPattern.CurrentCard.Type.Equals(u.MyCard.StrongVs))))
                {
                    if (!isPathfinding || Vector2.Distance(Parent.ParentController.ParentShip.Position.get(), PathfindingTarget) < 300)
                    {
                        isPathfinding     = true;
                        PathfindingTarget = PathFindingManager.TraceAttackPoint(Parent.ParentController.ParentShip.Position.get(), 10);
                    }
                }
                else
                {
                    isPathfinding = false;
                }
            }
            else
            {
                isPathfinding = false;
            }

            if (Parent.ParentController.ParentShip.Dead || !WaveFSM.WaveStepState.WeaponsFree)
            {
                AiState s = Parent.GetExistingState(typeof(PlaceTurretState));
                Parent.SetState(s == null ? new PlaceTurretState() : s);
            }

            base.Update(gameTime);
        }
コード例 #13
0
    IEnumerator Move(List <PathNode> path)
    {
        var linkedList = new LinkedList <PathNode>(path);

        foreach (var node in linkedList)
        {
            var next = linkedList.Find(node).Next?.Value;
            if (next != null)
            {
                var offset = new Vector2Int(next.x, next.z) - new Vector2Int(node.x, node.z);
                Entity.Direction = PathFindingManager.GetDirectionForOffset(offset);
            }

            MoveToIE = StartCoroutine(MoveTo(node));
            yield return(MoveToIE);
        }

        yield return(OnWalkEnd());
    }
コード例 #14
0
ファイル: Services.cs プロジェクト: huxii/OLU
    public static void Destroy()
    {
        //eventManager = null;
        //taskManager = null;
        pathFindingManager = null;
        tileMarkerManager = null;
        levelEventsController = null;
        mainController = null;
        inputController = null;
        cameraController = null;
        hudController = null;
        soundController = null;
        sceneController = null;
        sceneTransitionController = null;
        utils = null;
        gameEvents = null;
        comicEvents = null;
        dotweenEvents = null;

        men = null;
        menParentObj = null;
    }
コード例 #15
0
ファイル: PathFindingManagerEditor.cs プロジェクト: huxii/OLU
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        pathFinder = (PathFindingManager)target;

        if (GUILayout.Button("Refresh"))
        {
            pathFinder.Refresh();
        }

        if (GUILayout.Button("Add Navmesh"))
        {
            GameObject newNavmesh = pathFinder.AddNavmesh();
            Selection.activeGameObject = newNavmesh;
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
            EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
        }
    }
コード例 #16
0
    private void Update()
    {
        if (isWalking && !nodes.IsEmpty())
        {
            bool isEnd = false;
            while (_tick <= Core.Tick)
            {
                var current = nodes[nodeIndex];
                if (nodeIndex == nodes.Count - 1)
                {
                    isEnd = true;
                    break;
                }
                var next       = nodes[nodeIndex + 1];
                var isDiagonal = PathFindingManager.IsDiagonal(next, current);
                lastSpeed = (ushort)(isDiagonal ? Entity.GetBaseStatus().walkSpeed * 14 / 10 : Entity.GetBaseStatus().walkSpeed); //Diagonal walking is slower
                _tick    += lastSpeed;
                nodeIndex++;
            }

            var   currentNode = nodeIndex == 0 ? lastPosition : nodes[nodeIndex - 1];
            var   nextNode    = nodes[nodeIndex];
            var   direction   = nextNode - currentNode;
            float timeDelta   = 1 - Math.Max(_tick - Core.Tick, 0f) / lastSpeed;

            transform.position = currentNode + direction * timeDelta;
            Entity.Direction   = PathFindingManager.GetDirectionForOffset(nextNode, currentNode);

            if (isEnd)
            {
                isWalking = false;
                nodes.Clear();

                StartCoroutine(OnWalkEnd());
            }
        }
    }
コード例 #17
0
 public void Start()
 {
     pathFindingManager = GetComponent <PathFindingManager>();
     grid = pathFindingManager.grid;
     InitTextures();
 }
コード例 #18
0
 public override void Enter(AiStateManager Parent)
 {
     PathFindingManager.BuildAttackGrid();
     base.Enter(Parent);
 }
コード例 #19
0
 void Start()
 {
     rb2d = GetComponent <Rigidbody2D>();
     pathFindingManager = GetComponent <PathFindingManager>();
 }
コード例 #20
0
ファイル: Entity.cs プロジェクト: guilhermelhr/unityro
    public void LookTo(Vector3 position)
    {
        var offset = new Vector2Int((int)position.x, (int)position.z) - new Vector2Int((int)transform.position.x, (int)transform.position.z);

        Direction = PathFindingManager.GetDirectionForOffset(offset);
    }
コード例 #21
0
ファイル: Services.cs プロジェクト: huxii/OLU
    public static void Init()
    {
        eventManager = new Crowd.EventManager();

        if (taskManager == null)
        {
            taskManager = new Crowd.TaskManager();
        }

        if (GameObject.Find("PathFinder"))
        {
            pathFindingManager = GameObject.Find("PathFinder").GetComponent<PathFindingManager>();
        }
        else
        {
            pathFindingManager = null;
        }

        if (GameObject.Find("LevelEvents"))
        {
            levelEventsController = GameObject.Find("LevelEvents").GetComponent<LevelEventsControl>();
        }
        else
        {
            levelEventsController = null;
        }

        if (GameObject.FindGameObjectWithTag("GameController"))
        {
            mainController = GameObject.FindGameObjectWithTag("GameController").GetComponent<MainControl>();
            inputController = mainController.gameObject.GetComponent<InputControl>();
            sceneController = mainController.gameObject.GetComponent<SceneControl>();
            gameEvents = mainController.gameObject.GetComponent<GameEvents>();
            dotweenEvents = mainController.gameObject.GetComponent<DotweenEvents>();

            if (inputController != null && inputController.groundEnabled)
            {
                tileMarkerManager = new TileMarkerManager();
                tileMarkerManager.Init();
            }
            else
            {
                tileMarkerManager = null;
            }
        }
        else
        {
            mainController = null;
            inputController = null;
            sceneController = null;
            gameEvents = null;
            dotweenEvents = null;
        }

        if (GameObject.FindGameObjectWithTag("Transition"))
        {
            sceneTransitionController = GameObject.FindGameObjectWithTag("Transition").GetComponent<SceneTransitionControl>();
        }
        else
        {
            sceneTransitionController = null;
        }

        //if (GameObject.FindGameObjectWithTag("Comic"))
        //{
        //    comicEvents = GameObject.FindGameObjectWithTag("Comic").GetComponent<ComicEvents>();
        //}
        //else
        {
            comicEvents = null;
        }

        if (soundController == null)
        {
            soundController = new SoundControl();
            soundController.Init();
        }

        if (fmodController == null)
        {
            fmodController = new FmodControl();
            fmodController.Init();
        }

        if (GameObject.Find("CameraSystem"))
        {
            cameraController = GameObject.Find("CameraSystem").GetComponent<CameraControl>();
        }
        else
        {
            cameraController = null;
        }

        //if (GameObject.FindGameObjectWithTag("SoundSystem"))
        //{
        //    soundController = GameObject.FindGameObjectWithTag("SoundSystem").GetComponent<SoundControl>();
        //    fmodController = GameObject.FindGameObjectWithTag("SoundSystem").GetComponent<FmodControl>();
        //}
        //else
        //{
        //    soundController = null;
        //    fmodController = null;
        //}

        if (GameObject.Find("Canvas"))
        {
            hudController = GameObject.Find("Canvas").GetComponent<HUDControl>();
        }
        else
        {
            hudController = null;
        }

        utils = new Utils();

        men = new List<GameObject>(GameObject.FindGameObjectsWithTag("Man"));
        menParentObj = GameObject.Find("Actors");

        navMeshMinBound = new Vector3(float.MaxValue, float.MaxValue);
        navMeshMaxBound = new Vector3(-float.MaxValue, -float.MaxValue);
        GameObject[] navs = GameObject.FindGameObjectsWithTag("Ground");
        foreach (GameObject nav in navs)
        {
            Collider collider = nav.GetComponent<BoxCollider>();
            if (collider != null)
            {
                Vector3 c_min = collider.bounds.min;
                Vector3 c_max = collider.bounds.max;

                navMeshMinBound = new Vector2(
                    Mathf.Min(c_min.x, navMeshMinBound.x),
                    Mathf.Min(c_min.y, navMeshMinBound.y)
                    );

                navMeshMaxBound = new Vector2(
                    Mathf.Max(c_max.x, navMeshMaxBound.x),
                    Mathf.Max(c_max.y, navMeshMaxBound.y)
                    );
            }
        }
    }
コード例 #22
0
 // Use this for initialization
 void Start()
 {
     mapManager         = new MapManager(floor);
     pathFindingManager = new PathFindingManager();
 }
コード例 #23
0
ファイル: PathPointEditor.cs プロジェクト: huxii/OLU
 void Awake()
 {
     //pathPoint = (PathPoint)target;
     pathFinder = GameObject.Find("PathFinder").GetComponent <PathFindingManager>();
 }
コード例 #24
0
 void Awake()
 {
     Instance = this;
 }