refactor: add namespace for files in RD.Camera

This commit is contained in:
alexiscatnip
2022-08-06 02:43:06 +08:00
committed by alexiscatnip
parent 2533253ee2
commit 61174f22e8
3 changed files with 104 additions and 105 deletions
+9 -10
View File
@@ -1,16 +1,15 @@
using Raindrop;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraIdentifier : MonoBehaviour
namespace Raindrop.Camera
{
public CameraType type;
public enum CameraType
public class CameraIdentifier : MonoBehaviour
{
Main,
Minimap
public CameraType type;
public enum CameraType
{
Main,
Minimap
}
}
}
+70 -69
View File
@@ -1,95 +1,96 @@
using System;
using System.Collections;
using System.Collections.Generic;
using JetBrains.Annotations;
using OpenMetaverse;
using UnityEngine;
public class CamerasManager : MonoBehaviour
namespace Raindrop.Camera
{
#region Monobehavior Singleton stuff
private static CamerasManager _instance;
public static CamerasManager Instance
public class CamerasManager : MonoBehaviour
{
get
#region Monobehavior Singleton
private static CamerasManager _instance;
public static CamerasManager Instance
{
if (_instance == null)
get
{
Debug.LogError("you forget to attach the singleton CamerasManager script.");
if (_instance == null)
{
Debug.LogError("you forget to attach the singleton CamerasManager script.");
}
return _instance;
}
}
void Awake()
{
_instance = this;
DontDestroyOnLoad(this.gameObject);
}
#endregion
private Dictionary<CameraIdentifier.CameraType, UnityEngine.Camera> cameras =
new Dictionary<CameraIdentifier.CameraType, UnityEngine.Camera>();
public CameraIdentifier.CameraType currentCam;
//private CameraIdentifier.CameraType CurrentCamType;
public bool Ready { get; set; } = false;
private void Start()
{
//get all cameras.
foreach(Transform child in transform)
{
RegisterCamera(child.gameObject);
}
return _instance;
}
}
void Awake()
{
_instance = this;
DontDestroyOnLoad(this.gameObject);
}
#endregion
//get ready for work.
Ready = true;
private Dictionary<CameraIdentifier.CameraType, Camera> cameras =
new Dictionary<CameraIdentifier.CameraType, Camera>();
public CameraIdentifier.CameraType currentCam;
//private CameraIdentifier.CameraType CurrentCamType;
public bool Ready { get; set; } = false;
private void Start()
{
//get all cameras.
foreach(Transform child in transform)
{
RegisterCamera(child.gameObject);
ActivateCamera(currentCam);
}
//get ready for work.
Ready = true;
ActivateCamera(currentCam);
}
private void DeactivateAllCameras()
{
foreach(var cam in cameras)
private void DeactivateAllCameras()
{
cam.Value.enabled = false;
foreach(var cam in cameras)
{
cam.Value.enabled = false;
}
}
}
private void RegisterCamera(GameObject Camera)
{
Camera cam = Camera.GetComponent<Camera>();
var type = Camera.GetComponent<CameraIdentifier>();
if (cam && type)
private void RegisterCamera(GameObject Camera)
{
cameras.Add(type.type, cam);
UnityEngine.Camera cam = Camera.GetComponent<UnityEngine.Camera>();
var type = Camera.GetComponent<CameraIdentifier>();
if (cam && type)
{
cameras.Add(type.type, cam);
}
}
}
public void ActivateCamera(CameraIdentifier.CameraType type)
{
if (!Ready)
return;
public void ActivateCamera(CameraIdentifier.CameraType type)
{
if (!Ready)
return;
try
{
currentCam = type;
DeactivateAllCameras();
cameras[currentCam].enabled = true;
return;
}
catch (Exception e)
{
OpenMetaverse.Logger.Log("camera not available: " + type.ToString()
, Helpers.LogLevel.Error);
try
{
currentCam = type;
DeactivateAllCameras();
cameras[currentCam].enabled = true;
return;
}
catch (Exception e)
{
OpenMetaverse.Logger.Log("camera not available: " + type.ToString()
, Helpers.LogLevel.Error);
return;
}
return;
}
return;
}
}
@@ -1,39 +1,38 @@
using Raindrop;
using Raindrop.Presenters;
using System;
using System.Collections;
using System.Collections.Generic;
using Plugins.CommonDependencies;
using Raindrop.Presenters;
using UnityEngine;
//assign the target for the cinemachine freelook camera to look at.
public class RaindropCinemachineAssignLookAtAvatar : MonoBehaviour
namespace Raindrop.Camera
{
private RaindropInstance instance { get { return ServiceLocator.Instance.Get<RaindropInstance>(); } }
//private RaindropNetcom netcom { get { return instance.Netcom; } }
bool Active => instance.Client.Network.Connected;
public class RaindropCinemachineAssignLookAtAvatar : MonoBehaviour
{
private RaindropInstance instance { get { return ServiceLocator.Instance.Get<RaindropInstance>(); } }
//private RaindropNetcom netcom { get { return instance.Netcom; } }
bool Active => instance.Client.Network.Connected;
public AgentPresenter agents;
public Cinemachine.CinemachineFreeLook cinemachine;
private void Update()
{
TrySetTarget();
}
public void TrySetTarget()
{
if (Active)
public AgentPresenter agents;
public Cinemachine.CinemachineFreeLook cinemachine;
private void Update()
{
if (agents.agentReference != null) //todo: ok we should do a event driven way instead
TrySetTarget();
}
public void TrySetTarget()
{
if (Active)
{
SetCinemachineTarget(agents.agentReference);
if (agents.agentReference != null) //todo: ok we should do a event driven way instead
{
SetCinemachineTarget(agents.agentReference);
}
}
}
}
private void SetCinemachineTarget(GameObject agentReference)
{
cinemachine.LookAt = agentReference.transform;
cinemachine.Follow = agentReference.transform;
private void SetCinemachineTarget(GameObject agentReference)
{
cinemachine.LookAt = agentReference.transform;
cinemachine.Follow = agentReference.transform;
}
}
}