Example #1
0
    private bool AnimationPlay()
    {
        if(KindAnimation.NON == KindAnimationPlay)
        {	/* Not being requested changing animation */
            return(true);
        }

        int indexAnimation = TableIndexAnimation[(int)KindAnimationPlay];
        if(0 > indexAnimation)
        {	/* Invalid Animation's index */
            return(false);
        }

        ScriptRoot.AnimationPlay(-1, indexAnimation, 0);	/* play infinite */
        KindAnimationPlay = KindAnimation.NON;

        return(true);
    }
Example #2
0
    void Update()
    {
        /* Check Validity */
        if(false == FlagInitialized)
        {	/* Failed to initialize */
            return;
        }

        /* Adjust Parameters */
        if(0 >= SizePixelFontX)
        {
            SizePixelFontX = (int)Constant.FONTSIZE_DEFAULT;
        }

        if(0 > IndexFont)
        {
            IndexFont = 0;
        }
        if((int)Constant.FONT_MAX <= IndexFont)
        {
            IndexFont = (int)Constant.FONT_MAX - 1;
        }

        /* Clamp Value */
        int valueDisplay = Mathf.Clamp(Value, ValueMin, ValueMax);

        /* Check & Update Animation */
        if(FlagVibrationPrevious != FlagVibration)
        {
            /* MEMO: Simply, If animation-change is reserved, postpone to update.                                    */
            /*       This process does not matter because depend on the convenience for application's specification. */
            if(KindAnimation.NON == KindAnimationPlay)
            {	/* Not reserved */
                KindAnimationPlay = (true == FlagVibration) ? KindAnimation.ANIMATION_VIBRATION : KindAnimation.ANIMATION_NOMOVE;
                FlagVibrationPrevious = FlagVibration;
            }
            AnimationPlay();
        }

        /* Check & Update AdditionalColor */
        /* MEMO: The reason for checking two types of updates, "IndexColor" and "FlagChangeColor",                                   */
        /*        is that "FlagChangeColor" is updated from inspector and "IndexColor" is updated in the UserData-callback function. */
        if((FlagChangeColorPrevious != FlagChangeColor) || (IndexColorPrevious != IndexColor))
        {
            FlagChangeColorPrevious = FlagChangeColor;
            IndexColorPrevious = IndexColor;

            if(null != AdditionalColor)
            {
                /* MEMO: Created "AdditionalColor"'s Parameter can continue to be used unless call "AdditionalColorRelease". */
                /*       To temporarily-disable AdditionalColor, set "Library_SpriteStudio6.KindOperationBlend.NON".         */
                AdditionalColor.SetOverall((true == FlagChangeColor) ? Library_SpriteStudio6.KindOperationBlend.MUL : Library_SpriteStudio6.KindOperationBlend.NON,
                                            TableColorFont[IndexColor]
                                        );
            }
        }

        /* Check Update */
        bool flagUpdateText = false;
        if(ValuePrevious != Value)
        {
            ValuePrevious = Value;
            flagUpdateText |= true;
        }
        if(IndexFontPrevious != IndexFont)
        {
            IndexFontPrevious = IndexFont;
            flagUpdateText |= true;
        }
        if(FlagPaddingZeroPrevious != FlagPaddingZero)
        {
            FlagPaddingZeroPrevious = FlagPaddingZero;
            flagUpdateText |= true;
        }
        //		if(SizePixelFontXPrevious != SizePixelFontX)
        //		{
        //			SizePixelFontXPrevious = SizePixelFontX;
        //			flagUpdateText |= true;
        //		}
        if(FlagProportionalPrevious != FlagProportional)
        {
            FlagProportionalPrevious = FlagProportional;
            flagUpdateText |= true;
        }

        /* Update Text */
        if(true == flagUpdateText)
        {
            string textValue;

            /* Get Text */
            if(true == FlagPaddingZero)
            {	/* Zero-padding */
                textValue = valueDisplay.ToString("D" + ((int)(Constant.DIGIT_MAX)).ToString());
            }
            else
            {	/* Right-alignment */
                textValue = valueDisplay.ToString("D");
            }

            /* Update Digits */
            {
                /* Generate Text */
                char[] charactersDigit = textValue.ToCharArray();	/* Split to digit */
                int countDigit = charactersDigit.Length;
                int idParts;
                int indexCharacter;
                int positionPixelDigit = 0;
                for(int i=0; i<countDigit; i++)
                {
                    /* MEMO: Since "idParts == 0" is the "Root"-part, intentionally excluded.           */
                    /*       Setting HideSet's idParts to 0 is to control hidding the entire animation. */
                    idParts = TablePartsDigit[i].IDParts;
                    if(0 < idParts)
                    {
                        /* Change Cell */
                        /* MEMO: (IndexCellMap == 0) Because this Animation has 1 Texture. */
                        indexCharacter = IndexGetCharacter(charactersDigit[(countDigit - 1) - i]);
                        ScriptRoot.CellChangeParts(	idParts,
                                                    0,
                                                    TableCellCharacter[IndexFont, indexCharacter].IndexCell,
                                                    Library_SpriteStudio6.KindIgnoreAttribute.PERMANENT	/* Ignore "Reference-Cell" attribute even if change animation */
                                                );

                        /* Show Digit */
                        /* MEMO: Don't Effect to children */
                        ScriptRoot.HideSet(idParts, false, false);

                        /* Set Digit's position */
                        {
                            /* Get Pixel-Width */
                            int pixelSpaceNow = (true == FlagProportional) ? (int)(TableCellCharacter[IndexFont, indexCharacter].SizeCell.x) : SizePixelFontX;
                            pixelSpaceNow /= 2;	/* Spacing-width = (Previous digit's width + Now digit's width) / 2 */

                            /* Adjust Position */
                            if(0 < i)
                            {	/* The 1st-digit is Fixed-Position */
                                positionPixelDigit -= pixelSpaceNow;

                                /* MEMO: There are conditions that must be met to successfully overwrite part's "Transform" from script. */
                                /*       1. When overwrite position, "X Position", "Y Position" and "Z Position"                         */
                                /*           must not have key-frame data in animation (and "Setup" animation).                          */
                                /*       2. When overwrite rotation, "X-axis Rotation", "Y-axis Rotation" and "Z-axis Rotation"          */
                                /*           must not have key-frame data in animation (and "Setup" animation).                          */
                                /*       3. When overwrite scaling, "X Scale" and "Y Scale"                                              */
                                /*           must not have key-frame data in animation (and "Setup" animation).                          */
                                /*           ("Local X Scale" and "Local Y Scale" can have key-frame datas)                              */
                                Transform transformDigit = TablePartsDigit[i].Transform;
                                Vector3 localPositionDigit = transformDigit.localPosition;
                                localPositionDigit.x = (float)positionPixelDigit;
                                transformDigit.localPosition = localPositionDigit;
                            }
                            positionPixelDigit -= pixelSpaceNow;
                        }
                    }
                }
                for(int i=countDigit; i<(int)Constant.DIGIT_MAX; i++)
                {
                    idParts = TablePartsDigit[i].IDParts;
                    if(0 < idParts)
                    {
                        ScriptRoot.HideSet(idParts, true, false);
                    }
                }
            }
        }
    }
Example #3
0
    void Start()
    {
        /* Initialize WorkArea */
        FlagPaddingZeroPrevious = !FlagPaddingZero;	/* Since this value can not be set with initializer... */
        FlagProportionalPrevious = !FlagProportional;
        FlagChangeColorPrevious = !FlagChangeColorPrevious;
        FlagVibrationPrevious = !FlagVibrationPrevious;

        /* Get Animation Control Script-Component */
        GameObject gameObjectBase = GameObjectRoot;
        if(null == gameObjectBase)
        {
            gameObjectBase = gameObject;
        }
        /* MEMO: "Script_SpriteStudio6_Root.Parts.RootGet" is function for finding "Script_SpriteStudio6_Root" in GameObjects below.       */
        /*       (However, "Instance" is excluded. Find only "Highest-Root"-parts)                                                         */
        /*       You can find "shallowest hierarchy"-one from direct-children, but not guarantee the shallowest when deeper than children. */
        /*       Because wasteful to search every time access, recommend to cache.                                                         */
        ScriptRoot = Script_SpriteStudio6_Root.Parts.RootGet(gameObjectBase);
        if(null == ScriptRoot)
        {	/* Error */
            return;
        }

        /* Set UserData callback function */
        /* MEMO: Set up function to handle UserData callback.                                     */
        /*       To avoid receiving UserData callback, set "ScriptRoot.FunctionUserData" to null. */
        ScriptRoot.FunctionUserData = FunctionCallBackUserData;

        /* Get Animation Index */
        /* MEMO: Collect animation-indexs ahead of time.                 */
        /*       Every change animation, also you can get index by name. */
        /*       But wasteful to search each time.                       */
        TableIndexAnimation = AnimationIndexGet();
        if(null == TableIndexAnimation)
        {
            return;
        }

        /* Animation Start */
        KindAnimationPlay = (true == FlagVibration) ? KindAnimation.ANIMATION_VIBRATION : KindAnimation.ANIMATION_NOMOVE;
        AnimationPlay();

        /* Get Digit's Animation Parts */
        TablePartsDigit = PartsInformationGet();
        if(null == TablePartsDigit)
        {
            return;
        }
        /* MEMO: When position refresh occurs at animation initialize, refresh is prohibited                  */
        /*        to prevent overwriting position of digits' animation parts set at Update() with refreshing. */
        int countPartsDigit = TablePartsDigit.Length;
        int idParts;
        for(int i=0; i<countPartsDigit; i++)
        {
            idParts = TablePartsDigit[i].IDParts;
            if(0 <= idParts)
            {
                ScriptRoot.RefreshCancelTransform(idParts, true, false, false);
            }
        }

        /* Get Cell Information */
        TableCellCharacter = CellInformationGet();
        if(null == TableCellCharacter)
        {
            return;
        }

        /* Create Additional-Color Parameter */
        /* MEMO: Call "AdditionalColorRelease" when created parameter with "AdditionalColorCreate" are no longer used. */
        AdditionalColor = ScriptRoot.AdditionalColorCreate();

        /* Initialize Complete */
        FlagInitialized = true;
    }
Example #4
0
    void Update()
    {
        int indexAnimation;

        /* Check Validity */
        if (false == FlagInitialized)
        {               /* Failed to initialize */
            return;
        }

        /* Initialize Multi-Track & Connect Parts to Track */
        if (false == FlagInitializedTrack)
        {
            ScriptRoot.AnimationStop(-1);

            /* Initialize Multi-Track */
            /* MEMO: The number of tracks must be equal or more than the number of animations played at the same time.                      */
            /*       In this sample, allocate different animations for "upper body" and "lower body", so two are required at least.         */
            /*                                                                                                                              */
            /*       Also, the reason for creating 4 tracks is because of "Animation Transition".                                           */
            /*       "Animation Transitions" will play 2 animations during the transition so need 2 tracks when use "Animation Transition". */
            /*       In this sample, "upper body" and "lower body" are run separately, so the following 4 tracks are required.              */
            /*       - For playing "upper body"'s animation                                                                                 */
            /*       - For playing "lower body"'s animation                                                                                 */
            /*       - For "upper body"'s animation-transition                                                                              */
            /*       - For "lower body"'s animation-transition                                                                              */
            /*                                                                                                                              */
            /*       "Animation transition" is function to transition between 2 animations while interpolating TRS(Position, Rotation       */
            /*        and Scaling).                                                                                                         */
            /* MEMO: To initialize multi tracks, Seting number of tracks directly from "Script_SpriteStudio6_Root"'s inspector is also OK. */
            /*       In this sample, provide as a way to initialize from a script.                                                         */
            /*       However, not recommended that Increasing or decreasing the number of tracks frequently during appliacation running.   */
            /* MEMO: "TrackReboot" function will not reinstall the track if more than specified number of tracks are already exist. */
            /*       Also, current playing state is preserved.                                                                      */
            if (false == ScriptRoot.TrackReboot((int)KindTrack.TERMINATOR))
            {                   /* Error */
                return;
            }

            /* Connect Parts to Track */
            /* MEMO: You can link(connect) each animation's parts to "Track"s.                             */
            /*       Each "Track"s can play different animations, so you can blend animations as a result. */
            /*       However, can not assign plural tracks to 1 part.                                      */
            if (false == PartsConnectTrack())
            {
                return;
            }

            /* Initialize Animation */
            indexAnimation = TableIndexAnimation[(int)AnimationUpperBody];
            ScriptRoot.AnimationPlay((int)KindTrack.BODY_UPPER, indexAnimation, 0);
            AnimationUpperBodyPrevious = AnimationUpperBody;

            indexAnimation = TableIndexAnimation[(int)AnimationLowerBody];
            ScriptRoot.AnimationPlay((int)KindTrack.BODY_LOWER, indexAnimation, 0);
            AnimationLowerBodyPrevious = AnimationLowerBody;

            FlagInitializedTrack = true;
        }

        /* Adjust values */
        if (0.1f >= TimeAnimationTransition)
        {
            TimeAnimationTransition = 0.1f;
        }

        /* Update Animations */
        if (AnimationLowerBodyPrevious != AnimationLowerBody)
        {
            indexAnimation = TableIndexAnimation[(int)AnimationLowerBody];
            if (0 <= indexAnimation)
            {
                if (true == FlagAnimationTransition)
                {                       /* Transition (Fade) */
                                        /* MEMO: When start transition, you need to play destination animation on track for transition first. */
                    ScriptRoot.AnimationPlay((int)KindTrack.TRANSITION_LOWER, indexAnimation, 0);

                    /* MEMO: Connect transition track to current animation's track after destination animation is successfully played. */
                    /*       Set the transtion track to "indexTrackSlave".                                                             */
                    /* MEMO: Transition ends at set time(TimeAnimationTransition).                                     */
                    /*       At the end of the transition, transition track's playing state will move to master track. */
                    /* MEMO: Transition while animating when current animation or destination animation is not in the pause state. */
                    ScriptRoot.TrackTransition((int)KindTrack.BODY_LOWER,
                                               (int)KindTrack.TRANSITION_LOWER,
                                               TimeAnimationTransition,
                                               false                                                    /* Ignored if destination animation is not in pause state. */
                                               );

                    /* MEMO: If you want timing of transition end, set callback function to "FunctionPlayEndTrack [master track's index]" of ScriptRoot. */
                    ScriptRoot.FunctionPlayEndTrack[(int)KindTrack.BODY_LOWER] = FunctionPlayEndTrackBody;
                }
                else
                {                       /* Immediate */
                    ScriptRoot.AnimationPlay((int)KindTrack.BODY_LOWER, indexAnimation, 0);
                }
            }

            AnimationLowerBodyPrevious = AnimationLowerBody;
        }
        if (AnimationUpperBodyPrevious != AnimationUpperBody)
        {
            indexAnimation = TableIndexAnimation[(int)AnimationUpperBody];
            if (0 <= indexAnimation)
            {
                if (true == FlagAnimationTransition)
                {                       /* Transition (Fade) */
                                        /* MEMO: If you pause animation and make a transition, you can perform transition while stopping the animation. */
                    ScriptRoot.AnimationPlay((int)KindTrack.TRANSITION_UPPER, indexAnimation, 0);

                    ScriptRoot.AnimationPause((int)KindTrack.TRANSITION_UPPER, true);
                    ScriptRoot.AnimationPause((int)KindTrack.BODY_UPPER, true);

                    /* MEMO: Set "flagCancelPauseAfterTransition" to true to automatically unpause animation when transition is complete. */
                    /*       Of course, you can get the timing with transition end callback and cancel pause state by yourself.           */
                    /*       But this way is more easier.                                                                                 */
                    ScriptRoot.TrackTransition((int)KindTrack.BODY_UPPER,
                                               (int)KindTrack.TRANSITION_UPPER,
                                               TimeAnimationTransition,
                                               true
                                               );
                }
                else
                {                       /* Immediate */
                    ScriptRoot.AnimationPlay((int)KindTrack.BODY_UPPER, indexAnimation, 0);
                }
            }

            AnimationUpperBodyPrevious = AnimationUpperBody;
        }
    }