Exemplo n.º 1
0
        protected override bool Match(Component component)
        {
            var            obj  = component.gameObject;
            ParticleSystem comp = component as ParticleSystem;

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

            return(true);
        }
        public override void CollectUniformValues()
        {
            base.CollectUniformValues();
            var source = this.source;
            var values = this.data.values;

            if (source.HasProperty("_Tex"))
            {
                values.SetCubemap("tCube", source.GetTexture("_Tex") as Cubemap);
            }
            else
            {
                MyLog.LogWarning("请检查材质" + source.name + "Cubemap属性是否有值");
            }
        }
Exemplo n.º 3
0
        protected override void Serialize(UnityEngine.Object sourceAsset)
        {
            this._mesh = sourceAsset as UnityEngine.Mesh;

            if (this._target.GetComponent <UnityEngine.SkinnedMeshRenderer>() == null &&
                (this._target.GetComponent <UnityEngine.MeshFilter>() == null ||
                 this._target.GetComponent <UnityEngine.MeshRenderer>() == null) &&
                this._target.GetComponent <UnityEngine.ParticleSystemRenderer>() == null)
            {
                MyLog.LogWarning("Mesh glTF写入错误,请检查你的渲染器是否是SkinnedMeshRenderer,MeshRenderer,ParticleSystemRenderer中的任意一种");
                return;
            }

            this._bufferWriter = new BinaryWriter(new MemoryStream());
            ExportMesh();
        }
Exemplo n.º 4
0
        public override byte[] WriteGLTF()
        {
            if (this._target.GetComponent <UnityEngine.SkinnedMeshRenderer>() == null &&
                (this._target.GetComponent <UnityEngine.MeshFilter>() == null ||
                 this._target.GetComponent <UnityEngine.MeshRenderer>() == null) &&
                this._target.GetComponent <UnityEngine.ParticleSystemRenderer>() == null)
            {
                MyLog.LogWarning("Mesh glTF写入错误,请检查你的渲染器是否是SkinnedMeshRenderer,MeshRenderer,ParticleSystemRenderer中的任意一种");
                return(new byte[0]);
            }

            this.BeginWrite();
            ExportMesh();
            var res = this.EndWrite();

            return(res);
        }
        public void AddComponent(ComponentData comp)
        {
            if (!this.components.Contains(comp))
            {
                this.components.Add(comp);
            }

            if (comp.__class == SerializeClass.TreeNode)
            {
                if (this.treeNode != null)
                {
                    MyLog.LogWarning("一个实体多个transform组件");
                }
                this.treeNode = comp;
            }

            comp.entity = this;
        }
Exemplo n.º 6
0
        protected override bool Match(Component component)
        {
            var obj = component.gameObject;
            ParticleSystemRenderer comp = component as ParticleSystemRenderer;
            ParticleSystem         c    = obj.GetComponent <ParticleSystem>();

            if (c == null || !c.emission.enabled)
            {
                MyLog.LogWarning("无效的粒子组件:" + obj.name);
                return(false);
            }
            if (comp.renderMode == ParticleSystemRenderMode.Mesh && comp.mesh == null)
            {
                MyLog.LogWarning(obj.name + ": mesh 丢失");
                return(false);
            }

            return(true);
        }
Exemplo n.º 7
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);
        }
        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);
                }
            }
        }
Exemplo n.º 9
0
        public static EntityData SerializeEntity(GameObject obj)
        {
            //未激活的不导出
            if ((!ExportSetting.instance.common.exportUnactivatedObject && !obj.activeInHierarchy))
            {
                MyLog.Log(obj.name + "对象未激活");
                return(null);
            }

            if (obj.GetComponent <RectTransform>() != null)
            {
                return(null);
            }
            MyLog.Log("对象:" + obj.name);
            var entityData = currentData.CreateEntity();
            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 (!ExportSetting.instance.common.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;
                }
                var compData = SerializeObject.SerializeComponent(obj, compClass, comp, entityData);
                if (compData != null)
                {
                    entityData.AddComponent(compData);
                    MyLog.Log("--导出组件:" + compClass);
                }
                else
                {
                    MyLog.LogWarning("组件: " + compClass + " 导出失败");
                }
            }

            return(entityData);
        }
Exemplo n.º 10
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);
        }