Beispiel #1
0
    public static T GetComponent <T>(GameObject go, GetComponentPostCommand command = GetComponentPostCommand.None)
    {
        if (go == null)
        {
            return(default(T));
        }

        T component = go.GetComponent <T>();

        if (component != null && command == GetComponentPostCommand.DestroyGameObject)
        {
            UnityEngine.Object.Destroy(go);
        }

        return(component);
    }
Beispiel #2
0
    public static T GetComponentOrPanic <T>(GameObject go, GetComponentPostCommand command = GetComponentPostCommand.None)
    {
        if (go == null)
        {
            throw new ComponentNotFoundException("GameObject == null");
        }

        T component = GetComponent <T>(go, command);

        if (component == null)
        {
            throw new ComponentNotFoundException("Component: " + typeof(T).Name + " not found in GameObject: " + go);
        }

        return(component);
    }
Beispiel #3
0
 public static T GetComponentInGameObjectFoundWithTag <T>(string tag, GetComponentPostCommand command = GetComponentPostCommand.None)
 {
     return(GetComponent <T>(GameObject.FindGameObjectWithTag(tag), command));
 }
Beispiel #4
0
 public static T GetComponentInGameControllerOrPanic <T>(GetComponentPostCommand command = GetComponentPostCommand.None)
 {
     return(GetComponentOrPanic <T>(FindGameObjectWithTagOrPanic(CommonTags.GAME_CONTROLLER), command));
 }