refactor
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraPlayerFollow : MonoBehaviour
|
||||
{
|
||||
private Vector3 _cameraOffset;
|
||||
|
||||
private Transform _obstruction;
|
||||
|
||||
[SerializeField]
|
||||
[Range(0.01f, 1.0f)]
|
||||
private float _smoothFactor = 0.5f;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
_obstruction = null;
|
||||
_cameraOffset = transform.position - Player.Instance.transform.position;
|
||||
// .LookAt(_player);
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
Vector3 newPosition = Player.Instance.transform.position + _cameraOffset;
|
||||
|
||||
transform.position = Vector3.Slerp(transform.position, newPosition, _smoothFactor);
|
||||
ViewObstructed();
|
||||
}
|
||||
|
||||
private void ViewObstructed()
|
||||
{
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(transform.position, Player.Instance.transform.position - transform.position, out hit, 3.5f))
|
||||
{
|
||||
if (hit.collider.gameObject.tag != "Player")
|
||||
{
|
||||
_obstruction = hit.transform;
|
||||
_obstruction.gameObject.GetComponent<MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.ShadowsOnly;
|
||||
}
|
||||
}
|
||||
else if (_obstruction != null)
|
||||
{
|
||||
_obstruction.gameObject.GetComponent<MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
|
||||
_obstruction = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e81c6202b4f1294cb16972d7a25eeb8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,30 @@
|
||||
using Cinemachine;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraSystem : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private CinemachineVirtualCamera _camera;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
//transform.position = Player.Instance.transform.position;
|
||||
_camera.LookAt = Player.Instance.transform;
|
||||
_camera.Follow = Player.Instance.transform;
|
||||
}
|
||||
|
||||
//private void Update()
|
||||
//{
|
||||
// Vector3 inputDir = Vector3.zero;
|
||||
|
||||
// if (Input.GetKey(KeyCode.W)) inputDir.z = +1f;
|
||||
// if (Input.GetKey(KeyCode.S)) inputDir.z = -1f;
|
||||
// if (Input.GetKey(KeyCode.A)) inputDir.x = -1f;
|
||||
// if (Input.GetKey(KeyCode.D)) inputDir.x = +1f;
|
||||
|
||||
// Vector3 moveDir = transform.forward * inputDir.z + transform.right * inputDir.x;
|
||||
|
||||
// //if (moveDir == Vector3.zero && Player.Instance.stat) transform.position = Player.Instance.transform.position;
|
||||
// transform.position += moveDir * _moveSpeed * Time.deltaTime;
|
||||
//}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b80f4c0c91e48e418ea436255074f8e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class DontDestroy : MonoBehaviour
|
||||
{
|
||||
public static DontDestroy Instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
else
|
||||
Destroy(gameObject);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7675785cd5331f4bb7a2aa78bf300fc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class LookAtCamera : MonoBehaviour
|
||||
{
|
||||
private void LateUpdate()
|
||||
{
|
||||
transform.LookAt(Camera.main.transform);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a74888cae6f9f14ba0d76cfc5c0198a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class MouseInputManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private LayerMask _selectableLayerMask;
|
||||
[SerializeField]
|
||||
private LayerMask _walkableLayerMask;
|
||||
[SerializeField]
|
||||
private WaypointVisual _waypointVisual;
|
||||
|
||||
|
||||
public static event EventHandler<OnSelectedObjectChangedEventArgs> OnSelectedObjectChanged;
|
||||
|
||||
public static MouseInputManager Instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null)
|
||||
{
|
||||
Debug.Log("There's more than one mouse Input instance");
|
||||
}
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
if (!EventSystem.current.IsPointerOverGameObject() && Physics.Raycast(ray, out var mouseRaycastHit, 100f, _selectableLayerMask))
|
||||
{
|
||||
mouseRaycastHit.transform.TryGetComponent(out BaseInteractableObject baseObject);
|
||||
if (baseObject != null)
|
||||
{
|
||||
OnSelectedObjectChanged?.Invoke(this, new OnSelectedObjectChangedEventArgs() { SelectedObject = baseObject });
|
||||
if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
|
||||
{
|
||||
print($"Go to interaction point {baseObject._interactionPoint.position}");
|
||||
_waypointVisual.SetWaypoint(baseObject._interactionPoint.position);
|
||||
Player.Instance.AddTask(new PlayerTasks(Tasks.Interact, baseObject));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
OnSelectedObjectChanged?.Invoke(this, new OnSelectedObjectChangedEventArgs() { SelectedObject = null });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
OnSelectedObjectChanged?.Invoke(this, new OnSelectedObjectChangedEventArgs() { SelectedObject = null });
|
||||
if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
|
||||
{
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, 100f, _walkableLayerMask))
|
||||
{
|
||||
_waypointVisual.SetWaypoint(hit.point);
|
||||
Player.Instance.AddTask(new PlayerTasks(Tasks.Move, _waypointVisual));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dcf28888027a4ab4ba2df2a33b89899e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,72 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MovementPath : MonoBehaviour
|
||||
{
|
||||
public enum PathTypes { lenear, loop }
|
||||
public PathTypes PathType;
|
||||
|
||||
public int movementDirection = 1;
|
||||
public int movingTo = 0;
|
||||
public Transform[] PathElements;
|
||||
|
||||
public void OnDrawGizmos()
|
||||
{
|
||||
if (PathElements == null || PathElements.Length < 2)
|
||||
return;
|
||||
|
||||
for (int pointCount = 1; pointCount < PathElements.Length; pointCount++)
|
||||
{
|
||||
Gizmos.DrawLine(PathElements[pointCount - 1].position, PathElements[pointCount].position);
|
||||
}
|
||||
if (PathType == PathTypes.loop)
|
||||
{
|
||||
Gizmos.DrawLine(PathElements[0].position, PathElements[PathElements.Length - 1].position);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<Transform> GetNextPathPoint()
|
||||
{
|
||||
Debug.Log("GetNextPathPoint");
|
||||
if (PathElements == null || PathElements.Length < 2)
|
||||
{
|
||||
Debug.Log("not enough path elements");
|
||||
yield break;
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
yield return PathElements[movingTo];
|
||||
|
||||
if (PathElements.Length == 1)
|
||||
{
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (PathType == PathTypes.lenear)
|
||||
{
|
||||
if (movingTo <= 0)
|
||||
{
|
||||
movementDirection = 1;
|
||||
}
|
||||
else if (movingTo >= PathElements.Length - 1)
|
||||
{
|
||||
movementDirection = -1;
|
||||
}
|
||||
}
|
||||
movingTo = movingTo + movementDirection;
|
||||
|
||||
if (PathType == PathTypes.loop)
|
||||
{
|
||||
if (movingTo >= PathElements.Length)
|
||||
{
|
||||
movingTo = 0;
|
||||
}
|
||||
if (movingTo < 0)
|
||||
{
|
||||
movingTo = PathElements.Length - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7819b8e1ad3797d4da4153a0bfd3ebac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,38 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class SceneManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private LevelChanger _levelChanger;
|
||||
|
||||
public static SceneManager Instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
else
|
||||
Destroy(gameObject);
|
||||
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_levelChanger.gameObject.SetActive(true);
|
||||
_levelChanger.FadeIn(OnSceneChanged);
|
||||
}
|
||||
|
||||
public void ChangeScene(string sceneName)
|
||||
{
|
||||
_levelChanger.gameObject.SetActive(true);
|
||||
_levelChanger.FadeToLevel(sceneName, OnSceneChanged);
|
||||
|
||||
}
|
||||
private void OnSceneChanged()
|
||||
{
|
||||
_levelChanger.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fbda389b6a6aec14997efc4be22664e7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,138 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class TimeManager : MonoBehaviour
|
||||
{
|
||||
public static TimeManager Instance { get; private set; }
|
||||
|
||||
private const float MINUTE_TIME = 1f;
|
||||
private const float FF_TIME = 0.003f;
|
||||
|
||||
public Action OnMinuteChanged;
|
||||
public Action OnFastForwardEnd;
|
||||
|
||||
[SerializeField]
|
||||
private TimeSpan _startTime = new TimeSpan(1, 08, 00, 00);
|
||||
|
||||
//[SerializeField]
|
||||
//private Light _sunLight;
|
||||
|
||||
[SerializeField]
|
||||
private float _sunriseHour;
|
||||
[SerializeField]
|
||||
private float _sunsetHour;
|
||||
|
||||
private TimeSpan _sunriseTime;
|
||||
private TimeSpan _sunsetTime;
|
||||
|
||||
private float _timer;
|
||||
private float _sunInitialIntensity;
|
||||
|
||||
private float _minuteToRealTime;
|
||||
|
||||
private static TimeSpan _currentTime;
|
||||
public static TimeSpan CurrentTime => _currentTime;
|
||||
|
||||
|
||||
private TimeSpan _timeToStop;
|
||||
|
||||
private bool _isPause = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
else
|
||||
Destroy(gameObject);
|
||||
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
// _sunInitialIntensity = _sunLight.intensity;
|
||||
_timer = _minuteToRealTime;
|
||||
_currentTime = TimeSpan.Zero + _startTime;
|
||||
_timeToStop = _currentTime;
|
||||
_sunriseTime = TimeSpan.FromHours(_sunriseHour);
|
||||
_sunsetTime = TimeSpan.FromHours(_sunsetHour);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (!_isPause)
|
||||
{
|
||||
UpdateTime();
|
||||
RotateSun();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTime()
|
||||
{
|
||||
_timer -= Time.deltaTime;
|
||||
if (_timer <= 0)
|
||||
{
|
||||
_currentTime = _currentTime.Add(TimeSpan.FromMinutes(1));
|
||||
OnMinuteChanged?.Invoke();
|
||||
|
||||
if (_currentTime.TotalMinutes >= _timeToStop.TotalMinutes)
|
||||
{
|
||||
_minuteToRealTime = MINUTE_TIME;
|
||||
_timeToStop = TimeSpan.MaxValue;
|
||||
OnFastForwardEnd?.Invoke();
|
||||
}
|
||||
_timer = _minuteToRealTime;
|
||||
}
|
||||
}
|
||||
|
||||
public void FastForward(TimeSpan timeToStop)
|
||||
{
|
||||
_isPause = false;
|
||||
_timeToStop = _currentTime.Add(timeToStop);
|
||||
_minuteToRealTime = FF_TIME;
|
||||
}
|
||||
|
||||
private void RotateSun()
|
||||
{
|
||||
float intensityMultiplier = 1;
|
||||
float timeofDay = (float)(CurrentTime.TotalDays - CurrentTime.Days);
|
||||
//_sunLight.transform.localRotation = Quaternion.Euler((timeofDay * 360f) - 90, 170, 0);
|
||||
if (timeofDay > _sunriseTime.TotalDays && timeofDay < _sunsetTime.TotalDays)
|
||||
{
|
||||
if (timeofDay <= _sunsetTime.TotalDays)
|
||||
intensityMultiplier = Mathf.Clamp01((timeofDay - ((float)_sunsetTime.TotalDays - 0.02f)) * (1 / 0.02f));
|
||||
if (timeofDay >= _sunriseTime.TotalDays)
|
||||
intensityMultiplier = Mathf.Clamp01(1 - (timeofDay - ((float)_sunriseTime.TotalDays - 0.02f) * (1 / 0.02f)));
|
||||
}
|
||||
else
|
||||
{
|
||||
intensityMultiplier = 0;
|
||||
}
|
||||
// _sunLight.intensity = _sunInitialIntensity * intensityMultiplier;
|
||||
}
|
||||
|
||||
private TimeSpan CalculateTimeDifference(TimeSpan from, TimeSpan to)
|
||||
{
|
||||
TimeSpan diff = to - from;
|
||||
if (diff.TotalSeconds < 0)
|
||||
{
|
||||
diff += TimeSpan.FromHours(24);
|
||||
}
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
_isPause = true;
|
||||
}
|
||||
|
||||
internal void Resume()
|
||||
{
|
||||
_isPause = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00bbfcf5f7cdbb543bd6e09cd773f199
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class WaypointVisual : BaseInteractableObject
|
||||
{
|
||||
[SerializeField]
|
||||
private ParticleSystem _particleSystem;
|
||||
|
||||
public void SetWaypoint(Vector3 position)
|
||||
{
|
||||
_interactionPoint.position = position;
|
||||
_particleSystem.Play();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a49cd67cb3095a74d9b654426bc046b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user