public override bool WriteToJson(GameObject obj, Component component, MyJson_Object compJson)
        {
            Camera comp = component as Camera;

            if (comp.orthographic)
            {
                compJson.SetNumber("size", 2 * comp.orthographicSize);//half-size?
                compJson.SetInt("opvalue", 0);
            }
            else
            {
                compJson.SetNumber("fov", comp.fieldOfView / 57.3, 4);
                compJson.SetInt("opvalue", 1);
            }
            compJson.SetNumber("_near", comp.nearClipPlane);
            compJson.SetNumber("_far", comp.farClipPlane);
            // compJson.SetInt("cullingMask", 0xffffff);
            compJson.SetInt("cullingMask", comp.cullingMask);
            //clearFlag
            switch (comp.clearFlags)
            {
            case CameraClearFlags.Skybox:
            case CameraClearFlags.SolidColor:
                compJson.SetBool("clearOption_Color", true);
                compJson.SetBool("clearOption_Depth", true);
                break;

            case CameraClearFlags.Depth:
                compJson.SetBool("clearOption_Color", false);
                compJson.SetBool("clearOption_Depth", true);
                break;

            case CameraClearFlags.Nothing:
                compJson.SetBool("clearOption_Color", false);
                compJson.SetBool("clearOption_Depth", false);
                break;

            default:
                break;
            }

            //backgroundColor
            compJson.SetColor("backgroundColor", comp.backgroundColor);
            //viewport
            compJson.SetRect("viewport", comp.rect);
            //order
            compJson.SetNumber("order", comp.depth);

            return(true);
        }
Пример #2
0
        public override bool WriteToJson(GameObject obj, Component component, MyJson_Object compJson)
        {
            Light comp = component as Light;

            if (comp.type != LightType.Directional)
            {
                return(false);
            }

            compJson.SetBool("castShadows", comp.shadows != LightShadows.None);
            compJson.SetColor("color", comp.color);
            compJson.SetNumber("intensity", comp.intensity);
            // compJson.SetNumber("shadowBias", comp.shadowBias);

            return(true);
        }
Пример #3
0
        public static void ExportScene(List <GameObject> roots, string exportPath = "")
        {
            string sceneName = PathHelper.CurSceneName;

            //导出场景
            try
            {
                ExportImageTools.instance.Clear();
                ResourceManager.instance.Clean();
                //路径
                string scenePath = sceneName + ".scene.json";
                PathHelper.SetSceneOrPrefabPath(scenePath);
                //Scene
                var           scene     = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene();
                MyJson_Object sceneJson = new MyJson_Object();
                sceneJson.SetUUID(scene.GetHashCode().ToString());//用场景名称的hashCode
                sceneJson.SetUnityID(scene.GetHashCode());
                sceneJson.SetClass("paper.Scene");
                sceneJson.SetString("name", sceneName.Substring(sceneName.LastIndexOf('/') + 1));

                sceneJson.SetColor("ambientColor", RenderSettings.ambientLight);
                sceneJson.SetNumber("lightmapIntensity", UnityEditor.Lightmapping.indirectOutputScale);
                //allGameObjects
                var gameObjectsJson = new MyJson_Array();
                sceneJson["gameObjects"] = gameObjectsJson;
                GameObject[] allObjs = GameObject.FindObjectsOfType <GameObject>();
                for (int i = 0; i < allObjs.Length; i++)
                {
                    gameObjectsJson.AddHashCode(allObjs[i]);
                }
                //lightmaps
                sceneJson["lightmaps"] = ExportSceneTools.AddLightmaps(exportPath);
                ResourceManager.instance.AddObjectJson(sceneJson);
                //序列化
                foreach (var root in roots)
                {
                    SerializeObject.Serialize(root);
                }
                ResourceManager.instance.ExportFiles(scenePath, exportPath);
                MyLog.Log("----场景导出成功----");
            }
            catch (System.Exception e)
            {
                MyLog.LogError(sceneName + "  : 导出失败-----------" + e.StackTrace);
            }
        }
        public override bool WriteToJson(GameObject obj, Component component, MyJson_Object compJson)
        {
            Light comp = component as Light;

            if (comp.type != LightType.Spot)
            {
                return(false);
            }

            compJson.SetBool("castShadows", comp.shadows != LightShadows.None);
            compJson.SetColor("color", comp.color);
            compJson.SetNumber("intensity", comp.intensity);
            // compJson.SetNumber("shadowBias", comp.shadowBias);
            compJson.SetNumber("distance", comp.range);
            compJson.SetNumber("angle", comp.spotAngle * Math.PI / 180.0f);

            return(true);
        }