123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459 |
- using System;
- using System.Collections;
- using System.IO;
- using UnityEngine;
- public class PaperAirplaneManager : MonoBehaviour
- {
- private int totalScore
- {
- get
- {
- return this.miniGameManager.score / 10;
- }
- set
- {
- this.miniGameManager.ScoreBoard.score = value * 10;
- }
- }
- private void Awake()
- {
- this.playBGMName = Path.ChangeExtension(this.playBGMName, "ogg");
- this.throwPlaySeName = Path.ChangeExtension(this.throwPlaySeName, "ogg");
- this.throwMissPlaySeName = Path.ChangeExtension(this.throwMissPlaySeName, "ogg");
- this.explosionSeName = Path.ChangeExtension(this.explosionSeName, "ogg");
- }
- private void Start()
- {
- this.targetObject.onEndAnimationVanish = new Action(this.OnEndAnimationVanish);
- base.StartCoroutine(this.WaitVrStart());
- }
- private IEnumerator WaitVrStart()
- {
- while (GameMain.Instance.OvrMgr == null)
- {
- yield return null;
- }
- yield return null;
- GameMain.Instance.MainCamera.FadeIn(0.5f, false, null, true, true, default(Color));
- base.StartCoroutine(this.WaitFadeJob());
- yield break;
- }
- private IEnumerator WaitFadeJob()
- {
- while (GameMain.Instance.MainCamera.IsFadeProc())
- {
- yield return null;
- }
- this.AwakeMiniGame();
- yield break;
- }
- public void AwakeMiniGame()
- {
- GameMain.Instance.SoundMgr.PlayBGM(this.playBGMName, 0.5f, true);
- Vector3 vector = this.playerPosition.position;
- this.useCamera = GameMain.Instance.OvrMgr.OvrCamera;
- vector += this.playerPosition.forward * this.playerPositionDistance;
- vector = new Vector3(vector.x, this.useCamera.GetHeightStandAndSit(CameraMain.STAND_SIT.STAND), vector.z);
- this.useCamera.SetPos(vector);
- this.useCamera.SetRotation(Quaternion.LookRotation(this.appearancePosition[0].position - vector).eulerAngles);
- vector = this.maidPosition.position;
- GameMain.Instance.CharacterMgr.SetCharaAllPos(vector);
- Vector3 charaAllRot = new Vector3(0f, Quaternion.LookRotation(this.useCamera.GetPos() - vector).eulerAngles.y, 0f);
- GameMain.Instance.CharacterMgr.SetCharaAllRot(charaAllRot);
- this.is2DMode = false;
- if (this.devideType == GameMain.VRDeviceType.NON || this.devideType == GameMain.VRDeviceType.RIFT || this.devideType == GameMain.VRDeviceType.FOVE)
- {
- this.is2DMode = true;
- }
- this.useCamera.ForceHideUI(true);
- this.gaugeManager.ChangeDeviceMode(this.devideType);
- this.miniGameManager = VRMiniGameManager.Instance;
- VRMiniGameManager.VRMiniGameType type = VRMiniGameManager.VRMiniGameType.Kamihikouki;
- this.miniGameManager.Init(type);
- this.miniGameManager.CreateScoreBoard(this.scoreBoardPosition.position, Quaternion.LookRotation(this.scoreBoardPosition.position - this.useCamera.GetPos()));
- this.miniGameManager.ScoreBoard.gameObject.SetActive(false);
- if (!this.is2DMode)
- {
- Vector3 vector2 = this.useCamera.GetPos();
- vector2 -= Vector3.right * 1.5f;
- Quaternion uirot = Quaternion.LookRotation(vector2 - this.useCamera.GetPos());
- this.miniGameManager.StartRightLeftHand(vector2, uirot, delegate(AVRController con)
- {
- this.StartMiniGame(!con.m_bHandL);
- });
- }
- else
- {
- this.StartMiniGame(true);
- }
- }
- public void StartMiniGame(bool main_hand_right)
- {
- if (!this.is2DMode)
- {
- this.useCtrl = GameMain.Instance.OvrMgr.OvrCamera.GetVRControllerButtons(!main_hand_right);
- if (this.devideType == GameMain.VRDeviceType.RIFT_TOUCH)
- {
- this.grabber.SetGripTransform((!main_hand_right) ? "Rift_Left" : "Rift_Right");
- }
- else
- {
- this.grabber.SetGripTransform("HTC");
- }
- }
- else
- {
- this.useCtrl = this.dummyController;
- if (this.devideType == GameMain.VRDeviceType.NON)
- {
- this.grabber.SetGripTransform("2D");
- }
- else
- {
- this.grabber.SetGripTransform("Rift_Non");
- }
- }
- this.grabber.m_vrController = this.useCtrl;
- this.throwObject.onThrowObjectEvent = new WfGrabbableObject.OnThrowObjectEvent(this.OnThrowObject);
- this.throwObject.onCollisionEnter = new Action<WfGrabbableObject, Collision>(this.OnThrowObjectCollisionEnter);
- this.throwObject.onThrowObjectCorrectionVelocityEvent = new WfGrabbableObject.OnThrowObjectCorrectionVelocityEvent(this.OnThrowObjectCorrectionVelocity);
- int totalScore = 0;
- this.totalScore = totalScore;
- this.throwCount = totalScore;
- this.addPoint = 1;
- this.contactTime = 0f;
- this.throwFlag = (this.mistakeThrow = (this.isFinish = false));
- this.StopVoice();
- this.miniGameManager.ScoreBoard.gameObject.SetActive(true);
- this.gaugeManager.Stop();
- this.gaugeManager.onMouseClickDownEvent = delegate(VRMiniGameGaugeeManager eventObject)
- {
- if (this.gaugeManager.isPlay || !this.throwObject.IsGrabbed)
- {
- return;
- }
- this.gaugeManager.Play();
- };
- this.gaugeManager.onMouseClickUpEvent = new VRMiniGameGaugeeManager.OnMouseClickEvent(this.onMouseClickUpEvent);
- this.gaugeManager.enabledMouseClickEvent = true;
- this.GrabPaperAirplane();
- this.PopupTargetObject();
- }
- private void PopupTargetObject()
- {
- this.PopupTargetObject(this.throwCount);
- }
- private void PopupTargetObject(int throwCount)
- {
- if (0 <= throwCount && throwCount <= 10)
- {
- VRMiniGameManager.VoiceType type = (VRMiniGameManager.VoiceType)Enum.Parse(typeof(VRMiniGameManager.VoiceType), "Remaining" + (10 - throwCount).ToString());
- Debug.Log("throwCountボイス再生:" + throwCount);
- this.miniGameManager.AddQueueVoice(type);
- }
- Debug.Log(throwCount + 1 + "回目の投擲です");
- Vector3 pos = Vector3.zero;
- if (0 <= throwCount && throwCount < this.appearancePosition.Length)
- {
- Transform transform = this.appearancePosition[throwCount];
- int childCount = transform.childCount;
- pos = transform.GetChild(UnityEngine.Random.Range(0, childCount - 1)).position;
- }
- else
- {
- Debug.LogError("投擲回数は" + throwCount + "回目ですが、的位置の設定が見当たりません");
- pos = Vector3.zero;
- }
- this.targetObject.PopupPosition(pos);
- }
- private void GrabPaperAirplane()
- {
- Physics.gravity = this.customGravity;
- this.throwFlag = (this.mistakeThrow = false);
- this.contactTime = 0f;
- Rigidbody component = this.grabber.GetComponent<Rigidbody>();
- Rigidbody rigidbody = component;
- Vector3 zero = Vector3.zero;
- component.angularVelocity = zero;
- rigidbody.velocity = zero;
- this.throwObject.rigidBody.isKinematic = false;
- this.throwObject.rigidBody.useGravity = true;
- this.throwObject.StopLookRotationAnime();
- this.throwObject.transform.SetParent(base.transform, false);
- this.grabber.GrabBegin(this.throwObject);
- }
- private void OnThrowObjectCorrectionVelocity(ref Vector3 linearVelocity, ref Vector3 angularVelocity)
- {
- this.targetObject.OnThrowObjectCorrectionVelocity(this.throwObject.transform, ref linearVelocity, ref angularVelocity);
- }
- private void OnThrowObject(WfGrabbableObject throwObject, bool mistakeThrow)
- {
- this.throwFlag = true;
- this.mistakeThrow = mistakeThrow;
- if (!mistakeThrow)
- {
- this.throwCount++;
- this.PlaySe(this.throwPlaySeName);
- }
- else
- {
- this.PlaySe(this.throwMissPlaySeName);
- }
- }
- private void OnThrowObjectCollisionEnter(WfGrabbableObject throwObject, Collision collision)
- {
- if (!this.throwFlag)
- {
- return;
- }
- this.throwFlag = false;
- Physics.gravity = new Vector3(0f, -9.81f, 0f);
- throwObject.StopLookRotationAnime();
- if (collision.gameObject.layer == PaperAirplaneManager.MiniGameObjectLayerNumber)
- {
- throwObject.rigidBody.isKinematic = true;
- throwObject.rigidBody.useGravity = false;
- Rigidbody rigidBody = throwObject.rigidBody;
- Vector3 zero = Vector3.zero;
- throwObject.rigidBody.angularVelocity = zero;
- rigidBody.velocity = zero;
- Transform transform = collision.transform;
- while (transform != null)
- {
- PaperAirplaneTarget component = transform.GetComponent<PaperAirplaneTarget>();
- if (component != null)
- {
- component.Die();
- throwObject.transform.SetParent(component.modelTransform, true);
- break;
- }
- transform = transform.parent;
- }
- this.OnHit();
- }
- else if (this.mistakeThrow)
- {
- this.contactTime = Time.fixedTime;
- }
- else
- {
- this.OnMiss();
- }
- }
- private void OnHit()
- {
- this.PlaySe(this.explosionSeName);
- this.miniGameManager.AddQueueVoice(VRMiniGameManager.VoiceType.Hit);
- this.totalScore += this.addPoint;
- this.addPoint++;
- this.miniGameManager.ScoreBoard.life--;
- }
- private void OnMiss()
- {
- this.miniGameManager.AddQueueVoice(VRMiniGameManager.VoiceType.Miss);
- this.targetObject.Vanish();
- this.addPoint = 1;
- this.miniGameManager.ScoreBoard.life--;
- }
- private void OnEndAnimationVanish()
- {
- if (this.throwCount >= 10)
- {
- Physics.gravity = this.backupGravity;
- this.isFinish = true;
- this.gaugeManager.isVisible = false;
- this.miniGameManager.AddQueueVoice(VRMiniGameManager.VoiceType.Remaining0);
- this.miniGameManager.Result(null);
- }
- else
- {
- this.GrabPaperAirplane();
- this.PopupTargetObject();
- }
- }
- private void OnDestroy()
- {
- Physics.gravity = this.backupGravity;
- }
- private void FixedUpdate()
- {
- if (this.useCamera == null || this.isFinish)
- {
- return;
- }
- if (this.is2DMode)
- {
- this.dummyController.transform.position = this.useCamera.m_goCenterEye.transform.position + this.useCamera.m_goCenterEye.transform.forward * 0.2f;
- this.dummyController.transform.rotation = Quaternion.LookRotation(this.dummyController.transform.position - this.useCamera.m_goCenterEye.transform.position);
- }
- }
- private void onMouseClickUpEvent(VRMiniGameGaugeeManager eventObject)
- {
- if (!this.gaugeManager.isPlay || !this.throwObject.IsGrabbed)
- {
- return;
- }
- Vector3 a = this.dummyController.transform.position - this.useCamera.m_goCenterEye.transform.position;
- Vector3 eulerAngles = Quaternion.LookRotation(this.dummyController.transform.position - this.useCamera.m_goCenterEye.transform.position).eulerAngles;
- float d = this.gaugeRangeMin + (this.gaugeRangeMax - this.gaugeRangeMin) * this.gaugeManager.gaugeValue;
- this.grabber.GrabEnd(a * d, eulerAngles);
- this.gaugeManager.Stop();
- }
- private void Update()
- {
- if (this.useCamera == null || this.useCtrl == null || this.isFinish)
- {
- return;
- }
- if (this.throwObject.transform.position.y <= -3f)
- {
- if (-1000f < this.throwObject.transform.position.y)
- {
- if (!this.mistakeThrow)
- {
- this.throwObject.transform.position = new Vector3(0f, -1000f, 0f);
- this.throwObject.rigidBody.isKinematic = false;
- this.throwObject.rigidBody.useGravity = true;
- this.throwObject.StopLookRotationAnime();
- this.OnMiss();
- }
- else
- {
- this.GrabPaperAirplane();
- }
- }
- }
- else if (0f < this.contactTime && Time.fixedTime - this.contactTime >= 1.5f)
- {
- this.GrabPaperAirplane();
- }
- }
- private void PlaySe(string seFileName)
- {
- if (!string.IsNullOrEmpty(seFileName) && GameMain.Instance != null && GameMain.Instance.SoundMgr != null)
- {
- GameMain.Instance.SoundMgr.PlaySe(seFileName, false);
- }
- }
- private void StopVoice()
- {
- GameMain.Instance.SoundMgr.VoiceStopAll();
- }
- private GameMain.VRDeviceType devideType
- {
- get
- {
- return GameMain.Instance.VRDeviceTypeID;
- }
- }
- public static readonly int MiniGameObjectLayerNumber = 24;
- [SerializeField]
- public Vector3 customGravity = Physics.gravity;
- [SerializeField]
- private VRGrabber grabber;
- [SerializeField]
- private WfGrabbableObject throwObject;
- [SerializeField]
- private PaperAirplaneTarget targetObject;
- [SerializeField]
- private Transform[] appearancePosition;
- [SerializeField]
- [Tooltip("主人公の基準位置")]
- private Transform playerPosition;
- [SerializeField]
- [Tooltip("主人公の基準位置からの距離")]
- private float playerPositionDistance;
- [SerializeField]
- [Tooltip("メイドの位置")]
- private Transform maidPosition;
- [SerializeField]
- [Tooltip("スコアボードの位置")]
- private Transform scoreBoardPosition;
- [SerializeField]
- [Tooltip("再生BGM")]
- private string playBGMName = "BGM_vr0002";
- [SerializeField]
- [Tooltip("投擲成功の時呼ばれるSE")]
- private string throwPlaySeName = "SE_vrminigame003_01";
- [SerializeField]
- [Tooltip("投擲失敗の時呼ばれるSE")]
- private string throwMissPlaySeName = "SE_vrminigame003_01";
- [SerializeField]
- [Tooltip("対象にhitした時呼ばれるSE")]
- private string explosionSeName = string.Empty;
- [SerializeField]
- [Tooltip("2D用ダミーコントローラー")]
- private AVRControllerButtons dummyController;
- [SerializeField]
- [Tooltip("2D用ゲージマネージャー")]
- private VRMiniGameGaugeeManager gaugeManager;
- [SerializeField]
- [Tooltip("2D用ゲージの最小値")]
- private float gaugeRangeMin;
- [SerializeField]
- [Tooltip("2D用ゲージの最大値")]
- private float gaugeRangeMax;
- private OvrCamera useCamera;
- private AVRControllerButtons useCtrl;
- private VRMiniGameManager miniGameManager;
- private int throwCount;
- private bool throwFlag;
- private bool mistakeThrow;
- private float contactTime;
- private int addPoint = 1;
- private bool is2DMode;
- private Vector3 backupGravity = Physics.gravity;
- private bool isFinish;
- }
|