Ejemplo n.º 1
0
    //-------------------------------------------------------------------------------------------------------
    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);
                }
            }
        }
    }
Ejemplo n.º 2
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);
            }
        }
    }