コード例 #1
0
ファイル: PlayerInfo.cs プロジェクト: isoundy000/RiseFree
    //-------------------------------------------------------------------------------------------------------
    protected void updateInfo(bool enable = true)
    {
        if (mPlayer == null)
        {
            return;
        }
        mState = new List <PLAYER_STATE>(mPlayer.getStateMachine().getStateList().Keys);
        mActiveComponentList.Clear();
        Dictionary <string, GameComponent> allComponent = mPlayer.getAllComponent();

        foreach (var item in allComponent)
        {
            if (item.Value.isActive())
            {
                mActiveComponentList.Add(item.Value.getType().ToString());
            }
        }
        mCenterOfMass         = mPlayer.getRigidBody().centerOfMass;
        mSpeed                = mCharacterData.mSpeed;
        mCircle               = mCharacterData.mCircle;
        mCurWayPoint          = mCharacterData.mCurWayPoint;
        mRunDistance          = mCharacterData.mRunDistance;
        mTotalDistance        = mCharacterData.mTotalDistance;
        mProcessKey           = mPlayer.getProcessKey();
        mProcessTurn          = mPlayer.getProcessTurn();
        mProcessExternalSpeed = mPlayer.getProcessExternalSpeed();
        CharacterSpeedHardware hardwareSpeed = mPlayer.getFirstActiveComponent <CharacterSpeedHardware>();

        if (hardwareSpeed != null)
        {
            mTargetSpeed = hardwareSpeed.getTargetSpeed();
        }
        mActivedAnimationStateList.Clear();
        mAllAnimationStateList.Clear();
        if (enable)
        {
            foreach (var item in mAnimation)
            {
                AnimationState state = item as AnimationState;
                string         info  = "|" + state.name + "| |";
                info += (state.enabled ? "enabled" : "disabled") + "| |";
                info += "len:" + StringUtility.floatToString(state.length, 2) + "| |";
                info += "spd:" + StringUtility.floatToString(state.speed, 2) + "| |";
                info += "time:" + StringUtility.floatToString(state.time, 2) + "| |";
                info += "weight:" + StringUtility.floatToString(state.weight, 2) + "| |";
                info += state.wrapMode + "|";
                mAllAnimationStateList.Add(info);
                if (state.enabled)
                {
                    mActivedAnimationStateList.Add(info);
                }
            }
        }
    }
コード例 #2
0
    public override void execute()
    {
        Character character = mReceiver as Character;

        MathUtility.clamp(ref mAngle, 0.0f, 45.0f);
        CommandCharacterChangeSpeed cmdSpeed = newCmd(out cmdSpeed, false);

        cmdSpeed.mSpeed = Mathf.Sin(Mathf.Abs(mAngle * Mathf.Deg2Rad)) * character.getCharacterData().mSpeed;
        pushCommand(cmdSpeed, character);
        // 同时需要降低硬件速度组件中从当前速度加速到目标速度的快慢
        CharacterSpeedHardware speedHardware = character.getFirstComponent <CharacterSpeedHardware>();

        speedHardware.setAcceleration(0.0f);
        if (character.isType(CHARACTER_TYPE.CT_MYSELF))
        {
            GameTools.PLAY_AUDIO_UI(mScriptGlobalAudio.getAudioWindow(), SOUND_DEFINE.SD_HIT_WALL);
        }
    }
コード例 #3
0
    public override void execute()
    {
        Character character = mReceiver as Character;

        if (!character.isType(CHARACTER_TYPE.CT_OTHER))
        {
            return;
        }
        CharacterOther         charOther      = character as CharacterOther;
        CharacterSpeedHardware componentSpeed = character.getFirstActiveComponent <CharacterSpeedHardware>();

        if (componentSpeed != null)
        {
            if (!mExternalSpeed || charOther.getProcessExternalSpeed())
            {
                componentSpeed.setHardwareSpeed(mSpeed, mDirectSpeed);
            }
        }
    }
コード例 #4
0
    public override void execute()
    {
        Character character = mReceiver as Character;

        if (!character.isType(CHARACTER_TYPE.CT_OTHER))
        {
            return;
        }
        CharacterOther other = character as CharacterOther;

        // 玩家有护盾时,攻击没有任何影响
        if (other.hasState(PLAYER_STATE.PS_PROTECTED))
        {
            return;
        }
        if (mAttackSource == SCENE_ITEM.SI_LAND_MINE || mAttackSource == SCENE_ITEM.SI_MISSILE)
        {
            // 进入被攻击状态
            CommandCharacterAddState cmdState = newCmd(out cmdState);
            cmdState.mState = PLAYER_STATE.PS_ATTACKED;
            pushCommand(cmdState, other);
            // 设置角色的速度,当角色速度小于3km/h时,则不变,否则速度设置为3km/h
            CommandCharacterChangeSpeed cmd = newCmd(out cmd, false);
            cmd.mSpeed = Mathf.Min(MathUtility.KMHtoMS(3.0f), other.getCharacterData().mSpeed);
            pushCommand(cmd, other);
            // 播放摔倒动作
            Animation animation = other.getAnimation();
            animation.CrossFade(GameDefine.ANIM_FALL_DOWN);
            // 当速度为0时,摔到后为站立状态,否则开始骑行
            if (other.getCharacterData().mSpeed <= 0.01f)
            {
                animation.CrossFadeQueued(GameDefine.ANIM_STANDING);
            }
            else
            {
                animation.CrossFadeQueued(GameDefine.ANIM_RIDE);
            }
            // 同时需要降低硬件速度组件中从当前速度加速到目标速度的快慢
            CharacterSpeedHardware speedHardware = other.getFirstComponent <CharacterSpeedHardware>();
            speedHardware.setAcceleration(0.0f);
        }
    }
コード例 #5
0
    public override void enter(StateParam param)
    {
        mTurbo      = mObjectManager.createObject(mPlayer.getObject(), GameDefine.R_PARTICLE_PREFAB_PATH + GameDefine.TURBO);
        mTurbo.name = "Turbo";
        mTurbo.transform.localPosition = new Vector3(0.5f, -3.0f, 2.0f);
        float speed = mPlayer.getCharacterData().mSpeed;
        CommandCharacterHardwareSpeed cmd = newCmd(out cmd);

        cmd.mSpeed         = speed + GameUtility.getSprintIncreaseSpeed(speed);
        cmd.mExternalSpeed = false;
        pushCommand(cmd, mPlayer);
        // 提升加速度,加速度会自动恢复到正常值
        CharacterSpeedHardware component = mPlayer.getFirstComponent <CharacterSpeedHardware>();

        component.setAcceleration(50.0f);
        if (mPlayer.isType(CHARACTER_TYPE.CT_MYSELF))
        {
            GameTools.PLAY_AUDIO_UI(mScriptGlobalAudio.getAudioWindow(), SOUND_DEFINE.SD_SPRINT);
        }
    }
コード例 #6
0
    public override void update(float elapsedTime)
    {
        base.update(elapsedTime);
        int   targetIndex     = mWayPointManager.getPointIndexFromDistance(mData.mRunDistance + mTargetDistanceOffset, mData.mCurWayPoint);
        float targetDirection = mWayPointManager.getPointDirection(targetIndex);
        // 自身的朝向往目标点所在路段的朝向靠拢
        float curDirection = mCharacter.getRotation().y;

        MathUtility.adjustAngle180(ref curDirection);
        float dirDelta = targetDirection - curDirection;

        // 如果目标方向与当前方向的差值超过180,则转换到0-360再计算
        if (Mathf.Abs(dirDelta) > 180.0f)
        {
            MathUtility.adjustAngle360(ref curDirection);
            MathUtility.adjustAngle360(ref targetDirection);
            dirDelta = targetDirection - curDirection;
        }
        mData.mTurnAngle = MathUtility.lerp(mData.mTurnAngle, dirDelta, 0.1f);
        float curTargetSpeed = mAIBaseSpeed + mData.mNumber;
        CharacterSpeedHardware speedHardware = mCharacter.getFirstComponent <CharacterSpeedHardware>();

        if (!MathUtility.isFloatEqual(speedHardware.getTargetSpeed(), curTargetSpeed) && mCharacter.getProcessExternalSpeed())
        {
            CommandCharacterHardwareSpeed cmd = newCmd(out cmd);
            cmd.mSpeed         = curTargetSpeed;
            cmd.mExternalSpeed = true;
            pushCommand(cmd, mCharacter);
        }
        // 如果AI背包中有导弹,则一直搜寻可以瞄准的目标
        int missileIndex = mCharacter.getPlayerPack().getFirstItemIndex(PLAYER_ITEM.PI_MISSILE);

        if (missileIndex != -1 && !mCharacter.hasState(PLAYER_STATE.PS_AIM))
        {
            bool hasAvailableTarget = false;
            SortedDictionary <int, CharacterOther> allCharacterList = mRoleSystem.getAllPlayer();
            float playerDistance = mCharacter.getCharacterData().mRunDistance;
            foreach (var item in allCharacterList)
            {
                if (item.Value != mCharacter)
                {
                    float curDistance = item.Value.getCharacterData().mRunDistance - playerDistance;
                    if (MathUtility.isInRange(curDistance, 0.0f, GameDefine.MAX_LAUNCH_MISSILE_DISTANCE))
                    {
                        if (UnityUtility.whetherGameObjectInScreen(item.Value.getWorldPosition()))
                        {
                            hasAvailableTarget = true;
                            break;
                        }
                    }
                }
            }
            if (hasAvailableTarget)
            {
                // 需要选中导弹
                CommandCharacterSelectItem cmdSelect = newCmd(out cmdSelect);
                cmdSelect.mIndex = missileIndex;
                pushCommand(cmdSelect, mCharacter);
                // 给角色添加瞄准状态
                CommandCharacterAddState cmdCharacterAddState = newCmd(out cmdCharacterAddState);
                cmdCharacterAddState.mState = PLAYER_STATE.PS_AIM;
                pushCommand(cmdCharacterAddState, mCharacter);
            }
        }
    }