summaryrefslogtreecommitdiff
path: root/WorldlineKeepers/Assets/Scripts/Utils/GameObjectExtensions.cs
blob: 84ce560e21146c825d5a5ea554e6ba235ddfaf09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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;
    }
}