public EditorViewModel() { AppDomain.CurrentDomain.Load("SimpleGameEngine.Examples"); SceneObjectTypes = InheritedClassMethods.GetInheritedClasses <SceneObject>(); BehaviourTypes = InheritedClassMethods.GetInheritedClasses <BaseBehaviour>(); CreateNewScene(); InitCommands(); }
protected static void BehavioursFromJson(JObject jsObj, SceneObject parent) { var behaviourTypes = InheritedClassMethods.GetInheritedClasses <BaseBehaviour>(); foreach (var beh in jsObj[Properties.Behaviours]) { var type = behaviourTypes.First(x => x.Name.Equals(beh[BehaviourProperties.Type].Value <string>())); var instance = (BaseBehaviour)Activator.CreateInstance(type, parent); foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { if (!property.CanWrite || beh[property.Name] is null) { continue; } var fromJsonMethod = property.PropertyType.GetMethods().FirstOrDefault(x => x.Name == "FromJson"); var value = fromJsonMethod != null ? fromJsonMethod.Invoke(null, new object[] { beh[property.Name], parent }) : beh[property.Name].ToObject(property.PropertyType); property.SetValue(instance, value); } } }