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

            compJson.SetBool("_castShadows", comp.shadowCastingMode != UnityEngine.Rendering.ShadowCastingMode.Off);
            compJson.SetBool("_receiveShadows", comp.receiveShadows);
            compJson.SetMesh(obj, comp.sharedMesh);
            compJson.SetMaterials(obj, comp.sharedMaterials, false, true);

            return(true);
        }
Example #2
0
        public override bool WriteToJson(GameObject obj, Component component, MyJson_Object compJson)
        {
            MeshRenderer comp = component as MeshRenderer;

            compJson.SetInt("_lightmapIndex", comp.lightmapIndex);
            compJson.SetBool("_castShadows", comp.shadowCastingMode != UnityEngine.Rendering.ShadowCastingMode.Off);
            compJson.SetBool("_receiveShadows", comp.receiveShadows);
            compJson.SetVector4("_lightmapScaleOffset", comp.lightmapScaleOffset, 8);
            compJson.SetMaterials(obj, comp.sharedMaterials);

            return(true);
        }
Example #3
0
        public override bool WriteToJson(GameObject gameObject, Component component, MyJson_Object compJson)
        {
            var animation      = component as Animation;
            var animationClips = new List <UnityEngine.AnimationClip>();

            if (animation.clip)
            {
                animationClips.Add(animation.clip);
            }

            var clips = _getAnimationClips(animation);

            if (clips != null && clips.Length > 0)
            {
                foreach (var clip in clips)
                {
                    if (clip == animation.clip)
                    {
                        continue;
                    }

                    animationClips.Add(clip);
                }
            }

            if (animationClips.Count == 0)
            {
                return(false);
            }

            compJson.SetBool("autoPlay", animation.playAutomatically);
            compJson.SetAnimation(gameObject, animationClips.ToArray());
            return(true);
        }
Example #4
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);
        }
        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);
        }
        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);
        }
Example #7
0
        public override bool WriteToJson(GameObject gameObject, Component component, MyJson_Object compJson)
        {
            var aniamtior = component as Animator;

            if (aniamtior.runtimeAnimatorController == null)
            {
                MyLog.Log("缺少runtimeAnimatorController");
                return(false);
            }
            var clips = aniamtior.runtimeAnimatorController.animationClips;

            if (clips == null || clips.Length == 0)
            {
                MyLog.Log("clips为空");
                return(false);
            }

            compJson.SetBool("autoPlay", true); // TODO
            compJson.SetAnimation(gameObject, clips);

            return(true);
        }
        public static void Serialize(GameObject obj)
        {
            //未激活的不导出
            if ((!ExportToolsSetting.instance.exportUnactivatedObject && !obj.activeInHierarchy))
            {
                MyLog.Log(obj.name + "对象未激活");
                return;
            }

            if (obj.GetComponent <RectTransform>() != null)
            {
                return;
            }
            MyLog.Log("导出对象:" + obj.name);
            MyJson_Object item = new MyJson_Object();

            item.SetUUID(obj.GetInstanceID().ToString());
            item.SetUnityID(obj.GetInstanceID());
            item.SetClass("paper.GameObject");
            item.SetString("name", obj.name);
            item.SetString("tag", obj.tag);
            var layerMask = 1 << obj.layer;

            item.SetInt("layer", layerMask);
            // item.SetInt("layer", LAYER[obj.layer >= LAYER.Length ? 0 : obj.layer]);;
            item.SetBool("isStatic", obj.isStatic);

            var componentsItem = new MyJson_Array();

            item["components"] = componentsItem;
            ResourceManager.instance.AddObjectJson(item);

            var components = obj.GetComponents <Component>();

            var index = 0;//TODO

            foreach (var comp in components)
            {
                if (comp is Animator)
                {
                    components[index] = components[0];
                    components[0]     = comp;
                }

                index++;
            }

            //遍历填充组件
            foreach (var comp in components)
            {
                if (comp == null)
                {
                    MyLog.LogWarning("空的组件");
                    continue;
                }
                string compClass = comp.GetType().Name;
                MyLog.Log("组件:" + compClass);
                if (!ExportToolsSetting.instance.exportUnactivatedComp)
                {
                    //利用反射查看组件是否激活,某些组件的enabled不再继承链上,只能用反射,比如BoxCollider
                    var property = comp.GetType().GetProperty("enabled");
                    if (property != null && !((bool)property.GetValue(comp, null)))
                    {
                        MyLog.Log(obj.name + "组件未激活");
                        continue;
                    }
                }

                if (!SerializeObject.IsComponentSupport(compClass))
                {
                    MyLog.LogWarning("不支持的组件: " + compClass);
                    continue;
                }
                if (SerializeObject.SerializedComponent(obj, compClass, comp))
                {
                    MyLog.Log("--导出组件:" + compClass);
                    componentsItem.AddHashCode(comp);
                }
                else
                {
                    MyLog.LogWarning("组件: " + compClass + " 导出失败");
                }
            }
            //遍历子对象
            if (obj.transform.childCount > 0)
            {
                for (int i = 0; i < obj.transform.childCount; i++)
                {
                    var child = obj.transform.GetChild(i).gameObject;
                    Serialize(child);
                }
            }
        }