summaryrefslogtreecommitdiff
path: root/WorldlineKeepers/Assets/Scripts/Utils/GameObjectExtensions.cs
diff options
context:
space:
mode:
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