#37 Interaction and convarsation
This commit is contained in:
parent
79ec520c01
commit
4617e57d59
File diff suppressed because it is too large
Load Diff
@ -33,8 +33,8 @@ namespace BlueWaterProject
|
||||
|
||||
[MinMaxSlider(2, 50, true)]
|
||||
public Vector2 heightLimits = new Vector2(2, 50);
|
||||
|
||||
private void Awake()
|
||||
|
||||
protected override void OnAwake()
|
||||
{
|
||||
MainCam = Camera.main;
|
||||
}
|
||||
@ -120,20 +120,6 @@ namespace BlueWaterProject
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeInShipFollowOffset()
|
||||
{
|
||||
if (!GameManager.Inst.IsInShipMode) return;
|
||||
Vector3 targetOffset = new Vector3(0, 7, -10);
|
||||
StartSmoothTransition(targetOffset);
|
||||
}
|
||||
|
||||
public void RestoreInShipFollowOffset()
|
||||
{
|
||||
if (!GameManager.Inst.IsInShipMode) return;
|
||||
Vector3 targetOffset = new Vector3(0, 20, -10);
|
||||
StartSmoothTransition(targetOffset);
|
||||
}
|
||||
|
||||
private void StartSmoothTransition(Vector3 targetOffset)
|
||||
{
|
||||
if (currentCoroutine != null)
|
||||
@ -149,7 +135,7 @@ namespace BlueWaterProject
|
||||
if (transposer != null)
|
||||
{
|
||||
var elapsedTime = 0f;
|
||||
var duration = .25f; // 이 값은 원하는 대로 설정하십시오. 이 값은 전환에 걸리는 시간을 결정합니다.
|
||||
var duration = .5f; // 이 값은 원하는 대로 설정하십시오. 이 값은 전환에 걸리는 시간을 결정합니다.
|
||||
var startingOffset = transposer.m_FollowOffset;
|
||||
|
||||
while (elapsedTime < duration)
|
||||
@ -167,7 +153,8 @@ namespace BlueWaterProject
|
||||
if (!GameManager.Inst.IsInShipMode) return;
|
||||
inShipCam.Follow = target;
|
||||
inShipCam.LookAt = target;
|
||||
inShipCam.GetCinemachineComponent<CinemachineTransposer>().m_FollowOffset = new Vector3(0, 7, -10);
|
||||
var targetOffset = new Vector3(0, 9, -10);
|
||||
StartSmoothTransition(targetOffset);
|
||||
}
|
||||
|
||||
public void RestoreInShipFollowAndLookAt()
|
||||
@ -176,7 +163,8 @@ namespace BlueWaterProject
|
||||
var transform1 = GameManager.Inst.InShipPlayer.transform;
|
||||
inShipCam.Follow = transform1;
|
||||
inShipCam.LookAt = transform1;
|
||||
inShipCam.GetCinemachineComponent<CinemachineTransposer>().m_FollowOffset = new Vector3(0, 20, -10);
|
||||
var targetOffset = new Vector3(0, 20, -10);
|
||||
StartSmoothTransition(targetOffset);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
using System.Collections;
|
||||
using PixelCrushers.DialogueSystem.Wrappers;
|
||||
using PixelCrushers.DialogueSystem;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using DialogueActor = PixelCrushers.DialogueSystem.Wrappers.DialogueActor;
|
||||
using DialogueSystemTrigger = PixelCrushers.DialogueSystem.Wrappers.DialogueSystemTrigger;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace BlueWaterProject
|
||||
@ -10,10 +12,13 @@ namespace BlueWaterProject
|
||||
public class InShipPlayer : Player
|
||||
{
|
||||
private float characterSpeed;
|
||||
private Transform interactionTarget;
|
||||
private Transform visualLook;
|
||||
|
||||
private void Init()
|
||||
{
|
||||
characterSpeed = 5;
|
||||
visualLook = transform.Find("UnitRoot");
|
||||
}
|
||||
|
||||
protected override void Awake()
|
||||
@ -22,10 +27,17 @@ namespace BlueWaterProject
|
||||
Init();
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
TargetLayer = LayerMask.GetMask("Npc");
|
||||
}
|
||||
|
||||
protected override void FixedUpdate()
|
||||
{
|
||||
base.FixedUpdate();
|
||||
MoveCharacterPlayer();
|
||||
FindNearestTargetInRange(transform.position);
|
||||
}
|
||||
|
||||
private void OnInteraction(InputValue value)
|
||||
@ -35,7 +47,10 @@ namespace BlueWaterProject
|
||||
|
||||
private void OnCancel(InputValue value)
|
||||
{
|
||||
|
||||
if (GameManager.Inst.IsInteraction && !GameManager.Inst.IsConversation)
|
||||
{
|
||||
EndInteraction();
|
||||
}
|
||||
}
|
||||
|
||||
private void MoveCharacterPlayer()
|
||||
@ -62,50 +77,16 @@ namespace BlueWaterProject
|
||||
// var movement = transform.rotation * new Vector3(-movementInput.y, 0, movementInput.x) * (characterSpeed * Time.deltaTime);
|
||||
// rb.MovePosition(rb.position + movement);
|
||||
}
|
||||
|
||||
public void GotoShipDeck()
|
||||
{
|
||||
var point = GameManager.Inst.ShipPlayer.transform.Find("TeleportPoint");
|
||||
transform.position = point.position;
|
||||
}
|
||||
|
||||
public void StartConversation(Transform target)
|
||||
{
|
||||
GameManager.Inst.IsConversation = true;
|
||||
CameraManager.Inst.ChangeInShipFollowAndLookAt(target);
|
||||
|
||||
var targetPosition = target.position;
|
||||
var playerPosition = transform.position;
|
||||
|
||||
var directionToTarget = (targetPosition - playerPosition).normalized;
|
||||
|
||||
// 캐릭터가 NPC의 왼쪽 또는 오른쪽에 있는지 확인합니다.
|
||||
var crossProduct = Vector3.Cross(directionToTarget, transform.forward).y;
|
||||
|
||||
// 캐릭터가 NPC의 왼쪽에 있는 경우
|
||||
if (crossProduct > 0)
|
||||
{
|
||||
var desiredPosition = targetPosition + (target.right * -2f);
|
||||
// 장애물 감지 및 이동 경로 조정 로직을 추가합니다.
|
||||
// ...
|
||||
StartCoroutine(MoveCharacterToPosition(desiredPosition));
|
||||
}
|
||||
// 캐릭터가 NPC의 오른쪽에 있는 경우
|
||||
else
|
||||
{
|
||||
var desiredPosition = targetPosition + (target.right * 2f);
|
||||
// 장애물 감지 및 이동 경로 조정 로직을 추가합니다.
|
||||
// ...
|
||||
StartCoroutine(MoveCharacterToPosition(desiredPosition));
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator MoveCharacterToPosition(Vector3 position)
|
||||
private IEnumerator MoveCharacterToPosition(Vector3 position, float scaleX)
|
||||
{
|
||||
var elapsedTime = 0f;
|
||||
var duration = 1f; // 이동에 걸리는 시간 (초)
|
||||
var startingPosition = transform.position;
|
||||
|
||||
// 방향을 즉시 변경합니다.
|
||||
visualLook.localScale = new Vector3(scaleX, visualLook.localScale.y, visualLook.localScale.z);
|
||||
|
||||
while (elapsedTime < duration)
|
||||
{
|
||||
transform.position = Vector3.Lerp(startingPosition, position, elapsedTime / duration);
|
||||
@ -117,10 +98,78 @@ namespace BlueWaterProject
|
||||
}
|
||||
|
||||
|
||||
public void GotoShipDeck()
|
||||
{
|
||||
var point = GameManager.Inst.ShipPlayer.transform.Find("TeleportPoint");
|
||||
transform.position = point.position;
|
||||
}
|
||||
|
||||
public void StartInteraction(Transform target)
|
||||
{
|
||||
GameManager.Inst.IsInteraction = true;
|
||||
interactionTarget = target;
|
||||
CameraManager.Inst.ChangeInShipFollowAndLookAt(interactionTarget);
|
||||
|
||||
var targetPosition = interactionTarget.position;
|
||||
var playerPosition = transform.position;
|
||||
|
||||
var directionToTarget = (targetPosition - playerPosition).normalized;
|
||||
|
||||
// 캐릭터가 NPC의 왼쪽 또는 오른쪽에 있는지 확인합니다.
|
||||
var crossProduct = Vector3.Cross(directionToTarget, transform.forward).y;
|
||||
|
||||
Vector3 desiredPosition;
|
||||
float desiredScaleX; // 캐릭터의 방향을 나타냅니다.
|
||||
|
||||
if (crossProduct > 0) // 캐릭터가 NPC의 왼쪽에 있는 경우
|
||||
{
|
||||
desiredPosition = targetPosition + interactionTarget.right * 2f;
|
||||
desiredScaleX = 1f; // 오른쪽을 바라봅니다.
|
||||
}
|
||||
else // 캐릭터가 NPC의 오른쪽에 있는 경우
|
||||
{
|
||||
desiredPosition = targetPosition + interactionTarget.right * -2f;
|
||||
desiredScaleX = -1f; // 왼쪽을 바라봅니다.
|
||||
}
|
||||
|
||||
// 장애물 감지
|
||||
if (Physics.Raycast(playerPosition, (desiredPosition - playerPosition).normalized, Vector3.Distance(playerPosition, desiredPosition), LayerMask.GetMask("Obstacle")))
|
||||
{
|
||||
// 장애물이 감지되면, 반대쪽으로 이동
|
||||
desiredPosition = crossProduct > 0 ? targetPosition + interactionTarget.right * -2f : targetPosition + interactionTarget.right * 2f;
|
||||
desiredScaleX = -desiredScaleX; // 방향을 반전합니다.
|
||||
}
|
||||
|
||||
// 캐릭터를 원하는 위치와 방향으로 부드럽게 이동 및 회전
|
||||
StartCoroutine(MoveCharacterToPosition(desiredPosition, desiredScaleX));
|
||||
UiManager.Inst.InShipInteraction.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void StartConversation()
|
||||
{
|
||||
GameManager.Inst.IsConversation = true;
|
||||
if (interactionTarget != null)
|
||||
{
|
||||
GetComponent<ProximitySelector>().enabled = false;
|
||||
interactionTarget.GetComponent<DialogueSystemTrigger>().OnConversationStart(interactionTarget);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void EndInteraction()
|
||||
{
|
||||
GameManager.Inst.IsInteraction = false;
|
||||
CameraManager.Inst.RestoreInShipFollowAndLookAt();
|
||||
interactionTarget = null;
|
||||
UiManager.Inst.InShipInteraction.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void EndConversation()
|
||||
{
|
||||
GameManager.Inst.IsConversation = false;
|
||||
CameraManager.Inst.RestoreInShipFollowAndLookAt();
|
||||
GetComponent<ProximitySelector>().enabled = true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -34,6 +34,7 @@ namespace BlueWaterProject
|
||||
[field: SerializeField] public bool IsAssaultMode { get; set; }
|
||||
[field: SerializeField] public bool IsShipDeckMode { get; set; }
|
||||
[field: SerializeField] public bool IsConversation { get; set; }
|
||||
[field: SerializeField] public bool IsInteraction { get; set; }
|
||||
[field: SerializeField] public GlobalValue.PlayerMode CurrentPlayerMode { get; set; }
|
||||
|
||||
private void Init()
|
||||
|
@ -32,6 +32,7 @@ namespace BlueWaterProject
|
||||
|
||||
[Title("InteractionUI")]
|
||||
private Transform defaultInteraction;
|
||||
public Transform InShipInteraction { get; set; }
|
||||
|
||||
|
||||
private void Init()
|
||||
@ -49,6 +50,7 @@ namespace BlueWaterProject
|
||||
enemyMarker.sprite = DataManager.Inst.enemyMarker;
|
||||
|
||||
defaultInteraction = transform.Find("DefaultInteraction");
|
||||
InShipInteraction = transform.Find("InShipPlayerInteractionUI");
|
||||
}
|
||||
|
||||
protected override void OnAwake()
|
||||
|
@ -5964,7 +5964,7 @@ RectTransform:
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 1, y: 1}
|
||||
m_AnchoredPosition: {x: 0, y: 47.664093}
|
||||
m_AnchoredPosition: {x: 0, y: 48.4}
|
||||
m_SizeDelta: {x: 0, y: -172.9223}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &3853767788560671683
|
||||
|
Loading…
Reference in New Issue
Block a user