From 411470e66bcfd9631c7b6f82b0a00e5e1e1b0004 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Tue, 27 Jun 2023 18:43:09 +0800 Subject: + stage serialize --- .../Assets/Scripts/Utils/GameObjectExtensions.cs | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 WorldlineKeepers/Assets/Scripts/Utils/GameObjectExtensions.cs (limited to 'WorldlineKeepers/Assets/Scripts/Utils/GameObjectExtensions.cs') 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(this GameObject go) where T : Component + { + if (go == null) + { + return null; + } + + T val = go.GetComponent(); + if ((Object)val == (Object)null) + { + val = go.AddComponent(); + } + + return val; + } +} \ No newline at end of file -- cgit v1.1-26-g67d0