Created
May 9, 2016 15:28
-
-
Save mattak/b49bb8066f285123f963703c9f33a060 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
namespace App | |
{ | |
public class CameraFinder : MonoBehaviour | |
{ | |
public Camera DisposeCamera; | |
private Canvas _canvas; | |
// Use this for initialization | |
void Start() | |
{ | |
this._canvas = this.GetComponent<Canvas>(); | |
if (Camera.main != null | |
&& this.DisposeCamera != null | |
&& !System.Object.ReferenceEquals(this.DisposeCamera, Camera.main)) | |
{ | |
this._canvas.worldCamera = Camera.main; | |
Destroy(this.DisposeCamera.gameObject); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine.SceneManagement; | |
namespace App | |
{ | |
public class SceneManager : SingletonMonoBehaviour<SceneManager> | |
{ | |
public void Replace(string name) | |
{ | |
UnityEngine.SceneManagement.SceneManager.LoadScene(name, LoadSceneMode.Single); | |
} | |
public void Hover(string name) | |
{ | |
if (!UnityEngine.SceneManagement.SceneManager.GetSceneByName(name).isLoaded) | |
{ | |
UnityEngine.SceneManagement.SceneManager.LoadScene(name, LoadSceneMode.Additive); | |
} | |
} | |
public void Dispose(string name) | |
{ | |
if (UnityEngine.SceneManagement.SceneManager.GetSceneByName(name).isLoaded) | |
{ | |
UnityEngine.SceneManagement.SceneManager.UnloadScene(name); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
namespace App | |
{ | |
public class SingletonMonoBehaviour<T> : MonoBehaviour where T : SingletonMonoBehaviour<T> | |
{ | |
protected static T instance; | |
public static T Instance | |
{ | |
get | |
{ | |
if (instance == null) | |
{ | |
instance = (T) FindObjectOfType(typeof(T)); | |
if (instance == null) | |
{ | |
Debug.LogWarning(typeof(T) + "is nothing"); | |
} | |
} | |
return instance; | |
} | |
} | |
protected void Awake() | |
{ | |
CheckInstance(); | |
} | |
protected bool CheckInstance() | |
{ | |
if (instance == null) | |
{ | |
instance = (T) this; | |
return true; | |
} | |
else if (Instance == this) | |
{ | |
return true; | |
} | |
Destroy(this); | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment