Example #1
0
        public static void ShowWithOptions(string[] options, Action <int> callback)
        {
            SelectWindow window = GetWindow(typeof(SelectWindow)) as SelectWindow;

            window.mHasKeyDown = false;
            window.mOnSelected = callback;
            window.options     = options;
            window.Show();
            //window.Focus();
        }
 private void _setPickerObj(bool checkMulti = false)
 {
     if (mSelectingIndex >= 0 && mSelectingIndex < mTarget.UIArray.Count)
     {
         GameObject obj = EditorGUIUtility.GetObjectPickerObject() as GameObject;
         if (null != obj)
         {
             if (checkMulti)
             {
                 UIBehaviour[] uIBehaviours = obj.GetComponents <UIBehaviour>();
                 if (uIBehaviours.Length > 0)
                 {
                     if (uIBehaviours.Length > 1)
                     {
                         List <UIBehaviour> list    = new List <UIBehaviour>();
                         List <string>      options = new List <string>();
                         for (int i = 0; i < uIBehaviours.Length; i++)
                         {
                             UIBehaviour ui = uIBehaviours[i];
                             if (!mTarget.UIArray.Contains(ui) || mTarget.UIArray.IndexOf(ui) == mSelectingIndex)
                             {
                                 list.Add(ui);
                                 options.Add(ui.ToString());
                             }
                         }
                         if (list.Count > 1)
                         {
                             //TODO:显示选择窗口
                             SelectWindow.ShowWithOptions(options.ToArray(), (int index) =>
                             {
                                 //Debug.Log("Selceted:" + index + ",mTarget.UIArray.Count:" + mTarget.UIArray.Count + "ui index:" + mSelectingIndex);
                                 if (-1 == index)
                                 {
                                     mTarget.UIArray.RemoveAt(mSelectingIndex);
                                 }
                                 else
                                 {
                                     mTarget.UIArray[mSelectingIndex] = list[index];
                                 }
                             });
                         }
                         if (list.Count == 1)
                         {
                             mTarget.UIArray[mSelectingIndex] = list[0];
                         }
                     }
                     else
                     {
                         mTarget.UIArray[mSelectingIndex] = uIBehaviours[0];
                     }
                 }
             }
             else
             {
                 EditorGUIUtility.PingObject(obj);
                 mTarget.UIArray[mSelectingIndex] = obj.GetComponent <UIBehaviour>();
             }
         }
         else
         {
             mTarget.UIArray[mSelectingIndex] = null;
         }
     }
 }