Skip to content

Commit

Permalink
Merge pull request #64 from Dred95/master
Browse files Browse the repository at this point in the history
Related to issue #45
  • Loading branch information
intentor authored Nov 8, 2016
2 parents 2f8ee5e + 1635382 commit dbeecf5
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ public static class UnityBindingExtension {
"The type must be derived from UnityEngine.Component.";
private const string GAMEOBJECT_IS_NULL =
"There's no GameObject to bind the type to.";
private const string PREFAB_IS_NULL =
"There's no prefab to bind the type to.";
private const string GAMEOBJECT_NAME_TYPE_IS_NULL =
"There's no GameObject named \"{0}\" to bind the type {1} to.";
private const string GAMEOBJECT_TAG_TYPE_IS_NULL =
"There's no GameObject tagged \"{0}\" to bind the type {1} to.";
private const string PREFAB_NAME_TYPE_IS_NULL =
"There's no prefab named \"{0}\" to bind the type {1} to.";
private const string RESOURCE_IS_NULL =
"There's no resource to bind the type to.";

Expand Down Expand Up @@ -142,7 +146,10 @@ public static IBindingConditionFactory ToGameObject(this IBindingFactory binding
} else {
gameObject = GameObject.Find(name);
}


if (gameObject == null) {
throw new BindingException(string.Format(GAMEOBJECT_NAME_TYPE_IS_NULL, name, type.ToString()));
}
return CreateSingletonBinding(bindingFactory, gameObject, type, isGameObject);
}

Expand Down Expand Up @@ -223,6 +230,10 @@ public static IBindingConditionFactory ToGameObjectWithTag(this IBindingFactory

var gameObject = GameObject.FindWithTag(tag);

if (gameObject == null) {
throw new BindingException(string.Format(GAMEOBJECT_TAG_TYPE_IS_NULL, tag, type.ToString()));
}

return CreateSingletonBinding(bindingFactory, gameObject, type, isGameObject);
}

Expand Down Expand Up @@ -376,7 +387,7 @@ public static IBindingConditionFactory ToPrefab(this IBindingFactory bindingFact

var prefab = Resources.Load(name);
if (prefab == null) {
throw new BindingException(PREFAB_IS_NULL);
throw new BindingException(string.Format(PREFAB_NAME_TYPE_IS_NULL, name, type.ToString()));
}

var prefabBinding = new PrefabBinding(prefab, type);
Expand Down Expand Up @@ -451,7 +462,7 @@ public static IBindingConditionFactory ToPrefabSingleton(this IBindingFactory bi

var prefab = Resources.Load(name);
if (prefab == null) {
throw new BindingException(PREFAB_IS_NULL);
throw new BindingException(string.Format(PREFAB_NAME_TYPE_IS_NULL, name, type.ToString()));
}

var gameObject = (GameObject)MonoBehaviour.Instantiate(prefab);
Expand Down Expand Up @@ -512,4 +523,4 @@ private static IBindingConditionFactory CreateSingletonBinding(IBindingFactory b
}
}
}
}
}

0 comments on commit dbeecf5

Please sign in to comment.