public override void OnEnter(AIControllerBase aiController) { var navMeshAgent = aiController.Owner.GetComponent <NavMeshAgent>(); Assert.IsNotNull(navMeshAgent, string.Format("{0}に{1}がアタッチされていませんでした", aiController.Owner, typeof(NavMeshAgent))); var navMeshObstacle = aiController.Owner.GetComponent <NavMeshObstacle>(); Assert.IsNotNull(navMeshObstacle, string.Format("{0}に{1}がアタッチされていませんでした", aiController.Owner, typeof(NavMeshObstacle))); Assert.IsNotNull(aiController.Target, string.Format("{0}のAIにTargetが設定されていません", aiController.Owner)); navMeshObstacle.enabled = false; navMeshAgent.enabled = true; navMeshAgent.speed = this.speed; aiController.UpdateAsObservable() .Where(_ => aiController.isActiveAndEnabled) .Where(_ => navMeshAgent.enabled) .SubscribeWithState2(navMeshAgent, aiController, (_, n, a) => { n.destination = a.Target.CachedTransform.position; }) .AddTo(this.runningEvents) .AddTo(aiController); }
public override void OnEnter(AIControllerBase aiController) { var navMeshAgent = aiController.Owner.GetComponent <NavMeshAgent>(); Assert.IsNotNull(navMeshAgent, string.Format("{0}に{1}がアタッチされていませんでした", aiController.Owner, typeof(NavMeshAgent))); var navMeshObstacle = aiController.Owner.GetComponent <NavMeshObstacle>(); Assert.IsNotNull(navMeshObstacle, string.Format("{0}に{1}がアタッチされていませんでした", aiController.Owner, typeof(NavMeshObstacle))); navMeshAgent.enabled = false; navMeshObstacle.enabled = true; aiController.UpdateAsObservable() .Where(_ => aiController.isActiveAndEnabled) .SubscribeWithState2(this, aiController, (_, _this, a) => { var owner = a.Owner.CachedTransform; var v = a.Target.CachedTransform.position - owner.position; v.y = 0.0f; var current = owner.rotation.eulerAngles; var target = Quaternion.LookRotation(v.normalized).eulerAngles; var t = _this.rotationSmoothTime * Time.deltaTime; owner.rotation = Quaternion.Euler( Mathf.SmoothDampAngle(current.x, target.x, ref _this.rotationVelocity.x, t), Mathf.SmoothDampAngle(current.y, target.y, ref _this.rotationVelocity.y, t), Mathf.SmoothDampAngle(current.z, target.z, ref _this.rotationVelocity.z, t) ); }) .AddTo(this.runningEvents) .AddTo(aiController); Observable.Interval(TimeSpan.FromSeconds(this.interval)) .Where(_ => aiController.isActiveAndEnabled) .SubscribeWithState2(this, aiController, (_, _this, a) => { _this.Fire(a.Owner); }) .AddTo(this.runningEvents) .AddTo(aiController); if (this.enterOnAttack) { this.Fire(aiController.Owner); } }