/// <summary> /// Updates the turtles state, position and creates a speech bubble if any text is passed. /// </summary> /// <param name="state">Desired companion state</param> /// <param name="targetPos">Desired companion position</param> /// <param name="speech">What the companion should say</param> void UpdateTurtle(CompanionState state, Vector3 targetPos, string speech) { if (!string.IsNullOrEmpty(speech)) { if (!speech.Equals(speech_text.text)) { AcivateSpeech(speech); } } else { speech_canvas.SetActive(false); } switch (state) { case CompanionState.LookAtPlayer: break; case CompanionState.MoveToPosition: if (this.targetPos != targetPos) { this.targetPos = targetPos; MoveToPosition(targetPos); } break; } }
protected override void Start() { try { var comp = GameObject.FindGameObjectWithTag(companionTag); if (comp != null) { companion = comp.transform; } else { companionState = CompanionState.None; Debug.LogWarning("Cant find the " + companionTag); } } catch (UnityException e) { companionState = CompanionState.None; Debug.LogWarning("AICompanion Cant find the " + companionTag); Debug.LogWarning("AICompanion " + e.Message); } Init(); agent.enabled = true; StartCoroutine(CompanionStateRoutine()); StartCoroutine(FindTarget()); StartCoroutine(DestinationBehaviour()); }
protected override void Start() { //companionState = CompanionState.Stay; try { var comp = GameObject.FindGameObjectWithTag(companionTag); if (comp != null) { companion = comp.transform; } else { companionState = CompanionState.None; Debug.LogWarning("Cant find the " + companionTag); } } catch (UnityException e) { companionState = CompanionState.None; Debug.LogWarning("AICompanion Cant find the " + companionTag); Debug.LogWarning("AICompanion " + e.Message); } Init(); StartCoroutine(CompanionStateRoutine()); StartCoroutine(OffMeshLinkRoutine()); }
private void CheckState() { switch (state) { case CompanionState.Follow: if (shouldRespawn) { state = CompanionState.Teleport; } else if (xMove > 0 || zMove > 0 || goingUpDown) { state = CompanionState.Free; } break; case CompanionState.Free: if (shouldRespawn) { state = CompanionState.Teleport; } else { Vector2 move = new Vector2(xMove, zMove); animator.SetFloat("Speed", 1); if (move == Vector2.zero && isHovering && !goingUpDown) { animator.SetFloat("Speed", 0); returnTimer += Time.deltaTime; if (returnTimer >= returnTime) { state = CompanionState.Teleport; returnTimer = 0.0f; } } else { returnTimer = 0.0f; } } break; case CompanionState.Teleport: float distance = Vector3.Distance(transform.position, character.transform.position); if (distance <= followRadius + 2.0f) { shouldRespawn = false; state = CompanionState.Follow; } break; } }
/// <summary> /// Moves the companion to the target position. /// </summary> /// <param name="pos">Target position to move to</param> void MoveToPosition(Vector3 pos) { NavMeshHit hit; // sample a valid pathfinding spot around a given location if (NavMesh.SamplePosition(pos, out hit, 5, NavMesh.AllAreas)) { agent.updateRotation = true; state = CompanionState.MoveToPosition; agent.SetDestination(hit.position); } else { Debug.LogWarning("Unable to move turtle to location " + pos); } }
/// <summary> /// Simple state machine for handling the companions states /// </summary> void StateManager() { switch (state) { case CompanionState.LookAtPlayer: agent.updateRotation = false; LookAtTarget(playerSettings.HMD.position); break; case CompanionState.MoveToPosition: if (agent.remainingDistance < 0.5f) { state = CompanionState.LookAtPlayer; } break; } }
void CompanionInputs() { if (Input.GetKeyDown(KeyCode.Alpha1)) { companionState = CompanionState.Stay; agressiveAtFirstSight = false; } if (Input.GetKeyDown(KeyCode.Alpha2)) { companionState = CompanionState.Follow; agressiveAtFirstSight = false; } if (Input.GetKeyDown(KeyCode.Alpha3)) { agressiveAtFirstSight = !agressiveAtFirstSight; } if (Input.GetKeyDown(KeyCode.Alpha4) && moveToTarget != null) { SetMoveTo(moveToTarget); companionState = CompanionState.MoveTo; agressiveAtFirstSight = false; } }
/// <summary> /// Sets the target Move to. /// </summary> /// <param name="_target">Target.</param> public void SetMoveTo(Transform _target) { companionState = CompanionState.MoveTo; moveToTarget = _target; }
public Commands(CompanionState companionConvo) { CompanionConvo = companionConvo; }
public static StateResponse FromSuccess(CompanionState companionConvo) => new StateResponse(null, null, companionConvo);
public StateResponse(CommandError?error, string reason, CompanionState companion) : base(error, reason) { CompanionState = companion; }