-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 magicjar | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# com.agraris.core | ||
Agraris tools core components. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "Agraris.Tools.Core" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using UnityEngine; | ||
|
||
namespace Agraris.Tools.Core | ||
{ | ||
/// <summary> | ||
/// Persistent singleton. | ||
/// </summary> | ||
public class PersistentSingleton<T> : MonoBehaviour where T : Component | ||
{ | ||
protected static T _instance; | ||
|
||
/// <summary> | ||
/// The singleton instance. | ||
/// </summary> | ||
public static T Instance | ||
{ | ||
get | ||
{ | ||
if (_instance == null) | ||
{ | ||
GameObject obj = new GameObject(); | ||
_instance = obj.AddComponent<T>(); | ||
} | ||
return _instance; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// On awake, we check if there's already a copy of the object in the scene. If there's one, we destroy it. | ||
/// </summary> | ||
protected virtual void Awake() | ||
{ | ||
if (_instance != null) | ||
{ | ||
//there is already an instance: | ||
Destroy(gameObject); | ||
return; | ||
} | ||
|
||
//If I am the first instance, make me immortal | ||
_instance = this as T; | ||
DontDestroyOnLoad(transform.gameObject); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using UnityEngine; | ||
|
||
namespace Agraris.Tools.Core | ||
{ | ||
/// <summary> | ||
/// Singleton pattern. | ||
/// </summary> | ||
public class Singleton<T> : MonoBehaviour where T : Component | ||
{ | ||
protected static T _instance; | ||
|
||
/// <summary> | ||
/// The singleton instance. | ||
/// </summary> | ||
public static T Instance | ||
{ | ||
get | ||
{ | ||
if (_instance == null) | ||
{ | ||
GameObject obj = new GameObject(); | ||
_instance = obj.AddComponent<T>(); | ||
} | ||
return _instance; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// On awake, we check if there's already a copy of the object in the scene. If there's one, we destroy it. | ||
/// </summary> | ||
protected virtual void Awake() | ||
{ | ||
if (_instance != null) | ||
{ | ||
//there is already an instance: | ||
Destroy(gameObject); | ||
return; | ||
} | ||
|
||
_instance = this as T; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "com.agraris.core", | ||
"version": "1.0.0", | ||
"displayName": "Agraris Core", | ||
"description": "Agraris tools core components.", | ||
"unity": "2020.3", | ||
"keywords": [ | ||
"utility", | ||
"tool", | ||
"unity", | ||
"singleton" | ||
], | ||
"homepage": "https://agraris.github.io/", | ||
"bugs": { | ||
"url": "https://github.com//issues", | ||
"email": "[email protected]" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "" | ||
}, | ||
"license": "MIT", | ||
"author": { | ||
"name": "Agraris Entertainment" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.