コード例 #1
0
        /**
         * Enables the drag and drop functionality for this {@code DynamicListView}.
         * <p/>
         * <b>NOTE: This method can only be called on devices running ICS (14) and above, otherwise an exception will be thrown.</b>
         *
         * @throws java.lang.UnsupportedOperationException if the device uses an older API than 14.
         */
        //@SuppressLint("NewApi")
        public void enableDragAndDrop()
        {
            if (Build.VERSION.SdkInt < BuildVersionCodes.IceCreamSandwich)
            {
                throw new Java.Lang.UnsupportedOperationException("Drag and drop is only supported API levels 14 and up!");
            }

            mDragAndDropHandler = new DragAndDropHandler(this);
        }
コード例 #2
0
 /* <summary>
  * The function is called when the component is instantiated
  * </summary>
  */
 private void Awake()
 {
     if ((singleton != null) && (singleton != this))
     {
         Destroy(this);
         return;
     }
     singleton = this;
 }
コード例 #3
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(gameObject);
     }
 }
コード例 #4
0
 /**
  * Disables the drag and drop functionality.
  */
 public void disableDragAndDrop()
 {
     mDragAndDropHandler = null;
 }
コード例 #5
0
        public virtual XMLSerializable InspectorGUIDragAndDropField(string FieldLabel, XMLSerializable CurrentValue, DragAndDropHandler HandlerFunction, int Index = -1)
        {
            XMLSerializable NewObject = CurrentValue;

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.PrefixLabel(FieldLabel);

            GUILayout.Box(CurrentValue != null ? CurrentValue.EditorGetDisplayName() : "", GUILayout.ExpandWidth(true));

            Rect DropBoxRect = GUILayoutUtility.GetLastRect();

            if (DropBoxRect.Contains(Event.current.mousePosition))
            {
                EventType TypeOfEvent = Event.current.type;

                if (TypeOfEvent == EventType.DragUpdated || TypeOfEvent == EventType.DragPerform)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                    if (TypeOfEvent == EventType.DragPerform)
                    {
                        DragAndDrop.AcceptDrag();

                        NewObject = HandlerFunction(DragAndDrop.paths[0], Index);

                        if (NewObject == null)
                        {
                            NewObject = CurrentValue;
                        }
                    }

                    Event.current.Use();
                }
            }

            EditorGUILayout.EndHorizontal();

            return(NewObject);
        }
コード例 #6
0
        public virtual void InspectorGUIDictionaryDropAndObject <KeyType, ValueType>(string DictionaryName, string KeyPrefix, string ValuePrefix, ref Dictionary <KeyType, ValueType> CurrentDictionary, DragAndDropHandler DropHandler, GetEditorWrapper WrapperForValue, bool bReadOnly = false, bool bStartOpen = false)
            where KeyType : XMLSerializable, new()
            where ValueType : XMLSerializable, new()
        {
            if (!InspectorArrayExpanded.ContainsKey(DictionaryName))
            {
                InspectorArrayExpanded.Add(DictionaryName, bStartOpen);
            }

            bool bDictionaryExpanded = InspectorArrayExpanded[DictionaryName];

            bDictionaryExpanded = EditorGUILayout.Foldout(bDictionaryExpanded, DictionaryName);

            InspectorArrayExpanded[DictionaryName] = bDictionaryExpanded;

            if (bDictionaryExpanded)
            {
                EditorGUI.indentLevel += 1;

                int  NewDictionaryCount    = CurrentDictionary.Keys.Count;
                int  OldDictionaryCount    = NewDictionaryCount;
                bool bCountActuallyChanged = false;

                if (bReadOnly)
                {
                    EditorGUILayout.LabelField("Count", CurrentDictionary.Keys.Count.ToString());
                }
                else
                {
                    bCountActuallyChanged = InspectorGUIIntWaitForEnter(DictionaryName + "Count", "Count", OldDictionaryCount, out NewDictionaryCount);
                }

                if (bCountActuallyChanged && NewDictionaryCount != CurrentDictionary.Keys.Count)
                {
                    bInspectorHasChangedProperty = true;

                    if (NewDictionaryCount > CurrentDictionary.Keys.Count)
                    {
                        for (int CurrentElement = CurrentDictionary.Keys.Count; CurrentElement < NewDictionaryCount; ++CurrentElement)
                        {
                            CurrentDictionary.Add(new KeyType(), new ValueType());
                        }
                    }
                    else
                    {
                        int CurrentIndex = 0;

                        foreach (KeyValuePair <KeyType, ValueType> CurrentElement in CurrentDictionary)
                        {
                            if (CurrentIndex >= NewDictionaryCount)
                            {
                                CurrentDictionary.Remove(CurrentElement.Key);
                            }

                            ++CurrentIndex;
                        }
                    }
                }

                int SmallestSize = OldDictionaryCount > NewDictionaryCount ? NewDictionaryCount : OldDictionaryCount;

                for (int CurrentIndex = 0; CurrentIndex < SmallestSize; ++CurrentIndex)
                {
                    int CurrentDictionaryIndex = 0;

                    foreach (KeyValuePair <KeyType, ValueType> CurrentElement in CurrentDictionary)
                    {
                        if (CurrentIndex == CurrentDictionaryIndex)
                        {
                            EditorGUILayout.BeginVertical("box");

                            KeyType NewKey = (KeyType)InspectorGUIDragAndDropField(KeyPrefix + " " + CurrentIndex, CurrentElement.Key, DropHandler, CurrentIndex);

                            ValueType NewValue = CurrentElement.Value;

                            if (NewKey != CurrentElement.Key)
                            {
                                CurrentDictionary.Remove(CurrentElement.Key);
                                CurrentDictionary.Add(NewKey, NewValue);
                            }

                            InspectableObject ValueInspector = WrapperForValue(NewValue, CurrentIndex);

                            if (ValueInspector != null)
                            {
                                bInspectorHasChangedProperty = ValueInspector.InnerInspectorGUI() || bInspectorHasChangedProperty;
                            }

                            EditorGUILayout.EndVertical();

                            break;
                        }

                        ++CurrentDictionaryIndex;
                    }
                }

                EditorGUI.indentLevel -= 1;
            }
        }