コード例 #1
0
        public static void DrawTargetScript(ScriptSelector.OnSelectionCallback onSelected, SerializedObject serializedObject)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(7f);
            if (GUILayout.Button("Target Script", "DropDown", GUILayout.Width(96f)))
            {
                ScriptSelector.Show <MonoBehaviour>(onSelected);
            }

            ScriptSelector.DrawProperty("", serializedObject, "targetScript", false, GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();
        }
コード例 #2
0
ファイル: ScriptSelector.cs プロジェクト: yabos/SaveTheQueen
        public static void Show <T>(OnSelectionCallback callback) where T : Object
        {
            string         title    = "Select a target script";
            ScriptSelector selector = ScriptableWizard.DisplayWizard <ScriptSelector>(title);

            selector._title    = title;
            selector._type     = typeof(T);
            selector._callback = callback;
            selector._objects  = Resources.FindObjectsOfTypeAll(typeof(T));
            List <Object> objectList = new List <Object>();

            for (int i = 0; i < selector._objects.Length; i++)
            {
                Object obj = selector._objects[i];
                if (obj.GetType().GetInterface("IBTAI") != null)
                {
                    objectList.Add(obj);
                }
            }
            selector._objects = objectList.ToArray();

            if (selector._objects == null || selector._objects.Length == 0)
            {
                selector.Search();
            }
            else
            {
                System.Array.Sort(selector._objects, delegate(Object a, Object b)
                {
                    if (a == null)
                    {
                        return((b == null) ? 0 : 1);
                    }
                    if (b == null)
                    {
                        return(-1);
                    }
                    return(a.name.CompareTo(b.name));
                });
            }
        }