コード例 #1
0
ファイル: SkinUtil.cs プロジェクト: onamoni/edriven-gui
        /// <summary>
        /// Returns true if the skin fits to component<br/>
        /// The skin fits to component if it contains all the required parts (being of required types)
        /// </summary>
        /// <param name="skinType"></param>
        /// <param name="componentType"></param>
        /// <returns></returns>
        public static bool SkinFitsComponent(Type skinType, Type componentType)
        {
            var parts = SkinPartCache.Instance.Get(componentType);

            /**
             * 1. Must have all the required skin parts
             * */
            foreach (var id in parts.Keys)
            {
                if (!parts[id]) // if part not required, continue
                {
                    continue;
                }

                var cmpMember = GlobalMemberCache.Instance.Get(componentType, id);
                if (null == cmpMember)
                {
                    cmpMember = new MemberWrapper(componentType, id);
                    GlobalMemberCache.Instance.Put(componentType, id, cmpMember);
                }

                var skinMember = GlobalMemberCache.Instance.Get(componentType, id);
                if (null == skinMember)
                {
                    /* TODO: undirty this */
                    try
                    {
                        skinMember = new MemberWrapper(skinType, id);
                        GlobalMemberCache.Instance.Put(componentType, id, skinMember);
                    }
                    catch (MemberNotFoundException ex)
                    {
                        // ignore because the member doesn't exist
                    }
                }

                if (null == skinMember || skinMember.GetType() != cmpMember.GetType())
                {
                    return(false);
                }
            }

            /**
             * 2. Must have the same set of states
             * */
            // TODO:
            var skinStates = GuiReflector.GetSkinStates(componentType);

            var hostComponentType = GetHostComponent(skinType);
            var componentStates   = GuiReflector.GetSkinStates(hostComponentType);

            // in current impl. the states have to be in the same order
            var sameStates = ListUtil <string> .Equals(skinStates, componentStates);

            return(sameStates);
            //return true;
        }
コード例 #2
0
        /// <summary>
        /// Checks if there are any changes<br/>
        /// This method is being called when play mode stopped, giving the user a chance to cancel the persistence
        /// </summary>
        /// <returns></returns>
        internal void ProcessChanges()
        {
            //Debug.Log("HasChanges? " + _target);
            _sb = new StringBuilder();
            _changes.Clear();
            _hasChanges = false;

            foreach (MemberInfo memberInfo in _savedValues.Keys)
            {
                /**
                 * 1. Read both the old and new value (i.e. the original and changed value)
                 * */
                var oldValue = _originalValues[memberInfo];
                var newValue = _savedValues[memberInfo];
#if DEBUG
                if (DebugMode)
                {
                    //Debug.Log(string.Format("   {0} [{1}, {2}]", memberInfo, oldValue, newValue));
                }
#endif

                /**
                 * 2. If one of them is null, and the other is, then values are different
                 * */
                if (oldValue == null ^ newValue == null)
                {
                    //Debug.Log("Value differs: " + newValue);
                    RegisterChanges(memberInfo, oldValue, newValue);
                    continue;                     // no need to compare actual values
                }

                /**
                 * 3. If old value isn't null, then the new value isn't null neither (because of the previous check)
                 * Doing the specific check for each type using its own Equals implementation
                 * */
                if (oldValue != null)
                {
                    List <ComponentAdapter> oldList = oldValue as List <ComponentAdapter>;

                    if (null != oldList)
                    {
                        // we have a List value

                        List <ComponentAdapter> newList = newValue as List <ComponentAdapter>;

//                        Debug.Log(string.Format(@"***** Comparing 2 lists:
//--- old ---
//{0}
//--- new ---
//{1}",
//    ComponentAdapterUtil.DescribeAdapterList(oldList),
//    ComponentAdapterUtil.DescribeAdapterList(newList)));

                        bool hasChanges = null == newList;
                        if (!hasChanges)
                        {
                            // Note: if new element added to list, it's adapter is being destroyed by now
                            hasChanges = ComponentAdapterUtil.ListContainsNullReference(oldList);
                        }
                        if (!hasChanges)
                        {
                            hasChanges = ComponentAdapterUtil.ListContainsNullReference(newList);
                        }
                        if (!hasChanges)
                        {
                            hasChanges = !ListUtil <ComponentAdapter> .Equals(oldList, newList);
                        }

                        if (hasChanges)
                        {
//                            Debug.Log(string.Format(@"  -> List changed: {0}.{1}", null == _target ? "_": _target.ToString(), memberInfo.Name));
//                            Debug.Log(@"+++++ newList:
//" + ComponentAdapterUtil.DescribeAdapterList(newList, true));
                            RegisterChanges(memberInfo, oldValue, newValue);
// ReSharper disable once RedundantJumpStatement
                            continue;
                        }
                    }

                    else if (!oldValue.Equals(newValue))
                    {
#if DEBUG
                        if (DebugMode)
                        {
                            Debug.Log("Changes: " + memberInfo.Name + ": " + newValue);
                        }
#endif
                        RegisterChanges(memberInfo, oldValue, newValue);
// ReSharper disable once RedundantJumpStatement
                        continue;
                    }
                }
            }

#if DEBUG
            if (DebugMode)
            {
                if (_hasChanges)
                {
                    Debug.Log(string.Format(@"{0}: {1} changes detected:
			
{2}", null == _target ? "-" : _target.ToString(), _changes.Count, _sb), _target);
                }
                else
                {
                    Debug.Log("NO CHANGES detected.");
                }
            }
#endif
            //return _hasChanges;
        }