summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Utils/UnityExtends.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-07-27 09:40:26 +0800
committerchai <chaifix@163.com>2021-07-27 09:40:26 +0800
commit8bbc03542340b4ea7ca1e2beec2f11ff335851e8 (patch)
tree15a4bdebe7b8d9448c476e0f67b94a5a50bc2ec5 /Assets/Scripts/Utils/UnityExtends.cs
parent4ceee84cd45e4e3ec40ebd888e41bd47a938c2d5 (diff)
*mic
Diffstat (limited to 'Assets/Scripts/Utils/UnityExtends.cs')
-rw-r--r--Assets/Scripts/Utils/UnityExtends.cs16
1 files changed, 16 insertions, 0 deletions
diff --git a/Assets/Scripts/Utils/UnityExtends.cs b/Assets/Scripts/Utils/UnityExtends.cs
new file mode 100644
index 00000000..d1a66f48
--- /dev/null
+++ b/Assets/Scripts/Utils/UnityExtends.cs
@@ -0,0 +1,16 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public static class UnityExtends
+{
+ public static T GetOrAddComponent<T>(this GameObject go) where T : MonoBehaviour
+ {
+ T component = go.GetComponent<T>();
+ if (component == null)
+ component = go.AddComponent<T>();
+ return component;
+ }
+
+
+}