コード例 #1
0
        private void spawnPrefabs()
        {
            spawnedObjects = new List <GameObject>();
            prefabsToSpawn = new List <ScheduledSpawnData>();
            int num = SpawnData.Length;

            for (int i = 0; i < num; i++)
            {
                ScheduledSpawnData scheduledSpawnData = SpawnData[i];
                if (scheduledSpawnData.SpawnPrefabKey != null && !string.IsNullOrEmpty(scheduledSpawnData.SpawnPrefabKey.Key))
                {
                    prefabsToSpawn.Add(scheduledSpawnData);
                }
                else
                {
                    Log.LogError(this, $"Error: {base.gameObject.GetPath()} has a Spawn data field with a null prefab entry");
                }
            }
            if (prefabsToSpawn.Count <= 0)
            {
                return;
            }
            Service.Get <LoadingController>().AddLoadingSystem(this);
            spawnPrefabsLoadTimer = new Stopwatch();
            spawnPrefabsLoadTimer.Start();
            foreach (ScheduledSpawnData item in prefabsToSpawn)
            {
                if (Content.TryLoadImmediate(out var result, item.SpawnPrefabKey))
                {
                    onSpawnPrefabLoaded(result, item);
                }
            }
            Service.Get <LoadingController>().RemoveLoadingSystem(this);
            spawnPrefabsLoadTimer.Stop();
        }
コード例 #2
0
        private void onSpawnPrefabLoaded(GameObject prefab, ScheduledSpawnData data)
        {
            Transform spawnParentTransform = base.gameObject.transform;

            if (data.SpawnParentTransform != null)
            {
                spawnParentTransform = data.SpawnParentTransform;
            }
            GameObject gameObject = Object.Instantiate(prefab, spawnParentTransform);

            if (data.SpawnOffset != Vector3.zero)
            {
                gameObject.transform.localPosition = data.SpawnOffset;
            }
            if (data.SpawnRotation != Vector3.zero)
            {
                gameObject.transform.localEulerAngles = data.SpawnRotation;
            }
            if (data.SpawnScale != Vector3.zero)
            {
                gameObject.transform.localScale = data.SpawnScale;
            }
        }