/**
         *序列化组件数据
         */
        private static bool SerializedComponent(UnityEngine.GameObject obj, string compClass, UnityEngine.Component comp)
        {
            var parserList = componentParsers[compClass];

            if (parserList == null)
            {
                return(false);
            }

            var flag = false;

            foreach (var parser in parserList)
            {
                var compJson = new MyJson_Object();
                //组件必须拥有的属性
                compJson.SetComponent(comp.GetInstanceID(), parser.className);
                if (!parser.WriteToJson(obj, comp, compJson))
                {
                    continue;
                }

                ResourceManager.instance.AddCompJson(compJson);
                flag = true;
            }

            return(flag);
        }
Ejemplo n.º 2
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);
        }
        public static void SetAnimation(this MyJson_Object jsonNode, GameObject obj, UnityEngine.AnimationClip[] animationClips)
        {
            var exportAnimations = new MyJson_Array();

            jsonNode["_animations"] = exportAnimations;

            foreach (var animationClip in animationClips)
            {
                var gltfHash = animationClip.GetInstanceID();
                var url      = UnityEditor.AssetDatabase.GetAssetPath(animationClip);
                url = url.Substring(0, url.LastIndexOf(".")) + "_" + animationClip.name + ".ani.bin";
                url = PathHelper.CheckFileName(url);
                //
                var assetIndex = ResourceManager.instance.AddAssetUrl(url);
                if (!ResourceManager.instance.HaveCache(gltfHash))
                {
                    var glTFWriter = new AnimationXWriter(obj.transform, animationClip);
                    ResourceManager.instance.AddFileBuffer(url, glTFWriter.WriteGLTF());
                    //
                    ResourceManager.instance.SaveCache(gltfHash, url);
                }
                var aniItem = new MyJson_Tree();
                aniItem.SetInt("asset", assetIndex);
                exportAnimations.Add(aniItem);
            }
        }
        public override bool WriteToJson(GameObject obj, Component component, MyJson_Object compJson)
        {
            MeshFilter comp = component as MeshFilter;

            compJson.SetMesh(obj, comp.sharedMesh);

            return(true);
        }
        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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        public override bool WriteToJson(GameObject obj, Component component, MyJson_Object compJson)
        {
            SphereCollider comp       = component as SphereCollider;
            var            sphereItem = new MyJson_Array();

            sphereItem.AddNumber(comp.center.x);
            sphereItem.AddNumber(comp.center.y);
            sphereItem.AddNumber(comp.center.z);
            sphereItem.AddNumber(comp.radius);

            compJson.Add("sphere", sphereItem);

            return(true);
        }
        public int AddCompJson(MyJson_Object item)
        {
            for (var i = 0; i < this._comps.Count; i++)
            {
                var asset = this._comps[i];
                if (asset["uuid"] == item["uuid"])
                {
                    return(i);
                }
            }
            var index = this._comps.Count;

            this._comps.Add(item);
            return(index);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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 static void SetMesh(this MyJson_Object jsonNode, GameObject obj, Mesh mesh)
        {
            if (mesh == null)
            {
                return;
            }

            int    meshHash   = mesh.GetInstanceID();
            string url        = ResourceManager.instance.SaveMesh(obj.transform, mesh);
            var    assetIndex = ResourceManager.instance.AddAssetUrl(url);

            //mesh
            var meshItem = new MyJson_Tree(false);

            meshItem.SetInt("asset", assetIndex);
            jsonNode["_mesh"] = meshItem;
        }
        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);
        }
 private void ConvertJsonToString(System.Text.StringBuilder sb)
 {
     sb.Append("{\n\t\"assets\":[\n");
     for (int i = 0; i < this._assets.Count; i++)
     {
         var           assetUrl = this._assets[i];
         MyJson_Object asset    = new MyJson_Object();
         sb.Append("\t\t");
         // sb.Append(asset.ToString());
         sb.Append('"' + assetUrl + '"');//现在版本Asset只导出url
         if (i != this._assets.Count - 1)
         {
             sb.Append(',');
         }
         sb.Append("\n");
     }
     sb.Append("\t],\n\t\"objects\":[\n");
     for (int i = 0; i < this._objects.Count; i++)
     {
         MyJson_Object obj = this._objects[i];
         sb.Append("\t\t");
         sb.Append(obj.ToString());
         if (i != this._objects.Count - 1)
         {
             sb.Append(',');
         }
         sb.Append("\n");
     }
     sb.Append("\t],\n\t\"components\":[\n");
     for (int i = 0; i < this._comps.Count; i++)
     {
         MyJson_Object comp = this._comps[i];
         sb.Append("\t\t");
         sb.Append(comp.ToString());
         if (i != this._comps.Count - 1)
         {
             sb.Append(',');
         }
         sb.Append("\n");
     }
     //
     sb.Append("\t],\n");
     sb.Append("\n\t\"version\":" + VERSION + "\n}");
 }
        public override bool WriteToJson(GameObject obj, Component component, MyJson_Object compJson)
        {
            BoxCollider comp = component as BoxCollider;

            var          halfSize = comp.size * 0.5f;
            var          minimum  = comp.center - halfSize;
            var          maximum  = comp.center + halfSize;
            MyJson_Array aabbItem = new MyJson_Array();

            aabbItem.AddNumber(minimum.x);
            aabbItem.AddNumber(minimum.y);
            aabbItem.AddNumber(minimum.z);
            aabbItem.AddNumber(maximum.x);
            aabbItem.AddNumber(maximum.y);
            aabbItem.AddNumber(maximum.z);

            compJson.Add("aabb", aabbItem);
            return(true);
        }
Ejemplo n.º 16
0
        public override bool WriteToJson(GameObject obj, Component component, MyJson_Object compJson)
        {
            Transform comp = component as Transform;

            Vector3    localPosition = comp.localPosition;
            Quaternion localRotation = comp.localRotation;
            Vector3    localScale    = comp.localScale;

            //这里特殊处理一下,拥有SkinnedMeshRenderer组件的Transform属性清零,因为Egret3D实现不同,如果不清零,会影响动画

            /*if (obj.GetComponent<SkinnedMeshRenderer>() != null)
             * {
             *  localPosition = Vector3.zero;
             *  localRotation = Quaternion.identity;
             *  localScale = Vector3.one;
             * }*/
            //localPosition
            compJson.SetVector3("localPosition", localPosition);
            //localRotation
            compJson.SetQuaternion("localRotation", localRotation);
            //localScale
            compJson.SetVector3("localScale", localScale);
            if ((component as Transform).parent)
            {
                compJson.SetHashCode("_parent", comp.parent);
            }
            var childrenItem = new MyJson_Array();

            compJson["children"] = childrenItem;
            for (int i = 0; i < comp.childCount; i++)
            {
                var child = comp.GetChild(i);
                if (child.gameObject.activeInHierarchy)
                {
                    childrenItem.AddHashCode(child);
                }
            }

            return(true);
        }
Ejemplo n.º 17
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 SetMaterials(this MyJson_Object jsonNode, GameObject obj, Material[] materials, bool isParticleMat = false, bool isAnimationMat = false)
        {
            var materialsItem = new MyJson_Array();

            jsonNode["_materials"] = materialsItem;
            //写材质
            foreach (var material in materials)
            {
                if (!material)
                {
                    Debug.LogWarning(obj.gameObject.name + " 材质缺失,请检查资源");
                    continue;
                }

                int    hash       = material.GetInstanceID();
                string url        = ResourceManager.instance.SaveMaterial(material, isParticleMat, isAnimationMat);
                var    assetIndex = ResourceManager.instance.AddAssetUrl(url);

                var matItem = new MyJson_Tree();
                matItem.SetInt("asset", assetIndex);
                materialsItem.Add(matItem);
            }
        }
Ejemplo n.º 19
0
        public override bool WriteToJson(GameObject _object, Component component, MyJson_Object compJson)
        {
            ParticleSystemRenderer comp = component as ParticleSystemRenderer;
            ParticleSystem         c    = _object.GetComponent <ParticleSystem>();

            if (c == null || !c.emission.enabled)
            {
                MyLog.LogWarning("无效的粒子组件:" + _object.name);
                return(false);
            }
            compJson.SetNumber("velocityScale", comp.velocityScale);
            compJson.SetNumber("lengthScale", comp.lengthScale);
            compJson.SetEnum("_renderMode", comp.renderMode);
            if (comp.renderMode == ParticleSystemRenderMode.Mesh && comp.mesh == null)
            {
                throw new Exception(_object.name + ": mesh 丢失");
            }
            //Mesh
            compJson.SetMesh(_object, comp.mesh);
            //Material粒子系统不支持多材质
            compJson.SetMaterials(_object, new Material[] { comp.sharedMaterial }, true);
            return(true);
        }
Ejemplo n.º 20
0
        public override bool WriteToJson(GameObject obj, Component component, MyJson_Object compJson)
        {
            FB.PosePlus.AniPlayer comp = component as FB.PosePlus.AniPlayer;

            var animationsItem = new MyJson_Array();

            compJson["_animations"] = animationsItem;

            var animator = obj.GetComponent <Animator>();

            if (comp.clips.Count > 0 && animator != null)
            {
                int    gltfHash   = animator.runtimeAnimatorController.GetInstanceID();
                string url        = ResourceManager.instance.SaveAniPlayer(comp, animator);
                var    assetIndex = ResourceManager.instance.AddAssetUrl(url);

                var aniItem = new MyJson_Tree();
                aniItem.SetInt("asset", assetIndex);
                animationsItem.Add(aniItem);
            }

            return(true);
        }
Ejemplo n.º 21
0
 public virtual bool WriteToJson(GameObject _object, Component component, MyJson_Object compJson)
 {
     return(true);
 }
Ejemplo n.º 22
0
        public override bool WriteToJson(GameObject obj, Component component, MyJson_Object compJson)
        {
            ParticleSystem comp = component as ParticleSystem;

            if (!comp.emission.enabled || obj.GetComponent <ParticleSystemRenderer>() == null)
            {
                MyLog.LogWarning("无效的粒子组件:" + obj.name);
                return(false);
            }

            //main
            {
                var main     = comp.main;
                var mainItem = new MyJson_Tree(false);
                compJson["main"] = mainItem;
                mainItem.SetNumber("duration", main.duration);
                mainItem.SetBool("loop", main.loop);
                this.AddMinMaxCurve(mainItem, "startDelay", main.startDelay);
                this.AddMinMaxCurve(mainItem, "startLifetime", main.startLifetime);
                this.AddMinMaxCurve(mainItem, "startSpeed", main.startSpeed);

                mainItem.SetBool("startSize3D", main.startSize3D);
                if (main.startSize3D)
                {
                    this.AddMinMaxCurve(mainItem, "startSizeX", main.startSizeX);
                    this.AddMinMaxCurve(mainItem, "startSizeY", main.startSizeY);
                    this.AddMinMaxCurve(mainItem, "startSizeZ", main.startSizeZ);
                }
                else
                {
                    this.AddMinMaxCurve(mainItem, "startSizeX", main.startSize);
                    this.AddMinMaxCurve(mainItem, "startSizeY", main.startSize);
                    this.AddMinMaxCurve(mainItem, "startSizeZ", main.startSize);
                }

                mainItem.SetBool("_startRotation3D", main.startRotation3D);
                if (main.startRotation3D)
                {
                    this.AddMinMaxCurve(mainItem, "startRotationX", main.startRotationX);
                    this.AddMinMaxCurve(mainItem, "startRotationY", main.startRotationY);
                    this.AddMinMaxCurve(mainItem, "startRotationZ", main.startRotationZ);
                }
                else
                {
                    this.AddMinMaxCurve(mainItem, "startRotationX", main.startRotation);
                    this.AddMinMaxCurve(mainItem, "startRotationY", main.startRotation);
                    this.AddMinMaxCurve(mainItem, "startRotationZ", main.startRotation);
                }

                this.AddMinMaxGradient(mainItem, "startColor", main.startColor);
                this.AddMinMaxCurve(mainItem, "gravityModifier", main.gravityModifier);
                mainItem.SetEnum("_simulationSpace", main.simulationSpace);
                mainItem.SetEnum("scaleMode", main.scalingMode);
                mainItem.SetBool("playOnAwake", main.playOnAwake);
                if (ExportToolsSetting.instance.estimateMaxParticles)
                {
                    var value = this.EstimateMaxParticles(comp);
                    mainItem.SetInt("_maxParticles", value);
                    MyLog.Log(comp.gameObject.name + " 粒子估算:" + value);
                }
                else
                {
                    mainItem.SetInt("_maxParticles", main.maxParticles);
                }
            }

            //emission
            {
                var emissionItem = new MyJson_Tree(false);
                compJson["emission"] = emissionItem;
                this.AddMinMaxCurve(emissionItem, "rateOverTime", comp.emission.rateOverTime);
                emissionItem["bursts"] = new MyJson_Array();
                var bursts = new ParticleSystem.Burst[comp.emission.burstCount];
                comp.emission.GetBursts(bursts);
                foreach (var burst in bursts)
                {
                    MyJson_Array burstItem = new MyJson_Array();
                    burstItem.AddNumber(burst.time);
                    burstItem.AddInt(burst.minCount);
                    burstItem.AddInt(burst.maxCount);
                    burstItem.AddInt(burst.cycleCount);
                    burstItem.AddNumber(burst.repeatInterval);
                    (emissionItem["bursts"] as MyJson_Array).Add(burstItem);
                }
            }
            //shape
            if (comp.shape.enabled)
            {
                var shapItem = new MyJson_Tree(false);
                compJson["shape"] = shapItem;
                shapItem.SetEnum("shapeType", comp.shape.shapeType);
                shapItem.SetNumber("angle", comp.shape.angle);
                shapItem.SetNumber("length", comp.shape.length);
                shapItem.SetEnum("arcMode", comp.shape.arcMode);
                shapItem.SetNumber("arc", comp.shape.arc);
                shapItem.SetNumber("arcSpread", comp.shape.arcSpread);
                shapItem.SetEnum("radiusMode", comp.shape.radiusMode);
                shapItem.SetNumber("radius", comp.shape.radius);
                shapItem.SetNumber("radiusSpread", comp.shape.radiusSpread);
                shapItem.SetVector3("box", comp.shape.box);
                shapItem.SetBool("randomDirection", comp.shape.randomDirectionAmount > 0);
                shapItem.SetBool("spherizeDirection", comp.shape.sphericalDirectionAmount > 0);
                this.AddMinMaxCurve(shapItem, "arcSpeed", comp.shape.arcSpeed);
            }
            //velocityOverLifetiem
            if (comp.velocityOverLifetime.enabled)
            {
                var velocityOverItem = new MyJson_Tree(false);
                compJson["velocityOverLifetime"] = velocityOverItem;
                velocityOverItem.SetEnum("_mode", comp.velocityOverLifetime.x.mode);
                velocityOverItem.SetEnum("_space", comp.velocityOverLifetime.space);
                this.AddMinMaxCurve(velocityOverItem, "_x", comp.velocityOverLifetime.x);
                this.AddMinMaxCurve(velocityOverItem, "_y", comp.velocityOverLifetime.y);
                this.AddMinMaxCurve(velocityOverItem, "_z", comp.velocityOverLifetime.z);
            }
            //colorOverLifetime
            if (comp.colorOverLifetime.enabled)
            {
                var colorOverItem = new MyJson_Tree(false);
                compJson["colorOverLifetime"] = colorOverItem;
                this.AddMinMaxGradient(colorOverItem, "_color", comp.colorOverLifetime.color);
            }
            //sizeOverLifetime
            if (comp.sizeOverLifetime.enabled)
            {
                var sizeOverItem = new MyJson_Tree(false);
                compJson["sizeOverLifetime"] = sizeOverItem;
                sizeOverItem.SetBool("_separateAxes", comp.sizeOverLifetime.separateAxes);
                this.AddMinMaxCurve(sizeOverItem, "_size", comp.sizeOverLifetime.size);
                this.AddMinMaxCurve(sizeOverItem, "_x", comp.sizeOverLifetime.x);
                this.AddMinMaxCurve(sizeOverItem, "_y", comp.sizeOverLifetime.y);
                this.AddMinMaxCurve(sizeOverItem, "_z", comp.sizeOverLifetime.z);
            }
            //rotationOverLifetime
            if (comp.rotationOverLifetime.enabled)
            {
                var rotationOverItem = new MyJson_Tree(false);
                compJson["rotationOverLifetime"] = rotationOverItem;
                rotationOverItem.SetBool("_separateAxes", comp.rotationOverLifetime.separateAxes);
                this.AddMinMaxCurve(rotationOverItem, "_x", comp.rotationOverLifetime.x);
                this.AddMinMaxCurve(rotationOverItem, "_y", comp.rotationOverLifetime.y);
                this.AddMinMaxCurve(rotationOverItem, "_z", comp.rotationOverLifetime.z);
            }
            //textureSheetAnimationModule
            if (comp.textureSheetAnimation.enabled)
            {
                var textureSheetAnimation = new MyJson_Tree(false);
                compJson["textureSheetAnimation"] = textureSheetAnimation;
                textureSheetAnimation.SetInt("_numTilesX", comp.textureSheetAnimation.numTilesX);
                textureSheetAnimation.SetInt("_numTilesY", comp.textureSheetAnimation.numTilesY);
                textureSheetAnimation.SetEnum("_animation", comp.textureSheetAnimation.animation);
                textureSheetAnimation.SetBool("_useRandomRow", comp.textureSheetAnimation.useRandomRow);
                textureSheetAnimation.SetInt("_cycleCount", comp.textureSheetAnimation.cycleCount);
                textureSheetAnimation.SetInt("_rowIndex", comp.textureSheetAnimation.rowIndex);
                this.AddMinMaxCurve(textureSheetAnimation, "_frameOverTime", comp.textureSheetAnimation.frameOverTime, comp.textureSheetAnimation.numTilesX * comp.textureSheetAnimation.numTilesY);
                this.AddMinMaxCurve(textureSheetAnimation, "_startFrame", comp.textureSheetAnimation.startFrame);
            }

            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);
                }
            }
        }
Ejemplo n.º 24
0
 public override bool WriteToJson(GameObject obj, Component component, MyJson_Object compJson)
 {
     return(false);
 }