浏览代码

Code cleanup, refactored Anchors to be generic

/main
Ciro Continisio 3 年前
当前提交
313f8a7f
共有 11 个文件被更改,包括 46 次插入47 次删除
  1. 2
      UOP1_Project/Assets/Scripts/Audio/OrientListener.cs
  2. 2
      UOP1_Project/Assets/Scripts/Camera/CameraManager.cs
  3. 2
      UOP1_Project/Assets/Scripts/Characters/MovingCritterAttackController.cs
  4. 10
      UOP1_Project/Assets/Scripts/Characters/Protagonist.cs
  5. 2
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/ChasingTargetActionSO.cs
  6. 2
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/CritterFaceProtagonistSO.cs
  7. 2
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/NPCFaceProtagonistSO.cs
  8. 2
      UOP1_Project/Assets/Scripts/Events/ScriptableObjects/AudioCueEventChannelSO.cs
  9. 11
      UOP1_Project/Assets/Scripts/Gameplay/SpawnSystem.cs
  10. 34
      UOP1_Project/Assets/Scripts/RuntimeAnchors/RuntimeAnchorBase.cs
  11. 24
      UOP1_Project/Assets/Scripts/RuntimeAnchors/TransformAnchor.cs

2
UOP1_Project/Assets/Scripts/Audio/OrientListener.cs


void LateUpdate()
{
if(_cameraTransform.isSet)
transform.forward = _cameraTransform.Transform.forward;
transform.forward = _cameraTransform.Value.forward;
}
}

2
UOP1_Project/Assets/Scripts/Camera/CameraManager.cs


_frameObjectChannel.OnEventRaised += OnFrameObjectEvent;
_camShakeEvent.OnEventRaised += impulseSource.GenerateImpulse;
_cameraTransformAnchor.Transform = mainCamera.transform;
_cameraTransformAnchor.Value = mainCamera.transform;
}
private void OnDisable()

2
UOP1_Project/Assets/Scripts/Characters/MovingCritterAttackController.cs


// When the attack starts, the position targeted by the attack is determined and is not changed afterward
public void SetAttackTarget()
{
_propelTargetVector = (_playerTransform.Transform.position - transform.position) * _propelFactor / _propelDuration;
_propelTargetVector = (_playerTransform.Value.position - transform.position) * _propelFactor / _propelDuration;
}
// Trigger the propel movement during the attack

10
UOP1_Project/Assets/Scripts/Characters/Protagonist.cs


private void Update()
{
GroundCheck();
}
private void GroundCheck()
{
}
private void RecalculateMovement()

if (gameplayCameraTransform.isSet)
{
//Get the two axes from the camera and flatten them on the XZ plane
Vector3 cameraForward = gameplayCameraTransform.Transform.forward;
Vector3 cameraForward = gameplayCameraTransform.Value.forward;
Vector3 cameraRight = gameplayCameraTransform.Transform.right;
Vector3 cameraRight = gameplayCameraTransform.Value.right;
cameraRight.y = 0f;
//Use the two axes, modulated by the corresponding inputs, and construct the final vector

2
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/ChasingTargetActionSO.cs


[Tooltip("NPC chasing speed")]
[SerializeField] private float _chasingSpeed = default;
public Vector3 TargetPosition => _targetTransform.Transform.position;
public Vector3 TargetPosition => _targetTransform.Value.position;
public float ChasingSpeed => _chasingSpeed;
protected override StateAction CreateAction() => new ChasingTargetAction();

2
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/CritterFaceProtagonistSO.cs


{
if (_protagonist.isSet)
{
Vector3 relativePos = _protagonist.Transform.position - _actor.position;
Vector3 relativePos = _protagonist.Value.position - _actor.position;
relativePos.y = 0f; // Force rotation to be only on Y axis.
Quaternion rotation = Quaternion.LookRotation(relativePos);

2
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/NPCFaceProtagonistSO.cs


{
if (_protagonist.isSet)
{
Vector3 relativePos = _protagonist.Transform.position - _actor.position;
Vector3 relativePos = _protagonist.Value.position - _actor.position;
relativePos.y = 0f; // Force rotation to be only on Y axis.
Quaternion rotation = Quaternion.LookRotation(relativePos);

2
UOP1_Project/Assets/Scripts/Events/ScriptableObjects/AudioCueEventChannelSO.cs


}
else
{
Debug.LogWarning("An AudioCue play event was requested, but nobody picked it up. " +
Debug.LogWarning("An AudioCue play event was requested for " + audioCue.name +", but nobody picked it up. " +
"Check why there is no AudioManager already loaded, " +
"and make sure it's listening on this AudioCue Event channel.");
}

11
UOP1_Project/Assets/Scripts/Gameplay/SpawnSystem.cs


private Transform _defaultSpawnPoint;
[Header("Scene Ready Event")]
[SerializeField] private VoidEventChannelSO _OnSceneReady = default; //Raised when the scene is loaded and set active
[SerializeField] private VoidEventChannelSO _onSceneReady = default; //Raised by SceneLoader when the scene is set to active
private void Awake()
{

private void OnEnable()
{
_OnSceneReady.OnEventRaised += SpawnPlayer;
_onSceneReady.OnEventRaised += SpawnPlayer;
_OnSceneReady.OnEventRaised -= SpawnPlayer;
_onSceneReady.OnEventRaised -= SpawnPlayer;
}
private Transform GetSpawnLocation()

private Protagonist InstantiatePlayer(Protagonist playerPrefab, Transform spawnLocation)
{
if (playerPrefab == null)
throw new Exception("Player Prefab can't be null.");
Protagonist playerInstance = Instantiate(playerPrefab, spawnLocation.position, spawnLocation.rotation);
return playerInstance;

Protagonist playerInstance = InstantiatePlayer(_playerPrefab, GetSpawnLocation());
_playerInstantiatedChannel.RaiseEvent(playerInstance.transform); // The CameraSystem will pick this up to frame the player
_playerTransformAnchor.Transform = playerInstance.transform;
_playerTransformAnchor.Value = playerInstance.transform;
//TODO: Probably move this to the GameManager once it's up and running
_inputReader.EnableGameplayInput();

34
UOP1_Project/Assets/Scripts/RuntimeAnchors/RuntimeAnchorBase.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class RuntimeAnchorBase : ScriptableObject
public class RuntimeAnchorBase<T> : DescriptionBaseSO where T : UnityEngine.Object
[TextArea] public string description;
}
[HideInInspector] public bool isSet = false; // Any script can check if the transform is null before using it, by just checking this bool
public UnityAction AnchorProvided;
private T _value;
public T Value
{
get { return _value; }
set
{
_value = value;
isSet = _value != null;
//Notify whoever is waiting for this anchor
if(AnchorProvided != null)
{
AnchorProvided.Invoke();
Debug.Log(AnchorProvided.GetInvocationList()[0].Method.Name);
}
}
}
public void OnDisable()
{
_value = null;
isSet = false;
}
}

24
UOP1_Project/Assets/Scripts/RuntimeAnchors/TransformAnchor.cs


using UnityEngine;
using System.Collections;
using UnityEngine.Events;
public class TransformAnchor : RuntimeAnchorBase
{
[HideInInspector] public bool isSet = false; // Any script can check if the transform is null before using it, by just checking this bool
private Transform _transform;
public Transform Transform
{
get { return _transform; }
set
{
_transform = value;
isSet = _transform != null;
}
}
public void OnDisable()
{
_transform = null;
isSet = false;
}
}
public class TransformAnchor : RuntimeAnchorBase<Transform>{ }
正在加载...
取消
保存