예제 #1
0
    public GameObject Lift()
    {
        // 処理後状態なら入力が解除されるまで処理しない
        if (afterHoldInput)
        {
            return(null);
        }

        Debug.Log("lift");
        switch (St)
        {
        case LiftState.standby:
            // 重さ変更中は処理しない
            if (Pl.IsShift)
            {
                return(null);
            }

            // 範囲内で最も近い持ち上げられるオブジェクトを取得
            List <RaycastHit> hitInfos = new List <RaycastHit>();
            //			hitInfos.AddRange(Physics.BoxCastAll(transform.position, liftUpCol.localScale * 0.5f, (liftUpCol.position - transform.position),
            //				liftPoint.rotation, Vector3.Distance(transform.position, liftUpCol.position), boxMask));
            hitInfos.AddRange(Physics.BoxCastAll(liftUpCol.transform.position, liftUpCol.localScale * 0.5f, (transform.position - liftUpCol.position), liftPoint.rotation, float.Epsilon, boxMask));

            // 浮いているオブジェクトは持ち上げられない
            for (int idx = hitInfos.Count - 1; idx >= 0; idx--)
            {
                Landing    hitInfoLand     = hitInfos[idx].collider.GetComponent <Landing>();
                WaterState hitInfoWaterStt = hitInfos[idx].collider.GetComponent <WaterState>();
                if ((!hitInfoLand || !hitInfoWaterStt) ||
                    (!hitInfoLand.IsLanding && !hitInfoLand.IsWaterFloatLanding && !hitInfoWaterStt.IsWaterSurface))
                {
                    hitInfos.RemoveAt(idx);
                }
            }

            // 上下をオブジェクトに挟まれている場合
            if (Pl.IsSandwitch)
            {
                // 挟んでいるオブジェクト以外は持ち上げ対象から除外
                for (int idx = hitInfos.Count - 1; idx >= 0; idx--)
                {
                    if (!Pl.SandwitchCols.Contains(hitInfos[idx].collider))
                    {
                        hitInfos.RemoveAt(idx);
                    }
                }
            }

            GameObject liftableObj = null;
            float      dis         = float.MaxValue;
            //			Debug.LogWarning(hitInfos.Count);

            foreach (var hitInfo in hitInfos)
            {
                //				Debug.LogWarning(hitInfo.collider.name + " " + hitInfo.collider.tag);
                if (!underPriority)
                {
                    if ((hitInfo.collider.tag == "LiftableObject") && (hitInfo.distance < dis))
                    {
                        liftableObj = hitInfo.collider.gameObject;
                        dis         = hitInfo.distance;
                    }
                }
                else
                {
                    if ((hitInfo.collider.tag == "LiftableObject") && (!liftableObj || (hitInfo.transform.position.y < liftableObj.transform.position.y)))
                    {
                        liftableObj = hitInfo.collider.gameObject;
                    }
                }
            }

            // 持ち上げれるオブジェクトがあれば
            if (liftableObj != null)
            {
                if (!canHeavyLift)
                {
                    // 重さがプレイヤーより重ければ失敗フラグを立てる
                    heavyFailedFlg = (Pl.GetComponent <WeightManager>().WeightLv < liftableObj.GetComponent <WeightManager>().WeightLv);
                }

                // ジャンプ、重さ変更、振り向きを不可に
                Pl.CanJump         = false;
                Pl.CanShift        = false;
                Pl.CanRotationTurn = false;

                // 移動量を削除
                MoveMng.StopMoveVirticalAll();
                MoveMng.StopMoveHorizontalAll();

                // 持ち上げ中のオブジェクトが水で浮かないように
                WaterState liftWaterStt = liftableObj.GetComponent <WaterState>();
                liftWaterStt.CanFloat = false;

                // 持ち上げ開始
                return(LiftUpStart(liftableObj));
            }
            else
            {
                // 持ち上げキャンセル
                LiftObj = null;
            }
            break;

        case LiftState.lifting:
            // 重さ変更中は処理しない
            if (Pl.IsShift)
            {
                return(null);
            }

            //// 持ち上げ中オブジェクト以外のすり抜け中のオブジェクトがある場合は処理しない
            //foreach (var throughObj in MoveMng.ThroughObjList) {
            //	if (throughObj != LiftObj) {
            //		return null;
            //	}
            //}

            // ジャンプ、重さ変更、振り向きを不可に
            Pl.CanJump         = false;
            Pl.CanShift        = false;
            Pl.CanRotationTurn = false;

            // 下ろし始める
            LiftDownStart();

            // 移動量を削除
            MoveMng.StopMoveVirticalAll();
            MoveMng.StopMoveHorizontalAll();

            break;

        default:
            break;
        }
        return(null);
    }
예제 #2
0
    void UpdateLifting()
    {
        switch (St)
        {
        case LiftState.liftUp:
            // 移動不可
            MoveMng.StopMoveVirticalAll();
            MoveMng.StopMoveHorizontalAll();

            // 持ち上げ中オブジェクトを動かさない
            LiftObjMoveMng.StopMoveVirticalAll();
            LiftObjMoveMng.StopMoveHorizontalAll();

            // 持つオブジェクトの補間位置が現在のオブジェクトより高ければ
            bool liftMoveFlg = false;
            //float landVec = MoveMng.GravityForce;
            //WeightManager liftWeightMng = LiftObj.GetComponent<WeightManager>();
            //// 水中で水に浮く重さなら上方向に接地
            //if (LiftWaterStt && liftWeightMng && LiftWaterStt.IsInWater && !LiftWaterStt.IsWaterSurface && liftWeightMng.WeightLv <= WeightManager.Weight.light) {
            //	landVec = 1.0f;
            //}
            //if (landVec < 0.0f) {   // 接地方向が下
            if (Pl.RotVec.y == 0.0f)
            {
                if (PlAnim.GetBoxPosition().y > LiftObj.transform.position.y)
                {
                    liftMoveFlg = true;
                }
            }
            else                                // 接地方向が上
            {
                if (PlAnim.GetBoxPosition().y < LiftObj.transform.position.y)
                {
                    liftMoveFlg = true;
                }
            }

            // オブジェクトの位置を同期
            if (liftMoveFlg)
            {
                if (heavyFailedFlg || (!MoveManager.Move(GetLiftUpBoxMove(), LiftObj.GetComponent <BoxCollider>(), liftingColMask, false, true) && (Pl.transform.position.x != LiftObj.transform.position.x)))
                {
                    Debug.Log("持ち上げ失敗");

                    //					// 持ち上げ中オブジェクトの強制押し出しフラグを戻す
                    //					LiftObjMoveMng.enabled = false;

                    // 持ち上げ移動中フラグをfalseに
                    LiftObjMoveMng.IsLiftUpMove = false;

                    // 対象をすり抜けオブジェクトに追加
                    MoveMng.AddThroughCollider(LiftObj);

                    // 同期できなければ下ろす
                    St = LiftState.liftUpFailed;

                    // 失敗アニメーションへの遷移
                    PlAnim.FailedCatch();

                    return;
                }

                // プレイヤーのモデルと同じ回転をオブジェクトに加える
                LiftObjModel.transform.rotation = cameraLookTransform.rotation;
            }

            // 持ち上げ完了時
            if (PlAnim.CompleteCatch())
            {
                LiftUpEnd();
                //				// 持ち上げ中オブジェクトの判定と挙動を無効化
                //				LiftObj.GetComponent<BoxCollider>().enabled = false;
                //				LiftObj.GetComponent<MoveManager>().enabled = false;
                //
                //				// 持ち上げ中のプレイヤー当たり判定を有効化
                //				standbyCol.enabled = false;
                //				liftingCol.enabled = true;

                plAnim.ExitCatch();

                //				// 持ち上げ後処理状態
                //				St = LiftState.liftUpAfterHoldInput;
            }
            break;

        case LiftState.liftDown:
//			Debug.LogWarning(St.ToString() + " " + PlAnim.GetBoxPosition());

            // 移動不可
            MoveMng.StopMoveVirticalAll();
            MoveMng.StopMoveHorizontalAll();

            // 持ち上げ中オブジェクトを動かさない
            LiftObjMoveMng.StopMoveVirticalAll();
            LiftObjMoveMng.StopMoveHorizontalAll();

            // 回転終了待ち
            if (liftDownWeit)
            {
                if (Pl.CameraLookRatio == 0.0f)
                {
                    liftDownWeit = false;

                    // 持ち上げ中オブジェクトの判定を有効化
                    LiftObj.GetComponent <BoxCollider>().enabled = true;

                    // 下ろしアニメーションへの遷移
                    PlAnim.StartRelease();

                    // サウンド再生
                    SoundManager.SPlay(liftSE, liftDownSoundDeray);
                }
            }
            else
            {
                // オブジェクトの位置を同期
                if (!MoveManager.MoveTo(GetLiftDownBoxPosition(), LiftObj.GetComponent <BoxCollider>(), liftingColMask))
                {
                    Debug.Log("下ろし失敗");

                    if (Pl.RotVec.y == 1.0f)
                    {
                        Debug.LogWarning("下ろし失敗補正");
                        failedPosUpFlg = true;
                    }

                    LiftDownEnd();

                    // アニメーション遷移
                    PlAnim.ExitRelease();

                    return;
                }
            }

            // プレイヤーのモデルと同じ回転をオブジェクトに加える
            LiftObjModel.transform.rotation = cameraLookTransform.rotation;

            // 下ろし完了時
            if (!liftDownWeit && PlAnim.CompleteRelease())
            {
                Debug.LogWarning("下ろし完了");
                // オブジェクトを離す
                LiftDownEnd();

                //				// 持ち上げ中オブジェクトの判定と挙動を有効化
                //				LiftObj.GetComponent<BoxCollider>().enabled = true;
                //				LiftObj.GetComponent<MoveManager>().enabled = true;
                //
                //				// 持ち上げ中のプレイヤー当たり判定を無効化
                //				standbyCol.enabled = true;
                //				liftingCol.enabled = false;
                //
                //				// 持ち上げ中オブジェクトを下ろし切る
                //				MoveManager.MoveTo(liftPoint.position, LiftObj.GetComponent<BoxCollider>(), LayerMask.GetMask(new string[] { "" }));
                //				LiftObj = null;
                //
                //				// 下ろし処理後状態に
                //				St = LiftState.standby;
                //				afterHoldInput = true;

                // アニメーション遷移
                PlAnim.ExitRelease();
            }
            break;

        case LiftState.liftUpFailed:
            // 移動不可
            MoveMng.StopMoveVirticalAll();
            MoveMng.StopMoveHorizontalAll();

            // 持ち上げ中オブジェクトを動かさない
            LiftObjMoveMng.StopMoveVirticalAll();
            LiftObjMoveMng.StopMoveHorizontalAll();

            // オブジェクトの位置を同期
            if (!MoveManager.MoveTo(GetLiftDownBoxPosition(), LiftObj.GetComponent <BoxCollider>(), liftingColMask))
            {
                Debug.Log("持ち上げ失敗に失敗");

                // オブジェクトを離す
                LiftDownEnd();

                // アニメーション遷移
                PlAnim.ExitRelease();

                return;
            }

            // プレイヤーのモデルと同じ回転をオブジェクトに加える
            LiftObjModel.transform.rotation = cameraLookTransform.rotation;

            // 移動不可
            MoveMng.StopMoveVirticalAll();
            MoveMng.StopMoveHorizontalAll();

            // 持ち上げ失敗完了時
            if (PlAnim.CompleteCatchFailed())
            {
                Debug.Log("持ち上げ失敗完了");
                // 持ち上げオブジェクトを離す
                LiftDownEnd();

                // アニメーション遷移
                PlAnim.ExitCatchFailed();
            }
            break;


/// 現状の仕様では下ろし失敗状態に遷移する事はない
//		case LiftState.liftDownFailed:
//			// 移動不可
//			MoveMng.StopMoveVirticalAll();
//			MoveMng.StopMoveHorizontalAll();
//
//			// オブジェクトの位置を同期
//			if (!MoveManager.MoveTo(liftPoint.position, LiftObj.GetComponent<BoxCollider>(), LayerMask.GetMask(new string[] { "Stage", "Box" }))) {
//				Debug.Log("下ろし失敗");
//
//				// 同期できなければ持ち上げる
//				LiftUp(LiftObj);
//				return;
//			}
//
//			// 下ろし完了時
//			if (PlAnim.CompleteRelease()) {
//				// 持ち上げ中オブジェクトの判定と挙動を有効化
//				LiftObj.GetComponent<BoxCollider>().enabled = true;
//				LiftObj.GetComponent<MoveManager>().enabled = true;
//
//				// 持ち上げ中のプレイヤー当たり判定を無効化
//				standbyCol.enabled = true;
//				liftingCol.enabled = false;
//
//				// 持ち上げ中オブジェクトを下ろし切る
//				MoveManager.MoveTo(liftPoint.position, LiftObj.GetComponent<BoxCollider>(), LayerMask.GetMask(new string[] { "" }));
//				LiftObj = null;
//			}
//			break;

        case LiftState.lifting:
            // オブジェクトの位置を同期
            //			MoveManager.MoveTo(PlAnim.GetBoxPosition(), LiftObj.GetComponent<BoxCollider>(), liftingColMask);
            LiftObj.transform.position = PlAnim.GetBoxPosition();

            // プレイヤーのモデルと同じ回転をオブジェクトに加える
            LiftObjModel.transform.rotation = cameraLookTransform.rotation;

            break;

        default:
            break;
        }
    }