protected override JSONObject ToJSON(WXHierarchyContext context)
        {
            JSONObject json = new JSONObject(JSONObject.Type.OBJECT);
            JSONObject data = new JSONObject(JSONObject.Type.OBJECT);

            json.AddField("type", getTypeName());
            json.AddField("data", data);
            data.AddField("active", true);

            if (this.collider != null)
            {
                data.AddField("convex", this.collider.convex);
                data.AddField("isTrigger", this.collider.isTrigger);
                data.AddField("cookingOptions", (int)this.collider.cookingOptions);
                data.AddField("material", new WXPhysicsMaterial(this.collider.material).ToJSON());
                Mesh mesh = this.collider.sharedMesh;
                if (mesh != null)
                {
                    WXMesh meshConverter = new WXMesh(mesh);
                    string meshPath      = meshConverter.Export(context.preset);
                    data.AddField("mesh", meshPath);
                    context.AddResource(meshPath);
                }
            }

            return(json);
        }
Exemplo n.º 2
0
        // 处理Mesh包围球信息
        private JSONObject HandleMeshBoundingBall(Mesh mesh)
        {
            Vector3    vertexPositionMax = WXMesh.GetVertexPositionMax(mesh);
            float      radius            = WXMesh.CalCapsuleRadius(vertexPositionMax, mesh.vertices);
            JSONObject res    = new JSONObject(JSONObject.Type.OBJECT);
            JSONObject center = new JSONObject(JSONObject.Type.OBJECT);

            center.AddField("x", vertexPositionMax.x);
            center.AddField("y", vertexPositionMax.y);
            center.AddField("z", vertexPositionMax.z);
            res.AddField("radius", radius);
            res.AddField("center", center);
            return(res);
        }
        protected override JSONObject ToJSON(WXHierarchyContext context)
        {
            ParticleSystemRenderer particleSystemRenderer = particleSys.GetComponent <ParticleSystemRenderer>();

            JSONObject json = new JSONObject(JSONObject.Type.OBJECT);
            JSONObject data = new JSONObject(JSONObject.Type.OBJECT);

            json.AddField("type", getTypeName());
            json.AddField("data", data);

            JSONObject materials = new JSONObject(JSONObject.Type.ARRAY);

            data.AddField("materials", materials);
            Material[] mats = particleSystemRenderer.sharedMaterials;
            foreach (Material material in mats)
            {
                if (material != null)
                {
                    WXMaterial materialConverter = new WXMaterial(material, particleSystemRenderer);
                    string     materialPath      = materialConverter.Export(context.preset);
                    materials.Add(materialPath);
                    context.AddResource(materialPath);
                }
            }

            JSONObject modCommon     = new JSONObject(JSONObject.Type.OBJECT);
            JSONObject modCommonData = new JSONObject(JSONObject.Type.OBJECT);

            data.AddField("common", modCommonData);

            modCommonData.AddField("startSize3D", particleSys.main.startSize3D);
            if (particleSys.main.startSize3D)
            {
                modCommonData.AddField("startSizeX", ParseMinMaxCurve(particleSys.main.startSizeX));
                modCommonData.AddField("startSizeY", ParseMinMaxCurve(particleSys.main.startSizeY));
                modCommonData.AddField("startSizeZ", ParseMinMaxCurve(particleSys.main.startSizeZ));
            }
            else
            {
                modCommonData.AddField("startSize", ParseMinMaxCurve(particleSys.main.startSize));
            }
            modCommonData.AddField("startColor", ParseMinMaxGradient(particleSys.main.startColor));
            modCommonData.AddField("startLifetime", ParseMinMaxCurve(particleSys.main.startLifetime));
            modCommonData.AddField("startRotation3D", particleSys.main.startRotation3D);
            if (particleSys.main.startRotation3D)
            {
                modCommonData.AddField("startRotationX", ParseMinMaxCurve(particleSys.main.startRotationX, (float)(180 / Math.PI)));
                modCommonData.AddField("startRotationY", ParseMinMaxCurve(particleSys.main.startRotationY, (float)(180 / Math.PI)));
                modCommonData.AddField("startRotationZ", ParseMinMaxCurve(particleSys.main.startRotationZ, (float)(180 / Math.PI)));
            }
            else
            {
                modCommonData.AddField("startRotationZ", ParseMinMaxCurve(particleSys.main.startRotation, (float)(180 / Math.PI)));
            }
            modCommonData.AddField("startSpeed", ParseMinMaxCurve(particleSys.main.startSpeed));
            modCommonData.AddField("gravityModifier", ParseMinMaxCurve(particleSys.main.gravityModifier));
#if UNITY_2018_1_OR_NEWER
            modCommonData.AddField("randomizeRotation", particleSys.main.flipRotation);
#endif
            modCommonData.AddField("randomSeed", particleSys.randomSeed);
            modCommonData.AddField("autoRandomSeed", particleSys.useAutoRandomSeed);

            ParticleSystemScalingMode pScalingMode = particleSys.main.scalingMode;
            int pScalingModeNum = 0;
            switch (pScalingMode)
            {
            case ParticleSystemScalingMode.Hierarchy:
                pScalingModeNum = 0;
                break;

            case ParticleSystemScalingMode.Local:
                pScalingModeNum = 1;
                break;

            case ParticleSystemScalingMode.Shape:
                pScalingModeNum = 2;
                break;
            }
            modCommonData.AddField("scalingMode", pScalingModeNum);

            ParticleSystemSimulationSpace simulationSpace = particleSys.main.simulationSpace;
            int simulationSpaceNum = 0;
            switch (simulationSpace)
            {
            case ParticleSystemSimulationSpace.Local:
                simulationSpaceNum = 0;
                break;

            case ParticleSystemSimulationSpace.World:
                simulationSpaceNum = 1;
                break;

            case ParticleSystemSimulationSpace.Custom:
                simulationSpaceNum = 2;
                break;
            }
            modCommonData.AddField("simulationSpace", simulationSpaceNum);

            JSONObject emitter     = new JSONObject(JSONObject.Type.OBJECT);
            JSONObject emitterData = new JSONObject(JSONObject.Type.OBJECT);
            data.AddField("emitter", emitterData);
            emitterData.AddField("playOnAwake", particleSys.main.playOnAwake);
            emitterData.AddField("looping", particleSys.main.loop);
            emitterData.AddField("duration", particleSys.main.duration);
            emitterData.AddField("startDelay", ParseMinMaxCurve(particleSys.main.startDelay));


            if (particleSys.emission.enabled)
            {
                JSONObject burst = new JSONObject(JSONObject.Type.ARRAY);
                emitterData.AddField("bursts", burst);
                int count = particleSys.emission.burstCount;
                ParticleSystem.Burst[] bursts = new ParticleSystem.Burst[count];
                particleSys.emission.GetBursts(bursts);
                for (int i = 0; i < count; i++)
                {
                    //burst.Add(ParseBurst(particleSys.emission.GetBurst(i)));
                    burst.Add(ParseBurst(bursts[i]));
                }

                emitterData.AddField("rateOverTime", ParseMinMaxCurve(particleSys.emission.rateOverTime));
            }
            emitterData.AddField("maxParticles", particleSys.main.maxParticles);

            if (particleSystemRenderer.enabled)
            {
                JSONObject renderer     = new JSONObject(JSONObject.Type.OBJECT);
                JSONObject rendererData = new JSONObject(JSONObject.Type.OBJECT);
                data.AddField("renderer", rendererData);
                ParticleSystemRenderMode pRenderMode = particleSystemRenderer.renderMode;
                int pRenderModeNum = 0;
                switch (pRenderMode)
                {
                case ParticleSystemRenderMode.Billboard:
                    pRenderModeNum = 1;
                    break;

                case ParticleSystemRenderMode.Stretch:
                    pRenderModeNum = 2;
                    rendererData.AddField("cameraScale", particleSystemRenderer.cameraVelocityScale);
                    rendererData.AddField("speedScale", particleSystemRenderer.velocityScale);
                    rendererData.AddField("lengthScale", particleSystemRenderer.lengthScale);
                    break;

                case ParticleSystemRenderMode.HorizontalBillboard:
                    pRenderModeNum = 3;
                    break;

                case ParticleSystemRenderMode.VerticalBillboard:
                    pRenderModeNum = 4;
                    break;

                case ParticleSystemRenderMode.Mesh:
                    Mesh mesh = particleSystemRenderer.mesh;
                    if (mesh != null)
                    {
                        WXMesh meshConverter = new WXMesh(mesh);
                        string meshPath      = meshConverter.Export(context.preset);
                        rendererData.AddField("mesh", meshPath);
                        rendererData.AddField("meshCount", particleSystemRenderer.meshCount);
                        context.AddResource(meshPath);
                    }
                    else
                    {
                        Debug.LogError(string.Format("{0} mesh is null", particleSys.name));
                    }
                    pRenderModeNum = 5;
                    break;

                case ParticleSystemRenderMode.None:
                    pRenderModeNum = 0;
                    break;

                default:
                    pRenderModeNum = 1;
                    break;
                }
                rendererData.AddField("renderMode", pRenderModeNum);

                int mode = 1;
                switch (particleSystemRenderer.alignment)
                {
                case ParticleSystemRenderSpace.View:
                    mode = 1;
                    break;

                case ParticleSystemRenderSpace.World:
                    mode = 2;
                    break;

                case ParticleSystemRenderSpace.Local:
                    mode = 3;
                    break;

                case ParticleSystemRenderSpace.Facing:
                    mode = 4;
                    break;

#if UNITY_2017_1_OR_NEWER
                case ParticleSystemRenderSpace.Velocity:
                    mode = 5;
                    break;
#endif
                default:
                    break;
                }
                rendererData.AddField("renderAlignment", mode);


                mode = 0;
                switch (particleSystemRenderer.sortMode)
                {
                case ParticleSystemSortMode.None:
                    mode = 0;
                    break;

                case ParticleSystemSortMode.Distance:
                    mode = 1;
                    break;

                case ParticleSystemSortMode.OldestInFront:
                    mode = 2;
                    break;

                case ParticleSystemSortMode.YoungestInFront:
                    mode = 3;
                    break;

                default:
                    break;
                }
                rendererData.AddField("sortMode", mode);
                rendererData.AddField("sortingFudge", particleSystemRenderer.sortingFudge);
                rendererData.AddField("normalDirection", particleSystemRenderer.normalDirection);
                rendererData.AddField("minParticleSize", particleSystemRenderer.minParticleSize);
                rendererData.AddField("maxParticleSize", particleSystemRenderer.maxParticleSize);

                var flipValue = TryGetContainProperty(particleSystemRenderer, "flip");
                if (flipValue != null)
                {
                    rendererData.AddField("flip", GetVect3((Vector3)flipValue));
                }
                else
                {
                    renderer.AddField("flip", GetVect3(new Vector3(0, 0, 0)));
                }
                //rendererData.AddField("flip", GetVect3(particleSystemRenderer.flip));
                rendererData.AddField("pivot", GetVect3(particleSystemRenderer.pivot));

                var allowRollData = TryGetContainProperty(particleSystemRenderer, "allowRoll");
                if (allowRollData != null)
                {
                    rendererData.AddField("allowRoll", (bool)allowRollData);
                }
                else
                {
                    rendererData.AddField("allowRoll", false);
                }
            }
            else
            {
                String info = "entity: " + particleSys.gameObject.name + " 的粒子组件没有renderer模块,不可导出;请加上renderer模块,或删除该粒子组件";

                ErrorUtil.ExportErrorReporter.create()
                .setGameObject(particleSys.gameObject)
                .setHierarchyContext(context)
                .error(0, "粒子组件没有renderer模块,不可导出;请加上renderer模块,或删除该粒子组件");
            }

            if (particleSys.rotationOverLifetime.enabled)
            {
                JSONObject rotationByLife     = new JSONObject(JSONObject.Type.OBJECT);
                JSONObject rotationByLifeData = new JSONObject(JSONObject.Type.OBJECT);
                data.AddField("rotationByLife", rotationByLifeData);

                rotationByLifeData.AddField("separateAxes", particleSys.rotationOverLifetime.separateAxes);
                if (particleSys.rotationOverLifetime.separateAxes)
                {
                    rotationByLifeData.AddField("x", ParseMinMaxCurve(particleSys.rotationOverLifetime.x, (float)(180 / Math.PI)));
                    rotationByLifeData.AddField("y", ParseMinMaxCurve(particleSys.rotationOverLifetime.y, (float)(180 / Math.PI)));
                    rotationByLifeData.AddField("z", ParseMinMaxCurve(particleSys.rotationOverLifetime.z, (float)(180 / Math.PI)));
                }
                else
                {
                    rotationByLifeData.AddField("z", ParseMinMaxCurve(particleSys.rotationOverLifetime.z, (float)(180 / Math.PI)));
                }
            }

            if (particleSys.sizeOverLifetime.enabled)
            {
                JSONObject sizeOverLifetime     = new JSONObject(JSONObject.Type.OBJECT);
                JSONObject sizeOverLifetimeData = new JSONObject(JSONObject.Type.OBJECT);
                data.AddField("sizeByLife", sizeOverLifetimeData);

                sizeOverLifetimeData.AddField("separateAxes", particleSys.sizeOverLifetime.separateAxes);
                if (particleSys.sizeOverLifetime.separateAxes)
                {
                    sizeOverLifetimeData.AddField("x", ParseMinMaxCurve(particleSys.sizeOverLifetime.x));
                    sizeOverLifetimeData.AddField("y", ParseMinMaxCurve(particleSys.sizeOverLifetime.y));
                    sizeOverLifetimeData.AddField("z", ParseMinMaxCurve(particleSys.sizeOverLifetime.z));
                }
                else
                {
                    sizeOverLifetimeData.AddField("x", ParseMinMaxCurve(particleSys.sizeOverLifetime.size));
                }
            }

            if (particleSys.velocityOverLifetime.enabled)
            {
                JSONObject speedByLifeData = new JSONObject(JSONObject.Type.OBJECT);
                data.AddField("speedByLife", speedByLifeData);
                switch (particleSys.velocityOverLifetime.space)
                {
                case ParticleSystemSimulationSpace.Local:
                    speedByLifeData.AddField("space", 1);
                    break;

                case ParticleSystemSimulationSpace.World:
                    speedByLifeData.AddField("space", 2);
                    break;

                case ParticleSystemSimulationSpace.Custom:
                    break;

                default:
                    break;
                }

                speedByLifeData.AddField("x", ParseMinMaxCurve(particleSys.velocityOverLifetime.x));
                speedByLifeData.AddField("y", ParseMinMaxCurve(particleSys.velocityOverLifetime.y));
                speedByLifeData.AddField("z", ParseMinMaxCurve(particleSys.velocityOverLifetime.z));
#if UNITY_2018_1_OR_NEWER
                speedByLifeData.AddField("orbitalX", ParseMinMaxCurve(particleSys.velocityOverLifetime.orbitalX));
                speedByLifeData.AddField("orbitalY", ParseMinMaxCurve(particleSys.velocityOverLifetime.orbitalY));
                speedByLifeData.AddField("orbitalZ", ParseMinMaxCurve(particleSys.velocityOverLifetime.orbitalZ));
                speedByLifeData.AddField("orbitalOffsetX", ParseMinMaxCurve(particleSys.velocityOverLifetime.orbitalOffsetX));
                speedByLifeData.AddField("orbitalOffsetY", ParseMinMaxCurve(particleSys.velocityOverLifetime.orbitalOffsetY));
                speedByLifeData.AddField("orbitalOffsetZ", ParseMinMaxCurve(particleSys.velocityOverLifetime.orbitalOffsetZ));
                speedByLifeData.AddField("radial", ParseMinMaxCurve(particleSys.velocityOverLifetime.radial));
#endif
#if UNITY_2017_1_OR_NEWER
                speedByLifeData.AddField("speedScale", ParseMinMaxCurve(particleSys.velocityOverLifetime.speedModifier));
#endif
            }

            if (particleSys.limitVelocityOverLifetime.enabled)
            {
                JSONObject speedLimitByLifeData = new JSONObject(JSONObject.Type.OBJECT);
                data.AddField("speedLimitByLife", speedLimitByLifeData);
                speedLimitByLifeData.AddField("separateAxes", particleSys.limitVelocityOverLifetime.separateAxes);
                if (particleSys.limitVelocityOverLifetime.separateAxes)
                {
                    speedLimitByLifeData.AddField("x", ParseMinMaxCurve(particleSys.limitVelocityOverLifetime.limitX, particleSys.limitVelocityOverLifetime.limitXMultiplier));
                    speedLimitByLifeData.AddField("y", ParseMinMaxCurve(particleSys.limitVelocityOverLifetime.limitY, particleSys.limitVelocityOverLifetime.limitYMultiplier));
                    speedLimitByLifeData.AddField("z", ParseMinMaxCurve(particleSys.limitVelocityOverLifetime.limitZ, particleSys.limitVelocityOverLifetime.limitZMultiplier));
                }
                else
                {
                    speedLimitByLifeData.AddField("x", ParseMinMaxCurve(particleSys.limitVelocityOverLifetime.limit, particleSys.limitVelocityOverLifetime.limitMultiplier));
                }
                speedLimitByLifeData.AddField("dampen", particleSys.limitVelocityOverLifetime.dampen);
                switch (particleSys.limitVelocityOverLifetime.space)
                {
                case ParticleSystemSimulationSpace.Local:
                    speedLimitByLifeData.AddField("space", 1);
                    break;

                case ParticleSystemSimulationSpace.World:
                    speedLimitByLifeData.AddField("space", 2);
                    break;

                case ParticleSystemSimulationSpace.Custom:
                    break;

                default:
                    break;
                }
#if UNITY_2017_1_OR_NEWER
                speedLimitByLifeData.AddField("drag", ParseMinMaxCurve(particleSys.limitVelocityOverLifetime.drag));
                speedLimitByLifeData.AddField("dragMultiplyBySize", particleSys.limitVelocityOverLifetime.multiplyDragByParticleSize);
                speedLimitByLifeData.AddField("dragMultiplyBySpeed", particleSys.limitVelocityOverLifetime.multiplyDragByParticleVelocity);
#endif
            }

            if (particleSys.colorOverLifetime.enabled)
            {
                JSONObject colorOverLifetime     = new JSONObject(JSONObject.Type.OBJECT);
                JSONObject colorOverLifetimeData = new JSONObject(JSONObject.Type.OBJECT);
                data.AddField("colorByLife", colorOverLifetimeData);
                colorOverLifetimeData.AddField("gColor", ParseMinMaxGradient(particleSys.colorOverLifetime.color));
            }

            if (particleSys.shape.enabled)
            {
                JSONObject shapeData = new JSONObject(JSONObject.Type.OBJECT);
                var        haveShape = true;
                if (particleSys.shape.shapeType == ParticleSystemShapeType.Cone || particleSys.shape.shapeType == ParticleSystemShapeType.ConeVolume || particleSys.shape.shapeType == ParticleSystemShapeType.ConeVolumeShell || particleSys.shape.shapeType == ParticleSystemShapeType.ConeShell)
                {
                    shapeData.AddField("shape", ParseConeShape(particleSys.shape));
                }
                else if (particleSys.shape.shapeType == ParticleSystemShapeType.Sphere || particleSys.shape.shapeType == ParticleSystemShapeType.SphereShell)
                {
                    shapeData.AddField("shape", ParseSphereShape(particleSys.shape));
                }
                else if (particleSys.shape.shapeType == ParticleSystemShapeType.Circle || particleSys.shape.shapeType == ParticleSystemShapeType.CircleEdge)
                {
                    shapeData.AddField("shape", ParseCircleShape(particleSys.shape));
                }
                else if (particleSys.shape.shapeType == ParticleSystemShapeType.Box || particleSys.shape.shapeType == ParticleSystemShapeType.BoxEdge || particleSys.shape.shapeType == ParticleSystemShapeType.BoxShell)
                {
                    shapeData.AddField("shape", ParseBox(particleSys.shape));
                }
                else if (particleSys.shape.shapeType == ParticleSystemShapeType.Hemisphere || particleSys.shape.shapeType == ParticleSystemShapeType.HemisphereShell)
                {
                    shapeData.AddField("shape", ParseHemisphere(particleSys.shape));
                }
                // else if (particleSys.shape.shapeType == ParticleSystemShapeType.SingleSidedEdge) {
                //     shapeData.AddField("shape", ParseSingleSidedEdge(particleSys.shape));
                // }
                else
                {
                    var parentChain = go.name;
                    var parent      = go.transform.parent;
                    while (parent)
                    {
                        parentChain += " -> " + parent.gameObject.name;
                        parent       = parent.parent;
                    }
                    Debug.LogError("unSupport shape (" + particleSys.shape.shapeType.ToString() + ") at: " + parentChain);
                    haveShape = false;
                }
                if (haveShape)
                {
                    data.AddField("emitterShape", shapeData);
                }
            }

            if (particleSys.textureSheetAnimation.enabled)
            {
                JSONObject textureSheetAnimationData = new JSONObject(JSONObject.Type.OBJECT);
                data.AddField("textureSheetAnimation", textureSheetAnimationData);
                int mode = 1;
#if UNITY_2017_1_OR_NEWER
                mode = 1;
                switch (particleSys.textureSheetAnimation.mode)
                {
                case ParticleSystemAnimationMode.Grid:
                    mode = 1;
                    break;

                case ParticleSystemAnimationMode.Sprites:
                    mode = 2;
                    break;

                default:
                    break;
                }
                textureSheetAnimationData.AddField("mode", mode);
#endif
                JSONObject vec2 = new JSONObject(JSONObject.Type.ARRAY);
                vec2.Add(particleSys.textureSheetAnimation.numTilesX);
                vec2.Add(particleSys.textureSheetAnimation.numTilesY);
                textureSheetAnimationData.AddField("tiles", vec2);
                mode = 1;
                switch (particleSys.textureSheetAnimation.animation)
                {
                case ParticleSystemAnimationType.WholeSheet:
                    mode = 1;
                    break;

                case ParticleSystemAnimationType.SingleRow:
                    mode = 2;
                    break;

                default:
                    break;
                }
                textureSheetAnimationData.AddField("animationType", mode);
                textureSheetAnimationData.AddField("randomRow", particleSys.textureSheetAnimation.useRandomRow);
                textureSheetAnimationData.AddField("row", particleSys.textureSheetAnimation.rowIndex);

                //mode = 1;
                //switch (particleSys.textureSheetAnimation.timeMode)
                //{
                //    case ParticleSystemAnimationTimeMode.Lifetime:
                //        mode = 1;
                //        break;
                //    case ParticleSystemAnimationTimeMode.Speed:
                //        mode = 2;
                //        break;
                //    case ParticleSystemAnimationTimeMode.FPS:
                //        mode = 3;
                //        break;
                //    default:
                //        break;
                //}
                textureSheetAnimationData.AddField("timeMode", 1);
                if (mode == 1)
                {
                    textureSheetAnimationData.AddField("frameOverTime", ParseMinMaxCurve(particleSys.textureSheetAnimation.frameOverTime, particleSys.textureSheetAnimation.numTilesX * particleSys.textureSheetAnimation.numTilesY));
                }
                else
                {
                    textureSheetAnimationData.AddField("frameOverTime", ParseMinMaxCurve(particleSys.textureSheetAnimation.frameOverTime, particleSys.textureSheetAnimation.numTilesX));
                }
                textureSheetAnimationData.AddField("startFrame", ParseMinMaxCurve(particleSys.textureSheetAnimation.startFrame));
                textureSheetAnimationData.AddField("cycles", particleSys.textureSheetAnimation.cycleCount);
                mode = 0;
                var a = particleSys.textureSheetAnimation.uvChannelMask;
                var b = a & UVChannelFlags.UV0;
                if ((a & UVChannelFlags.UV0) != 0)
                {
                    mode += 1;
                }
                if ((a & UVChannelFlags.UV1) != 0)
                {
                    mode += 2;
                }
                if ((a & UVChannelFlags.UV2) != 0)
                {
                    mode += 3;
                }
                if ((a & UVChannelFlags.UV3) != 0)
                {
                    mode += 4;
                }

                textureSheetAnimationData.AddField("affectedUVChannels", mode);
            }

            if (particleSys.subEmitters.enabled)
            {
                JSONObject subEmittersData = new JSONObject(JSONObject.Type.ARRAY);
                data.AddField("subEmitters", subEmittersData);

                int count = particleSys.subEmitters.subEmittersCount;
                for (int i = 0; i < count; i++)
                {
                    ParticleSystemSubEmitterProperties properties = particleSys.subEmitters.GetSubEmitterProperties(i);
                    ParticleSystemSubEmitterType       type       = particleSys.subEmitters.GetSubEmitterType(i);
                    JSONObject res     = new JSONObject(JSONObject.Type.OBJECT);
                    int        typeNum = 0;
                    switch (type)
                    {
                    case ParticleSystemSubEmitterType.Birth:
                        typeNum = 0;
                        break;

                    case ParticleSystemSubEmitterType.Collision:
                        typeNum = 1;
                        break;

                    case ParticleSystemSubEmitterType.Death:
                        typeNum = 2;
                        break;

                    default:
                        break;
                    }
                    res.AddField("type", typeNum);
                    int propertiesNum = 0;
                    switch (properties)
                    {
                    case ParticleSystemSubEmitterProperties.InheritNothing:
                        propertiesNum = 0;
                        break;

                    case ParticleSystemSubEmitterProperties.InheritEverything:
                        propertiesNum = 1;
                        break;

                    case ParticleSystemSubEmitterProperties.InheritColor:
                        propertiesNum = 2;
                        break;

                    case ParticleSystemSubEmitterProperties.InheritSize:
                        propertiesNum = 3;
                        break;

                    case ParticleSystemSubEmitterProperties.InheritRotation:
                        propertiesNum = 4;
                        break;

                    default:
                        break;
                    }
                    res.AddField("properties", propertiesNum);

                    subEmittersData.Add(res);
                }
            }

            return(json);
        }
Exemplo n.º 4
0
        protected override JSONObject ToJSON(WXHierarchyContext context)
        {
            JSONObject json = new JSONObject(JSONObject.Type.OBJECT);
            JSONObject data = new JSONObject(JSONObject.Type.OBJECT);

            json.AddField("type", "MeshRenderer");
            json.AddField("data", data);

            Mesh mesh = (renderer.gameObject.GetComponent(typeof(MeshFilter)) as MeshFilter).sharedMesh;

            if (mesh != null)
            {
                WXMesh meshConverter = new WXMesh(mesh);
                string meshPath      = meshConverter.Export(context.preset);
                data.AddField("mesh", meshPath);
                context.AddResource(meshPath);
            }
            else
            {
                Debug.LogError(string.Format("{0} mesh is null", renderer.name));
            }

            JSONObject materialArray = new JSONObject(JSONObject.Type.ARRAY);

            Material[] materials = renderer.sharedMaterials;
            foreach (Material material in materials)
            {
                if (material != null)
                {
                    WXMaterial materialConverter = new WXMaterial(material, renderer);
                    string     materialPath      = materialConverter.Export(context.preset);
                    materialArray.Add(materialPath);
                    context.AddResource(materialPath);
                }
            }
            data.AddField("materials", materialArray);

            int        lightmapIndex  = renderer.lightmapIndex;
            JSONObject litmapScaleArr = new JSONObject(JSONObject.Type.ARRAY);

            data.AddField("lightMapScaleOffset", litmapScaleArr);
            litmapScaleArr.Add(renderer.lightmapScaleOffset.x);
            litmapScaleArr.Add(renderer.lightmapScaleOffset.y);
            litmapScaleArr.Add(renderer.lightmapScaleOffset.z);
            litmapScaleArr.Add(renderer.lightmapScaleOffset.w);
            data.AddField("lightMapIndex", lightmapIndex);

            ShadowCastingMode mode        = renderer.shadowCastingMode;
            StaticEditorFlags shadowFlags = GameObjectUtility.GetStaticEditorFlags(renderer.gameObject);

            if (mode == ShadowCastingMode.Off || (shadowFlags & StaticEditorFlags.LightmapStatic) != 0)
            {
                data.AddField("castShadow", false);
            }
            else
            {
                data.AddField("castShadow", true);
            }

            bool receiveShadow = renderer.receiveShadows;

            data.AddField("receiveShadow", receiveShadow);
            return(json);
        }
        protected override JSONObject ToJSON(WXHierarchyContext context)
        {
            JSONObject json = new JSONObject(JSONObject.Type.OBJECT);
            JSONObject data = new JSONObject(JSONObject.Type.OBJECT);

            json.AddField("type", "MeshRenderer");
            json.AddField("data", data);

            data.AddField("active", renderer.enabled);

            JSONObject materialArray = new JSONObject(JSONObject.Type.ARRAY);

            Material[] materials     = renderer.sharedMaterials;
            int        materialCount = 0;

            foreach (Material material in materials)
            {
                if (material != null)
                {
                    WXMaterial materialConverter = new WXMaterial(material, renderer);
                    string     materialPath      = materialConverter.Export(context.preset);
                    materialArray.Add(materialPath);
                    context.AddResource(materialPath);
                    materialCount++;
                }
            }
            data.AddField("materials", materialArray);

            MeshFilter meshFilter = renderer.gameObject.GetComponent <MeshFilter> ();

            if (meshFilter != null && meshFilter.sharedMesh != null)
            {
                Mesh   mesh          = meshFilter.sharedMesh;
                WXMesh meshConverter = new WXMesh(mesh, materialCount);
                string meshPath      = meshConverter.Export(context.preset);
                data.AddField("mesh", meshPath);
                context.AddResource(meshPath);
            }
            else
            {
                ErrorUtil.ExportErrorReporter.create()
                .setGameObject(renderer.gameObject)
                .setHierarchyContext(context)
                .error(ErrorUtil.ErrorCode.MeshRenderer_MeshNotFound, "Mesh资源转换失败,没法拿到对应的MeshFilter或者它上面的mesh");
            }

            int        lightmapIndex  = renderer.lightmapIndex;
            JSONObject litmapScaleArr = new JSONObject(JSONObject.Type.ARRAY);

            data.AddField("lightMapScaleOffset", litmapScaleArr);
            litmapScaleArr.Add(renderer.lightmapScaleOffset.x);
            litmapScaleArr.Add(renderer.lightmapScaleOffset.y);
            litmapScaleArr.Add(renderer.lightmapScaleOffset.z);
            litmapScaleArr.Add(renderer.lightmapScaleOffset.w);
            data.AddField("lightMapIndex", lightmapIndex);

            ShadowCastingMode mode        = renderer.shadowCastingMode;
            StaticEditorFlags shadowFlags = GameObjectUtility.GetStaticEditorFlags(renderer.gameObject);

#if UNITY_2019_2_OR_NEWER
            if (mode == ShadowCastingMode.Off || (shadowFlags & StaticEditorFlags.ContributeGI) != 0)
#else
            if (mode == ShadowCastingMode.Off || (shadowFlags & StaticEditorFlags.LightmapStatic) != 0)
#endif
            {
                data.AddField("castShadow", false);
            }
            else
            {
                data.AddField("castShadow", true);
            }

            bool receiveShadow = renderer.receiveShadows;
            data.AddField("receiveShadow", receiveShadow);
            return(json);
        }