-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
693 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// **************************************************************** // | ||
// | ||
// Copyright (c) RimuruDev. All rights reserved. | ||
// Contact me: | ||
// - Gmail: [email protected] | ||
// - LinkedIn: https://www.linkedin.com/in/rimuru/ | ||
// - GitHub: https://github.com/RimuruDev | ||
// | ||
// **************************************************************** // | ||
|
||
using UnityEngine; | ||
|
||
namespace IndieInjector | ||
{ | ||
[HelpURL("https://github.com/RimuruDev/IndieInject")] | ||
public class MonoSingleton<TComponent> : MonoBehaviour where TComponent : Component | ||
{ | ||
protected static TComponent instance; | ||
|
||
public static bool HasInstance => instance != null; | ||
|
||
public static TComponent TryGetInstance() => HasInstance ? instance : null; | ||
|
||
public static TComponent Current => instance; | ||
|
||
public static TComponent Self => instance; | ||
|
||
public static TComponent Instance | ||
{ | ||
get | ||
{ | ||
if (instance != null) | ||
return instance; | ||
|
||
instance = FindFirstObjectByType<TComponent>(); | ||
|
||
if (instance != null) | ||
return instance; | ||
|
||
var obj = new GameObject | ||
{ | ||
name = $"[ === {typeof(TComponent).Name} === ]" | ||
}; | ||
|
||
instance = obj.AddComponent<TComponent>(); | ||
|
||
return instance; | ||
} | ||
} | ||
|
||
protected virtual void Awake() => | ||
InitializeSingleton(); | ||
|
||
protected virtual void InitializeSingleton() | ||
{ | ||
if (!Application.isPlaying) | ||
return; | ||
|
||
instance = this as TComponent; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// **************************************************************** // | ||
// | ||
// Copyright (c) RimuruDev. All rights reserved. | ||
// Contact me: | ||
// - Gmail: [email protected] | ||
// - LinkedIn: https://www.linkedin.com/in/rimuru/ | ||
// - GitHub: https://github.com/RimuruDev | ||
// | ||
// **************************************************************** // | ||
|
||
namespace IndieInjector | ||
{ | ||
public interface IDependencyProvider | ||
{ | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// **************************************************************** // | ||
// | ||
// Copyright (c) RimuruDev. All rights reserved. | ||
// Contact me: | ||
// - Gmail: [email protected] | ||
// - LinkedIn: https://www.linkedin.com/in/rimuru/ | ||
// - GitHub: https://github.com/RimuruDev | ||
// | ||
// **************************************************************** // | ||
|
||
using System; | ||
using UnityEngine; | ||
|
||
namespace IndieInjector | ||
{ | ||
[HelpURL("https://github.com/RimuruDev/IndieInject")] | ||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Property)] | ||
public sealed class InjectAttribute : Attribute | ||
{ | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// **************************************************************** // | ||
// | ||
// Copyright (c) RimuruDev. All rights reserved. | ||
// Contact me: | ||
// - Gmail: [email protected] | ||
// - LinkedIn: https://www.linkedin.com/in/rimuru/ | ||
// - GitHub: https://github.com/RimuruDev | ||
// | ||
// **************************************************************** // | ||
|
||
using System; | ||
using UnityEngine; | ||
|
||
namespace IndieInjector | ||
{ | ||
[HelpURL("https://github.com/RimuruDev/IndieInject")] | ||
[AttributeUsage(AttributeTargets.Method)] | ||
public sealed class ProvideAttribute : Attribute | ||
{ | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// **************************************************************** // | ||
// | ||
// Copyright (c) RimuruDev. All rights reserved. | ||
// Contact me: | ||
// - Gmail: [email protected] | ||
// - LinkedIn: https://www.linkedin.com/in/rimuru/ | ||
// - GitHub: https://github.com/RimuruDev | ||
// | ||
// **************************************************************** // | ||
|
||
using UnityEngine; | ||
|
||
namespace IndieInjector | ||
{ | ||
[HelpURL("https://github.com/RimuruDev/IndieInject")] | ||
public static class IndieInjectorExtensions | ||
{ | ||
public static GameObject InstantiateWithDependencies(GameObject prefab, Vector3 position, Quaternion rotation) | ||
{ | ||
var instance = Object.Instantiate(prefab, position, rotation); | ||
IndieInjector.Instance.Inject(instance, InjectionType.All); | ||
return instance; | ||
} | ||
|
||
public static GameObject InstantiateWithFields(GameObject prefab, Vector3 position, Quaternion rotation) | ||
{ | ||
var instance = Object.Instantiate(prefab, position, rotation); | ||
IndieInjector.Instance.Inject(instance, InjectionType.Fields); | ||
return instance; | ||
} | ||
|
||
public static GameObject InstantiateWithProperties(GameObject prefab, Vector3 position, Quaternion rotation) | ||
{ | ||
var instance = Object.Instantiate(prefab, position, rotation); | ||
IndieInjector.Instance.Inject(instance, InjectionType.Properties); | ||
return instance; | ||
} | ||
|
||
public static GameObject InstantiateWithMethods(GameObject prefab, Vector3 position, Quaternion rotation) | ||
{ | ||
var instance = Object.Instantiate(prefab, position, rotation); | ||
IndieInjector.Instance.Inject(instance, InjectionType.Methods); | ||
return instance; | ||
} | ||
|
||
public static GameObject InstantiateWithDependencies(GameObject prefab, Transform parent) | ||
{ | ||
var instance = Object.Instantiate(prefab, parent); | ||
IndieInjector.Instance.Inject(instance, InjectionType.All); | ||
return instance; | ||
} | ||
|
||
public static GameObject InstantiateWithFields(GameObject prefab, Transform parent) | ||
{ | ||
var instance = Object.Instantiate(prefab, parent); | ||
IndieInjector.Instance.Inject(instance, InjectionType.Fields); | ||
return instance; | ||
} | ||
|
||
public static GameObject InstantiateWithProperties(GameObject prefab, Transform parent) | ||
{ | ||
var instance = Object.Instantiate(prefab, parent); | ||
IndieInjector.Instance.Inject(instance, InjectionType.Properties); | ||
return instance; | ||
} | ||
|
||
public static GameObject InstantiateWithMethods(GameObject prefab, Transform parent) | ||
{ | ||
var instance = Object.Instantiate(prefab, parent); | ||
IndieInjector.Instance.Inject(instance, InjectionType.Methods); | ||
return instance; | ||
} | ||
|
||
public static void DestroyWithDependencies(GameObject gameObject, float timeToDestroy = 0f) | ||
{ | ||
IndieInjector.Instance.RemoveDependencies(gameObject); | ||
Object.Destroy(gameObject, timeToDestroy); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// **************************************************************** // | ||
// | ||
// Copyright (c) RimuruDev. All rights reserved. | ||
// Contact me: | ||
// - Gmail: [email protected] | ||
// - LinkedIn: https://www.linkedin.com/in/rimuru/ | ||
// - GitHub: https://github.com/RimuruDev | ||
// | ||
// **************************************************************** // | ||
|
||
// TODO: Add Generic variant's | ||
|
||
using UnityEngine; | ||
|
||
namespace IndieInjector | ||
{ | ||
[HelpURL("https://github.com/RimuruDev/IndieInject")] | ||
public static class IndieObject | ||
{ | ||
public static GameObject InstantiateWithDependencies(GameObject prefab, Vector3 position, Quaternion rotation) | ||
{ | ||
return IndieInjectorExtensions.InstantiateWithDependencies(prefab, position, rotation); | ||
} | ||
|
||
public static GameObject InstantiateWithFields(GameObject prefab, Vector3 position, Quaternion rotation) | ||
{ | ||
return IndieInjectorExtensions.InstantiateWithFields(prefab, position, rotation); | ||
} | ||
|
||
public static GameObject InstantiateWithProperties(GameObject prefab, Vector3 position, Quaternion rotation) | ||
{ | ||
return IndieInjectorExtensions.InstantiateWithProperties(prefab, position, rotation); | ||
} | ||
|
||
public static GameObject InstantiateWithMethods(GameObject prefab, Vector3 position, Quaternion rotation) | ||
{ | ||
return IndieInjectorExtensions.InstantiateWithMethods(prefab, position, rotation); | ||
} | ||
|
||
public static GameObject InstantiateWithDependencies(GameObject prefab, Transform parent) | ||
{ | ||
return IndieInjectorExtensions.InstantiateWithDependencies(prefab, parent); | ||
} | ||
|
||
public static GameObject InstantiateWithFields(GameObject prefab, Transform parent) | ||
{ | ||
return IndieInjectorExtensions.InstantiateWithFields(prefab, parent); | ||
} | ||
|
||
public static GameObject InstantiateWithProperties(GameObject prefab, Transform parent) | ||
{ | ||
return IndieInjectorExtensions.InstantiateWithProperties(prefab, parent); | ||
} | ||
|
||
public static GameObject InstantiateWithMethods(GameObject prefab, Transform parent) | ||
{ | ||
return IndieInjectorExtensions.InstantiateWithMethods(prefab, parent); | ||
} | ||
|
||
public static void DestroyWithDependencies(GameObject gameObject, float timeToDestroy = 0f) | ||
{ | ||
IndieInjectorExtensions.DestroyWithDependencies(gameObject, timeToDestroy); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// **************************************************************** // | ||
// | ||
// Copyright (c) RimuruDev. All rights reserved. | ||
// Contact me: | ||
// - Gmail: [email protected] | ||
// - LinkedIn: https://www.linkedin.com/in/rimuru/ | ||
// - GitHub: https://github.com/RimuruDev | ||
// | ||
// **************************************************************** // | ||
|
||
using System; | ||
|
||
namespace IndieInjector | ||
{ | ||
[Flags] | ||
public enum InjectionType | ||
{ | ||
Fields = 1, | ||
Properties = 2, | ||
Methods = 4, | ||
All = Fields | Properties | Methods | ||
} | ||
} |
Oops, something went wrong.