예제 #1
0
        private void ShowAddTrackMenuBaseOnType(FContainerSetting setting)
        {
            Event.current.Use();
            GenericMenu menu = new GenericMenu();

            System.Reflection.Assembly fluxAssembly = typeof(FEvent).Assembly;
            List <KeyValuePair <Type, FEventAttribute> > validTypeList = new List <KeyValuePair <Type, FEventAttribute> >();

            for (int i = 0; i < setting._list.Count; i++)
            {
                string t = setting._list[i];
                if (string.IsNullOrEmpty(t))
                {
                    continue;
                }
                Type type = fluxAssembly.GetType(t);
                if (type == null || !typeof(FEvent).IsAssignableFrom(type))
                {
                    Debug.LogErrorFormat("定义{0} 不是事件类型.", t);
                    continue;
                }

                object[] attributes = type.GetCustomAttributes(typeof(FEventAttribute), false);
                if (attributes.Length == 0 || ((FEventAttribute)attributes[0]).menu == null)
                {
                    continue;
                }

                validTypeList.Add(new KeyValuePair <Type, FEventAttribute>(type, (FEventAttribute)attributes[0]));
            }

            validTypeList.Sort(delegate(KeyValuePair <Type, FEventAttribute> x, KeyValuePair <Type, FEventAttribute> y)
            {
                return(x.Value.menu.CompareTo(y.Value.menu));
            });

            foreach (KeyValuePair <Type, FEventAttribute> kvp in validTypeList)
            {
                menu.AddItem(new GUIContent(kvp.Value.menu), false, AddTrackMenu, kvp);
            }

            menu.ShowAsContext();
        }
예제 #2
0
        protected override void OnHeaderInput(Rect labelRect, Rect iconRect)
        {
            if (Event.current.type == EventType.MouseDown && Event.current.clickCount > 1 && labelRect.Contains(Event.current.mousePosition))
            {
                Selection.activeTransform = Container.Owner;
                Event.current.Use();
            }
            base.OnHeaderInput(labelRect, iconRect);

            if (Event.current.type == EventType.MouseDown && iconRect.Contains(Event.current.mousePosition))
            {
                FSettings         fSettings = FUtility.GetSettings();
                FContainerSetting setting   = fSettings.ContainerType.Find(c => c._type == Container.ConatinerType);
                if (setting == null)
                {
                    ShowAddTrackMenu();
                }
                else
                {
                    ShowAddTrackMenuBaseOnType(setting);
                }
            }
        }
예제 #3
0
파일: FSettings.cs 프로젝트: atom-chen/luxa
        public void Init()
        {
            if (_eventColorsHash == null)
            {
                _eventColorsHash = new Dictionary <string, FColorSetting>();
            }
            else
            {
                _eventColorsHash.Clear();
            }

            foreach (FColorSetting colorSetting in _eventColors)
            {
                if (string.IsNullOrEmpty(colorSetting._str))
                {
                    return;
                }

                if (_eventColorsHash.ContainsKey(colorSetting._str))
                {
                    return; // can't add duplicates!
                }
                _eventColorsHash.Add(colorSetting._str, colorSetting);
            }


            Type containerType            = typeof(Flux.FContainerEnum);
            var  fields                   = Enum.GetValues(containerType);
            List <FContainerSetting> cset = new List <FContainerSetting>(ContainerType);

            ContainerType.Clear();
            for (int i = 0; i < fields.Length; i++)
            {
                Flux.FContainerEnum e = (Flux.FContainerEnum)Enum.Parse(containerType, fields.GetValue(i).ToString());
                if (e == Flux.FContainerEnum.FContainer)
                {
                    continue;
                }

                string title = "-";
                foreach (var pair in Flux.FContainer.ContainerMap)
                {
                    if (pair.Value == e)
                    {
                        title = pair.Key;
                        break;
                    }
                }
                if (title.Equals("-"))
                {
                    continue;
                }

                int index = cset.FindIndex(m => m._type == e);
                if (index < 0)
                {
                    FContainerSetting container = new FContainerSetting(e, title, new List <string>());
                    ContainerType.Add(container);
                }
                else
                {
                    cset[index]._name = title;
                    ContainerType.Add(cset[index]);
                }
            }
        }