예제 #1
0
    private void DeleteResourceHandleAsync(ref LightingEffectResHandleInstance instance, System.Action <LightingEffectResHandleInstance> callBack)
    {
        if (null == instance)
        {
            return;
        }
        int effectID = instance.EffectID;
        LightingEffectResHandle node = AllocResourcesHandle(effectID);

        node.CacheInstance(instance, EffectCacheRoot.transform, CachePos);

        int refCount = node.Release();

        if (refCount <= 0)
        {
            //移除回调
            RemoveAllCallBack(effectID);
            //看看是否加载完成
            if (m_LightEffectHandleTable.Contains(effectID))
            {
                m_LightEffectHandleTable.Remove(effectID);
            }
            PushToCache(node);
            //else
            //{
            //    //没有加载完成的直接卸载了
            //    UnLoadResourceHandle(node);
            //}
        }
        else
        {
            RemoveCallBack(effectID, callBack);
        }
    }
예제 #2
0
 private void PushToCache(LightingEffectResHandle node)
 {
     //if(node.stage == LightingEffectResHandle.loadingStage.Stage_Finish)
     {
         node.currCacheTime = 0;
         m_CacheLightEffectResHandleTable.Add(node.EffectID);
     }
 }
예제 #3
0
    public static bool isNullOrEmpry(LightingEffectResHandle node)
    {
        if (null == node)
        {
            return(true);
        }

        return(!node.isValid);
    }
 public static void BuildInstance(LightingEffectResHandle node, ref LightingEffectResHandleInstance instance)
 {
     if (null == instance)
     {
         instance = new LightingEffectResHandleInstance();
     }
     instance.m_EffectID     = node.EffectID;
     instance.m_effectConfig = node.effectConfig;
     return;
 }
예제 #5
0
    private void UpdateCallBack()
    {
        if (m_AsyncLoadingEffectResHandle.Count <= 0)
        {
            return;
        }
        tempList.Clear();

        foreach (int id in m_AsyncLoadingEffectResHandle)
        {
            LightingEffectResHandle reslut = AllocResourcesHandle(id);

            if (reslut.stage == LightingEffectResHandle.loadingStage.Stage_Finish)
            {
                tempList.Add(id);
                continue;
            }

            if (reslut.stage == LightingEffectResHandle.loadingStage.Stage_Invalid)
            {
                reslut.effectConfig = ASpeedGame.Data.Scheme.SchemeLightingEffect.Instance.GetLightingEffect(reslut.EffectID);
                if (!reslut.effectConfig)
                {
                    OnHandleResLoadFinish(null, null, reslut);
                    tempList.Add(id);
                    continue;
                }
                reslut.prefabResNode = AssetBundleManager.GetAssetsAsync(AssetType.Asset_Prefab, OnHandleResLoadFinish, reslut.effectConfig.GetAssetGUID(), true, reslut);
                if (reslut.prefabResNode == null)
                {
                    OnHandleResLoadFinish(null, null, reslut);
                    tempList.Add(id);
                    continue;
                }

                reslut.stage = LightingEffectResHandle.loadingStage.Stage_Res;
            }
        }

        foreach (int id in tempList)
        {
            EffectFactoryNodeAsyncLoadingObj obj = AllocAsyncLoadingObj(id);
            RemoveAllCallBack(id);

            for (int i = 0; i < obj.CallBackList.Count; i++)
            {
                if (obj.CallBackList[i] != null)
                {
                    obj.CallBackList[i](obj.dataList[i]);
                }
            }

            obj.Clear();
        }
    }
예제 #6
0
    private void OnHandleResLoadFinish(ResConfigData cof, ResNode res, System.Object UserDataObj)
    {
        LightingEffectResHandle node = UserDataObj as LightingEffectResHandle;

        if (null == node)
        {
            Debug.LogError("光效异步加载致命bug---UserDataObj not match");
            return;
        }
        m_LightEffectHandleTable.Add(node.EffectID);
        node.OnLoadFinish(EffectCacheRoot.transform, res);
    }
 /// <summary>
 /// 关闭cache渲染
 /// </summary>
 public void InvActiveCacheRendering()
 {
     if (CurrCachingEffectTable.Count <= 0)
     {
         return;
     }
     foreach (int ids in CurrCachingEffectTable.Keys)
     {
         LightingEffectResHandle halde = LightingEffectFactory.Instance.AllocResourcesHandle(ids);
         halde.InvActiveCacheRendering(LightingEffectFactory.Instance.CachePos);
     }
 }
예제 #8
0
    private void UnLoadResourceHandle(LightingEffectResHandle instance)
    {
        if (null == instance)
        {
            return;
        }
        ResNode temp2 = instance.prefabResNode;

        instance.Clear();

        AssetBundleManager.DeleteAssetsAsync(ref temp2, OnHandleResLoadFinish, true);
    }
예제 #9
0
    private LightingEffectResHandle GetFromCache(int effectID)
    {
        LightingEffectResHandle reslut = null;

        if (m_CacheLightEffectResHandleTable.Contains(effectID))
        {
            m_CacheLightEffectResHandleTable.Remove(effectID);
            m_LightEffectHandleTable.Add(effectID);
            reslut = AllocResourcesHandle(effectID);
            reslut.currCacheTime = 0.0f;
        }
        return(reslut);
    }
예제 #10
0
    public LightingEffectResHandle AllocResourcesHandle(int effectID)
    {
        LightingEffectResHandle reslut = null;

        if (!m_AllocLightEffectResHandleTable.TryGetValue(effectID, out reslut))
        {
            reslut = new LightingEffectResHandle();
            reslut.Clear();

            reslut.EffectID = effectID;
            m_AllocLightEffectResHandleTable.Add(effectID, reslut);
        }
        return(reslut);
    }
예제 #11
0
        /// <summary>
        /// 激活cache渲染
        /// </summary>
        public void ActiveCacheRendering()
        {
            if (CurrCachingEffectTable.Count <= 0)
            {
                return;
            }
            Vector3 effectPos = Initialize.mainCam.transform.position;
            Vector3 pos       = Vector3.zero;

            pos.z      = 20;
            pos        = Initialize.mainCam.transform.rotation * pos;
            effectPos += pos;

            foreach (int ids in CurrCachingEffectTable.Keys)
            {
                LightingEffectResHandle halde = LightingEffectFactory.Instance.AllocResourcesHandle(ids);
                halde.ActiveCacheRendering(effectPos);
            }
        }
예제 #12
0
    /// <summary>
    /// 返回值是一个标示,必须在回调函数中判断是否有效
    /// </summary>
    /// <param name="effectID"></param>
    /// <param name="param"></param>
    /// <param name="callBack"></param>
    /// <returns></returns>
    private LightingEffectResHandleInstance GetResourceHandleAsync(int effectID, System.Action <LightingEffectResHandleInstance> callBack)
    {
        LightingEffectResHandleInstance Reslut = null;
        LightingEffectResHandle         node   = GetFromCache(effectID);

        if (null != node)
        {
            Reslut = node.Instantiate();
        }
        else
        {
            node   = AllocResourcesHandle(effectID);
            Reslut = node.Instantiate();
        }
        node.AddRef();
        PushCallBack(effectID, Reslut, callBack);

        return(Reslut);
    }
예제 #13
0
        public void UpdatePreWarmProgress()
        {
            if (CurrCachingEffectTable.Count <= 0)
            {
                return;
            }
            completeList.Clear();
            foreach (int ids in CurrCachingEffectTable.Keys)
            {
                LightingEffectResHandle halde = LightingEffectFactory.Instance.AllocResourcesHandle(ids);
                if (halde.stage == LightingEffectResHandle.loadingStage.Stage_Finish)
                {
                    completeList.Add(ids);
                }
            }

            foreach (int ids in completeList)
            {
                CurrCachingEffectTable.Remove(ids);
            }
        }
    public static void FillInstance(Transform parent, LightingEffectResHandle node, LightingEffectResHandleInstance instance)
    {
        if (LightingEffectResHandle.isNullOrEmpry(node))
        {
            return;
        }

        if (null == instance)
        {
            return;
        }
        if (instance.Valid)
        {
            return;
        }

        instance.m_EffectID     = node.EffectID;
        instance.m_effectConfig = node.effectConfig;


        instance.m_effectPrefab            = node.prefabResNode.InstanceMainRes();
        instance.m_AttackGroup             = instance.m_effectPrefab.GetComponent <AttackCollisionGroup>();
        instance.m_effect_ReplaceAnimation = instance.m_effectPrefab.GetComponent <Effect_ReplaceAnimation>();
        instance.m_effect_CameraAnimation  = instance.m_effectPrefab.GetComponent <Effect_CameraAnimation>();
        instance.m_effectNode = instance.m_effectPrefab.GetComponent <EffectNode>();
        if (instance.m_effectNode)
        {
            instance.m_effectNode.isStaticEffect = false;
            instance.m_effectNode.PlayOnAwake    = false;
            instance.m_effectNode.Init();
            instance.m_effectNode.StopEffect();
        }

        instance.m_effectPrefabTransform = instance.m_effectPrefab.transform;
        instance.m_effectPrefabTransform.SetParent(parent);
        instance.m_effectPrefabTransform.position = Vector3.one * 999.0f;
        instance.m_effectPrefab.name = node.prefabResNode.AssetName + "(effect" + node.EffectID + ")";
    }
예제 #15
0
    private void UpdateCache()
    {
        if (m_CacheLightEffectResHandleTable.Count <= 0)
        {
            return;
        }
        tempList.Clear();
        foreach (int id in m_CacheLightEffectResHandleTable)
        {
            LightingEffectResHandle reslut = AllocResourcesHandle(id);
            reslut.currCacheTime += Time.deltaTime;
            if (reslut.currCacheTime > MaxCacheTime)
            {
                tempList.Add(id);
                UnLoadResourceHandle(reslut);
            }
        }

        foreach (int id in tempList)
        {
            m_CacheLightEffectResHandleTable.Remove(id);
        }
    }
예제 #16
0
    private bool PreWarmEffect(int nID, int PreWarmCount)
    {
        if (m_allBehaviorTable.ContainsKey(nID))
        {
            //Debug.LogWarning("光效已经加载,不需要缓存,ID:" + nID);
            return(false);
        }
        LightingEffect config = ASpeedGame.Data.Scheme.SchemeLightingEffect.Instance.GetLightingEffect(nID);

        if (!config)
        {
            Debug.LogWarning("光效加载失败,找不到配置,ID:" + nID);
            return(false);
        }

        LightingEffectResHandle        handle = AllocResourcesHandle(nID);
        Queue <LightingEffectBehavior> list   = null;

        if (!m_behaviorCacheTable.TryGetValue(nID, out list))
        {
            list = new Queue <LightingEffectBehavior>();
            m_behaviorCacheTable.Add(nID, list);
        }

        for (int i = 0; i < PreWarmCount; i++)
        {
            LightingEffectBehavior          reslut   = CreateNewBehavior(nID, config.GetEffectType());
            LightingEffectResHandleInstance instance = GetResourceHandleAsync(nID, reslut.OnResourcesLoadFinish);
            handle.CacheInstance(instance, EffectCacheRoot.transform, CachePos);
            handle.Release();//缓存不需要保留引用
            reslut.FillData(config, null, instance, null);
            list.Enqueue(reslut);
        }

        return(true);
    }
    public void ResetBehavior(LightingEffectBehavior instance)
    {
        if (!isValid)
        {
            return;
        }
        if (null == instance)
        {
            return;
        }
        int effectID = instance.getID();

        if (effectID > 0)
        {
            LightingEffectResHandle handle = AllocResourcesHandle(instance.getID());
            handle.CacheInstance(instance.ResourceHandle, EffectCacheRoot.transform, CachePos);
            handle.Release();
        }

        DeleteBehaviorTransformAgent(instance.TransformAgent);
        //CacheBehaviorDestroyTimer(instance.BehaviorDestroyTimer);
        instance.ResetAllMembers();
        instance.SetInvalid();
    }