Ejemplo n.º 1
0
        public override bool Pair(string resname, Object res, System.Type type)
        {
            if (res == null)
            {
                Debuger.LogError("ABLoadScene.Pair " + resname + " " + type.ToString());

                return(false);
            }

            res.name = resname;

            if (type == typeof(GameObjectNav))
            {
                nav      = (GameObject)res;
                nav.name = res.name;
            }
            else if (type == typeof(GameObject))
            {
                scene      = (GameObject)res;
                scene.name = res.name;
            }
            else if (type == typeof(StringPrefab))
            {
                asset = (StringPrefab)res;
            }
            else if (type == typeof(LightMapAsset))
            {
                lightmap = (LightMapAsset)res;
            }

            return(true);
        }
Ejemplo n.º 2
0
    public override void Destory()
    {
        if (mLoadScene != null)
        {
            mLoadScene = null;
        }

        if (_ABLoadGoMono != null)
        {
            _ABLoadGoMono.Clear();
            GameObject.Destroy(_ABLoadGoMono);
            _ABLoadGoMono = null;
        }

        if (_scene != null)
        {
            _scene.SetActive(false);
            GameObject.Destroy(_scene);
            _scene = null;
        }
        _scene = null;

        if (_nav != null)
        {
            _nav.SetActive(false);
            GameObject.Destroy(_nav);
            _nav = null;
        }
        _nav      = null;
        _asset    = null;
        _lightmap = null;

        base.Destory();
    }
Ejemplo n.º 3
0
    static void ExportLightMap()
    {
        string        sceneName     = GetCurrentSceneName();
        string        abName        = "config/lightmap_" + sceneName;
        LightMapAsset lightmapAsset = ScriptableObject.CreateInstance <LightMapAsset>();

        int count = LightmapSettings.lightmaps.Length;

        lightmapAsset.lightmapFar  = new Texture2D[count];
        lightmapAsset.lightmapNear = new Texture2D[count];

        AmbientSetting am = new AmbientSetting();

        am.useFog                    = RenderSettings.fog;
        am.fogMode                   = RenderSettings.fogMode;
        am.fogColor                  = RenderSettings.fogColor;
        am.fogEndDistance            = RenderSettings.fogEndDistance;
        am.fogStartDistance          = RenderSettings.fogStartDistance;
        am.fogMode                   = RenderSettings.fogMode;
        am.ambientColor              = RenderSettings.ambientLight;
        lightmapAsset.ambientSetting = am;
        for (int i = 0; i < count; i++)
        {
            lightmapAsset.lightmapFar[i]  = LightmapSettings.lightmaps[i].lightmapColor;
            lightmapAsset.lightmapNear[i] = LightmapSettings.lightmaps[i].lightmapDir;
        }
        string path = ("Assets/GameResources/ArtResources/SceneConfig/LightMap/lightmap_" + sceneName.ToLower() + ".asset");

        AssetDatabase.CreateAsset(lightmapAsset, path);
        AssetImporter assetImporter = AssetImporter.GetAtPath(path);

        assetImporter.assetBundleName = abName;
    }
Ejemplo n.º 4
0
        public LightMapAsset CreateLightmap(Object obj, string path)
        {
            LightMapAsset lightmapAsset = ScriptableObject.CreateInstance <LightMapAsset>();

            // 制作Asset与Texture的关联
            int Count = LightmapSettings.lightmaps.Length;

            lightmapAsset.lightmapFar  = new Texture2D[Count];
            lightmapAsset.lightmapNear = new Texture2D[Count];
            for (int i = 0; i < Count; ++i)
            {
                // 这里把直接把lightmap纹理存起来
                lightmapAsset.lightmapFar[i]  = LightmapSettings.lightmaps[i].lightmapFar;
                lightmapAsset.lightmapNear[i] = LightmapSettings.lightmaps[i].lightmapNear;
            }

            string LightmapPath = mDestFolder + "/lightmap_.asset";

            AssetDatabase.CreateAsset(lightmapAsset, LightmapPath);

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            return(lightmapAsset);
        }
Ejemplo n.º 5
0
        public override void Unload()
        {
            base.Unload();

            nav      = null;
            lightmap = null;
            asset    = null;
            scene    = null;

            requestGo      = null;
            requestNav     = null;
            requestAsset   = null;
            requestTexture = null;

            {
                foreach (Material e in mMaterialObject.Values)
                {
                    Material m = (Material)e;

                    m = null;
                }
                mMaterialObject.Clear();
            }

            {
                foreach (AssetBundleRequest e in mAssetBundleRequestObject.Values)
                {
                    AssetBundleRequest requestTmp = (AssetBundleRequest)e;

                    requestTmp = null;
                }
                mAssetBundleRequestObject.Clear();
            }

            {
                foreach (ABLoad e in mAbLoadObject)
                {
                    ABLoad abloadTmp = (ABLoad)e;

                    switch (mABDataType)
                    {
                    case ABDataType.Mpq:
                        //((ABLoadMpq)abloadTmp).Unload();
                        break;

                    case ABDataType.Normal:
                        ((ABLoadFile)abloadTmp).Unload();
                        break;
                    }
                }
            }

            if (loadAdapter != null)
            {
                loadAdapter.Unload();
            }
        }
Ejemplo n.º 6
0
 void OnDestroy()
 {
     if (_SetLightMap)
     {
         LightmapSettings.lightmaps = null;
         _SetLightMap = false;
     }
     _LightMapAsset = null;
     _Config        = null;
     _LightMapDatas = null;
 }
Ejemplo n.º 7
0
    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;
    }
Ejemplo n.º 8
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");
    }
Ejemplo n.º 9
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);
        }
    }
Ejemplo n.º 10
0
    public static void Execute(string extension, BuildTarget target)
    {
        if (!Common.ClearDirectory("assetbundles"))
        {
            EditorUtility.DisplayDialog("����", "��ȷ��assetbundles�ļ���û�б�ռ��", "OK");
            return;
        }
        // ����Asset
        LightMapAsset lightmapAsset = ScriptableObject.CreateInstance <LightMapAsset>();
        int           iCount        = LightmapSettings.lightmaps.Length;

        lightmapAsset.lightmapFar  = new Texture2D[iCount];
        lightmapAsset.lightmapNear = new Texture2D[iCount];


        for (int i = 0; i < iCount; ++i)
        {
            // �����ֱ�Ӱ�lightmap���������
            lightmapAsset.lightmapFar[i]  = LightmapSettings.lightmaps[i].lightmapColor;
            lightmapAsset.lightmapNear[i] = LightmapSettings.lightmaps[i].lightmapDir;
        }

        string currScene     = EditorApplication.currentScene;
        string currSceneName = System.IO.Path.GetFileNameWithoutExtension(currScene);

        string tmpAssetPath = "Assets/tmp.asset";

        AssetDatabase.CreateAsset(lightmapAsset, tmpAssetPath);

        UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(tmpAssetPath, typeof(LightMapAsset));


        // ���
        string dest = Common.GetWindowPath("Assets/lightmap/" + currSceneName, extension);

        Common.CreatePath(dest);

        if (BuildPipeline.BuildAssetBundle(obj, null, dest, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, target))
        {
            byte[] bytes = AssetsEncrypt.ReadFileToByte(dest);
            AssetsEncrypt.EncryptBytes(bytes);
            AssetsEncrypt.WriteByteToFile(bytes, dest);
        }


        // ɾ����ʱ�ļ�
        AssetDatabase.DeleteAsset(tmpAssetPath);

        // ����Ϸ����ʱ�ָ�Lightmap���ݾͷdz����ˣ������Ƿ絶�IJ��Դ���Ƭ��
        //if (info.www.assetBundle.mainAsset is LightMapAsset)
        //{
        //    LightMapAsset lightmapAsset = info.www.assetBundle.mainAsset as LightMapAsset;
        //    int Count = lightmapAsset.lightmapFar.Length;
        //    LightmapData[] lightmapDatas = new LightmapData[Count];

        //     for(int i=0; i<Count; ++i)
        //   {
        //        LightmapData Lightmap = new LightmapData();
        //        Lightmap.lightmapFar = lightmapAsset.lightmapFar;
        //        Lightmap.lightmapNear = lightmapAsset.lightmapNear;
        //        lightmapDatas = Lightmap;
        //    }
        //    LightmapSettings.lightmaps = lightmapDatas;
        // }
    }