Пример #1
0
        internal void UnregisterObject(Object obj)
        {
            lock (ManagedObjects)
            {
                if (!ManagedObjects.Contains(obj))
                {
                    return;
                }

                ManagedObjects.Remove(obj);

                if (obj is GameObject gameObject)
                {
                    if ((gameObject.Id.Flags & ObjectIdFlags.Spawned) != 0)
                    {
                        SpawnedObjects.Remove(gameObject);
                    }
                }

                var updated = UpdatedObjects.FirstOrDefault(u => u.Associate == obj);

                if (updated == default)
                {
                    return;
                }

                UpdatedObjects.Remove(updated);
            }
        }
Пример #2
0
 public void AddObjects(GameObject[] ObjectsToAdd)
 {
     foreach (var ObjectToAdd in ObjectsToAdd.ToList())
     {
         SpawnedObjects.Add(ObjectToAdd);
     }
 }
Пример #3
0
        public void SpawnObject(int index)
        {
            if (this.PrefabsToInstantiate != null && index < this.PrefabsToInstantiate.Count)
            {
                MyType    = (EUnitType)index;
                EnemyType = MyType == EUnitType.FirstPlayer ? EUnitType.SecondPlayer : EUnitType.FirstPlayer;

                var prefab = this.PrefabsToInstantiate[index];

                if (prefab == null)
                {
                    return;
                }
#if UNITY_EDITOR
                Debug.Log("Auto-Instantiating: " + prefab.name);
#endif
                Vector3 spawnPos; Quaternion spawnRot;
                GetSpawnPoint(index, out spawnPos, out spawnRot);

                PhotonNetwork.Instantiate(EventHandler.name, spawnPos, spawnRot);

                var newobj = PhotonNetwork.Instantiate(prefab.name, spawnPos, spawnRot, 0);

                SpawnedObjects.Push(newobj);
            }
        }
Пример #4
0
        public override RunObject Spawn()
        {
            if (IsPipelineIsEmpty)
            {
                ProcessError("RunObjects.Dequeue(): Pipeline is empty");
                return(null);
            }

            var build   = Pipeline.Dequeue();
            var objType = build.GetObjectType();

            var obj = Spawn(objType);

            if (obj == null)
            {
                ProcessError("RunObjects.Dequeue(): Spawn(objType) == null");
                return(null);
            }

            build.Build(obj);

            SpawnedObjects.Add(obj);
            obj.OnObjectSpawned(build);

            if (IsPipelineIsEmpty)
            {
                OnPipelineBecameEmpty();
            }

            return(obj);
        }
Пример #5
0
    public void Spawn()
    {
        var newObject = Instantiate(spawnObject, transform);

        SpawnedObjects.Add(newObject.transform);
        SetRandomPosition(newObject.transform);
    }
        /// <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;
        }
Пример #7
0
    private GameObject GetClosestObstacle()
    {
        SpawnedObjects.SortByClosest(transform.position); //custom Jext function
        if (SpawnedObjects.Count > 0)
        {
            GameObject ret = SpawnedObjects[0];
            foreach (GameObject spawned in SpawnedObjects)
            {
                if (transform.position.x < spawned.transform.position.x) //if the object is behind the player
                {
                    ret = spawned;
                    break;
                }

                /*this is purely visually interesting since it shows what the AI is interested in
                 * I normally wouldn't use such an expensive for loop so many times a frame but it's nice for debugging
                 */
            }
            foreach (GameObject spawned in SpawnedObjects)
            {
                foreach (SpriteRenderer sR in spawned.GetComponentsInChildren <SpriteRenderer>())
                {
                    sR.color = spawned == ret ? Color.blue : Color.white;
                }
            }

            return(ret);
        }
        return(null);
    }
Пример #8
0
 /// <summary>
 /// Removes all spawned NPCs from this pool and makes it
 /// collectable by the GC (if not in Map anymore).
 /// </summary>
 /// <remarks>Requires map context</remarks>
 public void Clear()
 {
     Map.EnsureContext();
     foreach (O o in SpawnedObjects.ToArray())
     {
         o.DeleteNow();
     }
 }
        public void RegisterObjectAsSpawned(GameObject inst)
        {
            if (SpawnedObjects == null)
            {
                SpawnedObjects = new List <GameObject>();
            }

            SpawnedObjects.Add(inst);
        }
Пример #10
0
 public void Update()
 {
     foreach (var ObjectToCheck in SpawnedObjects.ToList())
     {
         if (!ObjectToCheck)
         {
             SpawnedObjects.Remove(ObjectToCheck);
         }
     }
 }
Пример #11
0
		/// <summary>
		/// Removes all spawned NPCs from this pool and makes it
		/// collectable by the GC (if not in Map anymore).
		/// </summary>
		/// <remarks>Requires map context</remarks>
		public void Clear()
		{
			Map.EnsureContext();

			var arr = SpawnedObjects.ToArray();
			for (var i = 0; i < arr.Length; i++)
			{
				var spawn = arr[i];
				spawn.DeleteNow();
			}
		}
Пример #12
0
        private void Add(ISpawnable spawn)
        {
            SpawnedObjects.Add(spawn);

            spawn.Spawner = this;

            if (spawn is BaseCreature creature)
            {
                creature.RemoveIfUntamed = RemoveIfUntamed;
            }
        }
    // Start is called before the first frame update
    void Start()
    {
        PlayerScript         = PlayerObject.GetComponent <Player>();
        SpawnedObjectsScript = SpawnedObjectContainer.GetComponent <SpawnedObjects>();

        StartCoroutine(SpawnThrash());

        if (Time.timeScale == 0.0f)
        {
            Time.timeScale = 1.0f;
        }
    }
Пример #14
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();
        }
Пример #15
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();
        }
        private void OnNetworkDestroy(NetworkWriter writer)
        {
            if (IsServer)
            {
                return;
            }

            int instanceID = writer.ReadInt16();

            NetworkIdentity identity = NetworkIdentityManager.Instance.Get(instanceID);

            SpawnedObjects?.Remove(identity.gameObject);

            DestroyedGameObject?.Invoke(identity);

            Object.Destroy(identity.gameObject);
        }
Пример #17
0
    private IEnumerator _RestartWithFadeout()
    {
        gameOverScreen.localPosition = startPosGameOverScreen;
        fadeToBlackObj.gameObject.SetActive(true); //multipurpose, this way it also blocks input

        yield return(StartCoroutine(Methods.FadeToBlack(
                                        fadeToBlackObj, fadeSpeed, Methods.FadeType.FadeOut)));

        SpawnedObjects.ForEach(x => Destroy(x));

        yield return(StartCoroutine(Methods.FadeToBlack(
                                        fadeToBlackObj, fadeSpeed, Methods.FadeType.FadeIn)));

        fadeToBlackObj.gameObject.SetActive(false);

        Restart();
    }
        private void OnDestroyPlayer(NetworkConnection conn)
        {
            NetworkPlayerObject playerObject = PlayerObjects?.Find(x => x.ConnectionID == conn.ConnectionID);

            if (playerObject != null)
            {
                if (SpawnedObjects?.Contains(playerObject.GameObject) ?? false)
                {
                    SpawnedObjects.Remove(playerObject.GameObject);
                }

                DestroyedGameObject?.Invoke(playerObject.NetworkIdentity);
                Object.Destroy(playerObject.GameObject);

                PlayerObjects.Remove(playerObject);
                m_PlayerObjectCache?.Remove(conn.ConnectionID);
            }

            if (m_BufferedPlayersCreations?.ContainsKey(conn.ConnectionID) ?? false)
            {
                m_BufferedPlayersCreations.Remove(conn.ConnectionID);
            }

            if (m_BufferedOwnerCreations?.ContainsKey(conn.ConnectionID) ?? false)
            {
                m_BufferedOwnerCreations.Remove(conn.ConnectionID);
            }

            if (m_AuthroityObjects?.ContainsKey(conn) ?? false)
            {
                foreach (NetworkIdentity identity in m_AuthroityObjects[conn])
                {
                    if (identity != null)
                    {
                        Destroy(identity.gameObject);
                    }
                }
                m_AuthroityObjects.Remove(conn);
            }

            m_BufferedPlayerConnections?.Remove(conn);
        }
            private static void DestroyCustomObjects()
            {
                while (SpawnedObjects.Count != 0)
                {
                    GameObject gameObject = SpawnedObjects[0];
                    SpawnedObjects.Remove(gameObject);
                    UnityEngine.Object.Destroy(gameObject);
                    foreach (TubeBloomPrePassLight tubeBloomPrePassLight in gameObject.GetComponentsInChildren <TubeBloomPrePassLight>(true))
                    {
                        //Unity requires this to be present, otherwise Unregister won't be called. Memory leaks may occour if this is removed.
                        tubeBloomPrePassLight.InvokeMethod <object, BloomPrePassLight>("UnregisterLight");
                    }
                }

                while (SpawnedComponents.Count != 0)
                {
                    Component component = SpawnedComponents[0];
                    SpawnedComponents.Remove(component);
                    UnityEngine.Object.Destroy(component);
                }
            }
Пример #20
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());
     }
 }
Пример #21
0
    // Update is called once per frame
    void Update()
    {
        if (CMapGenerator.bTool)
        {
            return;
        }

        if (!bSpawnStart)
        {
            return;
        }

        if (CurSpawnCount == 0)
        {
            if (false == bLoopSpawn)
            {
                bSpawnStart = false;
            }
            else if (bLoopSpawn && 0 == SpawnedObjects.Count)
            {
                RemainTime    = SpawnTime;
                CurSpawnCount = MaxSpawnCount;
            }
            return;
        }

        if (RemainTime <= 0)
        {
            GameObject spawnObj = Instantiate(CResourceMgr.LoadCharacter(GetLoadCharacterName(), ECharacterType.Enemy) /*, gameObject.transform*/);
            spawnObj.transform.position = gameObject.transform.position;
            SpawnedObjects.Add(spawnObj);
            RemainTime = SpawnTime;
            --CurSpawnCount;
        }
        else
        {
            RemainTime -= Time.fixedDeltaTime;
        }
    }
        /// <summary>
        /// Destroy a networked object.
        /// </summary>
        /// <param name="gameObject"></param>
        public void Destroy(GameObject gameObject)
        {
            if (!IsServer)
            {
                return;
            }

            if (!ServerValidateDestroy(gameObject, out NetworkIdentity identity))
            {
                return;
            }

            byte[] data = BitConverter.GetBytes((short)identity.InstanceID);

            NetworkController.Instance.SendToAll(NetworkController.ReliableSequencedChannel, DestroyMsg, data);

            DestroyedGameObject?.Invoke(identity);

            SpawnedObjects.Remove(identity.gameObject);

            Object.Destroy(gameObject);
        }
Пример #23
0
        internal void RegisterObject(Object obj)
        {
            lock (ManagedObjects)
            {
                if (ManagedObjects.Contains(obj))
                {
                    return;
                }

                OnObject.Invoke(obj);

                ManagedObjects.Add(obj);

                if (!(obj is GameObject gameObject))
                {
                    return;
                }

                if ((gameObject.Id.Flags & ObjectIdFlags.Spawned) != 0)
                {
                    SpawnedObjects.Add(gameObject);
                }
            }
        }
Пример #24
0
 public void Clear()
 {
     SpawnedObjects.Clear();
 }
Пример #25
0
        void ISpawner.Remove(ISpawnable spawn)
        {
            SpawnedObjects.Remove(spawn);

            CheckTimer();
        }
Пример #26
0
 public override void Despawn(RunObject ro)
 {
     Pool.Despawn(ro.transform);
     SpawnedObjects.Remove(ro);
     ro.OnObjectDespawned();
 }
Пример #27
0
 public RunObject GetFirstObject()
 {
     return(SpawnedObjects.FirstOrDefault());
 }
Пример #28
0
 public RunObject GetLatestObject()
 {
     return(SpawnedObjects.LastOrDefault());
 }