Exemple #1
0
        protected AnimationState GetAnimationStateByName(string animationName)
        {
            if (null == _AnimationUnitComp)
            {
                return(null);
            }
            if (null != _AnimationComp[animationName])
            {
                return(_AnimationComp[animationName]);
            }
            if (null == _AnimationInfo)
            {
                return(null);
            }

            string path = GetFullAssetPath(animationName);

            if (string.IsNullOrEmpty(path))
            {
                //HobaDebuger.Log("cant find animationPath and transform name  is "+ this.transform.name +" animationName is "+ animationName);
                return(null);
            }
            AnimationClip clip = CAssetBundleManager.SyncLoadAssetFromBundle <AnimationClip>(path, "animations", true);

            if (null == clip)
            {
                HobaDebuger.Log("cant Sync Load clip Resource and transform name  is " + this.transform.name + " animationName is " + animationName);
                return(null);
            }

            _AnimationComp.AddClip(clip, animationName);
            return(_AnimationComp[animationName]);
        }
Exemple #2
0
    private void LoadAndPlayMusic(CSoundEntry soundEntry, string soundName, float fadeInTime)
    {
        if (!string.IsNullOrEmpty(soundName) && soundName == soundEntry.Item.audioName && soundEntry.CurPhase == BgmChangePhase.OLD_FADE_OUT)
        {
            soundEntry.NewName    = soundName;
            soundEntry.CurPhase   = BgmChangePhase.NEW_FADE_IN;
            soundEntry.FadeInTime = fadeInTime;
        }
        else if (soundEntry.Item.audioName != soundName)
        {
            soundEntry.NewName    = soundName;
            soundEntry.CurPhase   = BgmChangePhase.OLD_FADE_OUT;
            soundEntry.FadeInTime = fadeInTime;

            if (!string.IsNullOrEmpty(soundEntry.NewName) && !IsClipCached(soundEntry.NewName))
            {
                Action <UnityEngine.Object> callback = asset =>
                {
                    if (!soundEntry.IsEnabled)
                    {
                        return;
                    }
                    CacheClipFromLoading(soundEntry.NewName, soundName, asset);
                };
                CAssetBundleManager.AsyncLoadResource(soundEntry.NewName, callback, false);
            }
        }
    }
Exemple #3
0
        protected AnimationState GetAnimationStateByName(string animationName, bool aysn = true)
        {
            if (null == _AnimationComponent)
            {
                return(null);
            }
            var anim = _AnimationComponent[animationName];

            if (null != anim)
            {
                return(anim);
            }
            if (!aysn || null == _AnimationInfo)
            {
                return(null);
            }

            var path = GetFullAssetPath(animationName);

            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            var clip = CAssetBundleManager.SyncLoadAssetFromBundle <AnimationClip>(path, "animations", true);

            if (null == clip)
            {
                return(null);
            }

            _AnimationComponent.AddClip(clip, animationName);
            return(_AnimationComponent[animationName]);
        }
        public void ChangeArmorEmbroidery(string path)
        {
            if (!_EmbroiderySetting.IsValid)
            {
                HobaDebuger.LogWarning("Current Armor does not support ChangeEmbroidery");
                return;
            }

            var bodyRender = GetSkinnedMeshRenderer(OutwardPart.Body);

            if (bodyRender == null)
            {
                HobaDebuger.LogWarningFormat("Current Armor named {0} has no Body Render", gameObject.name);
                return;
            }

            Material mat = new Material(bodyRender.sharedMaterial);

            if (string.IsNullOrEmpty(path))
            {
                ChangeArmorEmbroidery(mat, false, null, null, null, Vector4.zero);
                bodyRender.sharedMaterial = mat;

                var man = transform.GetComponent <EntityEffectComponent>();
                if (null != man)
                {
                    man.OnMaterialChanged(bodyRender);
                }
            }
            else
            {
                Vector4 rect = new Vector4(_EmbroiderySetting.XMin, _EmbroiderySetting.YMin, _EmbroiderySetting.XMax, _EmbroiderySetting.YMax);

                Action <UnityEngine.Object> callback = (asset) =>
                {
                    GameObject go = asset as GameObject;
                    if (go != null)
                    {
                        var imgset = go.GetComponent <EmbroideryImg>();
                        if (imgset != null)
                        {
                            ChangeArmorEmbroidery(mat, true, imgset.DiffuseTex as Texture2D,
                                                  imgset.NormalTex as Texture2D, imgset.SpecularTex as Texture2D, rect);
                            bodyRender.sharedMaterial = mat;

                            var man = transform.GetComponent <EntityEffectComponent>();
                            if (null != man)
                            {
                                man.OnMaterialChanged(bodyRender);
                            }
                        }
                    }
                    else
                    {
                        HobaDebuger.LogWarningFormat("Resource named {0} is null", path);
                    }
                };
                CAssetBundleManager.AsyncLoadResource(path, callback, false, "outward");
            }
        }
Exemple #5
0
    public void Show(TweenCallback cb)
    {
        if (_MaskGameObject == null)
        {
            Action <UnityEngine.Object> callback = (asset) =>
            {
                _MaskGameObject = CUnityUtil.Instantiate(asset) as GameObject;
                if (_MaskGameObject == null)
                {
                    return;
                }

                _MaskGameObject.transform.localScale = Vector3.one;
                _ImageComp = _MaskGameObject.transform.Find("Canvas/Image").GetComponent <Image>();
                _TextComp  = _MaskGameObject.transform.Find("Canvas/Text").GetComponent <Text>();

                if (_ImageComp != null)
                {
                    _ImageBenginAlpha = _ImageComp.color.a;
                    var tweener = _ImageComp.DOFade(1, 0.5F);
                    if (cb != null && tweener != null)
                    {
                        tweener.OnComplete <Tweener>(cb);
                    }
                }
                if (_TextComp != null)
                {
                    _TextBenginAlpha = _TextComp.color.a;
                    _TextComp.DOFade(1, 0.5F);
                }
            };

            CAssetBundleManager.AsyncLoadResource(CgMaskPath, callback, false);
        }
        else
        {
            _MaskGameObject.SetActive(true);
            _MaskGameObject.transform.localScale = Vector3.one;
            if (_ImageComp != null)
            {
                var c = _ImageComp.color;
                c.a = _ImageBenginAlpha;
                _ImageComp.color = c;
                var tweener = _ImageComp.DOFade(1, 0.5F);
                if (cb != null)
                {
                    tweener.OnComplete <Tweener>(cb);
                }
            }

            if (_TextComp != null)
            {
                var c = _TextComp.color;
                c.a             = _TextBenginAlpha;
                _TextComp.color = c;
                _TextComp.DOFade(1, 0.5F);
            }
        }
    }
Exemple #6
0
 private void Awake()
 {
     Debug.Log(Application.persistentDataPath + "/Brunhild/Bundles/");
     if (_itemDatabase == null)
     {
         _itemDatabase = CAssetBundleManager.GetItemDatabase();
     }
 }
        private void LoadOutwardGfx(OutwardPart part, OutwardSfx outwardSfx, string assetPath)
        {
            if (null == outwardSfx.OutwardSfxInfos || 0 == outwardSfx.OutwardSfxInfos.Length)
            {
                return;
            }

            for (int i = 0; i < outwardSfx.OutwardSfxInfos.Length; i++)
            {
                var boneRoot   = transform;
                var curSfxInfo = outwardSfx.OutwardSfxInfos[i];
                var isRootGfx  = string.IsNullOrEmpty(curSfxInfo.HangPointPath);
                if (!isRootGfx)
                {
                    boneRoot = transform.Find(curSfxInfo.HangPointPath);
                }

                if (boneRoot == null)
                {
                    return;
                }

                Action <UnityEngine.Object> callback = (asset) =>
                {
                    // 资源加载过程中,数据发生变化
                    if (_CurAssetPathPaths[(int)part] != assetPath)
                    {
                        return;
                    }

                    var gameObj = GameObject.Instantiate(asset) as GameObject;
                    if (null == gameObj)
                    {
                        return;
                    }

                    var obj = gameObj;
                    obj.transform.SetParent(boneRoot);
                    obj.transform.localPosition = curSfxInfo.Position;
                    obj.transform.localRotation = Quaternion.Euler(curSfxInfo.Rotation);
                    obj.transform.localScale    = curSfxInfo.Scale;
                    Util.SetLayerRecursively(obj, boneRoot.gameObject.layer);

                    _ExtraTransDic[(int)part].Add(obj.transform);

                    if (isRootGfx)
                    {
                        // 处于模型底部的特效
                        _RootSfxList.Add(obj);
                        if (_IsHidRootSfx)
                        {
                            obj.SetActive(false);
                        }
                    }
                };
                CAssetBundleManager.AsyncLoadResource(outwardSfx.OutwardSfxInfos[i].SfxPath, callback, false);
            }
        }
    private void LoadBlockWithCounter(string blockName, int effectiveType)
    {
        if (string.IsNullOrEmpty(_Config.BundleName))
        {
            var subStrings = blockName.Split('/');
            if (subStrings.Length > 2)
            {
                _Config.BundleName = subStrings[2].ToLower();
            }
            ;
        }

        if (string.IsNullOrEmpty(_Config.BundleName))
        {
            return;
        }

        int currentSceneId = _CurSceneGuid;
        Action <UnityEngine.Object> callback = (asset) =>
        {
            if (currentSceneId != _CurSceneGuid)
            {
                return;
            }

            if (null != asset)
            {
                GameObject sceneBlock = GameObject.Instantiate(asset) as GameObject;
                if (sceneBlock != null)
                {
                    sceneBlock.transform.SetParent(_BlocksRootTran);
                    if (!_LoadedObjectDic.ContainsKey(blockName))
                    {
                        if (!string.IsNullOrEmpty(blockName))
                        {
                            _LoadedObjectDic.Add(blockName, sceneBlock);
                        }

                        AddToSpecialObjectList(sceneBlock);
                    }
                    if (effectiveType != 0)
                    {
                        ShowSpecialBlock(sceneBlock, effectiveType, blockName);
                    }
                }
            }
            --_PreLoadBlockCounter;
            if (0 == _PreLoadBlockCounter && null != _CallBack)
            {
                _CallBack();
                _CallBack         = null;
                _BeginFrameUpdate = true;
            }
        };

        CAssetBundleManager.AsyncLoadResource(blockName, callback, false, _Config.BundleName);
    }
Exemple #9
0
    public CFxOne RequestUncachedFx(string fxName, bool isSingleton = true)
    {
        CFxOne fxone = null;

        if (!isSingleton || !_UncachedFxs.TryGetValue(fxName, out fxone) || fxone == null || fxone.gameObject == null)           //被清理
        {
            fxone          = new GameObject("UncachedFx").AddComponent <CFxOne>();
            fxone.Priority = -1;
            fxone.IsCached = false;
            Action <UnityEngine.Object> callback = (asset) =>
            {
                if (asset != null && fxone != null && fxone.gameObject != null)
                {
                    GameObject fx = GameObject.Instantiate(asset) as GameObject;
                    if (fx != null)
                    {
                        Transform fxTrans = fx.transform;
                        fxTrans.parent        = fxone.transform;
                        fxTrans.localPosition = Vector3.zero;
                        fxTrans.localRotation = Quaternion.identity;
                        fxTrans.localScale    = Vector3.one;
                        Util.SetLayerRecursively(fx, fxone.gameObject.layer);
                        fxone.SetFxGameObject(fx);
                        fxone.Active(true);
                        fxone.SetScale(fxone.RealScale);
                    }
                    else
                    {
                        HobaDebuger.LogWarningFormat("RequestUncachedFx asset is not GameObject!: {0}", fxName);
                    }
                }
            };

            CAssetBundleManager.AsyncLoadResource(fxName, callback, false, "sfx");
            if (isSingleton)
            {
                fxone.transform.parent = _UncachedFxsRootTrans;

                if (!_UncachedFxs.ContainsKey(fxName))
                {
                    _UncachedFxs.Add(fxName, fxone);
                }
                else
                {
                    _UncachedFxs[fxName] = fxone;
                }
            }
        }
        else
        {
            fxone.Active(true);
            fxone.SetScale(fxone.RealScale);
        }

        return(fxone);
    }
 private static void InitCheck()
 {
     if (_instance == null)
     {
         _instance           = new CAssetBundleManager();
         _instance._ui       = AssetBundle.LoadFromFile(CUtillity.assetBundlePath + "ui");
         _instance._database = AssetBundle.LoadFromFile(CUtillity.assetBundlePath + "database");
         return;
     }
 }
    // Use this for initialization
    void Start()
    {
        _uiItems = GetComponent <CSlotPanel>().uiItems;
        _uiItems.ForEach(item => item.isCraftingSlot = true);

        if (_recipeDatabase == null)
        {
            _recipeDatabase = CAssetBundleManager.GetRecipeDatabase();
        }
    }
Exemple #12
0
    private void TestLoadResource(string assetname)
    {
        Action <UnityEngine.Object> callback = (asset) =>
        {
            var obj = GameObject.Instantiate(asset) as GameObject;
            HobaDebuger.LogWarningFormat("GameObject Loaded! name: {0}", obj.name);
            GameObject.DestroyImmediate(obj);
        };

        CAssetBundleManager.AsyncLoadResource(assetname, callback, false);
    }
Exemple #13
0
    public static int UnloadBundle(IntPtr L)
    {
        int       count = LuaDLL.lua_gettop(L);
        const int nRet  = 0;

        if (count == 1 && LuaScriptMgr.CheckTypes(L, 1, typeof(string)))
        {
            var bundleName = LuaScriptMgr.GetString(L, 1);
            CAssetBundleManager.UnloadBundle(bundleName);
        }

        return(CheckReturnNum(L, count, nRet));
    }
Exemple #14
0
    public void Init(string name)
    {
        if (_IsLoading || _Asset != null)
        {
            return;
        }

        Action <UnityEngine.Object> callback = (asset) =>
        {
            _Asset     = asset as GameObject;
            _IsLoading = false;

            if (_Asset == null)
            {
                for (int i = 0; i < _DeferedGotFx.Count; ++i)
                {
                    var fxone = _DeferedGotFx[i];
                    fxone.Stop();
                }

                _DeferedGotFx.Clear();
            }
            else
            {
                for (int i = 0; i < _DeferedGotFx.Count; ++i)
                {
                    var fxone = _DeferedGotFx[i];
                    if (fxone.IsPlaying)
                    {
                        var       fx    = UnityEngine.Object.Instantiate(_Asset) as GameObject;
                        Transform trans = fx.transform;
                        trans.parent        = fxone.transform;
                        trans.localPosition = Vector3.zero;
                        trans.localRotation = Quaternion.identity;
                        trans.localScale    = Vector3.one;
                        Util.SetLayerRecursively(fx, fxone.gameObject.layer);
                        fxone.SetFxGameObject(fx);
                        fxone.DoRealPlay();
                    }
                    else
                    {
                        fxone.Stop();
                    }
                }
                _DeferedGotFx.Clear();
            }
        };

        _IsLoading = true;
        CAssetBundleManager.AsyncLoadResource(name, callback, false, "sfx");
    }
Exemple #15
0
    private void PlayCommonCG()
    {
        Action <UnityEngine.Object> callback = (asset) =>
        {
            // 异步加载中 可能存在其他操作(比如cg结束 切换成功)
            if (asset == null || _CgXmlConfig.Path == null || !_CgXmlConfig.Path.Contains(asset.name))
            {
                return;
            }

            var cg = CUnityUtil.Instantiate(asset) as GameObject;
            if (cg == null)
            {
                return;
            }

            var cgg = cg.GetComponent <CGGlobal>();
            if (cgg == null)
            {
                Destroy(cg);
                return;
            }

            _CurCGGlobal = cgg;
            _CurCutscene = cg.GetComponentInChildren <Cutscene>();
            _CurCutscene.CutsceneStarted  += OnCutsceneStarted;
            _CurCutscene.CutsceneFinished += OnCutsceneFinished;

            if (_CgXmlConfig.StartCallback != null)
            {
                _CgXmlConfig.StartCallback();
                _CgXmlConfig.StartCallback = null;
            }

            if (_CgXmlConfig.IsMaskShown)
            {
                _CGMask.Hide();
            }

            if (_CurCutscene != null)
            {
                _CurCutscene.Optimize();
                _CurCutscene.Play();
            }
        };

        CAssetBundleManager.AsyncLoadResource(_CgXmlConfig.Path, callback, false);
    }
    public void Clear()
    {
        _BeginFrameUpdate          = false;
        _BlocksRootTran            = null;
        _PlayerLightmapBundleAsset = null;

        _SceneLightmapDatas        = null;
        LightmapSettings.lightmaps = null;

        _LoadedAQUASReflectionDic.Clear();
        _LoadedStaticObjectAudioDic.Clear();
        _LoadedPoints.Clear();

        _CurSceneGuid = 0;

        foreach (var kv in _LoadedObjectDic)
        {
            if (null != kv.Value)
            {
                GameObject.Destroy(kv.Value);
            }
        }
        _LoadedObjectDic.Clear();

        foreach (var kv in _ObjectCacheDic)
        {
            if (null != kv.Value)
            {
                GameObject.Destroy(kv.Value);
            }
        }
        _ObjectCacheDic.Clear();

        _LightmapIdx2RefCountDic.Clear();

        _BeginFrameUpdate    = false;
        _CallBack            = null;
        _PreLoadBlockCounter = 0;

        _IsLightmapsUpdated = false;

        if (_Config != null && !string.IsNullOrEmpty(_Config.BundleName))
        {
            CAssetBundleManager.UnloadBundle(_Config.BundleName);
        }

        _Config = null;
    }
Exemple #17
0
    private void CreateDefault()
    {
        var parentTrans = GetTransformParent();

        if (parentTrans == null)
        {
            return;
        }

        var prefab = CAssetBundleManager.SyncLoadAssetFromBundle <GameObject>(path);

        if (prefab == null)
        {
            return;
        }

        var go = CUnityUtil.Instantiate(prefab) as GameObject;

        if (go != null)
        {
            go.name = EntityId;
            var goT = go.transform;
            if (clientPath != string.Empty)
            {
                GameObject goParent = GameObject.Find(clientPath);
                if (goParent)
                {
                    goT.parent = goParent.transform;
                }
                goT.localPosition = position;
                goT.localRotation = Quaternion.Euler(rotation);
            }
            else
            {
                goT.parent   = parentTrans;
                goT.position = position;
                goT.rotation = Quaternion.Euler(rotation);
            }

            Util.SetLayerRecursively(go, LAYER_CG);
            SetTransform(goT);

            if (type == EntityType.Sfx)
            {
                go.SetActive(false);
            }
        }
    }
Exemple #18
0
    public static void PreLoadUIFX(string fxPath)
    {
        if (string.IsNullOrEmpty(fxPath))
        {
            return;
        }

        PrefabCacheData sfx_pf;

        if (!_PrefabCache.TryGetValue(fxPath, out sfx_pf))
        {
            Action <UnityEngine.Object> callback = (asset) =>
            {
                PoolPrefabe(fxPath, asset);
            };
            CAssetBundleManager.AsyncLoadResource(fxPath, callback, false, "sfx");
        }
    }
Exemple #19
0
    IEnumerator LoadBundleCoroutine()
    {
        while (true)
        {
            bool          isAddable = true;
            CItemDatabase data      = CAssetBundleManager.GetItemDatabase();
            Sprite        sprite    = CAssetBundleManager.GetUISprite("ore_diamond");

            //foreach (CItemDatabase dat in datList)
            //{
            //    if (dat.Equals(data))
            //    {
            //        isAddable = false;
            //        break;
            //    }
            //}

            if (isAddable)
            {
                Debug.Log("데이터넣음");
                datList.Add(data);
            }

            isAddable = true;

            foreach (Sprite spr in sprList)
            {
                if (spr.Equals(sprite))
                {
                    isAddable = false;
                    break;
                }
            }

            if (isAddable)
            {
                Debug.Log("데이터넣음");
                sprList.Add(sprite);
            }

            yield return(null);
        }
    }
Exemple #20
0
    public void InitGroundEffect()
    {
        //ground effect
        _GroundShadow = _GroundT.Find("Shadow");
        _GroundWater  = _GroundT.Find("Water");

        if (GroundType == GROUND_TYPE.Shadow && _GroundShadow == null)
        {
            if (pbShadow == null)
            {
                //GameObject obj =CAssetBundleManager.SyncLoadAssetFromBundle<GameObject>(ShadowPath, ShadowBundlePath);
                //(ShadowPath, OnShadowLoaded, ShadowBundlePath);
                OnPBLoaded(pbShadow, ref _GroundShadow, GROUND_TYPE.Shadow);
            }
            else
            {
                OnPBLoaded(pbShadow, ref _GroundShadow, GROUND_TYPE.Shadow);
            }
        }
        else if (GroundType == GROUND_TYPE.Water && _GroundWater == null)
        {
            if (pbWater == null)
            {
                //CAssetBundleManager.SyncLoadAssetFromBundle(WaterPath, OnWaterLoaded, WaterBundlePath);
                pbWater = CAssetBundleManager.SyncLoadAssetFromBundle <GameObject>(WaterPath, WaterBundlePath);
                OnPBLoaded(pbWater, ref _GroundWater, GROUND_TYPE.Water);
            }
            else
            {
                OnPBLoaded(pbWater, ref _GroundWater, GROUND_TYPE.Water);
            }
        }

        if (_GroundWater != null)
        {
            _GroundWater.gameObject.SetActive(GroundType == GROUND_TYPE.Water);
        }
        if (_GroundShadow != null)
        {
            _GroundShadow.gameObject.SetActive(GroundType == GROUND_TYPE.Shadow);
        }
    }
Exemple #21
0
    private void PlayVideoCG()
    {
        if (_CommonVideoFrame == null)
        {
            if (_IsCommonVideoFrameLoading)
            {
                return;
            }

            Action <UnityEngine.Object> callback = (asset) =>
            {
                var cg = CUnityUtil.Instantiate(asset) as GameObject;
                if (cg == null)
                {
                    return;
                }

                _CommonVideoFrame    = cg;
                _VideoRawImage       = cg.transform.Find("UICanvas/UI_Video/Img_Video").GetComponent <RawImage>();
                _DialogueRoot        = cg.transform.Find("UICanvas/UIBasic/Down").gameObject;
                _DialogueNameText    = _DialogueRoot.transform.Find("Name").GetComponent <Text>();
                _DialogueContentText = _DialogueRoot.transform.Find("Content").GetComponent <Text>();

                _IsCommonVideoFrameLoading = false;

                // 异步加载中 可能存在其他操作(比如cg结束 切换成功)
                if (asset == null || _CgXmlConfig.Path == null || !_CgXmlConfig.IsVideo)
                {
                    return;
                }

                PlayVideoImp();
            };
            _IsCommonVideoFrameLoading = true;
            CAssetBundleManager.AsyncLoadResource(VIDEO_CG_COMMON_UI_PATH, callback, false);
        }
        else
        {
            PlayVideoImp();
        }
    }
Exemple #22
0
    private IEnumerable AssetBundlesPreprocess()
    {
        // Set DoNotReleaseBundle Info

        /*
         * var bundleNames = new []
         * {
         *  "animations", "commonatlas", "cganimator", "cg",
         *   "outward", "monsters", "characters",
         *  "interfaces_kr", "interfaces_tw", "interfaces",
         *   "sfx", "others",
         * };
         * */

        // AssetBundlesPreprocess: AnimationClip & Icon
        // 采用的是同步加载实现,需要预先加载
        foreach (var v in GameCustomConfigParams.PreloadBundles)
        {
            CAssetBundleManager.SyncLoadAssetBundle(v);
            yield return(null);
        }
    }
Exemple #23
0
    public void LoadAssets()
    {
        Action <UnityEngine.Object> callback = (asset) =>
        {
            _IsLoading   = false;
            _AssetBundle = null;

            var bundle = asset as AssetBundle;
            if (bundle == null)
            {
                HobaDebuger.LogError("Failed to load AssetBundle: shaders");
                return;
            }
            _AssetBundle = bundle;
        };

        var bundleName = "shader";

        _IsLoading   = true;
        _AssetBundle = null;
        CAssetBundleManager.AsyncLoadBundle(bundleName, callback);
    }
Exemple #24
0
    public void UpdateItem(CItem item)
    {
        this.item = item;

        if (item != null)
        {
            _icon.color  = Color.white;
            _icon.sprite = CAssetBundleManager.GetUISprite(item.iconPath);
            if (_icon.sprite == null)
            {
                _icon.color = Color.clear;
            }
        }
        else
        {
            _icon.color = Color.clear;
        }

        if (isCraftingSlot)
        {
            _craftingSlot.UpdateRecipe();
        }
    }
Exemple #25
0
    private static void DoAsyncLoadResource(IntPtr L, string assetname, int callbackRef, bool needInstantiate)
    {
        Action <UnityEngine.Object> callback = (asset) =>
        {
            if (LuaScriptMgr.Instance.GetLuaState() == null)
            {
                return;
            }

            var oldTop = LuaDLL.lua_gettop(L);
            LuaDLL.lua_rawgeti(L, LuaIndexes.LUA_REGISTRYINDEX, callbackRef); // cb
            LuaDLL.luaL_unref(L, LuaIndexes.LUA_REGISTRYINDEX, callbackRef);
            if (LuaDLL.lua_isnil(L, -1))
            {
                LuaDLL.lua_settop(L, oldTop);
                return;
            }

            LuaDLL.lua_pushvalue(L, -1);    //-> cb, cb
            if (asset != null)
            {
                LuaScriptMgr.Push(L, asset);
            }
            else
            {
                LuaDLL.lua_pushnil(L);
            }

            if (!LuaScriptMgr.Instance.GetLuaState().PCall(1, 0)) //-> cb, [err]
            {
                HobaDebuger.LogLuaError(LuaDLL.lua_tostring(L, -1));
            }
            LuaDLL.lua_settop(L, oldTop);
        };

        CAssetBundleManager.AsyncLoadResource(assetname, callback, needInstantiate);
    }
Exemple #26
0
    public IEnumerator AsyncInit()
    {
        CAssetBundleManager abm = CAssetBundleManager.Instance;

        bool        loadDone    = false;
        AssetBundle assetBundle = null;

        abm.LoadAssetBundleName(m_assetBundleToLoad, (a) => {
            loadDone    = true;
            assetBundle = a;
        });

        while (!loadDone)
        {
            yield return(false);
        }

        if (assetBundle != null)
        {
            //instantiate
            GameObject pfb = assetBundle.LoadAsset <GameObject>(m_prefabToLoad);

            if (pfb != null)
            {
                GameObject.Instantiate(pfb);
            }
            else
            {
                Debug.LogWarning("Asset not found : ");
            }
        }



        yield return(true);
    }
Exemple #27
0
 public void Start(Action action)
 {
     if (null == FrozenMaterial)
     {
         Action <UnityEngine.Object> callback = (asset) =>
         {
             FrozenMaterial = asset as Material;
             if (_LoadedCallback != null)
             {
                 _LoadedCallback();
                 _LoadedCallback = null;
             }
         };
         CAssetBundleManager.AsyncLoadResource(FrozenEffectMatPath, callback, false, "others");
         _LoadedCallback = action;
     }
     else
     {
         if (action != null)
         {
             action();
         }
     }
 }
    private void LoadAssetWithPlayerLight(SceneConfig.LightmapsConfig lightmapConf)
    {
        if (string.IsNullOrEmpty(lightmapConf._LightmapAssetName))
        {
            HobaDebuger.Log("this scenes 's lightmap asset name is null ,please check resources");
            return;
        }

        var loadedSceneId = _CurSceneGuid;
        Action <UnityEngine.Object> callback = (asset) =>
        {
            if (loadedSceneId != _CurSceneGuid)
            {
                HobaDebuger.LogWarning("the asset being loaded is not belong to this scene ");
                return;
            }
            LightMapAsset lightmapAsset = asset as LightMapAsset;

            if (null == lightmapAsset)
            {
                HobaDebuger.LogWarning("Lightmap asset loaded failed  ! ");
                return;
            }
            _PlayerLightmapBundleAsset = lightmapAsset;

            #region 预加载的物件光照信息补全

            List <int> tempList = new List <int>();
            for (int i = 0; i < lightmapConf._MeshLightmapInfos.Length; i++)
            {
                if (null != lightmapConf._MeshLightmapInfos[i]._Renderer)
                {
                    if (!tempList.Contains(lightmapConf._MeshLightmapInfos[i]._LightmapIndex))
                    {
                        tempList.Add(lightmapConf._MeshLightmapInfos[i]._LightmapIndex);
                    }
                    lightmapConf._MeshLightmapInfos[i]._Renderer.lightmapIndex       = lightmapConf._MeshLightmapInfos[i]._LightmapIndex;
                    lightmapConf._MeshLightmapInfos[i]._Renderer.lightmapScaleOffset = lightmapConf._MeshLightmapInfos[i]._LightmapScaleOffset;
                }
            }
            for (int i = 0; i < lightmapConf._TerrainLightmapInfos.Length; i++)
            {
                if (null != lightmapConf._TerrainLightmapInfos[i]._Terrain)
                {
                    if (!tempList.Contains(lightmapConf._TerrainLightmapInfos[i]._LightmapIndex))
                    {
                        tempList.Add(lightmapConf._TerrainLightmapInfos[i]._LightmapIndex);
                    }

                    lightmapConf._TerrainLightmapInfos[i]._Terrain.lightmapIndex       = lightmapConf._TerrainLightmapInfos[i]._LightmapIndex;
                    lightmapConf._TerrainLightmapInfos[i]._Terrain.lightmapScaleOffset = lightmapConf._TerrainLightmapInfos[i]._LightmapScaleOffset;
                }
            }

            for (int i = 0; i < tempList.Count; i++)
            {
                int v = _LightmapIdx2RefCountDic[tempList[i]];
                if (0 == v)
                {
                    _IsLightmapsUpdated = true;
                }
                _LightmapIdx2RefCountDic[tempList[i]] = v + 1;
            }
            UpdateLightmaps();
            #endregion 预加载的物件光照信息补全
            // if (EntryPoint.Instance._UsingStaticBatching)
            //   CUnityHelper.StaticBatching(gameObject);
        };

        CAssetBundleManager.AsyncLoadResource(lightmapConf._LightmapAssetName, callback, false, "scenes");
    }
Exemple #29
0
        public void ChangeOutward(OutwardPart part, string assetPath, LuaFunction cbref)
        {
            if (_OnFinishCallbackRefs[(int)part] != null)
            {
                _OnFinishCallbackRefs[(int)part].Release();
            }
            _OnFinishCallbackRefs[(int)part] = cbref;

            if (_CurAssetPathPaths[(int)part] == assetPath)
            {
                return;
            }

            _CurAssetPathPaths[(int)part]    = assetPath;
            _CurAssetLoadingState[(int)part] = true;

            if (_DynamicBonesCompList[(int)part] != null)
            {
                _DynamicBonesCompList[(int)part].Clear();
            }

            // assetPathId == 0表示换回初始设置
            if (string.IsNullOrEmpty(assetPath))
            {
                // 按照现行逻辑,此处应该是无用的,所有外观路径都会传,assetPath不可为空
                var smr         = GetSkinnedMeshRenderer(part);
                var defaultData = _DefaultOutwards[(int)part];
                if (smr != null && defaultData.SharedMesh != null && defaultData.Mat != null && defaultData.Bones != null)
                {
                    smr.sharedMesh     = defaultData.SharedMesh;
                    smr.sharedMaterial = defaultData.Mat;
                    smr.bones          = defaultData.Bones;
                }
                _EmbroiderySetting.IsValid       = false;
                _CurAssetLoadingState[(int)part] = false;

                CleanupExtraInfo(part);

                var man = transform.GetComponent <EntityEffectComponent>();
                if (null != man)
                {
                    man.OnMaterialChanged(smr);
                }

                OnChangeEnd(part);
            }
            else
            {
                Action <UnityEngine.Object> callback = (asset) =>
                {
                    // 资源加载过程中,数据发生变化
                    if (_CurAssetPathPaths[(int)part] != assetPath)
                    {
                        return;
                    }
                    _CurAssetLoadingState[(int)part] = false;

                    var prefab = asset as GameObject;
                    if (prefab == null)
                    {
                        HobaDebuger.LogWarningFormat("Outward Asset is null, path = {0}", assetPath);
                        return;
                    }

                    var smr = GetSkinnedMeshRenderer(part);
                    if (null == smr)
                    {
                        HobaDebuger.LogWarningFormat("fashion SkinnedMeshRenderer is null  = {0}", assetPath);
                        return;
                    }

                    // 外观源信息存在以下两种数据中:都包含mesh material bones信息
                    // 1 FashionOutwardInfo 时装,可能存在多余的骨骼
                    // 2 OutwardInfo 基础外观,换脸换发型
                    var isValid = UpdateFashionInfo(smr, part, prefab, assetPath) || UpdateOutwardInfo(smr, part, prefab, assetPath);
                    if (isValid)
                    {
                        var man = transform.GetComponent <EntityEffectComponent>();
                        if (null != man)
                        {
                            man.OnMaterialChanged(smr);
                        }

                        OnChangeEnd(part);
                    }
                };
                CAssetBundleManager.AsyncLoadResource(assetPath, callback, false);
            }
        }
Exemple #30
0
    public void Enable(bool enable)
    {
        if (enable)
        {
            if (!_IsSaved)
            {
                _OldSkyColor         = RenderSettings.ambientSkyColor;
                _OldEquatorColor     = RenderSettings.ambientEquatorColor;
                _OldGroundColor      = RenderSettings.ambientGroundColor;
                _OldAmbientIntensity = RenderSettings.ambientIntensity;

                _OldIsFogOn     = RenderSettings.fog;
                _OldFogColor    = RenderSettings.fogColor;
                _OldFogMode     = RenderSettings.fogMode;
                _OldFogBeginDis = RenderSettings.fogStartDistance;
                _OldFogEndDis   = RenderSettings.fogEndDistance;

                _IsSaved = true;
            }

            RenderSettings.ambientSkyColor     = _SkyColor;
            RenderSettings.ambientEquatorColor = _EquatorColor;
            RenderSettings.ambientGroundColor  = _GroundColor;
            RenderSettings.ambientIntensity    = _AmbientIntensity;
            RenderSettings.fog              = _IsFogOn;
            RenderSettings.fogColor         = _FogColor;
            RenderSettings.fogMode          = _FogMode;
            RenderSettings.fogStartDistance = _FogBeginDis;
            RenderSettings.fogEndDistance   = _FogEndDis;
        }
        else
        {
            if (_IsSaved)
            {
                RenderSettings.ambientSkyColor     = _OldSkyColor;
                RenderSettings.ambientEquatorColor = _OldEquatorColor;
                RenderSettings.ambientGroundColor  = _OldGroundColor;
                RenderSettings.ambientIntensity    = _OldAmbientIntensity;
                RenderSettings.fog              = _OldIsFogOn;
                RenderSettings.fogColor         = _OldFogColor;
                RenderSettings.fogMode          = _OldFogMode;
                RenderSettings.fogStartDistance = _OldFogBeginDis;
                RenderSettings.fogEndDistance   = _OldFogEndDis;
                _IsSaved = false;
            }
        }

        Shader.SetGlobalVector(ShaderIDs.SkySunDirchar1, AddonDirection);
        Shader.SetGlobalColor(ShaderIDs.SkyReflectionColor, RefColor);
        Shader.SetGlobalFloat(ShaderIDs.SkyAddon, HeadlightIntesity);
        if (null != _Sky)
        {
            if (null != _CubeMap)
            {
                _Sky.SkyCubeMap = _CubeMap;
            }
            else
            {
                if (string.IsNullOrEmpty(_CubeMapName))
                {
                    return;
                }
                var cubeMapName = HobaText.Format("Assets/Outputs/Scenes/SkySphere/Cubemaps/{0}.cubemap", _CubeMapName);
                Action <UnityEngine.Object> callback = (asset) =>
                {
                    if (null != asset)
                    {
                        _CubeMap = asset as Cubemap;

                        if (_Sky != null)
                        {
                            _Sky.SkyCubeMap = _CubeMap;
                        }
                    }
                };
                CAssetBundleManager.AsyncLoadResource(cubeMapName, callback, false, "scenes");
            }
            if (null != _EnvCubeMapStart)
            {
                Shader.SetGlobalTexture(ShaderIDs.EnvMap1, _EnvCubeMapStart);
            }
            else
            {
                if (string.IsNullOrEmpty(_EnvCubeMapNameStart))
                {
                    return;
                }
                var cubeMapName = HobaText.Format("Assets/Outputs/Scenes/SkySphere/Cubemaps/{0}.cubemap", _EnvCubeMapStart);
                Action <UnityEngine.Object> callback = (asset) =>
                {
                    Shader.SetGlobalTexture(ShaderIDs.EnvMap1, _EnvCubeMapStart);
                };
                CAssetBundleManager.AsyncLoadResource(cubeMapName, callback, false, "scenes");
            }
            if (null != _EnvCubeMapEnd)
            {
                Shader.SetGlobalTexture(ShaderIDs.EnvMap2, _EnvCubeMapEnd);
            }
            else
            {
                if (string.IsNullOrEmpty(_EnvCubeMapNameEnd))
                {
                    return;
                }
                var cubeMapName = HobaText.Format("Assets/Outputs/Scenes/SkySphere/Cubemaps/{0}.cubemap", _EnvCubeMapEnd);
                Action <UnityEngine.Object> callback = (asset) =>
                {
                    Shader.SetGlobalTexture(ShaderIDs.EnvMap2, _EnvCubeMapEnd);
                };
                CAssetBundleManager.AsyncLoadResource(cubeMapName, callback, false, "scenes");
            }
        }
    }