/// <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 T Current <T>(this IQueryableEntity entity) where T : Data.IData { return((T)entity.Current(DataMap <T> .Accessor)); }
/// <summary> /// Returns the data instance that should be edited based on the given edit state and data /// type. /// </summary> private static Data.IData GetEditedData(IQueryableEntity entity, DataEditState editState, Type dataType) { var accessor = new DataAccessor(dataType); switch (editState) { case DataEditState.Current: return entity.Current(accessor); case DataEditState.Previous: return entity.Previous(accessor); } throw new InvalidOperationException("Unknown edit state"); }
/// <summary> /// Called when we have an entity to inspect. /// </summary> private void DrawInspector(IQueryableEntity entity, GameObject context) { _inspectorScroll = EditorGUILayout.BeginScrollView(_inspectorScroll); EditorGUILayout.LabelField("Metadata", ForgeEditorUtils.HeaderStyle); entity.PrettyName = EditorGUILayout.TextField("Pretty Name", entity.PrettyName); if (GUI.changed) { BaseContainer container = context.GetComponent<BaseContainer>(); container.UpdateName(); } ForgeEditorUtils.DrawSeperator(); foreach (DataAccessor accessor in entity.SelectData(/*includeRemoved:*/ true)) { Type dataType = entity.Current(accessor).GetType(); _dataInspectorView.DrawDataInspector(entity, dataType, context); ForgeEditorUtils.DrawSeperator(); } DrawAddData(entity); EditorGUILayout.EndScrollView(); }
/// <summary> /// Returns the current data value for the given data type. /// </summary> /// <typeparam name="TData">The type of data to retrieve. It has to be one of the generic /// parameters for this type; if it is not, then an exception is thrown.</typeparam> /// <returns>The current value for the given data type.</returns> public TData Current <TData>() where TData : Data.IData { VerifyRequest <TData>(); return(_provider.Current <TData>()); }