void CreateBehavior() { System.Type type = classes[chosenType]; SteeringBehaviorAsset.BehaviorDef behavior = new SteeringBehaviorAsset.BehaviorDef(); behavior.type = type.FullName; behavior.name = type.Name; behavior.weight = weight; behavior.enabled = enabled; List <SteeringBehaviorAsset.LinkedProperty> props = new List <SteeringBehaviorAsset.LinkedProperty>(); object impl = System.Activator.CreateInstance(type); PropertyInfo[] properties = type.GetProperties( BindingFlags.Instance | BindingFlags.Public); foreach (PropertyInfo prop in properties) { if (prop.Name == "Weight" || prop.Name == "Enabled") { continue; } if (!prop.CanWrite) { continue; } string def = ""; SteeringBehaviorAsset.LinkedProperty linkedProp = new SteeringBehaviorAsset.LinkedProperty(); linkedProp.name = prop.Name; linkedProp.type = GetPropertyType(prop.PropertyType, out def); if (prop.CanRead) { object v = prop.GetValue(impl, null); if (v != null) { def = v.ToString(); } } linkedProp.defaultValue = def; props.Add(linkedProp); } behavior.properties = props.ToArray(); asset.AddBehavior(behavior); Close(); }
void CreateBehavior() { System.Type type = classes[chosenType]; SteeringBehaviorAsset.BehaviorDef behavior = new SteeringBehaviorAsset.BehaviorDef(); behavior.type = type.FullName; behavior.name = type.Name; behavior.weight = weight; behavior.enabled = enabled; List<SteeringBehaviorAsset.LinkedProperty> props = new List<SteeringBehaviorAsset.LinkedProperty>(); object impl = System.Activator.CreateInstance(type); PropertyInfo[] properties = type.GetProperties( BindingFlags.Instance | BindingFlags.Public); foreach(PropertyInfo prop in properties) { if(prop.Name == "Weight" || prop.Name == "Enabled") { continue; } if(!prop.CanWrite) { continue; } string def = ""; SteeringBehaviorAsset.LinkedProperty linkedProp = new SteeringBehaviorAsset.LinkedProperty(); linkedProp.name = prop.Name; linkedProp.type = GetPropertyType(prop.PropertyType, out def); if(prop.CanRead) { object v = prop.GetValue(impl, null); if(v != null) { def = v.ToString(); } } linkedProp.defaultValue = def; props.Add(linkedProp); } behavior.properties = props.ToArray(); asset.AddBehavior(behavior); Close(); }