/// <summary> /// Adds a type of <paramref name="trainingProperty"/> into this <see cref="ISceneObject"/>. /// </summary> /// <param name="sceneObject"><see cref="ISceneObject"/> to whom the <paramref name="trainingProperty"/> will be added.</param> /// <param name="trainingProperty">Typo of <see cref="ISceneObjectProperty"/> to be added to <paramref name="sceneObject"/>.</param> /// <returns>A reference to the <see cref="ISceneObjectProperty"/> added to <paramref name="sceneObject"/>.</returns> public static ISceneObjectProperty AddTrainingProperty(this ISceneObject sceneObject, Type trainingProperty) { if (AreParametersNullOrInvalid(sceneObject, trainingProperty)) { return(null); } ISceneObjectProperty sceneObjectProperty = sceneObject.GameObject.GetComponent(trainingProperty) as ISceneObjectProperty; if (sceneObjectProperty != null) { return(sceneObjectProperty); } if (trainingProperty.IsInterface) { // If it is an interface just take the first public found concrete implementation. Type propertyType = ReflectionUtils .GetAllTypes() .Where(trainingProperty.IsAssignableFrom) .Where(type => type.Assembly.GetReferencedAssemblies().All(assemblyName => assemblyName.Name != "UnityEditor" && assemblyName.Name != "nunit.framework")) .First(type => type.IsClass && type.IsPublic && type.IsAbstract == false); sceneObjectProperty = sceneObject.GameObject.AddComponent(propertyType) as ISceneObjectProperty; } else { sceneObjectProperty = sceneObject.GameObject.AddComponent(trainingProperty) as ISceneObjectProperty; } return(sceneObjectProperty); }
public T GetProperty <T>() where T : ISceneObjectProperty { ISceneObjectProperty property = FindProperty(typeof(T)); if (property == null) { throw new PropertyNotFoundException(this, typeof(T)); } return((T)property); }
/// <summary> /// Adds a type of <paramref name="trainingProperty"/> into this <see cref="ISceneObject"/>. /// </summary> /// <param name="sceneObject"><see cref="ISceneObject"/> to whom the <paramref name="trainingProperty"/> will be added.</param> /// <param name="trainingProperty">Typo of <see cref="ISceneObjectProperty"/> to be added to <paramref name="sceneObject"/>.</param> /// <returns>A reference to the <see cref="ISceneObjectProperty"/> added to <paramref name="sceneObject"/>.</returns> public static ISceneObjectProperty AddTrainingProperty(this ISceneObject sceneObject, Type trainingProperty) { if (AreParametersNullOrInvalid(sceneObject, trainingProperty)) { return(null); } ISceneObjectProperty sceneObjectProperty = sceneObject.GameObject.GetComponent(trainingProperty) as ISceneObjectProperty ?? sceneObject.GameObject.AddComponent(trainingProperty) as ISceneObjectProperty; return(sceneObjectProperty); }
private string GetUniqueNameFromTrainingProperty(GameObject selectedTrainingPropertyObject, Type valueType, string oldUniqueName) { ISceneObjectProperty trainingProperty = selectedTrainingPropertyObject.GetComponent(valueType) as ISceneObjectProperty; if (trainingProperty != null) { return(trainingProperty.SceneObject.UniqueName); } logger.WarnFormat("Scene Object \"{0}\" with Unique Name \"{1}\" does not have a {2} component.", selectedTrainingPropertyObject.name, oldUniqueName, valueType.Name); return(string.Empty); }
public static string GetNameFrom(ISceneObjectProperty property) { if (property == null) { return(null); } if (property.SceneObject == null) { return(null); } return(property.SceneObject.UniqueName); }
/// <summary> /// Extracts all <see cref="ISceneObjectProperty"/> from type T from the given condition. /// </summary> /// <param name="data">Condition to be used for extraction</param> /// <param name="checkRequiredComponentsToo">if true the [RequiredComponents] will be checked and added too.</param> public static List <ISceneObjectProperty> ExtractPropertiesFromConditions(IConditionData data, bool checkRequiredComponentsToo = true) { List <ISceneObjectProperty> result = new List <ISceneObjectProperty>(); List <MemberInfo> memberInfo = GetAllPropertyReferencesFromCondition(data); memberInfo.ForEach(info => { UniqueNameReference reference = ReflectionUtils.GetValueFromPropertyOrField(data, info) as UniqueNameReference; if (reference == null || string.IsNullOrEmpty(reference.UniqueName)) { return; } if (RuntimeConfigurator.Configuration.SceneObjectRegistry.ContainsName(reference.UniqueName) == false) { return; } IEnumerable <Type> refs = ExtractFittingPropertyTypeFrom <ISceneObjectProperty>(reference); Type refType = refs.FirstOrDefault(); if (refType != null) { IEnumerable <Type> types = new[] { refType }; if (checkRequiredComponentsToo) { types = GetDependenciesFrom(refType); } foreach (Type type in types) { ISceneObjectProperty property = GetFittingPropertyFromReference <ISceneObjectProperty>(reference, type); if (property != null) { result.Add(property); } } } }); return(result); }
/// <summary> /// Destroys game objects to which <paramref name="property"/> is attached. /// </summary> public static void DestroySceneObject(ISceneObjectProperty property) { DestroySceneObject(property.SceneObject); }