Esempio n. 1
0
        public FrameObject(Exporter exporter)
        {
            ObjectType = ObjectTypeFrame;
            //-------------------


            GameObject timelineRoot = null;

            if (exporter._Timeline != null)
            {
                timelineRoot = exporter._Timeline.GetRootObjectByTime(time);
            }

            // Debug.Log(timelineRoot);


            var objs = Object.FindObjectsOfType <GameObject>();

            if (objs == null)
            {
                return;
            }
            Array.Sort(objs, SortByPosition);


            //===================================================canvas
            var canvases = Object.FindObjectsOfType <FxCanvasObject>();

            Array.Sort(canvases, SortByNodeOrder);

            List <GameObject> canvasObjects = new List <GameObject>();

            if (true)
            {
                foreach (var c in canvases)
                {
                    if (c.root == null)
                    {
                        continue;
                    }

                    if (timelineRoot != null)
                    {
                        if (!c.root.transform.IsChildOf(timelineRoot.transform))
                        {
                            continue;
                        }
                    }

                    Camera cam = c.gameObject.GetComponent <Camera>();
                    commandlist.Add(new BeginCanvasCommand(c, exporter));


                    //Draw
                    foreach (var obj in objs)
                    {
                        //---------for timeline-------------------
                        if (exporter._Timeline != null)
                        {
                            if (timelineRoot == null)
                            {
                                continue;
                            }
                            if (!obj.transform.IsChildOf(timelineRoot.transform))
                            {
                                continue;
                            }
                        }
                        //-----------------------------------------------------

                        if (!obj.transform.IsChildOf(c.root.transform))
                        {
                            continue;
                        }

                        canvasObjects.Add(obj);
                        DrawObject(cam, obj, exporter);
                    }

                    commandlist.Add(new EndCanvasCommand(c));
                }
            }
            //===================================================


            //===================================================Draw
            if (true)
            {
                foreach (var obj in objs)
                {
                    //----------------skip content of canvas----------------
                    bool skip = (canvasObjects.IndexOf(obj) != -1);
                    // foreach (var c in canvases)
                    // {
                    //     if (c.root == null)
                    //     {
                    //         continue;
                    //     }
                    //
                    //     if (obj.gameObject.transform.IsChildOf(c.root.transform))
                    //     {
                    //         skip = true;
                    //         break;
                    //     }
                    //
                    //     if (skip) break;
                    // }
                    //--------------------------------


                    //---------for timeline-------------------
                    if (exporter._Timeline != null)
                    {
                        if (timelineRoot == null)
                        {
                            continue;
                        }
                        if (!obj.transform.IsChildOf(timelineRoot.transform))
                        {
                            continue;
                        }
                    }
                    //-----------------------------------------------------

                    if (skip)
                    {
                        continue;
                    }

                    //DrawObject(Camera.main,obj, exporter);
                    DrawObject(SceneConfig.currentCamera, obj, exporter);
                }
            }

            //===================================================
//            Debug.Log("DrawCommands:"+commandlist.Count);
        }
        public ChangeShaderCommand(Camera cam, GameObject gameObject, Exporter exporter)
        {
            ObjectType = CommandTypeChangeShader;
            //-------------------------------------------------
            var viewMatrix    = cam.worldToCameraMatrix;
            var projectMatrix = cam.projectionMatrix;

            matrixVP            = projectMatrix * viewMatrix;
            matirxObjectToWorld = gameObject.transform.localToWorldMatrix;


            //------------------
            var renderer = gameObject.GetComponent <Renderer>();

            var shader = renderer.material.shader;

            _shaderObject = exporter.GetObject(shader) as ShaderObject;

            //------------------
            renderer.GetPropertyBlock(block);


            var count = shader.GetPropertyCount();

            for (var i = 0; i < count; i++)
            {
                var p = new ShaderParameter(shader.GetPropertyName(i),
                                            ShaderParameter.GetTypeFromPropertyType(shader.GetPropertyType(i)));
                switch (p.type)
                {
                case ShaderParameter.ParameterTypeColor:
                    p.colorValue = block.GetColor(p.name);
                    if (p.colorValue == new Color(0, 0, 0, 0))
                    {
                        p.colorValue = renderer.material.GetColor(p.name);
                    }
                    break;

                case ShaderParameter.ParameterTypeFloat:
                    p.floatValue = block.GetFloat(p.name);
                    if (p.floatValue == 0.0f)
                    {
                        p.floatValue = renderer.material.GetFloat(p.name);
                    }
                    break;

                case ShaderParameter.ParameterTypeTexture2D:
                {
                    var tex = renderer.material.GetTexture(p.name);
                    if (tex == null)
                    {
                        tex = Texture2D.whiteTexture;
                    }
                    p.textureValue = exporter.GetObject(tex) as TextureObject;
                }
                break;

                case ShaderParameter.ParameterTypeFloat4:
                    p.vectorValue = block.GetVector(p.name);
                    if (p.vectorValue == new Vector4(0, 0, 0, 0))
                    {
                        p.vectorValue = renderer.material.GetVector(p.name);
                    }
                    break;
                }
                _parameters.Add(p);
                if (p.type == ShaderParameter.ParameterTypeTexture2D)
                {
                    var texcoord = new ShaderParameter(p.name + "_ST", ShaderParameter.ParameterTypeFloat4);
                    //texcoord.vectorValue = renderer.material.GetVector(texcoord.name);
                    texcoord.vectorValue = block.GetVector(texcoord.name);
                    if (texcoord.vectorValue == new Vector4(0, 0, 0, 0))
                    {
                        texcoord.vectorValue = renderer.material.GetVector(texcoord.name);
                    }
                    _parameters.Add(texcoord);
                }
            }
            //------------------------------------------------------
        }
        public TextFxSlotCommand(Camera cam, GameObject gameObject, Exporter exporter)
        {
            ObjectType = CommandTypeTextFxSlot;
            //----------------------------------
            var textobj = gameObject.GetComponent <TextFx>();

            id   = textobj.soltID;
            size = textobj.size;
            switch (textobj.align)
            {
            case TextAlignment.Left:
                textAlignment = AlignmentLeft;
                break;

            case TextAlignment.Center:
                textAlignment = AlignmentCenter;
                break;

            case TextAlignment.Right:
                textAlignment = AlignmentRight;
                break;
            }

            var viewMatrix    = cam.worldToCameraMatrix;
            var projectMatrix = cam.projectionMatrix;

            matrixVP            = projectMatrix * viewMatrix;
            matirxObjectToWorld = gameObject.transform.localToWorldMatrix;

            //----------time-----------
            starttime      = textobj.startTime;
            duration       = textobj.effectDuration;
            overlapPercent = textobj.interval;

            var clip = exporter.GetObject(textobj.clip) as AnimationClipObject;

            if (clip != null)
            {
                animationClips.Add(clip);
            }

            switch (textobj.animationType)
            {
            case TextAnimationType.Sequence:
                textAnimationType = TextAnimationTypeSequence;
                break;

            case TextAnimationType.Randomize:
                textAnimationType = TextAnimationTypeRandomize;
                break;
            }

            if (textobj.material != null)
            {
                var shader = exporter.GetObject(textobj.material.shader) as ShaderObject;
                if (shader != null)
                {
                    shaderID = shader.ObjectID;
                }
            }
            else
            {
                Debug.LogError("material of text is nuall:" + textobj.gameObject.name);
            }
        }