From 8bbc03542340b4ea7ca1e2beec2f11ff335851e8 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 27 Jul 2021 09:40:26 +0800 Subject: *mic --- Assets/Scripts/Utils/UnityExtends.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Assets/Scripts/Utils/UnityExtends.cs (limited to 'Assets/Scripts/Utils/UnityExtends.cs') 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(this GameObject go) where T : MonoBehaviour + { + T component = go.GetComponent(); + if (component == null) + component = go.AddComponent(); + return component; + } + + +} -- cgit v1.1-26-g67d0