void Release()
 {
     if (!Addressables.ReleaseInstance(gameObject))
     {
         Destroy(gameObject);
     }
 }
Beispiel #2
0
    private IEnumerator ReleaseInstance(AsyncOperationHandle <GameObject> asyncOperationHandle)
    {
        yield return(new WaitForSeconds(1));

        Debug.Log("开始 ReleaseInstance");
        Addressables.ReleaseInstance(asyncOperationHandle);
    }
Beispiel #3
0
 static public void ReleaseInstance(GameObject obj)
 {
     if (obj != null)
     {
         Addressables.ReleaseInstance(obj);
     }
 }
Beispiel #4
0
    IEnumerator BarrierBoxInitEffect()
    {
        material.SetFloat("_XLine", -0.5f);
        material.SetFloat("_YLine", -0.49f);
        material.SetFloat("_ZLine", -0.5f);
        material.SetFloat("_XFace", 0.5f);
        material.SetFloat("_YFace", -0.5f);
        material.SetFloat("_ZFace", 0.5f);
        StartCoroutine(ShaderFloatValueChanger(material, "_XLine", -0.5f, 0.5f, LineXTime));
        yield return(new WaitForSeconds(LineXTime));

        StartCoroutine(ShaderFloatValueChanger(material, "_ZLine", -0.5f, 0.5f, LineZTime));
        yield return(new WaitForSeconds(LineZTime));

        StartCoroutine(ShaderFloatValueChanger(material, "_YLine", -0.49f, 0.5f, LineYTime));
        StartCoroutine(ShaderFloatValueChanger(material, "_YFace", -0.5f, 0.5f, FaceYTime));
        yield return(new WaitForSeconds(FaceYTime));

        if (target)
        {
            target.GetComponent <IEnemy>()?.DestroyWithScore();
        }
        yield return(new WaitForSeconds(FaceYTime * 2));

        Addressables.ReleaseInstance(gameObject);
    }
Beispiel #5
0
 public override void Release(Object asset)
 {
     if (asset is GameObject)
     {
         Addressables.ReleaseInstance(asset as GameObject);
     }
 }
        /// <summary>
        /// Load & Instantiate Asset. this will be helpful if we deal with prefabs (ex: slots)
        /// </summary>
        /// <param name="assetReference"> target asset reference </param>
        public void Instantiate <T>(AssetReference assetReference, Action <T> onComplete, Action <string> onFailed = null)  where T : MonoBehaviour, IAsset
        {
            if (assetReference == null)
            {
                throw new NullReferenceException($"AssetReference must be not null!");
            }
            var operation = Addressables.InstantiateAsync(assetReference);

            operation.Completed += (response) =>
            {
                switch (operation.Status)
                {
                case AsyncOperationStatus.Failed:
                    onFailed?.Invoke(operation.PercentComplete.ToString());
                    break;

                case AsyncOperationStatus.Succeeded:
                    var asset = response.Result.GetComponent <IAsset>();
                    asset.OnDestroyed += () => { Addressables.ReleaseInstance(response.Result); };     //release
                    onComplete?.Invoke(response.Result.GetComponent <T>());
                    break;

                default:
                    Debug.LogError("No Result > " + response.Result);
                    break;
                }
            };
        }
    IEnumerator CheckIfAlive()
    {
        ParticleSystem ps = this.GetComponent <ParticleSystem>();

        while (true && ps != null)
        {
            yield return(new WaitForSeconds(0.5f));

            if (!ps.IsAlive(true))
            {
                if (OnlyDeactivate)
                {
                                        #if UNITY_3_5
                    this.gameObject.SetActiveRecursively(false);
                                        #else
                    this.gameObject.SetActive(false);
                                        #endif
                }
                else
                {
                    Addressables.ReleaseInstance(gameObject);
                }
                break;
            }
        }
    }
Beispiel #8
0
    IEnumerator ShowEffect()
    {
        {
            var ao = Addressables.InstantiateAsync("prefabs/cube.prefab");
            ao.Completed += handle =>
            {
                GameObject obj = ao.Result;
                obj.transform.position   = Vector3.zero;
                obj.transform.localScale = Vector3.one;
            };
            yield return(ao);
        }

        Addressables.ReleaseInstance(gameObject);
//        Addressables.ClearResourceLocators();
        Addressables.ClearDependencyCacheAsync("prefabs/launch.prefab");
        {
            var rootLayer = GameObject.Find("LaunchLayer").GetComponent <Canvas>();
            var loader    = KVResourceMgr.Instance.LoadAssetAsync("prefabs/launch.prefab");
            yield return(loader);

//            ao.Completed += handle =>
//            {
            GameObject obj = loader.asset as GameObject;
            obj = Instantiate(obj, rootLayer.transform);
            obj.transform.localPosition = Vector3.zero;
            obj.transform.localScale    = Vector3.one;
//            };
//            yield return ao;
        }        DestroyImmediate(gameObject);
    }
Beispiel #9
0
 private void OnTriggerExit(Collider other)
 {
     if (other.tag == "Boundary")
     {
         Addressables.ReleaseInstance(gameObject);
     }
 }
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Boundary" || other.tag == "Enemy")
        {
            return;
        }

        if (explosion != null)
        {
            // ADDRESSABLES UPDATES
            explosion.InstantiateAsync(transform.position, transform.rotation);
        }

        if (other.tag == "Player")
        {
            // ADDRESSABLES UPDATES
            playerExplosion.InstantiateAsync(other.transform.position, other.transform.rotation);

            gameController.GameOver();
        }

        gameController.AddScore(scoreValue);

        // ADDRESSABLES UPDATES
        Addressables.ReleaseInstance(other.gameObject);
        Addressables.ReleaseInstance(gameObject);
    }
Beispiel #11
0
 private void Validate()
 {
     #if !UNITY_EDITOR && !DEBUG_BUILD
     Addressables.ReleaseInstance(gameObject);
     #endif
     Debugging.DisplayDebugMessage("CHEATS ENABLED! \n Culprit: " + name);
 }
 private void OnDestroy()
 {
     if (_instanceHandle.IsValid())
     {
         Addressables.ReleaseInstance(_instanceHandle);
     }
 }
Beispiel #13
0
        /// <summary>
        /// 关闭UI
        /// </summary>
        /// <param name="uiName"></param>
        /// <param name="isDestroy">是否销毁</param>
        /// <param name="args"></param>
        public static void Close(string uiName, bool isDestroy = false, object args = null)
        {
            if (UIMaps.TryGetValue(uiName, out var ui))
            {
                if (ui.View.activeSelf)
                {
                    ui.Close(args);
                    if (ui.UIConfig.IsMask)
                    {
                        CloseMask(ui);
                    }
                }

                if (isDestroy)
                {
                    UIMaps.Remove(uiName);

                    if (ui.UIConfig.attachMode)
                    {
                        Object.Destroy(ui.View);
                    }
                    else
                    {
                        Addressables.ReleaseInstance(ui.View);
                    }

                    ui.Dispose();
                }
            }
        }
    public override void Exit(AState to)
    {
        missionPopup.gameObject.SetActive(false);
        inventoryCanvas.gameObject.SetActive(false);

        if (m_Character != null)
        {
            Addressables.ReleaseInstance(m_Character);
        }

        GameState gs = to as GameState;

        skyMeshFilter.gameObject.SetActive(false);
        UIGroundFilter.gameObject.SetActive(false);

        if (gs != null)
        {
            gs.currentModifier = m_CurrentModifier;

            // We reset the modifier to a default one, for next run (if a new modifier is applied, it will replace this default one before the run starts)
            m_CurrentModifier = new Modifier();

            if (m_PowerupToUse != Consumable.ConsumableType.NONE)
            {
                PlayerData.instance.Consume(m_PowerupToUse);
                Consumable inv = Instantiate(ConsumableDatabase.GetConsumbale(m_PowerupToUse));
                inv.gameObject.SetActive(false);
                gs.trackManager.characterController.inventory = inv;
            }
        }
    }
Beispiel #15
0
        public static bool CanRelease(this AsyncOperationHandle <GameObject> targetAsyncOperationHandle,
                                      bool autoRelease = false)
        {
            if (!targetAsyncOperationHandle.IsValid())
            {
                return(false);
            }

            if (targetAsyncOperationHandle.Status == AsyncOperationStatus.Succeeded)
            {
                if (autoRelease)
                {
                    // Not entirely sure about this one, as it makes sense that we should be moving to a instanced version,
                    // however games have shipped with the older method (.Release)
                    Addressables.ReleaseInstance(targetAsyncOperationHandle);
                }

                return(true);
            }

            if (targetAsyncOperationHandle.Result == null)
            {
                return(false);
            }

            if (autoRelease)
            {
                Addressables.ReleaseInstance(targetAsyncOperationHandle);
            }

            return(true);
        }
Beispiel #16
0
 void Update()
 {
     if (slaves.Count == 0)
     {
         Addressables.ReleaseInstance(gameObject);
     }
 }
Beispiel #17
0
 void Update()
 {
     if (Object != null)
     {
         Addressables.ReleaseInstance(Object);
     }
     this.enabled = false;
 }
Beispiel #18
0
        public void ReleaseObject(UnityEngine.Object obj, float delay = 0)
        {
#if USE_ADDRESSABLE
            Addressables.ReleaseInstance(obj, delay);
#else
            UnityEngine.Object.Destroy(obj, delay);
#endif
        }
Beispiel #19
0
        private void FinishDialogue()
        {
            UpdateManager.Instance.UnSubscribeFromGlobalUpdate(this.CheckPageFlip);
            QuestLibrary.BeginQuest(this.dialogue.questReference);
            PlayerController.Instance.EnableInputs();

            Addressables.ReleaseInstance(gameObject);
        }
Beispiel #20
0
            public void Release(string key, GameObject obj)
            {
#if UNITY_OBJECTPOOLING_ADDRESSABLES_MANAGER
                AddressablesManager.ReleaseInstance(key, obj);
#else
                Addressables.ReleaseInstance(obj);
#endif
            }
 // unload prefab from memory
 public void UnloadAssetInstance(Data obj)
 {
     if (!Addressables.ReleaseInstance(obj.instance))
     {
         Destroy(obj.instance);
         Addressables.Release(obj.asset);
     }
 }
Beispiel #22
0
 public void DeleteAll()
 {
     foreach (var expandViewItem in Items.Values)
     {
         Addressables.ReleaseInstance(expandViewItem.gameObject);
     }
     Items.Clear();
 }
Beispiel #23
0
 public void Close(string panelName)
 {
     if (_allPanelData.TryGetValue(panelName, out var panelData))
     {
         Addressables.ReleaseInstance(panelData.handle);
         _allPanelData.Remove(panelName);
     }
 }
 void Release()
 {
     //非经过Addressable创建的实例不能销毁,所以需要判断
     if (!Addressables.ReleaseInstance(gameObject))
     {
         Destroy(gameObject);
     }
 }
Beispiel #25
0
 /// <summary>
 /// Releases and destroys an object that was created via Addressables.InstantiateAsync.
 /// </summary>
 /// <param name="instance">The GameObject instance to be released and destroyed.</param>
 /// <returns>Returns true if the instance was successfully released.</returns>
 public static bool ReleaseInstance(GameObject instance)
 {
     if (!Addressables.ReleaseInstance(instance))
     {
         Destroy(instance);
     }
     return(true);
 }
Beispiel #26
0
 private void Despawn()
 {
     foreach (var instance in _instances)
     {
         Addressables.ReleaseInstance(instance);
     }
     _instances.Clear();
 }
Beispiel #27
0
    private void DestroyAllCube()
    {
        foreach (var cube in cubes)
        {
            Addressables.ReleaseInstance(cube);
        }

        cubes.Clear();
    }
 void OnDisable()
 {
     allAvailablePools.Remove(assetReferenceToInstantiate);
     foreach (var obj in pool)
     {
         Addressables.ReleaseInstance(obj);
     }
     pool = null;
 }
        private IEnumerator DestroyObjectOnDelay(PoolObject _poolObject, float _delay)
        {
            yield return(new WaitForSeconds(_delay));

            if (_poolObject.IsActivated == false)
            {
                Addressables.ReleaseInstance(_poolObject.gameObject);
            }
        }
Beispiel #30
0
 private void OnDestroy()
 {
     _loadAsssetsButton.onClick.RemoveAllListeners();
     foreach (var addressablePrefab in _addressablePrefabs)
     {
         Addressables.ReleaseInstance(addressablePrefab);
     }
     _addressablePrefabs.Clear();
 }