internal void LateUpdateMain(float timeElapsed,
                                 bool flagHideDefault,
                                 Library_SpriteStudio6.KindMasking masking,
                                 ref Matrix4x4 matrixCorrection,
                                 bool flagPlanarization
                                 )
    {
        if (0 == (Status & FlagBitStatus.VALID))
        {
            return;
        }
        if (null == DataEffect)
        {
            return;
        }
        if (false == DataEffect.StatusIsBootup)
        {               /* Re-import data? or Re-compile during playing animation? */
            return;
        }

        bool flagHide = flagHideDefault | FlagHideForce;

        /* Update Base */
        BaseLateUpdate(timeElapsed);

        /* Update Playing-Status */
        if (0 == (StatusPlaying & Library_SpriteStudio6.Control.Animation.Track.FlagBitStatus.PLAYING))
        {               /* Not-Playing */
            Status &= ~FlagBitStatus.PLAYING;
            return;
        }

        Status      |= FlagBitStatus.PLAYING;
        TimeElapsed += ((0 != (StatusPlaying & Library_SpriteStudio6.Control.Animation.Track.FlagBitStatus.PAUSING)) ||
                        (0 != (StatusPlaying & Library_SpriteStudio6.Control.Animation.Track.FlagBitStatus.PLAYING_START))
                        ) ? 0.0f : (timeElapsed * RateTime);
        Frame = TimeElapsed * FramePerSecond;
        if (0 != (Status & FlagBitStatus.PLAYING_INFINITY))
        {               /* Independent */
//			Frame %= FrameRange;
        }
        else
        {               /* Dependent */
            Frame = Mathf.Clamp(Frame, 0.0f, FrameRange);
        }

        /* Recover Draw-Cluster & Component for Rendering */
        if (null == ClusterDraw)
        {               /* Lost */
            if (false == ClusterBootUpDraw())
            {           /* Recovery failure */
                return;
            }
        }

        /* MEMO: Execute combining and drawing only at Highest-Parent-Root. */
        /* Clean Draw-Cluster & Component for Rendering */
        if (null == InstanceRootParent)
        {
            ClusterDraw.DataPurge();

//			if(false == RendererBootUpDraw(false))
//			{	/* Recovery failure */
//				return;
//			}
        }

        /* Update & Draw Effect */
        if (false == flagHide)
        {
            ControlEffect.Update(this, masking, ref matrixCorrection, flagPlanarization);
        }

        /* Mesh Combine & Set to Renderer */
        if ((null == InstanceRootParent) && (null != MeshCombined))
        {
            /* Clear Mesh */
            MeshCombined.Clear();
            MeshCombined.name = NameBatchedMesh;

            if (false == flagHide)
            {
                /* MEMO: Set the material-array to null issue "NullReferenceException". Leave as. */
                if (true == ClusterDraw.MeshCombine(MeshCombined, ref TableMaterialCombined))
                {
                    InstanceMeshRenderer.sharedMaterials = TableMaterialCombined;
                }
            }
            InstanceMeshFilter.sharedMesh = MeshCombined;
        }

        /* Clear transient status */
        StatusPlaying &= ~Library_SpriteStudio6.Control.Animation.Track.FlagBitStatus.PLAYING_START;
        Status        &= ~(FlagBitStatus.UPDATE_RATE_SCALELOCAL
                           | FlagBitStatus.UPDATE_RATE_OPACITY
                           | FlagBitStatus.CHANGE_TABLEMATERIAL
                           | FlagBitStatus.CHANGE_CELLMAP
                           );
    }
Example #2
0
    internal void LateUpdateMain(float timeElapsed,
                                 bool flagHideDefault,
                                 Library_SpriteStudio6.KindMasking masking,
                                 ref Matrix4x4 matrixCorrection,
                                 bool flagInitializeMatrixCorrection,
                                 bool flagPlanarization
                                 )
    {
        if (0 == (Status & FlagBitStatus.VALID))
        {               /* Status invalid */
            return;
        }
        if ((null == TableControlTrack) || (null == TableControlParts))
        {               /* Can not play */
            return;
        }
        if (null == DataAnimation)
        {               /* Master data lost */
            return;
        }
        if (false == DataAnimation.StatusIsBootup)
        {               /* Re-import data? or Re-compile during playing animation? */
            return;
        }

        /* Get Hidden state */
        bool flagHide = flagHideDefault | FlagHideForce;

        /* Clear Draw-Chain */
        if (false == ChainDrawBootUp())
        {               /* Failure Clear Draw-Chain */
            return;
        }

        /* Update Base */
        BaseLateUpdate(timeElapsed);

        /* Update Play-Track */
        if (null == TableControlTrack)
        {               /* Lost */
            ControlBootUpTrack(-1);
        }
        int countControlTrack = TableControlTrack.Length;

        for (int i = 0; i < countControlTrack; i++)
        {
            TableControlTrack[i].Update(timeElapsed);
        }

        /* Update Parts' Common-Parameters (GameObject etc.) */
        /* MEMO: In case of the most-Parent-"Root" node, if MeshRenderer's matrix is not acquired after updating Transform first, "matrixCorrection" shifts 1 frame. */
        int countControlParts = TableControlParts.Length;
        int indexTrackRoot    = TableControlParts[0].IndexControlTrack;         /* (0 < countControlParts) ? TableControlParts[0].IndexControlTrack : -1; */

        Status &= ~FlagBitStatus.ANIMATION_SYNTHESIZE;
        TableControlParts[0].Update(this,
                                    0,
                                    flagHide,
                                    ref matrixCorrection,
                                    indexTrackRoot
                                    );
        if (true == flagInitializeMatrixCorrection)
        {
            matrixCorrection = InstanceMeshRenderer.localToWorldMatrix.inverse;
        }
        for (int i = 1; i < countControlParts; i++)
        {
            TableControlParts[i].Update(this,
                                        i,
                                        flagHide,
                                        ref matrixCorrection,
                                        indexTrackRoot
                                        );
        }
        bool flagAnimationSynthesize = (0 != (Status & FlagBitStatus.ANIMATION_SYNTHESIZE));            /* ? true : false */

        /* Recover Draw-Cluster & Component for Rendering */
        if (null == ClusterDraw)
        {               /* Lost */
            if (false == ClusterBootUpDraw())
            {           /* Recovery failure */
                return;
            }
        }

        /* Exec Drawing */
        /* MEMO: At "Pre-Draw" ...                                                                                             */
        /*       First render all "Mask"s.                                                                                     */
        /*       After that, render "Mask"s again according to priority at "Draw" timing. (Process of removing "Mask"s)        */
        /*       Caution that rendering "Mask"s is only Highest-Parent-Root. ("Instance"s and "Effect"s do not render "Mask"s) */
        /* MEMO: At "Draw" ...                                                                                                 */
        /*       Caution that "Instance" and "Effect" are update in draw.                                                      */
        /*       Hidden "Normal" parts are not processed.(Not included in the Draw-Order-Chain)                                */
        /* MEMO: Before 1.0.x, draw-order are baked. */
        int idPartsDrawNext;

        if (true == flagAnimationSynthesize)
        {
            int countChainDraw;

            /* Sort Draw-Chain */
            /* MEMO: "PreDraw"'s drawing order is reversed, but since sort-key is inversed, not necessary to exec "Reverse()" after "Sort()". */
            ListPartsPreDraw.Sort();
            ListPartsDraw.Sort();

            if (null == InstanceRootParent)
            {
                /* Clean Draw-Cluster & Component for Rendering */
                /* MEMO: Execute combining and drawing only at Highest-Parent-Root. */
                ClusterDraw.DataPurge();

                /* Exec "Pre-Draw" */
                countChainDraw = ListPartsPreDraw.Count;
                for (int i = 0; i < countChainDraw; i++)
                {
                    idPartsDrawNext = ListPartsPreDraw[i] & Library_SpriteStudio6.Control.Animation.MaskSortKeyIDParts;
                    TableControlParts[idPartsDrawNext].PreDraw(this,
                                                               idPartsDrawNext,
                                                               flagHide,
                                                               masking,
                                                               ref matrixCorrection,
                                                               flagPlanarization
                                                               );
                }
            }

            /* Exec "Draw" */
            countChainDraw = ListPartsDraw.Count;
            for (int i = 0; i < countChainDraw; i++)
            {
                idPartsDrawNext = ListPartsDraw[i] & Library_SpriteStudio6.Control.Animation.MaskSortKeyIDParts;
                TableControlParts[idPartsDrawNext].Draw(this,
                                                        idPartsDrawNext,
                                                        flagHide,
                                                        masking,
                                                        ref matrixCorrection,
                                                        flagPlanarization
                                                        );
            }
        }
        else
        {
            if (null == InstanceRootParent)
            {
                /* Clean Draw-Cluster & Component for Rendering */
                /* MEMO: Execute combining and drawing only at Highest-Parent-Root. */
                ClusterDraw.DataPurge();

                /* Exec "Pre-Draw" */
                idPartsDrawNext = TableControlParts[0].IDPartsNextPreDraw;
                while (0 <= idPartsDrawNext)
                {
                    TableControlParts[idPartsDrawNext].PreDraw(this,
                                                               idPartsDrawNext,
                                                               flagHide,
                                                               masking,
                                                               ref matrixCorrection,
                                                               flagPlanarization
                                                               );
                    idPartsDrawNext = TableControlParts[idPartsDrawNext].IDPartsNextPreDraw;
                }
            }

            /* Exec "Draw" */
            idPartsDrawNext = TableControlParts[0].IDPartsNextDraw;
            while (0 <= idPartsDrawNext)
            {
                TableControlParts[idPartsDrawNext].Draw(this,
                                                        idPartsDrawNext,
                                                        flagHide,
                                                        masking,
                                                        ref matrixCorrection,
                                                        flagPlanarization
                                                        );
                idPartsDrawNext = TableControlParts[idPartsDrawNext].IDPartsNextDraw;
            }
        }

        /* Mesh Combine & Set to Renderer */
        if ((null == InstanceRootParent) && (null != MeshCombined))
        {
            /* Clear Mesh */
            MeshCombined.Clear();
            MeshCombined.name = NameBatchedMesh;

            if (false == flagHide)
            {
                /* MEMO: Set the material-array to null issue "NullReferenceException". Leave as. */
                if (true == ClusterDraw.MeshCombine(MeshCombined, ref TableMaterialCombined))
                {
                    InstanceMeshRenderer.sharedMaterials = TableMaterialCombined;
                    InstanceMeshRenderer.sortingOrder    = OrderInLayer;
                }
            }
            InstanceMeshFilter.sharedMesh = MeshCombined;
        }

        /* Check Track-End */
        int  indexTrackSlave     = -1;
        bool flagDecodeNextForce = false;
        bool flagStopAllTrack    = true;
        bool flagRequestPlayEndTrack;
        int  indexAnimation;

        for (int i = 0; i < countControlTrack; i++)
        {
            if (true == TableControlTrack[i].StatusIsPlaying)
            {
                flagRequestPlayEndTrack = TableControlTrack[i].StatusIsRequestPlayEnd;
                indexAnimation          = TableControlTrack[i].ArgumentContainer.IndexAnimation;

                /* Check Transition-End */
                flagDecodeNextForce = false;
                if (true == TableControlTrack[i].StatusIsRequestTransitionEnd)
                {
                    indexTrackSlave = TableControlTrack[i].IndexTrackSlave;
                    if (0 <= indexTrackSlave)
                    {
                        /* Change Track Slave to Master */
                        /* MEMO: Overwrite slave track status. */
                        flagRequestPlayEndTrack = TrackChangeSlaveToMaster(i, indexTrackSlave);

                        /* CallBack Transition-End */
                        if ((null != FunctionPlayEndTrack) && (null != FunctionPlayEndTrack[i]))
                        {
                            FunctionPlayEndTrack[i](this,
                                                    i,
                                                    indexTrackSlave,
                                                    indexAnimation,
                                                    TableControlTrack[i].ArgumentContainer.IndexAnimation
                                                    );
                        }
                        flagDecodeNextForce = true;
                    }
                }

                /* Check Track Play-End */
                if (true == flagRequestPlayEndTrack)
                {
                    /* Stop Track */
                    TableControlTrack[i].Stop();

                    /* CallBack Play-End */
                    /* MEMO: At Play-End callback, "indexTrackSlave" is always -1. */
                    if ((null != FunctionPlayEndTrack) && (null != FunctionPlayEndTrack[i]))
                    {
                        FunctionPlayEndTrack[i](this, i, -1, indexAnimation, -1);
                    }
                }
                else
                {
                    flagStopAllTrack = false;
                }

                TableControlTrack[i].StatusIsRequestPlayEnd       = false;
                TableControlTrack[i].StatusIsRequestTransitionEnd = false;
            }

#if false
            TableControlTrack[i].StatusClearTransient();
#else
            /* MEMO: Originally should call function, but directly process (taking call-cost into account). */
            /* MEMO: Since clear bits only, VALID is not judged.                                  */
            /*       (Even if clearing those bits of stopping track, processing is not affected.) */
            TableControlTrack[i].Status &= ~(Library_SpriteStudio6.Control.Animation.Track.FlagBitStatus.PLAYING_START
                                             | Library_SpriteStudio6.Control.Animation.Track.FlagBitStatus.DECODE_ATTRIBUTE
                                             | Library_SpriteStudio6.Control.Animation.Track.FlagBitStatus.TRANSITION_START
                                             );
            if (true == flagDecodeNextForce)
            {
                TableControlTrack[i].Status |= Library_SpriteStudio6.Control.Animation.Track.FlagBitStatus.DECODE_ATTRIBUTE;
            }

            TableControlTrack[i].TimeElapseReplacement = 0.0f;
#endif
        }

        /* Clear Transient-Status */
        Status &= ~(FlagBitStatus.UPDATE_RATE_SCALELOCAL
                    | FlagBitStatus.UPDATE_RATE_OPACITY
                    | FlagBitStatus.CHANGE_TABLEMATERIAL
                    | FlagBitStatus.CHANGE_CELLMAP
                    );
        if (null != AdditionalColor)
        {
            AdditionalColor.Status &= ~Library_SpriteStudio6.Control.AdditionalColor.FlagBitStatus.CHANGE;
        }

        /* Check Animation-End */
        if (true == flagStopAllTrack)
        {
            if (0 != (Status & FlagBitStatus.PLAYING))
            {                   /* Playing -> Stop */
                if (null != FunctionPlayEnd)
                {
                    if (false == FunctionPlayEnd(this, InstanceGameObjectControl))
                    {
                        if (null == InstanceRootParent)
                        {
                            /* MEMO: When "FunctionPlayEnd" returns false, destroy self. */
                            /*       If have "Control-Object", will destroy as well.     */
                            /*       However, can not destroy when "Instance".           */
                            if (null != InstanceGameObjectControl)
                            {
                                UnityEngine.Object.Destroy(InstanceGameObjectControl);
                            }
                            else
                            {
                                UnityEngine.Object.Destroy(gameObject);
                            }
                        }
                    }
                }
            }

            Status &= ~FlagBitStatus.PLAYING;
        }
        else
        {
            Status |= FlagBitStatus.PLAYING;
        }
    }