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 static void SetUVTransform(this Dictionary <string, IJsonNode> jsonNode, string desc, Vector4 data, int?digits = null)
        {
            var tx       = data.z;
            var ty       = data.w;
            var sx       = data.x;
            var sy       = data.y;
            var cx       = 0.0f;
            var cy       = 0.0f;
            var rotation = 0.0f;
            var c        = Math.Cos(rotation);
            var s        = Math.Sin(rotation);

            MyJson_Array cItemArr = new MyJson_Array();

            cItemArr.AddNumber(sx * c);
            cItemArr.AddNumber(sx * s);
            cItemArr.AddNumber(-sx * (c * cx + s * cy) + cx + tx);
            cItemArr.AddNumber(-sy * s);
            cItemArr.AddNumber(sy * c);
            cItemArr.AddNumber(-sy * (-s * cx + c * cy) + cy + ty);
            cItemArr.AddNumber(0.0);
            cItemArr.AddNumber(0.0);
            cItemArr.AddNumber(1.0);

            jsonNode[desc] = cItemArr;
        }
Beispiel #3
0
        protected void SetBlend(MyJson_Array enalbesJson, MyJson_Tree functionsJson, BlendMode blend)
        {
            if (blend == BlendMode.None)
            {
                return;
            }
            enalbesJson.AddInt((int)EnableState.BLEND);

            var blendFuncSeparate = new int[4];

            switch (blend)
            {
            case BlendMode.Add:
                blendFuncSeparate[0] = (int)BlendFactor.SRC_ALPHA;
                blendFuncSeparate[1] = (int)BlendFactor.ONE;
                blendFuncSeparate[2] = (int)BlendFactor.SRC_ALPHA;
                blendFuncSeparate[3] = (int)BlendFactor.ONE;
                break;

            case BlendMode.Blend:
                blendFuncSeparate[0] = (int)BlendFactor.SRC_ALPHA;
                blendFuncSeparate[1] = (int)BlendFactor.ONE_MINUS_SRC_ALPHA;
                blendFuncSeparate[2] = (int)BlendFactor.ONE;
                blendFuncSeparate[3] = (int)BlendFactor.ONE_MINUS_SRC_ALPHA;
                break;

            case BlendMode.Add_PreMultiply:
                blendFuncSeparate[0] = (int)BlendFactor.ONE;
                blendFuncSeparate[1] = (int)BlendFactor.ONE;
                blendFuncSeparate[2] = (int)BlendFactor.ONE;
                blendFuncSeparate[3] = (int)BlendFactor.ONE;
                break;

            case BlendMode.Blend_PreMultiply:
                blendFuncSeparate[0] = (int)BlendFactor.ONE;
                blendFuncSeparate[1] = (int)BlendFactor.ONE_MINUS_CONSTANT_ALPHA;
                blendFuncSeparate[2] = (int)BlendFactor.ONE;
                blendFuncSeparate[3] = (int)BlendFactor.ONE_MINUS_CONSTANT_ALPHA;
                break;

            case BlendMode.Multiply:
                blendFuncSeparate[0] = (int)BlendFactor.ZERO;
                blendFuncSeparate[1] = (int)BlendFactor.SRC_COLOR;
                blendFuncSeparate[2] = (int)BlendFactor.ZERO;
                blendFuncSeparate[3] = (int)BlendFactor.SRC_COLOR;
                break;

            case BlendMode.Multiply_PreMultiply:
                blendFuncSeparate[0] = (int)BlendFactor.ZERO;
                blendFuncSeparate[1] = (int)BlendFactor.SRC_COLOR;
                blendFuncSeparate[2] = (int)BlendFactor.ZERO;
                blendFuncSeparate[3] = (int)BlendFactor.SRC_ALPHA;
                break;
            }

            int[] blendEquationSeparate = { (int)BlendEquation.FUNC_ADD, (int)BlendEquation.FUNC_ADD };
            this.SetBlendEquationSeparate(functionsJson, blendEquationSeparate);
            this.SetBlendFuncSeparate(functionsJson, blendFuncSeparate);
        }
        //-------------------------------扩展部分--------------------------------

        /**
         * 组件的公共部分,Vector2
         */
        public static void SetVector2(this Dictionary <string, IJsonNode> jsonNode, string desc, Vector2 data, int?digits = null)
        {
            MyJson_Array cItemArr = new MyJson_Array();

            cItemArr.AddNumber(data.x, digits);
            cItemArr.AddNumber(data.y, digits);
            jsonNode[desc] = cItemArr;
        }
Beispiel #5
0
        protected void SetBlendFuncSeparate(MyJson_Tree functionsJson, int[] blendFuncSeparateValue)
        {
            var blendFuncSeparate = new MyJson_Array();

            foreach (var v in blendFuncSeparateValue)
            {
                blendFuncSeparate.AddInt((int)v);
            }
            functionsJson.Add("blendFuncSeparate", blendFuncSeparate);
        }
Beispiel #6
0
        protected void SetCullFace(MyJson_Tree functionsJson, int[] cullFaceValue)
        {
            var cullFace = new MyJson_Array();

            foreach (var v in cullFaceValue)
            {
                cullFace.AddInt(v);
            }
            functionsJson.Add("cullFace", cullFace);
        }
Beispiel #7
0
        protected void SetFrontFace(MyJson_Tree functionsJson, int[] frontFaceValue)
        {
            var frontFace = new MyJson_Array();

            foreach (var v in frontFaceValue)
            {
                frontFace.AddInt(v);
            }
            functionsJson.Add("frontFace", frontFace);
        }
Beispiel #8
0
        protected void SetDepthFunc(MyJson_Tree functionsJson, int[] depthFuncValue)
        {
            var depthFunc = new MyJson_Array();

            foreach (var v in depthFuncValue)
            {
                depthFunc.AddInt(v);
            }
            functionsJson.Add("depthFunc", depthFunc);
        }
        public static void SetColor3(this Dictionary <string, IJsonNode> jsonNode, string desc, Color data, int?digits = null)
        {
            MyJson_Array cItemArr = new MyJson_Array();

            cItemArr.AddNumber(data.r, digits);
            cItemArr.AddNumber(data.g, digits);
            cItemArr.AddNumber(data.b, digits);

            jsonNode[desc] = cItemArr;
        }
Beispiel #10
0
        protected void SetDepthMask(MyJson_Tree functionsJson, int[] depthMaskValue)
        {
            var depthMask = new MyJson_Array();

            foreach (var v in depthMaskValue)
            {
                depthMask.AddBool(v != 0);
            }
            functionsJson.Add("depthMask", depthMask);
        }
        /**
         * 组件的公共部分 Rect
         */
        public static void SetRect(this Dictionary <string, IJsonNode> jsonNode, string desc, Rect data, int?digits = null)
        {
            MyJson_Array cItemArr = new MyJson_Array();

            cItemArr.AddNumber(data.x, digits);
            cItemArr.AddNumber(data.y, digits);
            cItemArr.AddNumber(data.width, digits);
            cItemArr.AddNumber(data.height, digits);

            jsonNode[desc] = cItemArr;
        }
Beispiel #12
0
        protected void SetCullFace(MyJson_Array enalbesJson, MyJson_Tree functionsJson, bool cull)
        {
            if (cull)
            {
                int[] frontFace = { (int)FrontFace.CCW };
                this.SetFrontFace(functionsJson, frontFace);
                int[] cullFace = { (int)CullFace.BACK };
                this.SetCullFace(functionsJson, cullFace);

                enalbesJson.AddInt((int)EnableState.CULL_FACE);
            }
        }
Beispiel #13
0
        protected void AddCurve(MyJson_Tree curveItem, string key, Keyframe[] keys)
        {
            MyJson_Array frmes = new MyJson_Array();

            foreach (Keyframe k in keys)
            {
                MyJson_Array keyItem = new MyJson_Array();
                keyItem.AddNumber(k.time);
                keyItem.AddNumber(k.value);
                frmes.Add(keyItem);
            }
            curveItem[key] = frmes;
        }
Beispiel #14
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);
        }
Beispiel #15
0
        protected void SetDepth(MyJson_Array enalbesJson, MyJson_Tree functionsJson, bool zTest, bool zWrite)
        {
            if (zTest && zWrite)
            {
                return;
            }

            if (zTest)
            {
                int[] depthFunc = { (int)DepthFunc.LEQUAL };
                this.SetDepthFunc(functionsJson, depthFunc);
                enalbesJson.AddInt((int)EnableState.DEPTH_TEST);
            }

            int[] depthMask = { zWrite ? 1 : 0 };
            this.SetDepthMask(functionsJson, depthMask);
        }
Beispiel #16
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 byte[] WriteGLTF()
        {
            var target   = this._target;
            var gltfJson = new MyJson_Tree();
            //
            var assetJson = new MyJson_Tree();

            assetJson.SetInt("version", 2);
            gltfJson.Add("asset", assetJson);

            var materialsJson = new MyJson_Array();

            gltfJson.Add("materials", materialsJson);

            var extensionsRequired = new MyJson_Array();

            extensionsRequired.AddString("KHR_techniques_webgl");
            extensionsRequired.AddString("paper");
            gltfJson.Add("extensionsRequired", extensionsRequired);

            var extensionsUsed = new MyJson_Array();

            extensionsUsed.AddString("KHR_techniques_webgl");
            extensionsUsed.AddString("paper");
            gltfJson.Add("extensionsUsed", extensionsUsed);
            //
            gltfJson.SetInt("version", 4);

            //Unifrom or Defines
            var materialType = this.GetMaterialType();
            var writer       = MaterialWriterFactory.Create(materialType, target);

            var materialItemJson = writer.Write();

            materialsJson.Add(materialItemJson);
            writer.Clean();

            //
            gltfJson.isWithFormat = true;
            var jsonStr = gltfJson.ToString();

            return(System.Text.Encoding.UTF8.GetBytes(jsonStr));
        }
        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);
        }
Beispiel #19
0
        private static MyJson_Array AddLightmaps(string exportPath)
        {
            var lightmapsJson = new MyJson_Array();

            foreach (var lightmapData in LightmapSettings.lightmaps)
            {
                Texture2D lmTexture = lightmapData.lightmapColor;
                int       lmID      = lmTexture.GetInstanceID();
                if (!ResourceManager.instance.HaveCache(lmID))
                {
                    //格式转换
                    string suffix       = "png";
                    string relativePath = UnityEditor.AssetDatabase.GetAssetPath(lmTexture);
                    MyLog.Log("导出lightmap:" + relativePath);
                    string exrPath    = Path.Combine(Application.dataPath, relativePath.Replace("Assets/", ""));
                    string ralPngPath = PathHelper.CheckFileName(relativePath.Substring(0, relativePath.LastIndexOf('/') + 1) + lmTexture.name + "." + suffix);
                    string pngPath    = PathHelper.CheckFileName(Path.Combine(exportPath, ralPngPath));
                    // string ralPngPath = relativePath.Substring(0, relativePath.LastIndexOf('/') + 1) + lmTexture.name + "." + suffix;
                    // string pngPath = Path.Combine(exportPath, ralPngPath);

                    exrPath = exrPath.Replace("\\", "/");
                    pngPath = pngPath.Replace("\\", "/");
                    var bs = ExportImageTools.instance.EncodeToPNG(lmTexture);
                    ResourceManager.instance.AddFileBuffer(ralPngPath, bs);
                    // ExportImageTools.instance.AddExr(exrPath, pngPath);
                    //添加到 compList 和 assetsList
                    ResourceManager.instance.SaveTextureFormat(lmTexture, ralPngPath, ralPngPath + ".image", false);
                    string name        = lmTexture.name + ".image.json";
                    var    imgdescPath = PathHelper.CheckFileName(ralPngPath.Substring(0, ralPngPath.LastIndexOf("/") + 1) + name);

                    var assetIndex = ResourceManager.instance.AddAssetUrl(imgdescPath);

                    var assetItem = new MyJson_Tree();
                    assetItem.SetInt("asset", assetIndex);
                    lightmapsJson.Add(assetItem);
                }
            }
            // ExportImageTools.instance.ExrToPng();

            return(lightmapsJson);
        }
Beispiel #20
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);
        }
Beispiel #21
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);
        }
        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);
            }
        }
Beispiel #23
0
        protected void AddGradient(MyJson_Tree gradientItem, string key, Gradient gradient)
        {
            //alpha和color过渡值最大为4,如果不够手动填充,如果超过,中间的截掉
            GradientAlphaKey[] alphaKeys = this.FillGradientAlpha(gradient);
            GradientColorKey[] colorKeys = this.FillGradientColor(gradient);

            MyJson_Tree gradients = new MyJson_Tree(false);

            gradients.SetEnum("mode", gradient.mode);
            var alphaKeysItem = new MyJson_Array();
            var colorKeysItem = new MyJson_Array();

            gradients["alphaKeys"] = alphaKeysItem;
            gradients["colorKeys"] = colorKeysItem;

            //alphaKey
            foreach (GradientAlphaKey _ak in alphaKeys)
            {
                MyJson_Tree akItem = new MyJson_Tree(false);
                int         akHash = akItem.GetHashCode();
                akItem.SetNumber("alpha", _ak.alpha);
                akItem.SetNumber("time", _ak.time);
                alphaKeysItem.Add(akItem);
            }

            //colorKey
            foreach (GradientColorKey _ck in colorKeys)
            {
                MyJson_Tree ckItem = new MyJson_Tree(false);
                int         ckHash = ckItem.GetHashCode();
                ckItem.SetColor("color", _ck.color);
                ckItem.SetNumber("time", _ck.time);
                colorKeysItem.Add(ckItem);
            }

            gradientItem[key] = gradients;
        }
 public static void AddString(this MyJson_Array array, string value)
 {
     array.Add(new MyJson_String(value));
 }
 public static void AddBool(this MyJson_Array array, bool value)
 {
     array.Add(new MyJson_Number(value));
 }
 public static void AddInt(this MyJson_Array array, int value)
 {
     array.Add(new MyJson_Number(value));
 }
 public static void AddNumber(this MyJson_Array array, double value, int?digits = null)
 {
     array.Add(new MyJson_Number(Math.Round(value, digits ?? ExportToolsSetting.instance.floatRoundDigits)));
 }
Beispiel #28
0
        public MyJson_Tree Write()
        {
            this.Update();
            var customConfig = ExportConfig.instance.IsCustomShader(this.shaderName);
            //
            var materialItemJson = new MyJson_Tree();
            var extensions       = new MyJson_Tree();

            materialItemJson.Add("extensions", extensions);

            var KHR_techniques_webglJson = new MyJson_Tree();

            extensions.Add("KHR_techniques_webgl", KHR_techniques_webglJson);

            var paperJson = new MyJson_Tree();

            extensions.Add("paper", paperJson);

            var valuesJson = new MyJson_Tree();

            KHR_techniques_webglJson.Add("values", valuesJson);

            //
            var source     = this.source;
            var shaderName = source.shader.name.ToLower();

            MyLog.Log("Shader:" + shaderName);
            foreach (var value in this.values)
            {
                valuesJson.Add(value.Key, value.Value);
            }
            if (customConfig != null && !string.IsNullOrEmpty(customConfig.technique))
            {
                KHR_techniques_webglJson.SetString("technique", customConfig.technique);
            }
            else
            {
                KHR_techniques_webglJson.SetString("technique", this.technique);
            }
            //paper
            paperJson.SetInt("renderQueue", this.source.renderQueue);


            if (this.defines.Count > 0)
            {
                var definesJson = new MyJson_Array();
                foreach (var define in this.defines)
                {
                    definesJson.AddString(define);
                }
                paperJson.Add("defines", definesJson);
            }

            //
            //standard
            var isDoubleSide  = this.isDoubleSide;
            var isTransparent = this.isTransparent;

            var blend      = this.blendMode;
            var statesJson = new MyJson_Tree();
            var enable     = new MyJson_Array();

            if (isDoubleSide || blend != BlendMode.None || isTransparent || (customConfig != null && customConfig.enable != null))
            {
                //states
                paperJson.Add("states", statesJson);
                var functionsJson = new MyJson_Tree();
                statesJson.Add("enable", enable);
                statesJson.Add("functions", functionsJson);
                if (customConfig != null && customConfig.enable != null)
                {
                    foreach (var value in customConfig.enable)
                    {
                        enable.AddInt(value);
                    }
                    if (customConfig.blendEquationSeparate != null)
                    {
                        this.SetBlendEquationSeparate(functionsJson, customConfig.blendEquationSeparate);
                    }
                    if (customConfig.blendFuncSeparate != null)
                    {
                        this.SetBlendFuncSeparate(functionsJson, customConfig.blendFuncSeparate);
                    }
                    if (customConfig.frontFace != null)
                    {
                        this.SetFrontFace(functionsJson, customConfig.frontFace);
                    }
                    if (customConfig.cullFace != null)
                    {
                        this.SetCullFace(functionsJson, customConfig.cullFace);
                    }
                    if (customConfig.depthFunc != null)
                    {
                        this.SetDepthFunc(functionsJson, customConfig.depthFunc);
                    }
                    if (customConfig.depthMask != null)
                    {
                        this.SetDepthMask(functionsJson, customConfig.depthMask);
                    }
                }
                else
                {
                    this.SetBlend(enable, functionsJson, blend);
                    this.SetCullFace(enable, functionsJson, !isDoubleSide);
                    this.SetDepth(enable, functionsJson, true, !isTransparent);
                }
            }
            return(materialItemJson);
        }
 public static void AddHashCode(this MyJson_Array array, UnityEngine.Object value)
 {
     array.Add(new MyJson_HashCode(value.GetInstanceID()));
 }
        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);
                }
            }
        }