Пример #1
0
        public override void OnInspectorGUI()
        {
            var rect = EditorGUILayout.GetControlRect(false, 35f);

            rect = new Rect(rect.xMin + 10f, rect.yMin + 5f, rect.width - 20f, rect.height - 10f);

            if (GUI.Button(rect, "Add Spawn Modifier"))
            {
                TypeSelectionDropDownWindow.ShowAndCallbackOnSelect(rect, typeof(ISpawnerModifier), (tp) =>
                {
                    if (tp != null && TypeUtil.IsType(tp, typeof(Component)))
                    {
                        var go = GameObjectUtil.GetGameObjectFromSource(this.SerializedObject.targetObject);
                        if (go != null)
                        {
                            go.AddComponent(tp);
                        }
                    }
                }, false, false);
            }
        }
        public static System.Type TypeDropDown(Rect position, GUIContent label,
                                               System.Type baseType, System.Type selectedType,
                                               bool allowAbstractTypes           = false, bool allowInterfaces       = false,
                                               System.Type defaultType           = null, System.Type[] excludedTypes = null,
                                               TypeDropDownListingStyle listType = TypeDropDownListingStyle.Namespace)
        {
            /*
             *
             * if (!TypeUtil.IsType(selectedType, baseType)) selectedType = null;
             *
             * //var knownTypes = (from ass in System.AppDomain.CurrentDomain.GetAssemblies()
             * //                  from tp in ass.GetTypes()
             * //                  where TypeUtil.IsType(tp, baseType) && (allowAbstractTypes || !tp.IsAbstract) && (allowInterfaces || !tp.IsInterface)
             * //                  orderby tp.FullName.Substring(tp.FullName.LastIndexOf(".") + 1) ascending
             * //                  select tp).ToArray();
             * var knownTypes = (from tp in TypeUtil.GetTypesAssignableFrom(baseType)
             *                where (allowAbstractTypes || !tp.IsAbstract) && (allowInterfaces || !tp.IsInterface) && (excludedTypes == null || System.Array.IndexOf(excludedTypes, tp) < 0)
             *                orderby tp.FullName.Substring(tp.FullName.LastIndexOf(".") + 1) ascending
             *                select tp).ToArray();
             * GUIContent[] knownTypeNames = null;
             * switch (listType)
             * {
             *  case TypeDropDownListingStyle.Namespace:
             *      knownTypeNames = knownTypes.Select((tp) =>
             *      {
             *          return new GUIContent(tp.FullName.Replace(".", "/"));
             *      }).ToArray();
             *      break;
             *  case TypeDropDownListingStyle.Flat:
             *      knownTypeNames = (from tp in knownTypes select new GUIContent(tp.Name)).ToArray();
             *      break;
             *  case TypeDropDownListingStyle.ComponentMenu:
             *      knownTypeNames = knownTypes.Select((tp) =>
             *      {
             *          var menuAttrib = tp.GetCustomAttributes(typeof(AddComponentMenu), false).FirstOrDefault() as AddComponentMenu;
             *          if (menuAttrib != null && !string.IsNullOrEmpty(menuAttrib.componentMenu))
             *          {
             *              return new GUIContent(menuAttrib.componentMenu);
             *          }
             *          else if (tp.FullName == tp.Name)
             *          {
             *              return new GUIContent("Scripts/" + tp.Name);
             *          }
             *          else
             *          {
             *              if (tp.FullName.StartsWith("UnityEngine."))
             *              {
             *                  return new GUIContent(tp.FullName.Replace(".", "/"));
             *              }
             *              else
             *              {
             *                  return new GUIContent("Scripts/" + tp.FullName.Replace(".", "/"));
             *              }
             *          }
             *      }).ToArray();
             *      break;
             *  default:
             *      knownTypeNames = new GUIContent[0];
             *      break;
             * }
             *
             * if (defaultType == null)
             * {
             *  knownTypes = knownTypes.Prepend(null).ToArray();
             *  knownTypeNames = knownTypeNames.Prepend(new GUIContent("Nothing")).ToArray();
             * }
             *
             * int index = knownTypes.IndexOf(selectedType);
             * index = EditorGUI.Popup(position, label, index, knownTypeNames);
             * return (index >= 0) ? knownTypes[index] : defaultType;
             *
             */

            return(TypeSelectionDropDownWindow.Popup(position, label, baseType, selectedType, allowAbstractTypes, allowInterfaces, defaultType, excludedTypes, listType));
        }