Example #1
0
        public void Spawn(string path, string oname, OnSpawned cb, params object[] param)
        {
            GameObject         result = null;
            Stack <GameObject> q;

            if (pools.TryGetValue(path, out q))
            {
                if (q.Count > 0)
                {
                    result = q.Pop();
                }
            }
            if (result == null)
            {
                UnityEngine.GameObject prefab;
                if (prefabs.TryGetValue(path, out prefab) && prefab)
                {
                    GameObject go = GameObject.Instantiate(prefab);
                    AssetLoader2.Instance.ReplaceShader(go);
                    idMaps[go.GetInstanceID()] = path;
                    PoolGameObject po = go.AddComponent <PoolGameObject>();
                    po.disposeHandler = onDispose;
                    cb.Invoke(go, param);
                }
                else
                {
                    string             assetname = path.Substring(path.LastIndexOf("/") + 1);
                    List <LoadingItem> loadingItems;
                    if (!pendingLoad.TryGetValue(path, out loadingItems))
                    {
                        loadingItems      = new List <LoadingItem>();
                        pendingLoad[path] = loadingItems;
                        loadingItems.Add(new LoadingItem()
                        {
                            cb = cb, param = param
                        });
                        AssetLoader2.Instance.LoadAsset(path, oname, typeof(GameObject), onLoad, path);
                    }
                    else
                    {
                        loadingItems.Add(new LoadingItem()
                        {
                            cb = cb, param = param
                        });
                    }
                    //loadingItems.Add(new LoadingItem() { cb = cb, param = param });
                }
            }
            else
            {
                cb.Invoke(result, param);
            }
        }
Example #2
0
        /// <summary>
        /// Starts the spawning heroes.
        /// </summary>
        public void StartSpawning()
        {
            var hero = CreateUnit(heroData, SpawnPosition, Quaternion.identity);

            PlayerResources.SetSourceHero(hero);
            OnSpawned?.Invoke();
        }
Example #3
0
        /// <summary>
        /// Spawns the enemy waves.
        /// </summary>
        /// <returns>The yield instruction.</returns>
        private IEnumerator SpawnWaves()
        {
            if (settings == null)
            {
                yield break;
            }

            foreach (var wave in settings.WaveDatas)
            {
                yield return(new WaitForSeconds(wave.StartDelay));

                foreach (var enemySheet in wave.EnemiesSheets)
                {
                    var count = enemySheet.Count;
                    while (count-- > 0)
                    {
                        EnemyFactories.ForEach(factory =>
                                               factory.CreateUnit(enemySheet.EnemyData, RandomSpawnPosition, Quaternion.identity));

                        // To reduce lags when a lot of enemies get instantiated.
                        yield return(new WaitForSeconds(DEFAULT_DELAY_BETWEEN_ENEMIES_CREATION));
                    }
                }

                OnSpawned?.Invoke();
            }

            Debug.Log("Waves have ended");
        }
Example #4
0
 public void SpawnTrigger(EventParameter parameter)
 {
     if (SpawnerType.TrySpawn(out var spawnedGameObject))
     {
         ObjectPlaceType.Place(spawnedGameObject);
         OnSpawned?.Invoke(new EventParameter_GameObject(spawnedGameObject));
     }
 }
Example #5
0
 /// <summary>
 /// Spawns minions in coroutine.
 /// </summary>
 /// <returns>The yield instruction.</returns>
 private IEnumerator SpawnMinions()
 {
     while (true)
     {
         CreateUnit(settings.MinionData, spawnPoint.position, Quaternion.identity);
         OnSpawned?.Invoke();
         yield return(new WaitForSeconds(1f / settings.GetCreationSpeed(level)));
     }
 }
Example #6
0
        public Entity(string name, Vector2 position, IEnumerable <EntityComponent> components, bool isActiv = true, int teamId = -1)
        {
            this.name       = name;
            this.position   = position;
            this.isActiv    = isActiv;
            this.teamId     = teamId;
            id              = Count++;
            this.components = components.ToList();

            EntityManager.ActivEntityManager.SignIn(this);

            if (isActiv)
            {
                OnSpawned?.Invoke(this, EventArgs.Empty);
            }
        }
    private void spawnAsteroid()
    {
        int asteroidIndex = UnityEngine.Random.Range(0, 4);

        Vector2 position = new Vector2(-20, UnityEngine.Random.Range(-5, 5));

        Sprite randomAsteroidSprite = asteroidSprites[asteroidIndex];

        asteroid.GetComponent <Image>().sprite = randomAsteroidSprite;

        Asteroid spawned = Instantiate(asteroid, position, Quaternion.identity, transform);

        spawned.Initialize(pauseManager);

        OnSpawned?.Invoke(spawned);

        lastSpawn = Time.time;
    }
Example #8
0
        /// <summary>
        /// Revives the hero.
        /// </summary>
        /// <param name="obj">The countdowned object.</param>
        /// <exception cref="ArgumentNullException">obj</exception>
        private void ReviveHero(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            if (!(obj is Hero hero) || hero.IsNullOrMissing())
            {
                return;
            }

            var timer = reviveTimers.Find(timers => timers.Countdowned == obj);

            timer.Dispose();
            reviveTimers.Remove(timer);

            NotifyAllAboutNewUnit(hero);
            OnSpawned?.Invoke();
            hero.transform.position = SpawnPosition;
            hero.Reborn();
        }
Example #9
0
        private void SpawnWithNonUserEvents(Species toSpawn)
        {
            if (graveyard.ContainsKey(toSpawn.Idx))
            {
                // toSpawn.GObject.SetActive(true);
                graveyard.Remove(toSpawn.Idx);
            }
            spawnedSpecies[toSpawn.Idx] = toSpawn;
            if (toSpawn.Status == null)
            {
                toSpawn.Status = Instantiate(statusPrefab, statusCanvas.transform);
                toSpawn.Status.FollowSpecies(toSpawn.GObject);
                toSpawn.Status.SetSize(sizeTrait.PositivifyValue(toSpawn.BodySize));
                toSpawn.Status.SetGreed(greedTrait.PositivifyValue(toSpawn.Greediness));
                toSpawn.Status.ShowHealth();
            }

            // must be invoked first so that nodelink focuses after adding
            OnSpawned?.Invoke(toSpawn.Idx, toSpawn.IsProducer, toSpawn.GObject);

            OnSizeSet?.Invoke(toSpawn.Idx, sizeTrait.NormaliseValue(toSpawn.BodySize));
            OnGreedSet?.Invoke(toSpawn.Idx, greedTrait.NormaliseValue(toSpawn.Greediness));
        }
Example #10
0
 public void Spawn()
 {
     IsActiv = true;
     OnSpawned?.Invoke(this, EventArgs.Empty);
 }
Example #11
0
        public void Spawn(BattleUnit unitPrefab, UnitSpawnData?spawnData = null)
        {
            Transform spawnPoint    = null;
            Vector3   spawnPosition = Vector3.zero;

            if (spawnData.HasValue)
            {
                spawnPoint    = spawnData.Value.SpawnPoint;
                spawnPosition = spawnPoint.position;
            }
            else
            {
                if (_isExcludeSpawnPoints)
                {
                    if (_spawnPointList != null && !_spawnPointList.Any())
                    {
                        _spawnPointList = null;
                    }

                    if (_spawnPointList == null)
                    {
                        var pointsCopy = _spawnPoints.ToList();
                        pointsCopy.Shuffle();
                        _spawnPointList = new LinkedList <SpawnPoint>(pointsCopy);
                    }

                    var randomPoint = _spawnPointList.LastOrDefault();

                    Assert.IsNotNull(randomPoint, "randomPoint != null");
                    spawnPosition = randomPoint.transform.position;
                    spawnPoint    = randomPoint.transform;
                    _spawnPointList.Remove(randomPoint);
                }
                else
                {
                    spawnPoint    = _spawnPoints[Random.Range(0, _spawnPoints.Length)].transform;
                    spawnPosition = spawnPoint.position;
                }
            }


            var unitInstance = Instantiate(unitPrefab);

            unitInstance.transform.position = spawnPosition;

            var respawnableUnit = unitInstance.GetComponentInChildren <IRespawnableUnit>(true);

            if (respawnableUnit != null)
            {
                if (spawnData.HasValue)
                {
                    respawnableUnit.InitRespawnBehaviour(spawnData.Value);

                    unitInstance.TeamController.SetTeam(spawnData.Value.TeamType);
                }
                else
                {
                    respawnableUnit.InitRespawnBehaviour(new UnitSpawnData(
                                                             unitPrefab, this, spawnPoint, TeamType.TEAM_1
                                                             ));
                }
            }

            var setupableComponents = unitInstance.GetComponentsInChildren <ISetupable>(true);

            foreach (var setupable in setupableComponents)
            {
                if (setupable != null)
                {
                    setupable.Setup();
                }
            }

            InitUnit(unitInstance);

            OnSpawned?.Invoke(unitInstance);
        }
Example #12
0
    private IEnumerator Spawn()
    {
        yield return(ScaleEffect(true, speedScale));

        OnSpawned?.Invoke(this);
    }