player can enter the door

This commit is contained in:
Vladimir Koshevarov
2023-03-06 18:54:13 +02:00
parent 667c9901b6
commit ac5dce3507
35 changed files with 29063 additions and 1193 deletions
+9
View File
@@ -0,0 +1,9 @@
using UnityEngine;
public class DontDestroy : MonoBehaviour
{
private void Awake()
{
DontDestroyOnLoad(gameObject);
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 59acbdefe19456b4093c8081fc195458
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -3,7 +3,7 @@
public class BaseInteractableObject : MonoBehaviour
{
[SerializeField]
public Transform _playerArrivePoint;
public Transform _interactionPoint;
public virtual void Interact(Player player)
{
@@ -21,7 +21,7 @@ public class CashierDesk : BaseInteractableObject
finalPrice += item.Price;
}
var transform = Instantiate(_containerSO.prefab, _playerArrivePoint);
var transform = Instantiate(_containerSO.prefab, _interactionPoint);
var containerItem = transform.GetComponent<ContainerItem>();
if (containerItem == null)
{
@@ -0,0 +1,31 @@
using UnityEngine;
using UnityEngine.SceneManagement;
public class Door : BaseInteractableObject
{
[SerializeField]
private string _scene;
[SerializeField]
private string _exitName;
[SerializeField]
private string _enterName;
private void Start()
{
if (PlayerPrefs.GetString("lastExitName") == _enterName)
{
print($"Player came from to {_scene}");
Player.Instance.SetPosition(_interactionPoint.position);
}
}
public override void Interact(Player player)
{
print($"Player go to {_scene}");
if (!string.IsNullOrEmpty(_exitName))
{
PlayerPrefs.SetString("lastExitName", _exitName);
}
SceneManager.LoadScene(_scene);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 024987a58bcb1394a97473f1d70d0c47
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -11,7 +11,7 @@ public class ShopingContainer : BaseInteractableObject
{
if (!player.IsHoldContainerItem())
{
var transform = Instantiate(_containerSO.prefab, _playerArrivePoint);
var transform = Instantiate(_containerSO.prefab, _interactionPoint);
var containerItem = transform.GetComponent<ContainerItem>();
if (containerItem == null)
{
+2 -1
View File
@@ -38,7 +38,8 @@ public class MouseInputManager : MonoBehaviour
OnSelectedObjectChanged?.Invoke(this, new OnSelectedObjectChangedEventArgs() { SelectedObject = baseObject });
if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
{
_waypointVisual.SetWaypoint(baseObject._playerArrivePoint.position);
print($"Go to interaction point {baseObject._interactionPoint.position}");
_waypointVisual.SetWaypoint(baseObject._interactionPoint.position);
Player.Instance.AddTask(new PlayerTasks(Tasks.Interact, baseObject));
}
}
+19 -16
View File
@@ -22,7 +22,6 @@ public class Player : MonoBehaviour
private Transform _holdPoint;
private AnimationStates _currentAnimation;
private Vector3 _groundDeltaPosition;
public Dictionary<StatsId, Stat> Stats;
public IWorkPlace WorkPlace { get; set; }
@@ -36,17 +35,21 @@ public class Player : MonoBehaviour
private void Awake()
{
if (Instance != null)
{
Destroy(gameObject);
Debug.Log("There's more than one player instance");
return;
}
PlayerPrefs.SetString("lastExitName", string.Empty);
Instance = this;
DontDestroyOnLoad(gameObject);
}
private void Start()
{
TimeManager.OnMinuteChanged += UpdateStatsByClock;
_animator.applyRootMotion = true;
_navAgent.updatePosition = false;
Stats = PlayerStats.CreateInitialStats();
}
@@ -75,7 +78,7 @@ public class Player : MonoBehaviour
switch (_currentTask.Task)
{
case Tasks.Rotate:
_currentTask.UpdateStatus(Rotate(_currentTask.TagretObject._playerArrivePoint.forward));
_currentTask.UpdateStatus(Rotate(_currentTask.TagretObject._interactionPoint.forward));
break;
case Tasks.Move:
if (_currentAnimation == AnimationStates.Sitting)
@@ -83,11 +86,11 @@ public class Player : MonoBehaviour
SetPlayerAnimation(AnimationStates.Standing);
return;
}
_navAgent.SetDestination(_currentTask.TagretObject._playerArrivePoint.position);
_navAgent.SetDestination(_currentTask.TagretObject._interactionPoint.position);
_currentTask.UpdateStatus(MoveToPoint());
break;
case Tasks.Interact:
if (IsPathComplete(_currentTask.TagretObject._playerArrivePoint.position))
if (IsPathComplete(_currentTask.TagretObject._interactionPoint.position))
_currentTask.UpdateStatus(InteractWithObject(_currentTask.TagretObject));
else
{
@@ -101,17 +104,21 @@ public class Player : MonoBehaviour
}
}
public void SetPosition(Vector3 desiredPosition)
{
_navAgent.Warp(desiredPosition);
_navAgent.updatePosition = false;
}
private TaskStatus MoveToPoint()
{
_navAgent.isStopped = false;
SetPlayerAnimation(AnimationStates.Walking);
var worldDeltaPosition = _navAgent.nextPosition - transform.position;
_groundDeltaPosition.x = Vector3.Dot(transform.right, worldDeltaPosition);
_groundDeltaPosition.y = Vector3.Dot(transform.forward, worldDeltaPosition);
Vector2 velocity = (Time.deltaTime > 1e-5f) ? _groundDeltaPosition / Time.deltaTime : Vector2.zero;
_animator.SetFloat(WALK_VELOCITY, velocity.y);
//transform.position = Vector3.MoveTowards(_navAgent.transform.position, _navAgent.pathEndPosition, _navAgent.speed * Time.deltaTime);
// transform.position = _animator.(_navAgent.pathEndPosition);
_animator.SetFloat(WALK_VELOCITY, _navAgent.velocity.magnitude);
return IsPathComplete(_navAgent.destination) ? TaskStatus.Complete : TaskStatus.InProgress;
}
@@ -126,6 +133,7 @@ public class Player : MonoBehaviour
if (!_navAgent.hasPath || _navAgent.velocity.sqrMagnitude < 0.2f)
{
SetPlayerAnimation(AnimationStates.Idle);
_navAgent.isStopped = true;
return true;
}
}
@@ -176,11 +184,6 @@ public class Player : MonoBehaviour
return false;
}
private void OnAnimatorMove()
{
transform.position = _navAgent.nextPosition;
}
public void AddTask(PlayerTasks task)
{
_tasks.Enqueue(task);
+17
View File
@@ -0,0 +1,17 @@
using UnityEngine;
using UnityEngine.AI;
public class RootMotion : MonoBehaviour
{
private NavMeshAgent _navMeshAgent;
private void Start()
{
_navMeshAgent = GetComponentInParent<NavMeshAgent>();
}
private void OnAnimatorMove()
{
transform.parent.position = _navMeshAgent.nextPosition;
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cf9ddd6d77ff9a7479edaeb2c8ae1078
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
-57
View File
@@ -1,19 +1,9 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SpawnManager : MonoBehaviour
{
public static SpawnManager Instance { get; private set; }
public GameObject DefaultPlayer;
private Transform _defaultPoint;
private Vector3 _spawnLocation;
private bool setPoint;
private void Awake()
{
if (Instance == null)
@@ -23,53 +13,6 @@ public class SpawnManager : MonoBehaviour
}
else
Destroy(gameObject);
}
private void Start()
{
SceneManager.sceneLoaded += SceneLoaded;
}
private void SetSpawn(Vector3 spawn)
{
_spawnLocation = spawn;
setPoint = true;
}
private void SceneLoaded(Scene arg0, LoadSceneMode arg1)
{
print(_spawnLocation);
if(arg0.buildIndex > 1)
{
var temp = GameObject.Find("SpawnHere").transform;
DefaultPlayer.transform.position = temp.position;
//Instantiate(DefaultPlayer, temp.position, Quaternion.identity);
}
if(arg0.buildIndex == 1)
{
if (!setPoint)
{
print("no default location set");
SpawnAtStart();
}
else
SpawnAtSetLocation();
}
}
private void SpawnAtSetLocation()
{
print("Spawn at set location");
DefaultPlayer.transform.position = _spawnLocation;
setPoint = false;
}
private void SpawnAtStart()
{
_defaultPoint = GameObject.Find("DefaultPoint").transform;
DefaultPlayer.transform.position = _defaultPoint.position;
}
}
+1 -4
View File
@@ -1,13 +1,10 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Startup : MonoBehaviour
{
// Start is called before the first frame update
private void Start()
{
SceneManager.LoadScene(1);
// SceneManager.LoadScene(1);
}
}
+1 -3
View File
@@ -4,12 +4,10 @@ public class WaypointVisual : BaseInteractableObject
{
[SerializeField]
private ParticleSystem _particleSystem;
[SerializeField]
private Transform _wayPoint;
public void SetWaypoint(Vector3 position)
{
_wayPoint.position = position;
_interactionPoint.position = position;
_particleSystem.Play();
}
}