private void Update() { if (this.transform.position.y < -500.0f) { Pooler.Destroy(this.gameObject); } }
public static void DestroyChildren(this GameObject gameObject) { for (int i = gameObject.transform.childCount - 1; i >= 0; i--) { Pooler.Destroy(gameObject.transform.GetChild(i).gameObject); } }
private void Update() { this.waitTime -= Time.deltaTime; if (this.waitTime < 0) { if (this.meshRenderer != null && this.meshRenderer.material != null) { if (this.meshRenderer.material.shader != diffuseTrnasparentShader) { this.meshRenderer.material.shader = diffuseTrnasparentShader; } Color newColor = this.meshRenderer.material.color.OffsetA(-Time.deltaTime * this.fadeSpeed); this.meshRenderer.material.color = newColor; if (newColor.a <= 0.0f) { Pooler.Destroy(this.gameObject); } } else { Pooler.Destroy(this.gameObject); } } }
public NetworkIdentity CreateNetworkIdentity(string resourceName, long ownerId, Vector3 position) { NetworkIdentity networkIdentityPrefab = null; if (resourcePrefabCache.TryGetValue(resourceName, out networkIdentityPrefab) == false) { networkIdentityPrefab = Resources.Load <NetworkIdentity>(resourceName); resourcePrefabCache.Add(resourceName, networkIdentityPrefab); } var newNetworkIdentity = Pooler.Instantiate(networkIdentityPrefab); newNetworkIdentity.GenerateNewNetworkId(); newNetworkIdentity.SetOwner(ownerId); newNetworkIdentity.ResourceName = resourceName; newNetworkIdentity.Destroyed += this.NetworkIdentityDestroyed; newNetworkIdentity.transform.position = position; // Registering it with the dynamic game objects this.dynamicNetworkObjectsHash.Add(newNetworkIdentity.NetworkId, newNetworkIdentity); this.dynamicNetworkObjectsList.Add(newNetworkIdentity); this.networkIdentityCreatedMessage.NetworkId = newNetworkIdentity.NetworkId; this.networkIdentityCreatedMessage.OwnerId = newNetworkIdentity.OwnerId; this.networkIdentityCreatedMessage.ResourceName = resourceName; this.networkIdentityCreatedMessage.Position = position; this.SendNetworkMessage(this.networkIdentityCreatedMessage); return(newNetworkIdentity); }
public static void DestroyAllChildren(this Transform transform) { for (int i = transform.childCount - 1; i >= 0; i--) { Pooler.Destroy(transform.GetChild(i).gameObject); } }
public void AddItem(string name, UnityAction customAction) { var newItem = Pooler.Instantiate <DebugMenuItem>(this.debugMenuItemPrefab); newItem.transform.SetParent(this.contentTransform); newItem.transform.Reset(); newItem.Initialize(name, customAction, this.Hide); }
void ISerializationCallbackReceiver.OnBeforeSerialize() { if (this.prefabInstance != null) { Pooler.DestroyImmediate(this.prefabInstance); this.prefabInstance = null; } }
private static void PrivateDestroyAllRecursively(GameObject gameObject) { for (int i = 0; i < gameObject.transform.childCount; i++) { PrivateDestroyAllRecursively(gameObject.transform.GetChild(i).gameObject); } Pooler.DestroyImmediate(gameObject); }
private void Initialize() { if (this.prefabInstance == null && this.prefab != null) { this.prefabInstance = Pooler.Instantiate(this.prefab); this.prefabInstance.hideFlags = HideFlags.HideAndDontSave; this.prefabInstance.transform.SetParent(this.transform); this.prefabInstance.transform.localPosition = Vector3.zero; } }
public void RemoveItem(string name) { foreach (var menuItem in this.contentTransform.GetComponentsInChildren <DebugMenuItem>()) { if (menuItem.Name == name) { Pooler.Destroy(menuItem.gameObject); } } }
public void Shutdown() { this.gameServer?.Shutdown(); if (Platform.IsApplicationQuitting == false) { // Destroy all dynamic objects foreach (var dynamic in this.dynamicNetworkObjectsList) { Pooler.Destroy(dynamic.gameObject); } } }
#pragma warning restore 0649 private void Update() { this.waitTime -= Time.deltaTime; if (this.waitTime < 0.0f) { if (this.destroyEffect != null) { GameObject destroyEffect = Pooler.Instantiate(this.destroyEffect); destroyEffect.transform.position = this.transform.position; } Pooler.Destroy(this.gameObject); } }
public void Shutdown() { this.gameClient?.Shutdown(); if (Platform.IsApplicationQuitting == false) { // Destroy all dynamic objects foreach (var dynamic in this.dynamicNetworkObjectsList) { if (dynamic?.gameObject) { Pooler.Destroy(dynamic?.gameObject); } } this.dynamicNetworkObjectsList.Clear(); this.dynamicNetworkObjectsHash.Clear(); } }
private IEnumerator FadeOutCoroutine() { yield return(WaitForUtil.Seconds(this.waitTime)); var meshRenderer = this.GetComponent <MeshRenderer>(); var material = meshRenderer?.material; if (this.transparentMaterial == null) { Debug.Log("this.transparentMaterial is NULL!"); } if (material != null && this.transparentMaterial != null) { Material newTransparent = Object.Instantiate(this.transparentMaterial); // Copy over color properties if (this.colorsPropertiesToCopy != null) { for (int i = 0; i < this.colorsPropertiesToCopy.Length; i++) { newTransparent.SetColor(this.colorsPropertiesToCopy[i], material.GetColor(this.colorsPropertiesToCopy[i])); } } // Copy over texture properties if (this.texturesPropertiesToCopy != null) { for (int i = 0; i < this.texturesPropertiesToCopy.Length; i++) { newTransparent.SetTexture(this.texturesPropertiesToCopy[i], material.GetTexture(this.texturesPropertiesToCopy[i])); } } meshRenderer.material = newTransparent; yield return(newTransparent.FadeAlpha(this.colorPropertyToAnimate, 1.0f, 0.0f, this.fadeTime)); Object.Destroy(newTransparent); } Pooler.Destroy(this.gameObject); }
public void InitializeDots() { // making sure it hasn't already been initialized if (this.dotContainer != null && this.dotContainer.transform.childCount > 0) { return; } // initializing the dots if (this.dotPrefab != null && this.dotContainer != null) { for (int i = 0; i < this.ChildCount; i++) { var newDot = Pooler.Instantiate(this.dotPrefab); newDot.transform.SetParent(this.dotContainer); newDot.transform.localScale = new Vector3(this.minScale, this.minScale, this.minScale); newDot.transform.localPosition = Vector3.zero; } } }
private NetworkIdentity CreateDynamicNetworkIdentity(string resourceName, long networkId, long ownerId, Vector3 position) { NetworkIdentity networkIdentityPrefab = null; if (resourcePrefabCache.TryGetValue(resourceName, out networkIdentityPrefab) == false) { networkIdentityPrefab = Resources.Load <NetworkIdentity>(resourceName); resourcePrefabCache.Add(resourceName, networkIdentityPrefab); } var newNetworkIdentity = Pooler.Instantiate(networkIdentityPrefab); newNetworkIdentity.SetNetworkId(networkId); newNetworkIdentity.SetOwner(ownerId); newNetworkIdentity.ResourceName = resourceName; newNetworkIdentity.transform.position = position; // Registering the new dynamic object this.dynamicNetworkObjectsHash.Add(newNetworkIdentity.NetworkId, newNetworkIdentity); this.dynamicNetworkObjectsList.Add(newNetworkIdentity); return(newNetworkIdentity); }
private void ClientReceivedMessage(Message message) { switch (message.GetId()) { case NetworkIdentityCreated.Id: { if (NetworkManager.Instance.IsClientAndServer) { return; } var networkIdentityCreated = (NetworkIdentityCreated)message; this.CreateDynamicNetworkIdentity( networkIdentityCreated.ResourceName, networkIdentityCreated.NetworkId, networkIdentityCreated.OwnerId, networkIdentityCreated.Position); break; } case NetworkIdentityUpdate.Id: { if (NetworkManager.Instance.IsClientAndServer) { return; } var networkIdentityUpdatedMessage = (NetworkIdentityUpdate)message; if (networkIdentityUpdatedMessage.OwnerId != this.gameClient.UserId) { if (this.staticNetworkObjectsHash.TryGetValue(networkIdentityUpdatedMessage.NetworkId, out NetworkIdentity staticIdentity)) { networkIdentityUpdatedMessage.PopulateNetworkIdentity(staticIdentity); } else if (this.dynamicNetworkObjectsHash.TryGetValue(networkIdentityUpdatedMessage.NetworkId, out NetworkIdentity dynamicIdentity)) { networkIdentityUpdatedMessage.PopulateNetworkIdentity(dynamicIdentity); } else { if (string.IsNullOrEmpty(networkIdentityUpdatedMessage.ResourceName) == false) { var newIdentity = this.CreateDynamicNetworkIdentity( networkIdentityUpdatedMessage.ResourceName, networkIdentityUpdatedMessage.NetworkId, networkIdentityUpdatedMessage.OwnerId, networkIdentityUpdatedMessage.Position); networkIdentityUpdatedMessage.PopulateNetworkIdentity(newIdentity); } } } break; } case NetworkBehaviourMessage.Id: { if (NetworkManager.Instance.IsClientAndServer) { return; } var networkBehaviourMessage = (NetworkBehaviourMessage)message; this.staticNetworkObjectsHash.TryGetValue(networkBehaviourMessage.NetworkId, out NetworkIdentity staticIdentity); this.dynamicNetworkObjectsHash.TryGetValue(networkBehaviourMessage.NetworkId, out NetworkIdentity dynamicIdentity); var identity = staticIdentity ?? dynamicIdentity; if (identity != null && identity.IsOwner == false) { reader.Replace(networkBehaviourMessage.Data); identity.Behaviours[networkBehaviourMessage.BehaviourIndex].Deserialize(reader); } break; } case NetworkIdentitiesDestroyed.Id: { var networkIdentitiesDestoryed = (NetworkIdentitiesDestroyed)message; foreach (long networkId in networkIdentitiesDestoryed.DestroyedNetworkIds) { this.staticNetworkObjectsHash.TryGetValue(networkId, out NetworkIdentity staticIdentity); this.dynamicNetworkObjectsHash.TryGetValue(networkId, out NetworkIdentity dynamicIdentity); var identity = staticIdentity ?? dynamicIdentity; if (identity != null) { Pooler.Destroy(identity.gameObject); } } break; } } }
private void Awake() { Pooler.DestroyImmediate(this.gameObject); }