Esempio n. 1
0
    public void Show(float PosDelay, float RotationDelay, float ScaleDelay)
    {
#if USE_DOTWEEN    // use DOTween: https://www.assetstore.unity3d.com/en/#!/content/27676 Documentation: http://dotween.demigiant.com/documentation.php
#elif USE_HOTWEEN  // use HOTween: https://www.assetstore.unity3d.com/#/content/3311 Documentation:  http://hotween.demigiant.com/documentation.html
                   // tween position
        m_PosValue = 0;
        HOTween.To(this, m_PosDuration, new TweenParms()
                   .Prop("m_PosValue", 1.0f, false)
                   .Delay(PosDelay)
                   .Ease(EaseType.EaseOutElastic)
                   .OnStart(UpdateTransformPos_Start)
                   .OnUpdate(UpdateTransformPos_Transforming)
                   .OnStepComplete(UpdateTransformPos_Finished)
                   );

        // tween rotation
        m_RotationValue = 0;
        if (m_RotationType == FCProp.eRotationType.Endless)
        {
            FCGameObjectUtil pFCGameObjectUtil = m_PropGameObject.AddComponent <FCGameObjectUtil>();
            pFCGameObjectUtil.InitRotation(m_Rotation);
        }
        else if (m_RotationType == FCProp.eRotationType.LimitedRound)
        {
            HOTween.To(this, m_RotationDurationPerRound * m_MaxRotationRound, new TweenParms()
                       .Prop("m_RotationValue", (float)m_MaxRotationRound, false)
                       .Delay(RotationDelay)
                       .Ease(EaseType.EaseInOutQuad)
                       .OnStart(UpdateRotation_Start)
                       .OnUpdate(UpdateRotation_Transforming)
                       .OnStepComplete(UpdateRotation_Finished)
                       );
        }

        // tween scale
        if (m_ScaleType == eScaleType.Enable)
        {
            HOTween.To(this, m_ScaleDuration, new TweenParms()
                       .Prop("m_ScaleValue", 1.0f, false)
                       .Delay(ScaleDelay)
                       .Ease(EaseType.EaseOutElastic)
                       .OnStart(UpdateScale_Start)
                       .OnUpdate(UpdateScale_Transforming)
                       .OnStepComplete(UpdateScale_Finished)
                       );
        }
#elif USE_LEANTWEEN // use LeanTween: https://www.assetstore.unity3d.com/#/content/3595 Documentation: http://dentedpixel.com/LeanTweenDocumentation/classes/LeanTween.html
        // tween position
//UpdateTransformPos_Start();
        LeanTween.value(m_PropGameObject, UpdateTransformPos_TransformingWithValue, 0.0f, 1.0f, m_PosDuration)
        .setDelay(PosDelay)
        .setEase(LeanTweenType.easeOutElastic)
        .setOnComplete(UpdateTransformPos_Finished);

        // tween rotation
        if (m_RotationType == FCProp.eRotationType.Endless)
        {
            FCGameObjectUtil pFCGameObjectUtil = m_PropGameObject.AddComponent <FCGameObjectUtil>();
            pFCGameObjectUtil.InitRotation(m_Rotation);
        }
        else if (m_RotationType == FCProp.eRotationType.LimitedRound)
        {
            //UpdateRotation_Start();
            LeanTween.value(m_PropGameObject, UpdateRotation_TransformingWithValue, 0.0f, (float)m_MaxRotationRound, m_RotationDurationPerRound * m_MaxRotationRound)
            .setDelay(RotationDelay)
            .setEase(LeanTweenType.easeInOutQuad)
            .setOnComplete(UpdateRotation_Finished);
        }

        // tween scale
        if (m_ScaleType == eScaleType.Enable)
        {
            //UpdateScale_Start();
            LeanTween.value(m_PropGameObject, UpdateScale_TransformingWithValue, 0.0f, 1.0f, m_ScaleDuration)
            .setDelay(ScaleDelay)
            .setEase(LeanTweenType.easeOutElastic)
            .setOnComplete(UpdateScale_Finished);
        }
#else // use iTween: https://www.assetstore.unity3d.com/#/content/84 Documentation: http://itween.pixelplacement.com/documentation.php
        // tween position
        iTween.ValueTo(m_PropGameObject, iTween.Hash("from", 0, "to", 1,
                                                     "time", m_PosDuration,
                                                     "delay", PosDelay,
                                                     "easeType", FCEaseType.EaseTypeConvert(m_PosEaseType),
                                                     "onstart", "UpdateTransformPos_Start",
                                                     "onupdate", "UpdateTransformPos_TransformingWithValue",
                                                     "onupdatetarget", this.gameObject,
                                                     "oncomplete", "UpdateTransformPos_Finished"));

        // tween rotation
        if (m_RotationType == FCProp.eRotationType.Endless)
        {
            FCGameObjectUtil pFCGameObjectUtil = m_PropGameObject.AddComponent <FCGameObjectUtil>();
            pFCGameObjectUtil.InitRotation(m_Rotation);
            pFCGameObjectUtil.StartRotation();
        }
        else if (m_RotationType == FCProp.eRotationType.LimitedRound)
        {
            iTween.ValueTo(m_PropGameObject, iTween.Hash("from", 0, "to", m_MaxRotationRound,
                                                         "time", m_RotationDurationPerRound * m_MaxRotationRound,
                                                         "delay", RotationDelay,
                                                         "easeType", FCEaseType.EaseTypeConvert(m_RotationEaseType),
                                                         "onstart", "UpdateRotation_Start",
                                                         "onupdate", "UpdateRotation_TransformingWithValue",
                                                         "onupdatetarget", this.gameObject,
                                                         "oncomplete", "UpdateRotation_Finished"));
        }

        // tween scale
        if (m_ScaleType == eScaleType.Enable)
        {
            iTween.ValueTo(m_PropGameObject, iTween.Hash("from", 0, "to", 1,
                                                         "time", m_ScaleDuration,
                                                         "delay", ScaleDelay,
                                                         "easeType", FCEaseType.EaseTypeConvert(m_ScaleEaseType),
                                                         "onstart", "UpdateScale_Start",
                                                         "onupdate", "UpdateScale_TransformingWithValue",
                                                         "onupdatetarget", this.gameObject,
                                                         "oncomplete", "UpdateScale_Finished"));
        }
#endif
    }
Esempio n. 2
0
    // ########################################
    // Close Lid Functions
    // ########################################

    #region Close Lid Functions

    // Lid is Closed
    void Update_LidStateIsChanged_Close()
    {
        m_OpenValue    = 1;
        m_LidStatusOld = m_LidStatus;

        m_ChangingState = true;

        // Display Open/Close status on Console
        //Debug.Log(this.name + ": Closed");

#if USE_DOTWEEN      // use DOTween: https://www.assetstore.unity3d.com/en/#!/content/27676 Documentation: http://dotween.demigiant.com/documentation.php
#elif USE_HOTWEEN    // use HOTween: https://www.assetstore.unity3d.com/#/content/3311 Documentation:  http://hotween.demigiant.com/documentation.html
        HOTween.To(this, m_CloseDuration, new TweenParms()
                   .Prop("m_OpenValue", 0.0f, false)
                   .Delay(0)
                   .Ease(FCEaseType.EaseTypeConvert(m_CloseEaseType))
                   .OnUpdate(OpenLid)
                   .OnStepComplete(Update_LidIsOpeningOrClosing_Closing_Finished)
                   );
#elif USE_LEANTWEEN // use LeanTween: https://www.assetstore.unity3d.com/#/content/3595 Documentation: http://dentedpixel.com/LeanTweenDocumentation/classes/LeanTween.html
        LeanTween.value(this.gameObject, OpenLidByValue, 1.0f, 0.0f, m_CloseDuration)
        .setDelay(0.0f)
        .setEase(FCEaseType.EaseTypeConvert(m_CloseEaseType))
        .setOnComplete(Update_LidIsOpeningOrClosing_Closing_Finished);
#else // use iTween: https://www.assetstore.unity3d.com/#/content/84 Documentation: http://itween.pixelplacement.com/documentation.php
        iTween.ValueTo(this.gameObject, iTween.Hash("from", 1.0f, "to", 0.0f,
                                                    "time", m_CloseDuration,
                                                    "delay", 0,
                                                    "easeType", FCEaseType.EaseTypeConvert(m_CloseEaseType),
                                                    "onupdate", "OpenLidByValue",
                                                    "onupdatetarget", this.gameObject,
                                                    "oncomplete", "Update_LidIsOpeningOrClosing_Closing_Finished"));
#endif

        if (m_Main.getProp() != null)
        {
            if (m_Main.getProp().enabled == true)
            {
                if (m_Main.getProp().getPrefab() != null)
                {
                    // Make Prop to a none-parent object
                    m_Main.getProp().getPropGameObject().transform.parent = null;

                    if (m_Main.getProp().isShowing() == false)
                    {
                        // Stop Prop
                        if (m_Main.getProp() != null)
                        {
                            if (m_Main.getProp().m_RemovedWhenChestClose == true)
                            {
                                m_Main.getProp().Remove();
                            }
                        }

                        // Stop Prop particle
                        if (m_Main.getPropParticle() != null)
                        {
                            if (m_Main.getPropParticle().m_RemovedWhenChestClose == true)
                            {
                                RemovePropParticle();
                            }
                        }
                    }
                    else
                    {
                        m_LidStatus = m_LidStatusOld;
                    }
                }
            }
        }

        // Create Chest particle
        if (m_Main.getChestParticle() != null)
        {
            if (m_Main.getChestParticle().m_CreateWhenChestClose == true)
            {
                CreateChestParticle();
            }
        }

        // Play Bounce animation
        PlayChestCloseBounceAnimation();

        // Play Close sound
        if (m_Main.getSound() != null)
        {
            if (m_Main.getSound().enabled == true)
            {
                // Play Close sound
                m_Main.getSound().PlaySoundClose();

                // Play Lock sound if Chest is locked
                if (m_LockStatus == eLockStatus.Locked)
                {
                    m_Main.getSound().PlaySoundSetLock();
                }
            }
        }
    }
Esempio n. 3
0
    // Play bounce animation for closing
    void PlayChestCloseBounceAnimation()
    {
        if (m_Main.m_Elastic == true)
        {
            float BounceCount  = 1;
            float durationStep = m_Main.m_BounceDuration / ((BounceCount * 2 * 2) + 1);
            float duration     = durationStep;
            float delay        = 0;
            if (m_Lid != null)
            {
                delay = m_CloseDuration;
            }
            float BounceForce = m_Main.m_BounceForce / 2;

#if USE_DOTWEEN    // use DOTween: https://www.assetstore.unity3d.com/en/#!/content/27676 Documentation: http://dotween.demigiant.com/documentation.php
#elif USE_HOTWEEN  // use HOTween: https://www.assetstore.unity3d.com/#/content/3311 Documentation:  http://hotween.demigiant.com/documentation.html
            HOTween.To(this.gameObject.transform, duration, new TweenParms()
                       .Prop("localScale", new Vector3(m_Main.m_Scale.x + BounceForce, m_Main.m_Scale.y - BounceForce, m_Main.m_Scale.z + BounceForce), false)
                       .Ease(EaseType.EaseInOutSine)
                       .Delay(delay)
                       );
            delay += duration;

            for (int i = 0; i < BounceCount; i++)
            {
                HOTween.To(this.gameObject.transform, duration, new TweenParms()
                           .Prop("localScale", new Vector3(m_Main.m_Scale.x - BounceForce, m_Main.m_Scale.y + BounceForce, m_Main.m_Scale.z - BounceForce), false)
                           .Ease(EaseType.EaseInOutSine)
                           .Delay(delay)
                           );
                delay += duration;

                HOTween.To(this.gameObject.transform, duration, new TweenParms()
                           .Prop("localScale", new Vector3(m_Main.m_Scale.x + BounceForce, m_Main.m_Scale.y - BounceForce, m_Main.m_Scale.z + BounceForce), false)
                           .Ease(EaseType.EaseInOutSine)
                           .Delay(delay)
                           );
                delay += duration;

                duration   += durationStep;
                BounceForce = BounceForce / 3;
            }

            HOTween.To(this.gameObject.transform, duration, new TweenParms()
                       .Prop("localScale", new Vector3(m_Main.m_Scale.x, m_Main.m_Scale.y, m_Main.m_Scale.z), false)
                       .Ease(EaseType.EaseInOutSine)
                       .Delay(delay)
                       );
            delay += duration;
#elif USE_LEANTWEEN // use LeanTween: https://www.assetstore.unity3d.com/#/content/3595 Documentation: http://dentedpixel.com/LeanTweenDocumentation/classes/LeanTween.html
            LeanTween.scale(this.gameObject, new Vector3(m_Main.m_Scale.x + BounceForce, m_Main.m_Scale.y - BounceForce, m_Main.m_Scale.z + BounceForce), duration)
            .setDelay(delay)
            .setEase(LeanTweenType.easeInOutBounce);
            delay += duration;

            for (int i = 0; i < BounceCount; i++)
            {
                LeanTween.scale(this.gameObject, new Vector3(m_Main.m_Scale.x - BounceForce, m_Main.m_Scale.y + BounceForce, m_Main.m_Scale.z - BounceForce), duration)
                .setDelay(delay)
                .setEase(LeanTweenType.easeInOutBounce);
                delay += duration;

                LeanTween.scale(this.gameObject, new Vector3(m_Main.m_Scale.x + BounceForce, m_Main.m_Scale.y - BounceForce, m_Main.m_Scale.z + BounceForce), duration)
                .setDelay(delay)
                .setEase(LeanTweenType.easeInOutBounce);
                delay += duration;

                duration   += durationStep;
                BounceForce = BounceForce / 3;
            }

            LeanTween.scale(this.gameObject, new Vector3(m_Main.m_Scale.x, m_Main.m_Scale.y, m_Main.m_Scale.z), duration)
            .setDelay(delay)
            .setEase(LeanTweenType.easeInOutBounce);
            delay += duration;
#else // use iTween: https://www.assetstore.unity3d.com/#/content/84 Documentation: http://itween.pixelplacement.com/documentation.php
            iTween.ScaleTo(this.gameObject, iTween.Hash("scale", new Vector3(m_Main.m_Scale.x + BounceForce, m_Main.m_Scale.y - BounceForce, m_Main.m_Scale.z + BounceForce),
                                                        "time", duration, "delay", delay + 0.05f,
                                                        "easetype", FCEaseType.EaseTypeConvert(FCEaseType.eEaseType.spring)));
            delay += duration + 0.05f;

            for (int i = 0; i < BounceCount; i++)
            {
                iTween.ScaleTo(this.gameObject, iTween.Hash("scale", new Vector3(m_Main.m_Scale.x - BounceForce, m_Main.m_Scale.y + BounceForce, m_Main.m_Scale.z - BounceForce),
                                                            "time", duration, "delay", delay,
                                                            "easetype", FCEaseType.EaseTypeConvert(FCEaseType.eEaseType.spring)));
                delay += duration;

                iTween.ScaleTo(this.gameObject, iTween.Hash("scale", new Vector3(m_Main.m_Scale.x + BounceForce, m_Main.m_Scale.y - BounceForce, m_Main.m_Scale.z + BounceForce),
                                                            "time", duration, "delay", delay,
                                                            "easetype", FCEaseType.EaseTypeConvert(FCEaseType.eEaseType.spring)));
                delay += duration;

                duration   += durationStep;
                BounceForce = BounceForce / 3;
            }

            iTween.ScaleTo(this.gameObject, iTween.Hash("scale", new Vector3(m_Main.m_Scale.x, m_Main.m_Scale.y, m_Main.m_Scale.z),
                                                        "time", duration, "delay", delay,
                                                        "easetype", FCEaseType.EaseTypeConvert(FCEaseType.eEaseType.spring)));
#endif
        }
    }
Esempio n. 4
0
    // Lid is Opened
    void Update_LidStateIsChanged_Open()
    {
        // Open failed when Chest is locked
        if (m_LockStatus == eLockStatus.Locked)
        {
            // Set m_LidStatus to close
            m_LidStatus    = eState.Close;
            m_LidStatusOld = m_LidStatus;

            // Set m_ChangingState to false
            m_ChangingState = false;

            //Debug.Log(this.name + ": Open failed");

            // Play Bounce animation
            PlayChestOpenFailedBounceAnimation(m_Main.m_BounceForce / 2);

            // Play Open Failed sound
            if (m_Main.getSound() != null)
            {
                if (m_Main.getSound().enabled == true)
                {
                    m_Main.getSound().PlaySoundOpenFailed();
                }
            }
        }
        // Open succeed when Chest is unlocked
        else
        {
            m_OpenValue    = 0;
            m_LidStatusOld = m_LidStatus;

            // Set m_ChangingState to true
            m_ChangingState = true;

            // Display Open/Close status on Console
            //Debug.Log(this.name + ": Opened");

#if USE_DOTWEEN      // use DOTween: https://www.assetstore.unity3d.com/en/#!/content/27676 Documentation: http://dotween.demigiant.com/documentation.php
#elif USE_HOTWEEN    // use HOTween: https://www.assetstore.unity3d.com/#/content/3311 Documentation:  http://hotween.demigiant.com/documentation.html
            HOTween.To(this, m_OpenDuration, new TweenParms()
                       .Prop("m_OpenValue", 1.0f, false)
                       .Delay(0)
                       .Ease(FCEaseType.EaseTypeConvert(m_OpenEaseType))
                       .OnUpdate(OpenLid)
                       .OnStepComplete(Update_LidIsOpeningOrClosing_Opening_Finished)
                       );
#elif USE_LEANTWEEN // use LeanTween: https://www.assetstore.unity3d.com/#/content/3595 Documentation: http://dentedpixel.com/LeanTweenDocumentation/classes/LeanTween.html
            LeanTween.value(this.gameObject, OpenLidByValue, 0.0f, 1.0f, m_OpenDuration)
            .setDelay(0.0f)
            .setEase(FCEaseType.EaseTypeConvert(m_OpenEaseType))
            .setOnComplete(Update_LidIsOpeningOrClosing_Opening_Finished);
#else // use iTween: https://www.assetstore.unity3d.com/#/content/84 Documentation: http://itween.pixelplacement.com/documentation.php
            iTween.ValueTo(this.gameObject, iTween.Hash("from", 0.0f, "to", 1.0f,
                                                        "time", m_OpenDuration,
                                                        "delay", 0,
                                                        "easeType", FCEaseType.EaseTypeConvert(m_OpenEaseType),
                                                        "onupdate", "OpenLidByValue",
                                                        "onupdatetarget", this.gameObject,
                                                        "oncomplete", "Update_LidIsOpeningOrClosing_Opening_Finished"));
#endif

            // Play Bounce animation
            PlayChestOpenBounceAnimation();

            // Create Prop and Particles
            if (m_Main.getProp() != null)
            {
                if (m_Main.getProp().enabled == true)
                {
                    if (m_Main.getProp().getPrefab() != null)
                    {
                        if (m_Main.getProp().isShowing() == false)
                        {
                            // Create Prop
                            if (m_Main.getProp() != null)
                            {
                                m_Main.getProp().CreateProp();
                            }

                            // Create Prop particle
                            if (m_Main.getPropParticle() != null)
                            {
                                if (m_Main.getPropParticle().m_CreateWhenChestOpen == true)
                                {
                                    CreatePropParticle();
                                }
                            }

                            // Show Prop
                            if (m_Main.getProp() != null)
                            {
                                m_Main.getProp().Show();
                            }
                        }
                        else
                        {
                            m_LidStatus = m_LidStatusOld;
                        }
                    }
                }
            }

            // Stop Chest particle
            if (m_Main.getChestParticle() != null)
            {
                if (m_Main.getChestParticle().m_RemoveWhenChestOpen == true)
                {
                    RemoveChestParticle();
                }
            }

            // Play Open sound and Prop sound even there is no Prop
            if (m_Main.getSound() != null)
            {
                if (m_Main.getSound().enabled == true)
                {
                    m_Main.getSound().PlaySoundOpen();
                    m_Main.getSound().PlaySoundProp();
                }
            }
        }
    }