private void ClearSkinParts() { if (null == _thisType) // not yet added { return; } var partDict = SkinPartCache.Instance.Get(_thisType); if (null != partDict) { foreach (var id in partDict.Keys) { var p = CoreReflector.GetValue(this, id); if (!(p is IFactory)) { PartRemoved(id, p); } else { //var len:int = numDynamicParts(id); //for (var j:int = 0; j < len; j++) // removeDynamicPartInstance(id, getDynamicPartAt(id, j)); } CoreReflector.SetValue(this, id, null); } } }
/** * Create an instance of a dynamic skin part. * Dynamic skin parts should always be instantiated by this method, * rather than directly by calling the <code>newInstance()</code> method on the factory. * This method creates the part, but does not add it to the display list. * The component must call the <code>Group.addElement()</code> method, or the appropriate * method to add the skin part to the display list. * * Param: partName The name of the part. */ /// <summary> /// /// </summary> /// <param name="partName"></param> /// <returns></returns> protected object CreateDynamicPartInstance(string partName) { IFactory factory = (IFactory)CoreReflector.GetValue(Skin, partName); if (null != factory) { DisplayObject instance = (DisplayObject)factory.NewInstance(); // Add to the dynamic parts cache if (null == _dynamicPartsCache) { _dynamicPartsCache = new Dictionary <string, List <object> >(); } if (!_dynamicPartsCache.ContainsKey(partName)) { _dynamicPartsCache[partName] = new List <object>(); } _dynamicPartsCache[partName].Add(instance); // Send notification PartAdded(partName, instance); return(instance); } return(null); }
/// <summary> /// Initializes the Singleton instance /// </summary> private void Initialize() { _adapters = new Dictionary <Type, StyleClientAdapterBase>(); var adapters = GuiReflector.GetAllLoadedTypesDecoratedWith(typeof(StyleClientAdapterAttribute)); #if DEBUG if (DebugMode) { Debug.Log(string.Format(@"Found {0} adapters", adapters.Count)); } #endif foreach (var adapter in adapters) { if (!(typeof(StyleClientAdapterBase).IsAssignableFrom(adapter))) { throw new Exception(string.Format("{0} is not StyleClientAdapterBase", adapter)); } var attributes = CoreReflector.GetClassAttributes <StyleClientAdapterAttribute>(adapter); var client = (StyleClientAdapterBase)Activator.CreateInstance(adapter); _adapters[attributes[0].Type] = client; } #if DEBUG if (DebugMode) { Debug.Log(string.Format(@"Retrieved {0} style client adapters: {1}", _adapters.Count, DictionaryUtil <Type, StyleClientAdapterBase> .Format(_adapters))); } #endif }
private int NumericCompare(object a, object b) { float fa; try { //fa = _name == null ? (float)a : (float)a[_name]; fa = _name == null ? (float)a : (float)CoreReflector.GetValue(a, _name); } catch (Exception ex) { } float fb; try { //fb = null == _name ? (float)b : (float)b[_name]; fb = null == _name ? (float)b : (float)CoreReflector.GetValue(b, _name); } catch (Exception ex) { } //return ObjectUtil.numericCompare(fa, fb); return(0); // TEMP }
private int StringCompare(object a, object b) { string fa; try { //fa = _name == null ? (string)a : (string)a[_name]; fa = (string)(_name == null ? a : CoreReflector.GetValue(a, _name)); } catch (Exception ex) { } string fb; try { //fb = _name == null ? (string)b : (string)b[_name]; fa = (string)(_name == null ? b : CoreReflector.GetValue(b, _name)); } catch (Exception ex) { } //return ObjectUtil.stringCompare(fa, fb, _caseInsensitive); return(0); // TEMP }
private int DateCompare(object a, object b) { DateTime fa; try { //fa = _name == null ? (a as DateTime) : a[_name] as Date; fa = (DateTime)(_name == null ? a : CoreReflector.GetValue(a, _name)); } catch (Exception ex) { } DateTime fb; try { //fb = _name == null ? (b as DateTime?) : b[_name] as Date; fb = (DateTime)(_name == null ? b : CoreReflector.GetValue(b, _name)); } catch (Exception ex) { } //return ObjectUtil.dateCompare(fa, fb); return(0); //TEMP }
private static string GetSignals(Type componentType) { var memberNames = CoreReflector.GetFieldAndPropertyNames(componentType); //memberNames.Sort(MemberInfoSort); List <MemberInfo> infos = new List <MemberInfo>(); foreach (var name in memberNames) { MemberWrapper mw = new MemberWrapper(componentType, name); if (mw.MemberType == typeof(Signal)) { infos.Add(mw.MemberInfo); } } infos.Sort(MemberInfoSort); StringBuilder sb = new StringBuilder(); foreach (var memberInfo in infos) { sb.AppendLine(memberInfo.Name); } return(string.Format(@"Signals ({0}): {1} {2}", infos.Count, Line, sb) + NewLine /* + NewLine*/); }
public override void Play(object target) { if (_played) { return; } _played = true; #if DEBUG if (DebugMode) { Debug.Log(string.Format("SetProperty.Play {0}, {1}, {2}", Target, Property, Value)); } #endif //object val; //if (Relative) // val = ReflectionUtil.GetValue(Target, Property) + Value; //else // val = Value; CoreReflector.SetValue(Target, Property, Value); //if (IsChild) //{ // //Parent.FinishedCount++; // Parent.Count--; //} }
/// <summary> /// Used for deffered parts /// </summary> /// <param name="e"></param> private void SkinPropertyChangeHandler(Event e) { if (null != SkinParts) { PropertyChangeEvent pce = (PropertyChangeEvent)e; string skinPartID = pce.Property; if (SkinParts.ContainsKey(skinPartID)) { var part = CoreReflector.GetValue(Skin, skinPartID); if (pce.NewValue == null) { if (!(part is IFactory)) { PartRemoved(skinPartID, part); } CoreReflector.SetValue(this, skinPartID, pce.NewValue); } else { part = pce.NewValue; if (!(part is IFactory)) { PartAdded(skinPartID, part); } } } } }
public FadeInUp2() { Name = "Fade in up"; Add( new SetProperty("Visible", true) { Name = "Setting Visible" }, new SetProperty("Alpha", 0f) { Name = "Setting Alpha" }, new SetPropertyFunc(delegate(object target) { CoreReflector.SetValue(target, "Y", (float)CoreReflector.GetValue(target, "Y") + Offset * 2); }), new Sequence( new Parallel( new Tween { Property = "Alpha", Duration = 0.3f, Easer = Linear.EaseIn, StartValue = 0f, //StartValueReader = new PropertyReader("Alpha"), EndValue = 1f }, new Tween { Property = "Y", Duration = 0.5f, Easer = Expo.EaseOut, StartValueReaderFunction = StartValueReaderFunc, EndValueReaderFunction = EndValueReaderFunc } ), new Tween { Property = "Y", Duration = 0.5f, Easer = Expo.EaseInOut, StartValueReaderFunction = StartValueReaderFunc, EndValueReaderFunction = EndValueReaderFunc } ) //new Action(delegate { Debug.Log("Finished"); }) ); }
/// <summary> /// Returns the collection of available styles for a given type /// </summary> /// <param name="type"></param> /// <returns></returns> public override Dictionary <string, MemberDescriptor> GetStyleDescriptors(Type type) { // we should reflect a given component type and get properties and fields //return EditorReflector.GetStyleProperties(type, true); // restrict Dictionary <string, MemberDescriptor> output = new Dictionary <string, MemberDescriptor>(); // 1. getting all public fields var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public); foreach (var fieldInfo in fields) { var name = fieldInfo.Name; object @default = null; var styleAttributes = CoreReflector.GetMemberAttributes <StyleAttribute>(fieldInfo); if (styleAttributes.Count > 0) { @default = styleAttributes[0].GetDefault(); /*if (!string.IsNullOrEmpty(styleAttributes[0].Name)) * name = styleAttributes[0].Name; // attribute value overrides the name*/ } var prop = new MemberDescriptor(name, fieldInfo.FieldType, GetStyleIcon(fieldInfo.FieldType), @default);// StyleProperty.CreateProperty(fieldInfo.FieldType); output[fieldInfo.Name] = prop; } // 2. getting all public properties having a *setter* var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (var propertyInfo in properties) { //if (propertyInfo.GetSetMethod() == null) if (!propertyInfo.CanWrite) { continue; // get only writeable propertis } var name = propertyInfo.Name; object @default = null; var styleAttributes = CoreReflector.GetMemberAttributes <StyleAttribute>(propertyInfo); if (styleAttributes.Count > 0) { @default = styleAttributes[0].GetDefault(); /*if (!string.IsNullOrEmpty(styleAttributes[0].Name)) * name = styleAttributes[0].Name; // attribute value overrides the name*/ } var prop = new MemberDescriptor(name, propertyInfo.PropertyType, GetStyleIcon(propertyInfo.PropertyType), @default);// StyleProperty.CreateProperty(fieldInfo.FieldType); output[propertyInfo.Name] = prop; } return(output); }
///<summary> ///</summary> ///<param name="item"></param> ///<param name="labelField"></param> ///<param name="labelFunction"></param> ///<returns></returns> public static string ItemToLabel(object item, string labelField /*=null*/, LabelFunction labelFunction /*=null*/) { if (null != labelFunction) { return(labelFunction(item)); } // early check for Strings if (item is string) { return((string)item); } if (item != null) { try { //if (item[labelField] != null) // item = item[labelField]; var val = CoreReflector.GetValue(item, labelField); if (null != val) { item = val; } } catch (Exception ex) { Debug.LogError(string.Format(@"Cannot read value ""{0}"" from object {1}: {2}", labelField, item, ex)); } } // late check for strings if item[labelField] was valid if (item is string) { return((string)item); } try { if (null != item) { return(item.ToString()); } } catch (Exception ex) { Debug.LogError(string.Format(@"Cannot convert to string: ""{0}"": {1}", item, ex)); } return(" "); }
/*public static List<EventAttribute> GetEvents(Type componentType) * { * object[] list = componentType.GetCustomAttributes(typeof(EventAttribute), true); * var events = new List<EventAttribute>(); * foreach (var e in list) * { * events.Add((EventAttribute) e); * } * return events; * }*/ private static void GetEventsRecursive(ComponentAdapter clickedAdapter, ComponentAdapter currentAdapter, ref Dictionary <string, EventAttribute> dict, bool bubbling, ICollection <ComponentAdapter> adaptersToExclude) { Type componentType = currentAdapter.ComponentType; if (null == adaptersToExclude || !adaptersToExclude.Contains(currentAdapter)) { //object[] list = componentType.GetCustomAttributes(typeof (EventAttribute), true); var eventAttributes = CoreReflector.GetClassAttributes <EventAttribute>(componentType); foreach (EventAttribute attribute in eventAttributes) { if (clickedAdapter == currentAdapter) { /** * 1. If this is a clicked adapter, get all events * */ dict[attribute.Name] = attribute; } else if (bubbling && attribute.Bubbles) // if (bubbling) { /** * 2. Else get only events that may bubble from children * */ dict[attribute.Name] = attribute; } /*if (!bubbling || attribute.Bubbles) // if (bubbling) * { * // bubbling events only * if (attribute.Bubbles) * dict[attribute.Name] = attribute; * } * else * { * // target events only * dict[attribute.Name] = attribute; * }*/ //Debug.Log(" --> " + attribute.Name); } } if (bubbling) { Transform transform = currentAdapter.transform; var childCount = transform.childCount; for (int i = 0; i < childCount; i++) { var childTransform = transform.GetChild(i); ComponentAdapter childAdapter = GuiLookup.GetAdapter(childTransform); GetEventsRecursive(clickedAdapter, childAdapter, ref dict, true, adaptersToExclude); } } }
public static Type GetHostComponent(Type skinType) { var hostComponentAttributes = CoreReflector.GetClassAttributes <HostComponentAttribute>(skinType); //Debug.Log("hostComponentAttributes.Length: " + hostComponentAttributes.Length); if (hostComponentAttributes.Count > 0) { var attr = hostComponentAttributes[0]; return(attr.Type); } return(null); }
/// <summary> /// Reads the property /// </summary> /// <returns></returns> public object Read() { object value = CoreReflector.GetValue(Target, Property); #if DEBUG if (DebugMode) { Debug.Log(string.Format("Value read [{0}, {1}]: {2}", Target, Property, value)); } #endif return(value); }
internal static object GetProxyMemberValue(Type proxyType, string memberName) { object singleton = GetProxySingleton(proxyType); try { return(CoreReflector.GetValue(singleton, memberName)); } catch (Exception ex) { throw new Exception(string.Format("Cannot get member named [{0}] on singleton instance of type [{1}]", memberName, proxyType), ex); } }
public int Compare(T xWord, T yWord) { // GetEaser property values object xValue = CoreReflector.GetValue(xWord, _sortField); object yValue = CoreReflector.GetValue(yWord, _sortField); // Determine sort order if (_descending) { return(CompareDescending(xValue, yValue)); } return(CompareAscending(xValue, yValue)); }
/// <summary> /// Describes mulricast delegates /// </summary> /// <param name="componentType"></param> /// <returns></returns> public static string GetMulticastDelegates(Type componentType) { var memberNames = CoreReflector.GetFieldAndPropertyNames(componentType); //memberNames.Sort(MemberInfoSort); List <string> data = new List <string>(); foreach (var name in memberNames) { MemberWrapper mw = new MemberWrapper(componentType, name); if (mw.MemberType == typeof(Core.Events.MulticastDelegate)) { var output = mw.MemberInfo.Name; /*var clazz = mw.MemberInfo.DeclaringType; * if (null != clazz) * { * var types = * * * var instance = Activator.CreateInstance(clazz); * var value = mw.GetValue(instance); * if (null != value) * output = string.Format(@"{0} [{1}]", output, value.GetType().FullName); * }*/ var attributes = CoreReflector.GetMemberAttributes <EventAttribute>(mw.MemberInfo); if (attributes.Count > 0) { var eventAttribute = attributes[0]; output = string.Format(@"{0} → {1}", output, eventAttribute); } data.Add(output); } } data.Sort(); StringBuilder sb = new StringBuilder(); foreach (var item in data) { sb.AppendLine(item); } return(string.Format(@"Multicast delegates ({0}): {1} {2}", data.Count, Line, sb) + NewLine /* + NewLine*/); }
public override void UpdateStyles(Selector selector, DictionaryDelta delta) { // nothing yet //Debug.Log("UpdateStyles: " + delta); var components = GetComponentsMatchingSelector(selector); delta.Process(); foreach (Component component in components) { // TODO: find out which property changed and its value //var changedProp = _modifiedPropertyName; //component.SetStyle("paddingLeft", 30); // 1. for removals, clear the style foreach (string removal in delta.Removals.Keys) { // TODO: set the default value (if exists) // (default values should be implemented via the attribute) //Debug.Log("Removing -> " + removal); MemberWrapper wrapper = new MemberWrapper(component.GetType(), removal); object value = null; var attributes = CoreReflector.GetMemberAttributes <StyleAttribute>(wrapper.MemberInfo); if (attributes.Count > 0) { value = attributes[0].GetDefault(); } wrapper.SetValue(component, value); } // 2. for additions, set the style foreach (KeyValuePair <string, object> addition in delta.Additions) { MemberWrapper wrapper = new MemberWrapper(component.GetType(), addition.Key); wrapper.SetValue(component, addition.Value); } // 3. for updates, set the style foreach (KeyValuePair <string, object> update in delta.Updates) { MemberWrapper wrapper = new MemberWrapper(component.GetType(), update.Key); wrapper.SetValue(component, update.Value); } UnityComponentStylingGizmo.Show(components); } }
public override Dictionary <string, bool> Get(Type key) { //Debug.Log("Key: " + key); var partDict = base.Get(key); if (null == partDict) { partDict = new Dictionary <string, bool>(); MemberInfo[] proxyMembers = key.GetMembers(BindingFlags.Public | BindingFlags.GetField | BindingFlags.Instance /*BindingFlags.NonPublic | BindingFlags.Instance*/); //BindingFlags.Public | BindingFlags.GetField | BindingFlags.GetProperty); foreach (MemberInfo proxyMemberInfo in proxyMembers) { //var skinPartAttributes = proxyMemberInfo.GetCustomAttributes(typeof(SkinPartAttribute), true); var skinPartAttributes = CoreReflector.GetMemberAttributes <SkinPartAttribute>(proxyMemberInfo); foreach (SkinPartAttribute attribute in skinPartAttributes) { if (null != attribute) { string id = attribute.Id; if (string.IsNullOrEmpty(id)) // Id is optional { // If Id not defined, lookup by member name // Skin should contain a member having the same name id = proxyMemberInfo.Name; } partDict.Add(id, attribute.Required); //Debug.Log(" -> " + id + ": " + skinPartAttribute.Required); } } } Instance.Put(key, partDict); #if DEBUG if (DebugMode) { Debug.Log("Type added to SkinPartCache: " + key); } #endif } return(partDict); }
/// <summary> /// Describes component events /// </summary> /// <param name="componentType"></param> /// <returns></returns> public static string GetEvents(Type componentType) { //var events = ReflectionUtil.GetEvents(componentType); var events = CoreReflector.GetClassAttributes <EventAttribute>(componentType); events.Sort(EventSort); StringBuilder sb = new StringBuilder(); foreach (var eventAttribute in events) { sb.AppendLine(eventAttribute.ToString()); } return(string.Format(@"Events ({0}): {1} {2}", events.Count, Line, sb) + NewLine /* + NewLine*/); }
/// <summary> /// Gets all style properties /// </summary> /// <param name="type"></param> /// <param name="restrictToInspectableTypes"></param> public static List <StyleAttribute> GetStyleAttributes(Type type) { if (StyleAttributeCache.ContainsKey(type)) { return(StyleAttributeCache[type]); } var styleAttributes = CoreReflector.GetClassAttributes <StyleAttribute>(type); List <StyleAttribute> attributes = new List <StyleAttribute>(); foreach (StyleAttribute attribute in styleAttributes) { /* with "skinClass" style, the Type isn't required. Set it here */ /*if (attribute.Name == "skinClass" && null == attribute.Type) * attribute.Type = typeof(object);*/ if (/*!restrictToInspectableTypes || */ (attribute.Name == "skinClass" || null != attribute.Type /* && StyleProperty.AlowedTypes.ContainsKey(attribute.Type)*/)) { /** * Important: Avoid duplication * Subclass attributes are being added before the superclass attributes, so we're fine * */ var name = attribute.Name; if (!attributes.Exists(delegate(StyleAttribute a) { return(a.Name == name); })) { attributes.Add(attribute); } else { //Debug.Log(type + " has duplicated attribute: " + name + ": " + attribute.GetDefault()); } } } StyleAttributeCache[type] = attributes; return(attributes); }
public override void Play() { #if DEBUG if (DebugMode) { Debug.Log(string.Format("SetProperty.Play {0}, {1}, {2}", Target, Property, Value)); } #endif CoreReflector.SetValue(Target, Property, Value); //if (IsChild) //{ // //Parent.FinishedCount++; // Parent.Count--; //} //if (DestroyOnFinish) // Destroy(); }
public void ReflectAttribute() { var attributes = CoreReflector.GetClassAttributes <StyleModuleAttribute>(GetType()); if (attributes.Count == 0) { throw new Exception("Style module must be decorated with StyleModuleAttribute"); } StyleModuleAttribute attribute = attributes[0]; Id = attribute.Id; Description = attribute.Description; Icon = attribute.Icon; AllowMultipleClients = attribute.AllowMultipleClients; AllowSubjectOmmision = attribute.AllowSubjectOmmision; ProcessEditModeChanges = attribute.ProcessEditModeChanges; ProcessPlayModeChanges = attribute.ProcessPlayModeChanges; }
/// <summary> /// Recursively instantiates components specified by descriptors in the hierarchy /// </summary> /// <param name="assignToDescriptor">Register to transform, and put into registry so it is available by clicking</param> public virtual void InstantiateChildren(bool assignToDescriptor) { // getting references to collections var childGroupDescriptors = DesignerReflection.GetChildGroupsReferences(this); foreach (ChildGroupDescriptor groupDescriptor in childGroupDescriptors) { List <ComponentAdapter> childAdapters = groupDescriptor.GetChildAdaptersCollection(this); if (null == childAdapters) { continue; } if (null == Component) // not instantiated { return; } Group targetContainer; if (null != groupDescriptor.TargetContainerMemberInfo) { /** * 1. Try reading the member as a Group * */ targetContainer = (Group)CoreReflector.GetMemberValue( groupDescriptor.TargetContainerMemberInfo, Component ); } else { /** * 2. Try casting this to Group (if this is a Stage class for instance) * */ targetContainer = Component as Group; } ComponentAdapterUtil.PopulateContainer(Component, targetContainer, childAdapters.ToArray(), assignToDescriptor, false, true); } }
/// <summary> /// Gets all skin classes /// </summary> public static List <Type> GetAllStyleableClasses() { List <Type> allTypes = TypeReflector.GetAllLoadedTypes(); List <Type> output = new List <Type>(); foreach (Type type in allTypes) { if (type.IsClass) { if (/*!GuiComponentsOnly || */ StyleClientType.IsAssignableFrom(type)) { if (CoreReflector.HasClassAttributes <StyleAttribute>(type)) { output.Add(type); } } } } return(output); }
/** * * This method allows us to determine what underlying data type we need to * perform comparisions on and set the appropriate compare method. * If an option like numeric is set it will take precedence over this aspect. */ internal void InitCompare(object obj) { // if the compare function is not already set then we can set it if (!UsingCustomCompareFunction) { if (null != Numeric) { _compareFunction = NumericCompare; } else if (_caseInsensitive || (Numeric is bool && (bool)Numeric == false)) { _compareFunction = StringCompare; } else { // we need to introspect the data a little bit object value = null; if (!string.IsNullOrEmpty(_name)) { try { //value = obj[_name]; value = CoreReflector.GetValue(obj, _name); } // ReSharper disable once EmptyGeneralCatchClause catch (Exception ex) { } } //this needs to be an == null check because !value will return true //where value == 0 or value == false if (value == null) { value = obj; } var typ = value.GetType(); if (typ == typeof(string)) { _compareFunction = StringCompare; } else if (typ == typeof(object)) { if (value is DateTime) { _compareFunction = DateCompare; } else { _compareFunction = StringCompare; string test = null; try { test = value.ToString(); } // ReSharper disable once EmptyGeneralCatchClause catch (Exception ex) { } if (null == test /* || test == "[object Object]"*/) { _compareFunction = NullCompare; } } } else if (typ == typeof(bool) || typ == typeof(float)) { _compareFunction = NumericCompare; } /*switch (typ) * { * case "string": * _compareFunction = stringCompare; * break; * case "object": * if (value is Date) * { * _compareFunction = dateCompare; * } * else * { * _compareFunction = stringCompare; * var test:String; * try * { * test = value.toString(); * } * catch(error2:Error) * { * } * if (!test || test == "[object Object]") * { * _compareFunction = nullCompare; * } * } * break; * case "xml": * _compareFunction = xmlCompare; * break; * case "boolean": * case "number": * _compareFunction = numericCompare; * break; * }*/ } // else } // if }
/// <summary> /// Reads the value from the given object /// TODO: use the one from Core utils? /// </summary> /// <param name="target"></param> /// <param name="variableName"></param> /// <returns></returns> public static object ReadValue(object target, string variableName) { //return target.GetType().GetProperty(variableName).GetValue(target, Index); return(CoreReflector.GetValue(target, variableName)); }
/// <summary> /// Constructor /// </summary> /// <param name="target">The target</param> internal PersistedComponent(Object target) { /** * 1. Save metadata * */ _target = target; _type = _target.GetType(); _instanceId = _target.GetInstanceID(); var adapter = _target as ComponentAdapter; if (null != adapter) { ComponentRegistry.Instance.Register(_instanceId, adapter); } #if DEBUG if (DebugMode) { _sb = new StringBuilder(); foreach (MemberInfo memberInfo in _type.GetMembers()) { var attributes = CoreReflector.GetMemberAttributes <SaveableAttribute>(memberInfo); //foreach (Attribute attr in memberInfo.GetCustomAttributes(typeof(SaveableAttribute), true)) foreach (var attribute in attributes) { if (attribute.IsSaveable) { _sb.AppendLine(string.Format(" - {0}; {1}", memberInfo.Name, memberInfo)); } } } Debug.Log(string.Format(@"[{0}] SaveableMembers: {1} {2}", _target, SaveableMembers.Count(_type), _sb), _target); } #endif /** * 2. Adding the new member info to SaveableMembers dictionary * This is done for each saveable type in the component * Each member that must be persisted should be decorated with [Saveable] * */ foreach (MemberInfo memberInfo in _type.GetMembers()) { var attributes = CoreReflector.GetMemberAttributes <SaveableAttribute>(memberInfo); foreach (SaveableAttribute attribute in attributes) { if (attribute.IsSaveable) { // doesn't add anything if it already exists SaveableMembers.Put(_type, memberInfo); } } } /** * 3. Take a snapshot of the original values * */ TakeSnapshot(_originalValues); }
private void FindSkinParts() { if (null == _thisType) { _thisType = GetType(); } var parts = SkinParts.Keys; foreach (var id in parts) { object part = null; /** * 1. If this is a mapper skin, * */ if (_isMapperSkin) { part = Skin.GetChildComponent(id); //if (null != part) // Debug.Log("Found mapper skin part: " + part); //else // Debug.Log(Skin + " -> Couldn't find mapper skin part: " + id); } else { if (CoreReflector.HasMember(Skin, id)) { try { part = CoreReflector.GetValue(Skin, id); } catch (InvalidCastException /* ex*/) { Debug.LogError(string.Format("Cannot cast the skin part to InteractiveComponent. Skin: {0}; Part: {1}", Skin, id)); } } //else // Debug.LogWarning("Couldn't find member: " + id); } if (SkinParts[id]) // == true (required part) { if (null == part) { throw new Exception("Required skin part not found: " + id); } } if (null != part) { /** * Note: we've been having a hard-core bug here (20131216)! * The system FREEZED when using Panel with children in designer * For instance, a panel had a single button child as a content child (not tool or control bar child) * This is also the source of bug whereever we add a child prior to adding itself to the display list (both designer and code) * I think it might be related to styles and StyleProtoChain process (?) * This shoould - of course - be fixed * The problem with designer was in ComponentAdapter ("Produce" method): * _component.AddEventListener(FrameworkEvent.PREINITIALIZE, InitializeHandler) * During the PREINITILIZE, child components have not yet been created - so the skin wasn't created * When I changed it to INITILIZE, it started to work properly: * _component.AddEventListener(FrameworkEvent.INITIALIZE, InitializeHandler) * * */ /*if (id == "ContentGroup") * Debug.LogWarning("ContentGroup: " + part);*/ //CoreReflector.SetValue(this, id, part); MemberWrapper wrapper = new MemberWrapper(GetType(), id); wrapper.SetValue(this, part); // If the assigned part has already been instantiated, call partAdded() here, // but only for static parts. try { /* Note: this fails, because the wrapper wraps around the Skin's property, not the Panel's */ //var p = CoreReflector.GetValue(this, id); wrapper = new MemberWrapper(GetType(), id); var p = wrapper.GetValue(this); // TODO: we should get the value silently here, because not to disturb the DoubleGroup.Modified flag //Debug.Log("Just added: " + p); // If the assigned part has already been instantiated, call partAdded() here, // but only for static parts. if (null != p && !(p is IFactory)) { PartAdded(id, p); } } catch (ArgumentException ex) { throw ex; } } } }