Example #1
0
        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");
            }
        }
Example #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);
            }
        }
    }
Example #3
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);
            }
        }
    }
Example #4
0
        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);
            }
        }
Example #5
0
    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);
    }
Example #6
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);
    }
Example #7
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);
    }
Example #8
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");
    }
Example #9
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);
    }
Example #10
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");
        }
    }
Example #11
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();
        }
    }
Example #12
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);
    }
Example #13
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();
         }
     }
 }
Example #14
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");
            }
        }
    }
Example #15
0
    public static GameObject Play(string fxPath, GameObject target, GameObject hook_point, GameObject clipper = null, float duration = -1, float secondsStayInCache = 20f, int orderOffset = 1
#if IN_GAME
                                  , LuaInterface.LuaFunction luaCall = null
#endif
                                  )
    {
        if (string.IsNullOrEmpty(fxPath) || target == null)
        {
            return(null);
        }

        UISfxBehaviour sfx = _AllCreatedList.Find(item => { return(item.Target == target && item.FxPath == fxPath); });

        if (sfx == null)
        {
            GameObject sfx_obj = new GameObject("FXObj");
            sfx = sfx_obj.AddComponent <UISfxBehaviour>();
            _AllCreatedList.Add(sfx);
        }

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

        sfx.SetData(fxPath, target, hook_point, duration, secondsStayInCache, orderOffset);
        sfx.SetClipRect(clipper);
        if (luaCall != null)
        {
#if IN_GAME
            sfx.SetOnLoadCallBack(luaCall);
#endif
        }

        if (sfx._FxObject == null)
        {
            if (!sfx._IsLoading)
            {
                PrefabCacheData sfx_pf;
                if (_PrefabCache.TryGetValue(fxPath, out sfx_pf))
                {
                    sfx.OnPrefabLoaded(sfx_pf.Obj as GameObject);
                }
                else
                {
                    sfx._IsLoading = true;
#if IN_GAME
                    Action <UnityEngine.Object> callback = (asset) =>
                    {
                        if (sfx != null)
                        {
                            sfx.OnPrefabLoaded(asset);
                        }
                    };
                    CAssetBundleManager.AsyncLoadResource(fxPath, callback, false, "sfx");
#elif UNITY_EDITOR && ART_USE
                    GameObject prefab = UnityEditor.AssetDatabase.LoadAssetAtPath(fxPath, typeof(GameObject)) as GameObject;
                    if (!_PrefabCache.ContainsKey(fxPath))
                    {
                        _PrefabCache.Add(fxPath, prefab as GameObject);
                    }
                    //DoPlay(fxPath, sfx_pf, sfx_obj);
                    sfx.OnPrefabLoaded(prefab);
#endif
                }
            }
        }
        else
        {
            sfx.RestartPlay();
        }

        return(sfx.gameObject);
    }
Example #16
0
    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");
    }
Example #17
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);
            }
        }
Example #18
0
    void OnEnable()
    {
        if (null == _LightMapAsset)
        {
            if (null == _Config)
            {
                _Config = this.GetComponent <SceneConfig>();
            }
            if (null == _Config)
            {
                return;
            }
            string assetName = _Config._LightmapConfig._LightmapAssetName;
            if (string.IsNullOrEmpty(assetName))
            {
                return;
            }
            Action <UnityEngine.Object> callback = (asset) =>
            {
                _LightMapAsset = asset as LightMapAsset;
                if (null == _LightMapAsset)
                {
                    return;
                }
                if (null == _Config)
                {
                    return;
                }

                int Count = _LightMapAsset._LightmapFar.Length;
                _LightMapDatas = new LightmapData[Count];
                for (int i = 0; i < Count; ++i)
                {
                    LightmapData Lightmap = new LightmapData();
                    Lightmap.lightmapColor = _LightMapAsset._LightmapFar[i];
                    Lightmap.lightmapDir   = _LightMapAsset._LightmapNear[i];
                    _LightMapDatas[i]      = Lightmap;
                }
                LightmapSettings.lightmapsMode = _Config._LightmapConfig._LightmapMode;
                LightmapSettings.lightmaps     = _LightMapDatas;

                _SetLightMap = true;
                #region

                for (int i = 0; i < _Config._LightmapConfig._MeshLightmapInfos.Length; i++)
                {
                    if (null != _Config._LightmapConfig._MeshLightmapInfos[i]._Renderer)
                    {
                        _Config._LightmapConfig._MeshLightmapInfos[i]._Renderer.lightmapIndex       = _Config._LightmapConfig._MeshLightmapInfos[i]._LightmapIndex;
                        _Config._LightmapConfig._MeshLightmapInfos[i]._Renderer.lightmapScaleOffset = _Config._LightmapConfig._MeshLightmapInfos[i]._LightmapScaleOffset;
                    }
                }
                var terrainInfo = _Config._LightmapConfig._TerrainLightmapInfos;
                for (var i = 0; i < terrainInfo.Length; i++)
                {
                    if (terrainInfo[i]._Terrain != null)
                    {
                        terrainInfo[i]._Terrain.lightmapIndex       = terrainInfo[i]._LightmapIndex;
                        terrainInfo[i]._Terrain.lightmapScaleOffset = terrainInfo[i]._LightmapScaleOffset;
                    }
                }
                #endregion
            };
            CAssetBundleManager.AsyncLoadResource(_Config._LightmapConfig._LightmapAssetName, callback, false);
        }
    }
Example #19
0
    private EffectAudioSourceItem _PlaySFX(string audioName, AudioType aType, Transform point, Vector3 pos, int sortId, bool isLoop)
    {
        if (string.IsNullOrEmpty(audioName))
        {
            return(null);
        }

        if (_IsEffectAudioEnabled)
        {
            CheckAudioListener();

            SafeInitSFX();

            if (IsClipCached(audioName))
            {
                //PlayAttachAudio(_ClipCache[audioName], false, trans, audioName, sortId, IsLoop);
                EffectAudioSourceItem item = GetUsableItem(aType, sortId, pos);
                if (item != null && item.audioSource != null)
                {
                    AudioClip clip;
                    LoadCache(audioName, out clip);
                    GetProperSettingOfItem(item, aType, clip, audioName, sortId, isLoop);

                    if (aType == AudioType.AttS3D)
                    {
                        item.attachedPos = point;
                    }
                    if (aType == AudioType.S3D)
                    {
                        item.audioSource.transform.position = pos;
                    }

                    item.audioSource.Play();
                    return(item);
                }
            }
            else
            {
                EffectAudioSourceItem item_arranged = GetUsableItem(aType, sortId, pos);

                if (item_arranged != null)
                {
                    Action <UnityEngine.Object> callback = asset =>
                    {
                        if (!_IsEffectAudioEnabled || asset == null)
                        {
                            if (item_arranged != null)
                            {
                                item_arranged.isLoading = 0;
                                item_arranged.audioName = "";
                            }
                            return;
                        }

                        if (item_arranged != null)
                        {
                            if (item_arranged.id != -1 && item_arranged.audioSource != null)
                            {
                                if (item_arranged.isLoading == 1 && audioName == item_arranged.audioName)
                                {
                                    //EffectAudioSourceItem item = FindInternalItem(item_arranged);

                                    item_arranged.isLoading = 0;

                                    GetProperSettingOfItem(item_arranged, aType, asset as AudioClip, audioName, sortId, isLoop);

                                    if (aType == AudioType.AttS3D)
                                    {
                                        item_arranged.attachedPos = point;
                                    }
                                    if (aType == AudioType.S3D)
                                    {
                                        item_arranged.audioSource.transform.position = pos;
                                    }

                                    if (item_arranged.audioSource != null)
                                    {
                                        item_arranged.audioSource.Play();
                                    }
                                }
                            }
                            item_arranged = null;
                        }
                    };

                    item_arranged.isLoading = 1;
                    item_arranged.audioName = audioName;
                    //Debug.Log("Ask " + audioName + " " + item_arranged.audioSource.name);
                    CAssetBundleManager.AsyncLoadResource(audioName, callback, false);
                    return(item_arranged);
                }
            }
        }

        return(null);
    }