/// <summary> /// Constructs a container GameObject for the given entity under the given root object. /// </summary> /// <param name="entity">The entity to create a GameObject for</param> /// <param name="root">The root object to create the GameObject under</param> /// <returns>The created GameObject.</returns> protected static GameObject CreateGameObject(IQueryableEntity entity, GameObject root) { GameObject created = null; // There is special logic for instantiating an object If the entity contains prefab data // that specifies it should be instantiated from a specific resource, then we load that // resource and clone it instead of creating a new object if (entity.ContainsData<PrefabData>()) { string resourcePath = entity.Current<PrefabData>().PrefabResourcePath; GameObject prefab = (GameObject)Resources.Load(resourcePath); if (prefab == null) { created = new GameObject(""); Debug.LogError("Unable to find prefab resource \"" + resourcePath + "\"", created); } else { created = (GameObject)Instantiate(prefab); } } else { created = new GameObject(""); } created.transform.parent = root.transform; return created; }
public static bool ContainsData <T>(this IQueryableEntity entity) where T : Data.IData { return(entity.ContainsData(DataMap <T> .Accessor)); }
private void ComputeDataTypes(IEnumerable<Type> requiredTypes, IQueryableEntity entity, out List<Type> missing, out List<Type> contained) { missing = new List<Type>(); contained = new List<Type>(); foreach (var type in requiredTypes) { DataAccessor accessor = new DataAccessor(type); if (entity.ContainsData(accessor)) { contained.Add(type); } else { missing.Add(type); } } }