-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIMonoBehaviour.cs
42 lines (39 loc) · 1.46 KB
/
IMonoBehaviour.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using UnityEngine;
namespace Minerva.Module
{
/// <summary>
/// interface that connect to a monobehaviour directly
/// <br> note: an class/struct of <see cref="IMonoBehaviour"/> doesn't have to be a subclass of <see cref="MonoBehaviour"/> </br>
/// </summary>
public interface IMonoBehaviour
{
public bool enabled { get; set; }
public Transform transform { get; }
public GameObject gameObject { get; }
/// <summary>
/// The MonoBehaviour self
/// </summary>
public MonoBehaviour Script => this as MonoBehaviour;
}
/// <summary>
/// interface that connect to a monobehaviour directly
/// <br> note: an class/struct of <see cref="IMonoBehaviour"/> doesn't have to be a subclass of <see cref="MonoBehaviour"/> </br>
/// </summary>
public interface IMonoBehaviour<out T> : IMonoBehaviour where T : MonoBehaviour
{
public new T Script => this as T;
}
public static class MonobehaviourInterfaceExtension
{
/// <summary>
/// checking unity object exist
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="instance"></param>
/// <returns>null (real null) if the object does not exist, the object if the object exist</returns>
public static MonoBehaviour Exist(this IMonoBehaviour instance)
{
return instance != null && instance.Script ? instance.Script : null;
}
}
}