Esempio n. 1
0
        public static PostureState CreateDiveState()
        {
            PostureState state = new DiveState(PostureStateId.Dive);

            #region dive to swim


            state.AddTransition(new DiveTransition(
                                    state.AvailableTransitionId(),
                                    (int)PostureStateId.Swim,
                                    SingletonManager.Get <CharacterStateConfigManager>().GetPostureTransitionTime(PostureInConfig.Dive, PostureInConfig.Swim),
                                    AnimatorParametersHash.Instance.SwimStateDiveValue,
                                    AnimatorParametersHash.Instance.SwimStateSwimValue,
                                    FsmInput.Swim),
                                new[] { FsmInput.Swim });

            #endregion

            #region dive to stand

            AddTransitionFromWaterToStand(state);

            #endregion

            return(state);
        }
Esempio n. 2
0
 void OnChangedStage(BattleGroup b)
 {
     diveState = DiveState.Finish;
     if (coDive != null)
     {
         StopCoroutine(coDive);
         coDive = null;
     }
 }
Esempio n. 3
0
 public DiveSegment(double depth, TimeSpan time, DiveState state, int startTime, int endTime, Gas gas, double cns,
     double otu)
 {
     Depth = depth;
     Time = time;
     State = state;
     StartTime = startTime;
     EndTime = endTime;
     CurrentGas = gas;
     Otu = otu;
     Cns = cns;
 }
Esempio n. 4
0
    void OnOwnerDie(BattleUnit unit)
    {
        //battleHero.skeletonAnimation.transform.localPosition = originalSkeletonPos;
        battleHero.skeletonAnimation.transform.localEulerAngles = Vector3.zero;

        diveState = DiveState.Finish;

        if (coDive != null)
        {
            StopAllCoroutines();
            coDive = null;
        }
    }
Esempio n. 5
0
    void OnRestartedBattle(BattleGroup b)
    {
        if (battleHero)
        {
            battleHero.skeletonAnimation.transform.localPosition = originalSkeletonPos;
        }

        diveState = DiveState.Finish;
        if (coDive != null)
        {
            StopAllCoroutines();
            coDive = null;
        }
    }
Esempio n. 6
0
    void OnEnable()
    {
        if (battleHero)
        {
            battleHero.skeletonAnimation.transform.localPosition = originalSkeletonPos;
        }

        diveState = DiveState.Finish;
        if (coDive != null)
        {
            StopCoroutine(coDive);
            coDive = null;
        }
    }
Esempio n. 7
0
    /// <summary>
    /// Larger than 1.0f: Fully in water
    /// 0.0f - 1.0f: half in water
    /// Less than 0.0f: On land (full gravity)
    /// </summary>
    /// <param name="ratio"></param>
    public void submergeAmount(float ratio)
    {
        if (ratio < 0.0f)
        {
            diveState = DiveState.onLand;
        }
        else if (ratio < 1.0f)
        {
            if (diveState == DiveState.fullyInWater)
            {
                OnSurface.Invoke();
            }
            diveState = DiveState.halfInWater;
        }
        else
        {
            if (diveState != DiveState.fullyInWater)
            {
                OnFullySubmerge.Invoke();
            }
            diveState = DiveState.fullyInWater;
        }
        RB.gravityScale = Mathf.Lerp(1.0f, gravityWater, ratio);
        RB.drag         = Mathf.Lerp(dragAir, dragWater, ratio);

        // Calculate bubble effect
        if (bubbleSystem != null)
        {
            ParticleSystem.EmissionModule emission = bubbleSystem.emission;
            emission.rateOverTime = baseBubbleRate;

            if (diveState == DiveState.halfInWater)
            {
                float submergeDelta = ratio - prevSubmergeRatio;
                if (submergeDelta > 0.0f)
                {
                    emission.rateOverTime = baseBubbleRate + submergeDelta * 5000;
                }

                prevSubmergeRatio = ratio;
            }
        }
    }
Esempio n. 8
0
    /// <summary>
    /// Start the turtles diving under water
    /// </summary>
    /// <param name="isDiving"></param>
    private void ToggleDive(bool isDiving)
    {
        _diveState = isDiving ? DiveState.Diving : DiveState.Surfacing;
        //Debug.Log($"ToggleDive(isDiving: {isDiving}");
        foreach (Transform child in transform)
        {
            var obj = child.gameObject;
            if (obj.name == "Player")
            {
                // Kick player off turtle
                Debug.Log("Kick player off turtle when it dives");
                obj.gameObject.GetComponent <PlayerRideable>()?.RemovePlayerFromRideable();

                // Player should check water collision again
                obj.gameObject.GetComponent <PlayerDrownable>()?.WaterContactTrigger();
                continue;
            }

            var animator = obj.GetComponent <Animator>();
            animator.SetInteger("DiveState", (int)_diveState); // Should be 1 or 3
        }
    }
Esempio n. 9
0
    IEnumerator Dive()
    {
        diveState = DiveState.MoveToDest;

        //battleHero.skeletonAnimation.transform.localPosition = originalSkeletonPos;

        Vector3 startPos = battleHero.transform.position;

        bool isFlipPreCheck = false;

        if (castTarget == null)
        {
            isFlipPreCheck = battleHero.transform.position.x > backPoint.x;
        }
        else
        {
            isFlipPreCheck = battleHero.transform.position.x > castTarget.transform.position.x;
        }

        //x축 이동은 캐릭터 통채로

        float destPosOffsetX = skillSettingDive.destPosOffset.x;

        if (isFlipPreCheck)
        {
            destPosOffsetX *= -1f;
        }

        Vector2 destPos;

        if (castTarget == null)
        {
            destPos = backPoint;
        }
        else
        {
            destPos = (Vector2)castTarget.transform.position + Vector2.right * destPosOffsetX;
        }

        destPos = new Vector2(Mathf.Clamp(destPos.x, owner.battleGroup.spwonPointXMin + 5f, owner.battleGroup.spwonPointXMax - 5f)
                              , Mathf.Clamp(destPos.y, owner.battleGroup.spwonPointYMin, owner.battleGroup.spwonPointYMax));

        float distance = Vector2.Distance(battleHero.skeletonAnimation.transform.position, destPos);


        /*float */ animValue = 0f;
        //float distance = castTarget.GetDistanceFrom(battleHero);
        float velocity = skillSettingDive.startSpeed;
        float goalTime = distance / velocity;//  (distance / 4f);

        if (goalTime < skillSettingDive.minDiveTime)
        {
            goalTime = skillSettingDive.minDiveTime;
        }

        float finishTime = goalTime + skillSettingDive.finishAnimStartOffset;


        //destPos = skillData.canCastToAir && castTarget.collider ? castTarget.collider.transform.position : castTarget.transform.position;
        //destPos = new Vector3(Mathf.Clamp(destPos.x, owner.battleGroup.xMin, owner.battleGroup.xMax), destPos.y, destPos.z);

        float startPosY = battleHero.skeletonAnimation.transform.localPosition.y;

        bool triggeredOnDive    = false;
        bool changeIdleAtFinish = true;

        if (skillData.effectType == "Trail")
        {
            owner.GetComponentInChildren <EffectTrail>().DrawTrail(true);
        }
        //강습 시작
        float deltaTime = 0f;
        float lastTime  = Time.time;
        float startTime = Time.time;

        while (animValue < 1f)
        {
            //if (!castTarget)
            //{
            //    changeIdleAtFinish = true;
            //    break;
            //}

            if (owner.isBlockMove || owner.isBlockAttack)
            {
                break;
            }

            deltaTime = Time.time - lastTime;
            float elapsedTime = Time.time - startTime;

            velocity = Mathf.Max(velocity + skillSettingDive.acc * deltaTime, 0.01f);

            //destPos = (Vector2)castTarget.skeletonAnimation.transform.position + Vector2.right * destPosOffsetX;
            //destPos = new Vector2(Mathf.Clamp(destPos.x, owner.battleGroup.xMin + 5f, owner.battleGroup.xMax - 5f), destPos.y);

            //distance = Vector3.Distance(battleHero.collider.transform.position, destPos + (Vector2)skillSettingDive.destPosOffset);//  castTarget.GetDistanceFrom(battleHero);
            distance = Vector2.Distance(battleHero.skeletonAnimation.transform.position, destPos);
            //goalTime = (distance / velocity);
            //if (goalTime < skillSettingDive.minDiveTime)
            //    goalTime = skillSettingDive.minDiveTime;

            finishTime = goalTime + skillSettingDive.finishAnimStartOffset;

            //animValue = elapsedTime / goalTime;

            if (goalTime <= 0f)
            {
                animValue = 1f;
            }
            else
            {
                animValue = elapsedTime / goalTime;
                //animValue += deltaTime / goalTime;
            }

            //목표 지점이 왼쪽에 있으면 몸 뒤집기
            if (skeletonAnimation.AnimationName == skillSettingDive.animationName)
            {
                isFlip           = battleHero.transform.position.x > destPos.x;
                battleHero.flipX = isFlip;
            }

            //y축 이동 + y축 커브 보정
            float   offsetY       = skillSettingDive.curveStartY.Evaluate(animValue);
            Vector3 skeletonPos   = battleHero.skeletonAnimation.transform.localPosition;
            float   destLocalPosY = 0f;

            if (castTarget != null)
            {
                destLocalPosY = skillData.canCastToAir && castTarget ? castTarget.skeletonAnimation.transform.localPosition.y : 0f;
            }

            //if (castTarget.collider)
            //    destLocalPosY += castTarget.collider.transform.localPosition.y;
            float y = Mathf.Lerp(/*skeletonPos.y*/ startPosY, destLocalPosY + skillSettingDive.destPosOffset.y, animValue);
            y = y + offsetY;

            battleHero.skeletonAnimation.transform.localPosition = Vector3.up * y;

            float x = skillSettingDive.curveStartX.Evaluate(animValue);
            if (isFlipPreCheck)
            {
                x *= -1f;
            }

            //Vector3 pos = Vector3.Lerp(battleHero.transform.position, destPos, animValue);
            Vector3 pos = Vector3.Lerp(startPos, destPos, animValue);
            pos = new Vector3(pos.x + x, pos.y, pos.z);

            //battleHero.flipX = castTarget.transform.position.x < transform.position.x;

            if (elapsedTime > finishTime)
            {
                if (skeletonAnimation.AnimationName != skillSettingDive.animationFinish)
                {
                    if (!string.IsNullOrEmpty(skillSettingDive.animationFinish))
                    {
                        skillSettingDive.animationName = skillSettingDive.animationFinish;
                        skeletonAnimation.state.SetAnimation(0, skillSettingDive.animationFinish, false);

                        changeIdleAtFinish = false;
                    }
                }

                // 목표 지점 도달 event 발생
                if (triggeredOnDive == false && skillEffectDic.ContainsKey("OnDive"))
                {
                    triggeredOnDive = true;
                    //if(castTarget)
                    //    battleHero.flipX = castTarget.transform.position.x < transform.position.x;

                    List <ISkillEffect> skillEventList = skillEffectDic["OnDive"];
                    for (int i = 0; i < skillEventList.Count; i++)
                    {
                        skillEventList[i].TriggerEffect();
                    }

                    changeIdleAtFinish = false;
                }
            }

            battleHero.transform.position = pos;


            lastTime = Time.time;
            yield return(null);
        }


        //위치 정확하게 리셋
        //battleHero.skeletonAnimation.transform.localPosition = originalSkeletonPos;
        //battleHero.skeletonAnimation.transform.localEulerAngles = Vector3.zero;

        //skeletonAnimation.AnimationState.ClearTrack(0);
        while (skeletonAnimation.AnimationName == skillSettingDive.animationFinish)
        {
            yield return(null);
        }

        // 목표 지점 도달 event 발생
        if (changeIdleAtFinish)
        {
            skeletonAnimation.AnimationState.SetAnimation(0, battleHero.idleAnimation, true);
        }

        if (skillSettingDive.backOriginalPos)
        {
            transform.position = startPos;
        }

        diveState = DiveState.Finish;
        coDive    = null;
    }
Esempio n. 10
0
 public void SetDiveState(DiveState diveState)
 {
     _diveState = diveState;
 }
Esempio n. 11
0
    public void SetDiveState(DiveState diveState)
    {
        var obj = transform.parent.gameObject;

        obj.GetComponent <TurtleDive>().SetDiveState(diveState);
    }