public void TransitionToPattern(string id)
        {
            PatternBase next = Get(id);

            if (next == null)
            {
                Debug.LogError("no pattern detected : " + id);
            }

            List <PatternBase> patterns = new List <PatternBase>();

            foreach (var patternPair in currentPriority)
            {
                patterns.Add(patternPair.Key);
            }

            foreach (var item in patterns)
            {
                if (item == next)
                {
                    continue;
                }

                AddPriority(item);
            }

            StartPattern(next);
        }
        private void AddPriority(PatternBase pattern)
        {
            float p = currentPriority[pattern];

            p += priorityMult * (pattern.GetPriority() / priorityMid);

            p = Mathf.Clamp(p, 0, pattern.GetPriority());

            currentPriority[pattern] = p;
        }
        private void SubtractPriority(PatternBase pattern)
        {
            float p = currentPriority[pattern];

            p -= priorityMid;

            p = Mathf.Clamp(p, 0, pattern.GetPriority());

            currentPriority[pattern] = p;
        }
        private void StartPattern(PatternBase next)
        {
            SubtractPriority(next);

            SortByPriority(currentPriority);

            if (currentPattern != null)
            {
                Debug.Log("Previous Pattern : " + currentPattern.id + ", Next Pattern : " + next.id);
            }
            else
            {
                Debug.Log("Next Pattern : " + next.id);
            }

            TransitionToState(next.id);
            currentPattern = next;
        }
        private void SortPriorityOrigins(List <PatternBase> patterns)
        {
            List <PatternBase> unsorted = new List <PatternBase>();

            foreach (var pattern in patterns)
            {
                unsorted.Add(pattern);
            }

            int count = unsorted.Count;

            for (int i = 0; i < count; i++)
            {
                PatternBase highest = GetHighestPriority(unsorted);
                Add(highest);
                unsorted.Remove(highest);
                origins.Add(highest);
            }
        }
        private PatternBase GetHighestPriority(Dictionary <PatternBase, float> patterns)
        {
            float max = 0;

            PatternBase result = null;

            foreach (var pattern in patterns)
            {
                if (pattern.Value < max)
                {
                    continue;
                }

                max = pattern.Value;

                result = pattern.Key;
            }

            return(result);
        }
        private PatternBase GetHighestPriority(List <PatternBase> patterns)
        {
            int max = 0;

            PatternBase result = null;

            foreach (var pattern in patterns)
            {
                if (pattern.GetPriority() < max)
                {
                    continue;
                }

                max = pattern.GetPriority();

                result = pattern;
            }

            return(result);
        }
        private void SortByPriority(Dictionary <PatternBase, float> currentPriority)
        {
            Dictionary <PatternBase, float> unsorted = new Dictionary <PatternBase, float>();

            foreach (var pattern in currentPriority)
            {
                unsorted.Add(pattern.Key, pattern.Value);
            }

            currentPriority.Clear();

            int count = unsorted.Count;

            for (int i = 0; i < count; i++)
            {
                PatternBase highest = GetHighestPriority(unsorted);
                currentPriority.Add(highest, unsorted[highest]);
                unsorted.Remove(highest);
            }
        }