今日やったこと
ワーキングメモリートレーニング
瞑想
鬼計算、鬼ネズミ、計算20、計算100。
Lv.11のみ140問程度。
力学
ゲーム分析
キミガシネ
ゲーム開発
ThrowBombManagerクラスの作成
Playerがボムを投げられる状態か否かを管理するThrowBombManagerクラスを作成しました。 UniRxのReactivePropertyを使っています。
using UniRx; namespace Manager { public class ThrowBombManager { private ReactiveProperty<bool> isThrow = new ReactiveProperty<bool>(false); public IReadOnlyReactiveProperty<bool> CanThrowBomb => isThrow; public bool IsThrow => isThrow.Value; public void SetBool(bool Bool) { isThrow.Value = Bool; } } }
SceneInstallerも変更します。
using UnityEngine; using Zenject; namespace Manager { public class SceneInstaller : MonoInstaller { public override void InstallBindings() { Container .Bind<GameStateManager>() .AsSingle(); Container .Bind<PlayerStateManager>() .AsSingle(); Container .Bind<ThrowBombManager>() .AsSingle(); } } }
BombThrowerクラスの作成
using System.Collections; using System.Collections.Generic; using UnityEngine; using Zenject; using Manager; using UniRx; namespace Player { public class BombThrower : MonoBehaviour { [SerializeField] private GameObject bomb; [Inject] private ThrowBombManager throwBombManager; [SerializeField] private Vector3 direction; [SerializeField] private float force; private Vector3 e_x = new Vector3(0.1f, 0, 0); private Vector3 d; private void Start() { throwBombManager .IsThrowBomb .Where(Bool => Bool) .Subscribe(_ => ThrowBomb(direction.normalized, force)) .AddTo(this); } public void ThrowBomb(Vector3 dir, float force) { //ボムを生成する位置を調整するためのベクトル d = Quaternion.Euler(0, this.transform.rotation.eulerAngles.y, 0) * e_x; //ボムを生成 GameObject bombThrowed = Instantiate(bomb, this.transform.localPosition + d, this.transform.rotation); //生成したボムのRigidbodyを取得 Rigidbody bombRb = bombThrowed.GetComponent<Rigidbody>(); //投げるボムの方向をプレイヤーの方向に合わせる dir = Quaternion.Euler(0, this.transform.rotation.eulerAngles.y, 0) * dir; //ボムに力を加える bombRb.AddForce(dir * force, ForceMode.Impulse); } } }
Bombクラスの作成
using UnityEngine; using UniRx; using System; namespace Bomb { public class Bomb : MonoBehaviour { [SerializeField] private GameObject explosionObject; // Start is called before the first frame update void Start() { Explode(); } private void Explode() { Observable .Timer(TimeSpan.FromSeconds(1)) .Subscribe(_ => Destroy(this.gameObject)); Observable .Timer(TimeSpan.FromSeconds(1)) .Subscribe(_ => Instantiate(explosionObject,this.transform.localPosition,Quaternion.identity)); } } }
爆発のエフェクトの実装
爆発のエフェクトはPartcleSystemを使って実装しました。
ExplosionDestroyerクラスの実装
爆発エフェクト用のParticleSystemがアタッチされているGameObjectを削除するクラスを作成しました。
using UnityEngine; using System; namespace Bomb { public class ExplosionDestroyer : MonoBehaviour { // Start is called before the first frame update void Start() { ParticleSystem particle = this.GetComponent<ParticleSystem>(); Destroy(this.gameObject, particle.main.duration); } } }
ゲーム画面
ゲーム画面はこんな感じになっています。
クラス図
クラス図はこんな感じになっています。
今日のパフォーマンス
JINS MEME ESという最新の学術研究の成果を元に人間の心理状態を測定できるウェアラブルデバイスを使って本日の僕の集中状態を測定した結果は以下のようになりました。
作業時間 9h43m
集中時間 2h55m
集中率 30%