Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
magicjar committed Apr 3, 2021
0 parents commit 83482e2
Show file tree
Hide file tree
Showing 15 changed files with 208 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
21 changes: 21 additions & 0 deletions LICENSE
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.
7 changes: 7 additions & 0 deletions LICENSE.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# com.agraris.core
Agraris tools core components.
7 changes: 7 additions & 0 deletions README.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Runtime.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Runtime/Agraris.Tools.Core.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Agraris.Tools.Core"
}
7 changes: 7 additions & 0 deletions Runtime/Agraris.Tools.Core.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Runtime/Singletons.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions Runtime/Singletons/PresistentSingleton.cs
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);
}
}
}
11 changes: 11 additions & 0 deletions Runtime/Singletons/PresistentSingleton.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions Runtime/Singletons/Singleton.cs
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;
}
}
}
11 changes: 11 additions & 0 deletions Runtime/Singletons/Singleton.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions package.json
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"
}
}
7 changes: 7 additions & 0 deletions package.json.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 83482e2

Please sign in to comment.