Beispiel #1
0
        void Update()
        {
            SpawningFunctions.TriggerSpawnOverridesLogic = TriggerSpawnOverridesLogic;
            SpawningFunctions.IsTriggerSpawn             = TriggerSpawn;
            SpawningFunctions.UseOcclusionCulling        = UseOcclusionCulling;

            SpawnedObjects.Update();

            if (DoSpawnIfNotInRange)
            {
                this.UpdateDistance();
            }

            SpawnInterval += Time.deltaTime;

            PositioningComponent = null;

            switch (SelectedSpawningStyle)
            {
            case SpawningStyles.Wave:
                PositioningComponent = GetComponentInChildren <SpawnArea>();
                break;

            case SpawningStyles.Continuous:
                if (SelectedSpawnPositionOption == PositioningOptions.Area)
                {
                    PositioningComponent = GetComponentInChildren <SpawnArea>();
                }

                else
                {
                    PositioningComponent = SpawnPositions[SelectedSpawnPosition];
                }
                break;
            }

            Camera camera = null;

            if (!DoSpawnInFrustum)
            {
                camera = FrustumCamera;
            }

            if (IsSpawningAllowed())
            {
                TriggerSpawn = false;
                GameObject[] ReturnedObjects = SpawningFunctions.Spawn(PositioningComponent, camera, SelectedSpawningStyle);
                if (ReturnedObjects != null)
                {
                    SpawnedObjects.AddObjects(ReturnedObjects);
                    SpawnInterval = 0f;
                }
            }
        }
Beispiel #2
0
        public static GameObject[] Spawn(SpawningComponent PositioningComponent, Camera FrustumCamera, SpawningStyles SpawnType)
        {
            if (PositioningComponent is SpawnPosition && SpawnType == SpawningStyles.Wave)
            {
                return(null);
            }

            List <SpawnAbleObject> NotEmptyObjects = new List <SpawnAbleObject>();

            for (int i = 0; i < PositioningComponent.Objects_to_Spawn.Length; i++)
            {
                if (PositioningComponent.Objects_to_Spawn[i].ObjectToSpawn != null)
                {
                    NotEmptyObjects.Add(PositioningComponent.Objects_to_Spawn[i]);
                }
            }

            foreach (var Object in NotEmptyObjects)
            {
                if (Object.ObjectToSpawn.GetComponent <PersonalLogicScript>())
                {
                    if (!Object.ObjectToSpawn.GetComponent <PersonalLogicScript>().DoSpawn)
                    {
                        NotEmptyObjects.Remove(Object);
                    }
                }
            }

            if (NotEmptyObjects.Count == 0)
            {
                return(null);
            }

            SpawnAbleObject[] Objects = NotEmptyObjects.ToArray();

            int IndexOfObject = 0;

            if (!GetHighestSpawnPriority(Objects, out IndexOfObject))
            {
                return(null);
            }

            Vector3[] Positions = new Vector3[0];

            int SpawnAmount = WaveSpawnAmount;

            if (SpawnType == SpawningStyles.Continuous)
            {
                SpawnAmount = 1;
            }

            if (!PositioningComponent.GetPositions(Objects[IndexOfObject], SpawnAmount, FrustumCamera, false, out Positions))
            {
                return(null);
            }

            GameObject[] ObjectsToReturn = new GameObject[Positions.Length];

            for (int index = 0; index < Positions.Length; index++)
            {
                ObjectsToReturn[index] = GameObject.Instantiate(Objects[IndexOfObject].ObjectToSpawn, Positions[index], Objects[IndexOfObject].ObjectToSpawn.transform.rotation);
            }

            return(ObjectsToReturn);
        }