コード例 #1
0
            private void OnDragPerform(EventBase evt)
            {
                Object validatedObject = DNDValidateObject();

                if (validatedObject != null)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
                    m_ObjectField.SetValueAndNotify(validatedObject);

                    DragAndDrop.AcceptDrag();
                    RemoveFromClassList("acceptDrop");

                    evt.StopPropagation();
                }
            }
コード例 #2
0
            private void OnIMGUI(EventBase evt)
            {
                if (evt.imguiEvent.type == EventType.DragUpdated || evt.imguiEvent.type == EventType.DragPerform)
                {
                    Object[] references      = DragAndDrop.objectReferences;
                    Object   validatedObject = EditorGUI.ValidateObjectFieldAssignment(references, m_ObjectField.objectType, null, EditorGUI.ObjectFieldValidatorOptions.None);

                    if (validatedObject != null)
                    {
                        // If scene objects are not allowed and object is a scene object then clear
                        if (!m_ObjectField.allowSceneObjects && !EditorUtility.IsPersistent(validatedObject))
                        {
                            validatedObject = null;
                        }
                    }

                    if (validatedObject != null)
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
                        if (evt.imguiEvent.type == EventType.DragPerform)
                        {
                            m_ObjectField.SetValueAndNotify(validatedObject);

                            DragAndDrop.AcceptDrag();

                            evt.StopPropagation();

                            RemoveFromClassList("acceptDrop");
                        }
                        else
                        {
                            AddToClassList("acceptDrop");
                        }
                    }
                }
            }