private bool TryToFindObject(out T value) { var gameObject = new MaskFinder().Find(_path); if (gameObject == null) { value = default(T); return(false); } if (typeof(T) == typeof(GameObject)) { value = (T)(object)gameObject; return(true); } if (typeof(T) == typeof(Transform)) { value = (T)(object)gameObject.transform; return(true); } var components = gameObject.GetComponents <Component>(); T component = components.OfType <T>().FirstOrDefault(); if (component != null) { value = component; return(true); } value = default(T); return(false); }
private T FindObject() { var gameObject = new MaskFinder().Find(_path); if (gameObject == null) { throw new ContainerException("Can't find game object \"" + _path + "\""); } if (typeof(T) == typeof(GameObject)) { return((T)(object)gameObject); } if (typeof(T) == typeof(Transform)) { return((T)(object)gameObject.transform); } var components = gameObject.GetComponents <Component>(); T component = components.OfType <T>().FirstOrDefault(); if (component != null) { return(component); } throw new ContainerException("Can't find component \"" + typeof(T).FullName + "\" of game object \"" + _path + "\""); }
public T GetObject(DIContainer container) { var gameObject = new MaskFinder().Find(_path); if (gameObject == null) { throw new ContainerException("Can't find game object \"" + _path + "\""); } if (!_inited) { container.BuildUp(gameObject); _inited = true; } if (typeof(T) == typeof(GameObject)) { return((T)(object)gameObject); } if (typeof(T) == typeof(Transform)) { return((T)(object)gameObject.transform); } T component = gameObject.GetComponents <Component>().OfType <T>().FirstOrDefault(); if (component != null) { return(component); } throw new ContainerException("Can't find component \"" + typeof(T).FullName + "\" of game object \"" + _path + "\""); }