summaryrefslogtreecommitdiff
path: root/WorldlineKeepers/Assets/Scripts/Utils/GameObjectExtensions.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-06-27 18:43:09 +0800
committerchai <215380520@qq.com>2023-06-27 18:43:09 +0800
commit411470e66bcfd9631c7b6f82b0a00e5e1e1b0004 (patch)
tree9a3d3b453702834eb4ad6a4b7eabb6a7b5422880 /WorldlineKeepers/Assets/Scripts/Utils/GameObjectExtensions.cs
parent3d1e930feed19641f0f386463f4de33385f24c51 (diff)
+ stage serialize
Diffstat (limited to 'WorldlineKeepers/Assets/Scripts/Utils/GameObjectExtensions.cs')
-rw-r--r--WorldlineKeepers/Assets/Scripts/Utils/GameObjectExtensions.cs46
1 files changed, 46 insertions, 0 deletions
diff --git a/WorldlineKeepers/Assets/Scripts/Utils/GameObjectExtensions.cs b/WorldlineKeepers/Assets/Scripts/Utils/GameObjectExtensions.cs
new file mode 100644
index 0000000..84ce560
--- /dev/null
+++ b/WorldlineKeepers/Assets/Scripts/Utils/GameObjectExtensions.cs
@@ -0,0 +1,46 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public static class GameObjectExtensions
+{
+ public static void SetParent(this GameObject obj, Transform parent)
+ {
+ if (!(obj == null))
+ {
+ obj.transform.SetParent(parent);
+ }
+ }
+
+ public static GameObject Find(this GameObject obj, string name)
+ {
+ if (obj == null)
+ {
+ return null;
+ }
+
+ Transform transform = obj.transform.Find(name);
+ if (!(transform != null))
+ {
+ return null;
+ }
+
+ return transform.gameObject;
+ }
+
+ public static T GetOrAddComponent<T>(this GameObject go) where T : Component
+ {
+ if (go == null)
+ {
+ return null;
+ }
+
+ T val = go.GetComponent<T>();
+ if ((Object)val == (Object)null)
+ {
+ val = go.AddComponent<T>();
+ }
+
+ return val;
+ }
+} \ No newline at end of file