/// <summary>
        /// Cleanup all data.
        /// </summary>
        public void Clear()
        {
            UnregisterEvents();

            if (SpawnedObjects != null)
            {
                foreach (GameObject obj in SpawnedObjects)
                {
                    Object.Destroy(obj);
                }

                SpawnedObjects.Clear();
            }

            if (PlayerObjects != null)
            {
                foreach (NetworkPlayerObject obj in PlayerObjects)
                {
                    Object.Destroy(obj.GameObject);
                }

                PlayerObjects.Clear();
            }

            m_BufferedPlayersCreations?.Clear();
            m_BufferedOwnerCreations?.Clear();
            m_BufferedPlayerConnections?.Clear();
            m_PlayerObjectCache?.Clear();
            m_AuthroityObjects?.Clear();
            DestroyedGameObject = null;
            CreatedGameObject   = null;
        }
Example #2
0
        private void InternalDeleteSpawnedObjects()
        {
            foreach (ISpawnable spawnable in SpawnedObjects)
            {
                spawnable.Spawner = null;

                bool uncontrolled = spawnable is not BaseCreature creature || !creature.Controlled;

                if (uncontrolled)
                {
                    spawnable.Delete();
                }
            }

            SpawnedObjects.Clear();
        }
Example #3
0
        private void InternalDeleteSpawnedObjects()
        {
            foreach (ISpawnable spawnable in SpawnedObjects)
            {
                spawnable.Spawner = null;

                bool uncontrolled = (spawnable as BaseCreature)?.Controlled != true;

                if (uncontrolled)
                {
                    spawnable.Delete();
                }
            }

            SpawnedObjects.Clear();
        }
Example #4
0
 private void OnTriggerStay2D(Collider2D collision)
 {
     if ((!destroyFlag || SpawnedObjects.Any(x => x == null)) && collision.gameObject.tag == "Player")
     {
         ClearAllObjects();
         SpawnedObjects.Clear();
         destroyFlag = true;
         for (int i = 0; i < NumberOfObjects; i++)
         {
             if (SpawnedObjects.Count == 0 || i + 1 == NumberOfObjects)
             {
                 SpawnedObjects.Add(Instantiate(objectToSpawn, new Vector3((transform.position.x + (transform.localScale.x / 2)) - (OffSetSpawn + OffsetOfObjects * i), transform.position.y, transform.position.z), Quaternion.identity));
             }
             else
             {
                 SpawnedObjects.Add(Instantiate(objectToSpawn, new Vector3((transform.position.x + (transform.localScale.x / 2)) - (OffSetSpawn + OffsetOfObjects * i), SpawnedObjects.Last().transform.position.y + Random.Range(-YAxisOffset / 2, YAxisOffset / 2), transform.position.z), Quaternion.identity));
             }
         }
         StartCoroutine(destroyObjectsAfter());
     }
 }
Example #5
0
 public void Clear()
 {
     SpawnedObjects.Clear();
 }