2 using System.Collections.Generic;
5 namespace Jypeli.LevelEditor
10 [Save]
public List<Property> Items {
get;
private set; }
14 Items =
new List<Property>();
17 private void Add(
string name,
object value )
19 Items.Add(
new Property( name, value ) );
24 for (
int i = 0; i < propSet.
Items.Count; i++ )
26 SetValue( propSet.
Items[i].Name, propSet.
Items[i].Value );
30 public void Remove(
string propName )
32 Remove( item => item.Name == propName );
35 private void Remove( Predicate<Property> pred )
37 for (
int i = Items.Count - 1; i >= 0; i-- )
39 if ( pred( Items[i] ) )
46 for (
int i = 0; i < Items.Count; i++ )
48 if ( Items[i].Name == propName )
57 return IndexOf( propName ) >= 0;
62 int propIndex = IndexOf( propName );
63 if ( propIndex < 0 )
throw new KeyNotFoundException();
64 return Items[propIndex].Value;
67 public T GetValue<T>(
string propName )
69 return (
T)GetValue( propName );
76 return GetValue( propName );
78 catch ( KeyNotFoundException )
84 public void SetValue(
string propName,
object propValue )
86 int propIndex = IndexOf( propName );
90 Property property = Items[propIndex];
91 property.
Value = propValue;
92 Items[propIndex] = property;
95 Add( propName, propValue );
100 Type type = obj.GetType();
102 for (
int i = 0; i < Items.Count; i++ )
104 if ( Items[i].Name ==
"Type" )
107 BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetProperty;
108 PropertyInfo prop = type.GetProperty( Items[i].Name, flags );
111 prop.SetValue( obj, Items[i].Value, null );
119 for (
int i = 0; i < sets.Length; i++ )
121 result.Add( sets[i] );
object TryGetValue(string propName)
int IndexOf(string propName)
object GetValue(string propName)
static PropertySet Merge(params PropertySet[] sets)
void Remove(string propName)
bool Contains(string propName)
void SetValue(string propName, object propValue)
void Add(PropertySet propSet)
void Apply(ref GameObject obj)
Property(string name, object value)
Pelialueella liikkuva olio. Käytä fysiikkapeleissä PhysicsObject-olioita.