Exemple #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);
        }
Exemple #2
0
        /// <summary>
        /// This method will audit all the MessageDispatcher components assigned
        /// </summary>
        public void AuditAllMessageDispatchers()
        {
            var newDict           = NewMessageDictionary <GeneralPageNavigationMessage>();
            var updatedDictionary = KeepExistingAddNewRemoveOutdated(newDict, defaultBehaviourUnactiveMessages);

            defaultBehaviourUnactiveMessages = updatedDictionary;
        }
Exemple #3
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);
        }