Example #1
0
    public static void LightMapRecover()
    {
        //string dirPath = Application.dataPath + "/Res/SceneConfig";
        Object[] objs = Selection.GetFiltered(typeof(Object), SelectionMode.Assets);
        for (int i = 0; i < objs.Length; i++)
        {
            string objName = objs[i].name;

            string   dirFullPath = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf('/')) + "/" + AssetDatabase.GetAssetPath(objs[i]);
            string[] filePaths   = Directory.GetFiles(dirFullPath);
            if (!File.Exists(dirFullPath + "/" + objName + ".exr"))
            {
                continue;
            }
            Debug.Log("name : " + objName);
            for (int j = 0; j < filePaths.Length; j++)
            {
                if (filePaths[j].Contains(".meta") || filePaths[j].Contains(".exr"))
                {
                    continue;
                }
                Debug.Log(filePaths[j]);
                StreamReader reader      = new StreamReader(filePaths[j]);
                string       fileContent = reader.ReadToEnd();
                reader.Close();
                SceneItemJson itemjson = fastJSON.JSON.ToObject <SceneItemJson>(fileContent);
                itemjson.lightMapName = objName + ".exr";
                string jsonContent = fastJSON.JSON.ToJSON(itemjson);
                SceneLightHelper.CreateJson(filePaths[j], jsonContent);
            }
        }
    }
 void OnGUI()
 {
     if (GUILayout.Button("Check"))
     {
         OnCheck();
     }
     EditorGUILayout.LabelField("======================================================================");
     scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
     for (int i = 0; i < missLightmap.Count; i++)
     {
         string lightmap = missLightmap[i].lightMapPath;
         if (string.IsNullOrEmpty(missLightmap[i].lightMapPath))
         {
             lightmap = "miss lightMap";
         }
         if (GUILayout.Button(lightmap + " --  " + missLightmap[i].sceneName + "  --  " + missLightmap[i].groupName))
         {
             StreamReader reader      = new StreamReader(missLightmap[i].lightConfigPath);
             string       fileContent = reader.ReadToEnd();
             reader.Close();
             SceneItemJson itemjson = fastJSON.JSON.ToObject <SceneItemJson>(fileContent);
             itemjson.lightMapName = missLightmap[i].lightMapPath;
             string jsonContent = fastJSON.JSON.ToJSON(itemjson);
             SceneLightHelper.CreateJson(missLightmap[i].lightConfigPath, jsonContent);
         }
     }
     EditorGUILayout.EndScrollView();
 }
Example #3
0
    /// <summary>
    /// 保存光照信息
    /// </summary>
    void SaveLightData()
    {
        #region  老版本

        /*
         * //提前光照信息
         * if (selectDataIndex >= 0 && m_allAssetName.Count > selectDataIndex)
         * {
         *  string lightPath = "Assets/Res/Scene/" + sceneName + "/Lightmap-0_comp_light.exr";
         *  TextureImporter textureImporter = AssetImporter.GetAtPath(lightPath) as TextureImporter;
         *  if (textureImporter == null)
         *  {
         *      return;
         *  }
         *  textureImporter.isReadable = true;
         *  AssetDatabase.ImportAsset(lightPath);
         *  Texture2D tex = AssetDatabase.LoadAssetAtPath<Texture2D>(lightPath);
         *  string[] assetName = m_allAssetName[selectDataIndex].Split('.');
         *  if (assetName.Length == 2 && tex != null)
         *  {
         *      string mapPath = jsonPath + "lightData/";
         *      if (!Directory.Exists(mapPath))
         *      {
         *          Directory.CreateDirectory(mapPath);
         *      }
         *      SceneLightHelper.createObjLightData(itemInfos, mapPath + assetName[0] + "_light.json", itemObjs, tex);
         *  }
         * }*/
        #endregion

        if (itemInfos == null || itemObjs == null)
        {
            return;
        }
        string lightPath     = Application.dataPath + scenePath + "/" + norLightMapName;
        string tempLightPath = Application.dataPath + lightTempPath + "/" + norLightMapName;
        if (File.Exists(tempLightPath))
        {
            if (selectDataIndex >= 0 && selectDataIndex < m_allAssetName.Count)
            {
                string[] assetNames = m_allAssetName[selectDataIndex].Split('.');
                if (assetNames.Length == 2)
                {
                    string groupLightPath = Application.dataPath + lightTempPath + "/" + assetNames[0] + ".exr";
                    if (itemInfos != null)
                    {
                        itemInfos.lightMapName = assetNames[0] + ".exr";
                    }
                    File.Copy(lightPath, groupLightPath, true);
                }
            }
        }
        AssetDatabase.Refresh();
        SceneLightHelper.setLightMapData(itemInfos, itemObjs);
        SaveJsonData();
    }
Example #4
0
    private void CopyLightMap(SceneItemJson itemJson)
    {
        TotalLightMapData destJson = new TotalLightMapData();

        destJson.SetData(itemJson);
        string jsonStr       = fastJSON.JSON.ToJSON(destJson);
        string newSingleName = GetLightName(srcPath);

        SceneLightHelper.CreateJson(rootPath + newSingleName, jsonStr);
    }
Example #5
0
    /// <summary>
    /// 保存位置数据
    /// </summary>
    void SaveJsonData()
    {
        if (!Directory.Exists(jsonPath))
        {
            Directory.CreateDirectory(jsonPath);
        }
        ///获取服务端数据
        //SceneItemServerJson serverJson = fastJSON.JSON.ToObject<SceneItemServerJson>();
        SceneDataJson serverJson = getServerData();

        if (serverJson == null)
        {
            serverJson            = new SceneDataJson(); //服务端数据
            serverJson.sceneDatas = new List <SceneItemServerJson>();
        }
        //SceneDataJson sceneDataJson = new SceneDataJson(); //服务端数据
        //sceneDataJson.sceneDatas = new List<SceneItemServerJson>();
        for (int i = 0; i < m_allItemInfo.Count; i++)
        {
            SceneItemInfo scenePageData = m_allItemInfo[i];//AssetDatabase.LoadAssetAtPath<SceneItemInfo>(m_allAssetPath[i]);
            if (scenePageData != null)
            {
                SceneItemJson itemJson = new SceneItemJson(scenePageData);
                //sceneDataJson.sceneDatas.Add(itemJson);
                string jsonStr = fastJSON.JSON.ToJSON(itemJson);
                SceneLightHelper.CreateJson(jsonPath + scenePageData.jsonName, jsonStr);

                int groupID = int.Parse(scenePageData.jsonName.Split('.')[0]);
                SceneItemServerJson itemServerJson = new SceneItemServerJson(scenePageData);
                itemServerJson.groupId = groupID;
                //sceneDataJson.sceneDatas.Add(itemServerJson);
                bool isexist = false;
                for (int j = 0; j < serverJson.sceneDatas.Count; j++)
                {
                    SceneItemServerJson serverJson00 = serverJson.sceneDatas[j];
                    if (serverJson00.groupId == groupID)
                    {
                        serverJson.sceneDatas[j] = itemServerJson;
                        isexist = true;
                        break;
                    }
                }
                if (!isexist)
                {
                    serverJson.sceneDatas.Add(itemServerJson);
                }
            }
        }

        //服务端数据
        string serverJsonStr = fastJSON.JSON.ToJSON(serverJson);

        SceneLightHelper.CreateJson(Application.streamingAssetsPath + "/SceneData/scenedata.json", serverJsonStr);
    }
Example #6
0
    public static void CreateServerSceneData()
    {
        string        path       = Application.dataPath + "/Res/SceneConfig/";
        SceneDataJson serverJson = new SceneDataJson(); //服务端数据

        serverJson.sceneDatas = new List <SceneItemServerJson>();
        GetData(path, serverJson);
        //服务端数据
        string serverJsonStr = fastJSON.JSON.ToJSON(serverJson);

        SceneLightHelper.CreateServerJson("../config/scenedata.json", serverJsonStr);
    }
Example #7
0
    private void TransLightMap()
    {
        string        srcJsonStr = GetJsonString(rootPath + srcPath);
        SceneItemJson groupData  = fastJSON.JSON.ToObject <SceneItemJson>(srcJsonStr);

        string        destJsonStr   = GetJsonString(rootPath + destPath);
        SceneItemJson destGroupData = fastJSON.JSON.ToObject <SceneItemJson>(destJsonStr);

        CopyToDestLightMap(groupData, destGroupData);

        string newJson = fastJSON.JSON.ToJSON(destGroupData);

        SceneLightHelper.CreateJson(rootPath + destPath, newJson);
    }
Example #8
0
    List <ItemPosInfo> srcObjLightData = new List <ItemPosInfo>(); //记录基础场景烘焙的数据

    void SaveBaseSceneLight()
    {
        GameObject[] rootObjs = GameObject.FindGameObjectsWithTag("LightingMap");
        srcObjLightData.Clear();
        for (int j = 0; j < rootObjs.Length; j++)
        {
            GameObject rootObj = rootObjs[j];
            if (rootObj == null)
            {
                continue;
            }
            MeshRenderer[] srcRender = rootObj.transform.GetComponentsInChildren <MeshRenderer>();
            for (int i = 0; i < srcRender.Length; i++)
            {
                ItemPosInfo posInfo = new ItemPosInfo();
                SceneLightHelper.SetLightData(srcRender[i], posInfo);
                srcObjLightData.Add(posInfo);
            }
        }
        //GameObject rootObj = GameObject.Find("Scene");
    }
Example #9
0
    void SetBaseSceneLight()
    {
        GameObject rootObj = GameObject.Find("Scene");

        if (rootObj == null)
        {
            return;
        }
        MeshRenderer[] srcRender = rootObj.transform.GetComponentsInChildren <MeshRenderer>();
        if (srcRender.Length != srcObjLightData.Count)
        {
            return;
        }
        for (int i = 0; i < srcRender.Length; i++)
        {
            if (srcRender[i] == null)
            {
                continue;
            }
            SceneLightHelper.getLightData(srcRender[i], srcObjLightData[i]);
        }
    }
Example #10
0
 const string norLightMapName = "Lightmap-0_comp_light.exr";  //基础场景光照贴图
 //const string tempLightMapName = "LightmapTemp.exr"; //临时lightmap
 //const string tempTargetLightName = "LightmapTarget.exr"; //第二张贴图
 void SceneBake()
 {
     SetAllObjPos();
     if (LightmapSettings.lightmaps != null && LightmapSettings.lightmaps.Length > 0)
     {
         lightMapTex = LightmapSettings.lightmaps[0].lightmapColor;
         if (!Directory.Exists(Application.dataPath + lightTempPath))
         {
             Directory.CreateDirectory(Application.dataPath + lightTempPath);
         }
         string lightPath     = Application.dataPath + scenePath + "/" + norLightMapName;
         string tempLightPath = Application.dataPath + lightTempPath + "/" + norLightMapName;
         if (File.Exists(lightPath) && !File.Exists(tempLightPath))
         {
             File.Move(lightPath, tempLightPath);
         }
     }
     AssetDatabase.Refresh();
     SaveBaseSceneLight();
     //重新烘焙场景
     SceneLightHelper.SceneBake();
     isRunning = true;
 }
Example #11
0
    private static void SetSceneData(string path)
    {
        string[] dirs = Directory.GetDirectories(path);
        for (int i = 0; i < dirs.Length; i++)
        {
            SetSceneData(dirs[i]);
        }
        string[] files = Directory.GetFiles(path);
        for (int i = 0; i < files.Length; i++)
        {
            if (!files[i].Contains(".json") || files[i].Contains("meta"))
            {
                continue;
            }
            //FileInfo fileinfo = new FileInfo(files[i]);
            StreamReader reader  = new StreamReader(files[i]);
            string       jsonStr = reader.ReadToEnd();
            reader.Close();
            SceneItemJson groupData = fastJSON.JSON.ToObject <SceneItemJson>(jsonStr);
            for (int j = 0; j < groupData.items.Count; j++)
            {
                groupData.items[j].itemPercent = 100;
            }
            string groupDataJson = fastJSON.JSON.ToJSON(groupData);
            SceneLightHelper.CreateJson(files[i], groupDataJson);

            //string fileName = fileinfo.Name.Replace(".json", "");
            //long groupID = -1;
            //long.TryParse(fileName, out groupID);
            //if (groupID > 0)
            //{
            //    SceneItemServerJson itemServerJson = new SceneItemServerJson(groupData);
            //    itemServerJson.groupId = groupID;
            //    serverJson.sceneDatas.Add(itemServerJson);
            //}
        }
    }