mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
fix(PlayerCamera): Improved cleanup
- avoids error in editor
This commit is contained in:
parent
bb97db4eaa
commit
e9a8e02a40
@ -19,11 +19,6 @@ void Awake()
|
||||
mainCam = Camera.main;
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
//Debug.Log("PlayerCamera.OnDisable");
|
||||
}
|
||||
|
||||
public override void OnStartLocalPlayer()
|
||||
{
|
||||
if (mainCam != null)
|
||||
@ -38,16 +33,46 @@ public override void OnStartLocalPlayer()
|
||||
Debug.LogWarning("PlayerCamera: Could not find a camera in scene with 'MainCamera' tag.");
|
||||
}
|
||||
|
||||
void OnApplicationQuit()
|
||||
{
|
||||
//Debug.Log("PlayerCamera.OnApplicationQuit");
|
||||
ReleaseCamera();
|
||||
}
|
||||
|
||||
public override void OnStopLocalPlayer()
|
||||
{
|
||||
//Debug.Log("PlayerCamera.OnStopLocalPlayer");
|
||||
ReleaseCamera();
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
//Debug.Log("PlayerCamera.OnDisable");
|
||||
ReleaseCamera();
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
//Debug.Log("PlayerCamera.OnDestroy");
|
||||
ReleaseCamera();
|
||||
}
|
||||
|
||||
void ReleaseCamera()
|
||||
{
|
||||
if (mainCam != null && mainCam.transform.parent == transform)
|
||||
{
|
||||
//Debug.Log("PlayerCamera.ReleaseCamera");
|
||||
|
||||
mainCam.transform.SetParent(null);
|
||||
SceneManager.MoveGameObjectToScene(mainCam.gameObject, SceneManager.GetActiveScene());
|
||||
mainCam.orthographic = true;
|
||||
mainCam.orthographicSize = 15f;
|
||||
mainCam.transform.localPosition = new Vector3(0f, 70f, 0f);
|
||||
mainCam.transform.localEulerAngles = new Vector3(90f, 0f, 0f);
|
||||
|
||||
if (mainCam.gameObject.scene != SceneManager.GetActiveScene())
|
||||
SceneManager.MoveGameObjectToScene(mainCam.gameObject, SceneManager.GetActiveScene());
|
||||
|
||||
mainCam = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user