public bool explicitType; // store object type with property in file public Property(string name, GetProperty getter, SetProperty setter, PropertyGUI gui) { this.name = name; this.getter = getter; this.setter = setter; this.gui = gui; explicitType = false; }
public Property(string name, GetProperty getter, SetProperty setter, PropertyGUI gui, bool explicitType) { this.name = name; this.getter = getter; this.setter = setter; this.gui = gui; this.explicitType = explicitType; }
// merge properties of objects public StoredPropertiesObject(PropertiesObject[] objects) { properties = new List <Property>(); if (objects.Length == 0) { return; } if (objects[0] != null) { type = objects[0].ObjectType(); } // check that all objects have the same type. if they don't, fail foreach (PropertiesObject obj in objects) { PropertiesObjectType objType = null; if (obj != null) { objType = obj.ObjectType(); } if (objType != type) { type = DIFFERENT_OBJECT_TYPE; return; } } if (type == null) { return; // null objects, no properties } // first index: object // second index: property List <List <Property> > objectPropertiesSets = new List <List <Property> >(); foreach (PropertiesObject obj in objects) { objectPropertiesSets.Add(new List <Property>(obj.Properties())); } int numObjects = objectPropertiesSets.Count; int numProperties = objectPropertiesSets[0].Count; for (int propertyI = 0; propertyI < numProperties; propertyI++) { int _propertyI = propertyI; // for use in lambda functions -- won't change Property firstProperty = objectPropertiesSets[0][propertyI]; GetProperty getter = () => { object value = objectPropertiesSets[0][_propertyI].getter(); for (int objectI = 0; objectI < numObjects; objectI++) { if (!(objectPropertiesSets[objectI][_propertyI].getter().Equals(value))) { return(NOT_EQUAL_VALUE); } } return(value); }; SetProperty setter = value => { for (int objectI = 0; objectI < numObjects; objectI++) { objectPropertiesSets[objectI][_propertyI].setter(value); } }; PropertyGUI gui = property => { if (property.getter() == (object)NOT_EQUAL_VALUE) { GUILayout.BeginHorizontal(); PropertyGUIs.AlignedLabel(property); if (GUILayout.Button("different")) { // set all properties to one value property.setter(firstProperty.getter()); } GUILayout.EndHorizontal(); } else { firstProperty.gui(property); } }; properties.Add(new Property( firstProperty.id, firstProperty.name, getter, setter, gui, firstProperty.explicitType)); } }