예제 #1
0
        /// <summary>
        /// Generate a new dictionary containing all the messages handled by all the MessageDispatcher componenents
        /// </summary>
        /// <typeparam name="T">The reserved Message Class accountable about the Page behaviour</typeparam>
        /// <returns>A new dictionary containing all the messages</returns>
        private DictionaryOfStringBool NewMessageDictionary <T>()
        {
            DictionaryOfStringBool tmpDictionary = new DictionaryOfStringBool();

            // Get all available Messages Types
            var availableMessagesTypes = TypeResolver.TypesWithMessageAttribute.OrderBy(message => message.ToString()).ToArray();

            // Getting al message dispatchers
            MessagesDispatcher[] messagesDispatcherComponents = GetComponents <MessagesDispatcher>();
            foreach (var messagesDispatcherComponent in messagesDispatcherComponents)
            {
                // Choose the index chosen by unity editor
                int indexChosenByComponent = messagesDispatcherComponent.UnityEditorSelectedMessageTypeIndex;
                // Optaining the type of the message
                if (indexChosenByComponent < 0 || indexChosenByComponent > availableMessagesTypes.Length)
                {
                    // Not a valid Message has been chosen nothing to do here...
                }
                else
                {
                    var type = (Type)availableMessagesTypes[indexChosenByComponent];
                    // Checking if the type is a Subclass of GeneralUpdateMessage
                    if (type.IsSubclassOf(typeof(T)))
                    {
                        if (tmpDictionary.ContainsKey(type.Name))
                        {
                            tmpDictionary[type.Name] = true;
                        }
                        tmpDictionary.Add(type.Name, true);
                    }
                }
            }
            return(tmpDictionary);
        }
예제 #2
0
        /// <summary>
        /// This method will update the values of the first dictionary and update them with the latter
        /// </summary>
        /// <param name="newDict"></param>
        /// <param name="oldDict"></param>
        /// <returns></returns>
        private DictionaryOfStringBool KeepExistingAddNewRemoveOutdated(Dictionary <string, bool> newDict, DictionaryOfStringBool oldDict)
        {
            var tmpDict = new DictionaryOfStringBool();

            foreach (var rowEntry in newDict)
            {
                if (oldDict.ContainsKey(rowEntry.Key))
                {
                    tmpDict[rowEntry.Key] = oldDict[rowEntry.Key];
                }
                else
                {
                    tmpDict.Add(rowEntry.Key, rowEntry.Value);
                }
            }

            return(tmpDict);
        }