コード例 #1
0
        PopupLists GetPopupLists(GameObject obj)
        {
            PopupLists lists = null;

            if (!mPopupCache.TryGetValue(obj, out lists))
            {
                List <string> events = ReflectionHelpers.GetAllFieldOfType(typeof(UnityEvent), obj);
                events.Insert(0, string.Empty);
                List <string> displayNames = new List <string>();
                displayNames.InsertRange(0, events);
                for (int i = 1; i < displayNames.Count; ++i)
                {
                    string[] parts = displayNames[i].Split('.');
                    for (int j = 0; j < parts.Length; ++j)
                    {
                        parts[j] = InspectorUtility.NicifyClassName(parts[j]);
                    }
                    displayNames[i] = string.Join("/", parts);
                }
                displayNames[0] = "(none)";
                lists           = new PopupLists {
                    eventNames = events, displayNames = displayNames
                };
            }
            return(lists);
        }
コード例 #2
0
        bool DrawEventPopup(Rect r, SerializedProperty eventProp, GameObject eventObj)
        {
            bool       changed   = false;
            PopupLists lists     = GetPopupLists(eventObj);
            int        current   = lists.eventNames.IndexOf(eventProp.stringValue);
            int        selection = EditorGUI.Popup(r, current, lists.displayNames.ToArray());

            if (selection != current)
            {
                eventProp.stringValue = selection < 0 ? string.Empty : lists.eventNames[selection];
                eventProp.serializedObject.ApplyModifiedProperties();
                changed = true;
            }
            return(changed);
        }