示例#1
0
        public void InitNavMesh(PathTD p, int ID, int wID)
        {
            Init();

            path       = p;
            instanceID = ID;
            waveID     = wID;

            if (path != null)
            {
                tgtPos = path.wpList[path.wpList.Count - 1].position;
            }

            agent = thisObj.GetComponent <NavMeshAgent>();
            if (agent)
            {
                useNavMesh = true;
                agent.SetDestination(tgtPos);
                agent.stoppingDistance = .02f;
                agent.speed            = GetMoveSpeed();

                if (behaviour == Behaviour.Default)
                {
                    StartCoroutine(CheckDestination());
                }
            }
        }
示例#2
0
        public int AddSubPath(PathTD pathInstance, int wpID, Transform startP, Transform endP)
        {
            walkable = true;

            int ID = subPathList.Count;

            SubPath subPath = new SubPath();

            subPath.parentPath   = pathInstance;
            subPath.wpIDPlatform = wpID;
            subPath.connectStart = startP;
            subPath.connectEnd   = endP;

            subPathList.Add(subPath);

            return(ID);
        }
示例#3
0
        public void Init(PathTD p, int ID, int wID, UnitCreep parentUnit = null)
        {
            //this.realAttackRange = GetAttackRange() < 2 ? GetAttackRange() : .5f;
            Init();
            path       = p;
            instanceID = ID;
            waveID     = wID;
            float dynamicX = Random.Range(-path.dynamicOffset, path.dynamicOffset);
            float dynamicZ = Random.Range(-path.dynamicOffset, path.dynamicOffset);

            pathDynamicOffset = new Vector3(dynamicX, 0, dynamicZ);
            thisT.position   += pathDynamicOffset;

            if (parentUnit == null)
            {
                waypointID    = 1;
                subWaypointID = 0;
                subPath       = path.GetWPSectionPath(waypointID);
            }
            else
            {
                //inherit stats and path from parent unit
                waypointID    = parentUnit.waypointID;
                subWaypointID = parentUnit.subWaypointID;
                subPath       = parentUnit.subPath;

                fullHP     = parentUnit.fullHP * parentUnit.spawnUnitHPMultiplier;
                fullShield = parentUnit.fullShield * parentUnit.spawnUnitHPMultiplier;
                HP         = fullHP; shield = fullShield;
            }

            distFromDestination = CalculateDistFromDestination();

            if (type == _CreepType.Offense)
            {
                StartCoroutine(ScanForTargetRoutine());
                StartCoroutine(TurretRoutine());
            }
            if (type == _CreepType.Support)
            {
                StartCoroutine(SupportRoutine());
            }

            InitNavMesh(p, ID, wID);
        }
示例#4
0
        // Use this for initialization
        void Start()
        {
            if (defaultPath == null)
            {
                Debug.Log("DefaultPath on SpawnManager not assigned, auto search for one");
                defaultPath = (PathTD)FindObjectOfType(typeof(PathTD));
            }

            if (spawnLimit == _SpawnLimit.Infinite || procedurallyGenerateWave)
            {
                waveGenerator.CheckPathList();
                if (defaultPath != null && waveGenerator.pathList.Count == 0)
                {
                    waveGenerator.pathList.Add(defaultPath);
                }
            }

            //waveGenerator.Generate(i);
            if (spawnLimit == _SpawnLimit.Finite && procedurallyGenerateWave)
            {
                for (int i = 0; i < waveList.Count; i++)
                {
                    waveList[i] = waveGenerator.Generate(i);
                }
            }

            if (spawnLimit == _SpawnLimit.Infinite)
            {
                waveList = new List <Wave>();
            }
            if (spawnLimit == _SpawnLimit.Finite)
            {
                for (int i = 0; i < waveList.Count; i++)
                {
                    waveList[i].waveID = i;
                }
            }

            if (autoStart)
            {
                StartCoroutine(AutoStartRoutine());
            }
        }
示例#5
0
        void Awake()
        {
            instance = (PathTD)target;

            EditorUtility.SetDirty(instance);
        }
示例#6
0
        IEnumerator SpawnSubWave(SubWave subWave, Wave parentWave)
        {
            yield return(new WaitForSeconds(subWave.delay));

            PathTD path = defaultPath;

            if (subWave.path != null)
            {
                path = subWave.path;
            }

            Vector3    pos = path.GetSpawnPoint().position;
            Quaternion rot = path.GetSpawnPoint().rotation;

            int spawnCount = 0;

            while (spawnCount < subWave.count)
            {
                GameObject obj  = ObjectPoolManager.Spawn(subWave.unit, pos, rot);
                UnitCreep  unit = obj.GetComponent <UnitCreep>();

                if (subWave.overrideShield > 0)
                {
                    unit.defaultShield = subWave.overrideShield;
                }
                if (subWave.overrideMoveSpd > 0)
                {
                    unit.moveSpeed = subWave.overrideMoveSpd;
                }

                unit.Init(path, totalSpawnCount, parentWave.waveID);

                totalSpawnCount += 1;
                activeUnitCount += 1;

                parentWave.activeUnitCount += 1;

                spawnCount += 1;
                if (spawnCount == subWave.count)
                {
                    break;
                }

                yield return(new WaitForSeconds(subWave.interval));
            }

            parentWave.subWaveSpawnedCount += 1;
            if (parentWave.subWaveSpawnedCount == parentWave.subWaveList.Count)
            {
                parentWave.spawned = true;
                spawning           = false;
                //Debug.Log("wave "+(parentWave.waveID+1)+" has done spawning");

                yield return(new WaitForSeconds(0.5f));

                if (currentWaveID <= waveList.Count - 2)
                {
                    //for UI to show spawn button again
                    if (spawnMode == _SpawnMode.Continous && allowSkip && onEnableSpawnE != null)
                    {
                        onEnableSpawnE();
                    }
                    if (spawnMode == _SpawnMode.WaveCleared && allowSkip && onEnableSpawnE != null)
                    {
                        onEnableSpawnE();
                    }
                }
            }
        }