Exemple #1
0
        protected override void OnDragEnded(BaseHandle handle, HandleEventData eventData)
        {
            if (m_DraggedField)
            {
                m_DraggedField.EndSliderDrag(eventData.rayOrigin);
            }

            // Delay call fixes errors when you close the workspace or change data while dragging a field
            EditorApplication.delayCall += () =>
            {
                if (m_DragClone)
                {
                    ObjectUtils.Destroy(m_DragClone.gameObject);
                }
            };

            if (!m_DragObject)
            {
                InputField inputField = null;
                var        fieldBlock = handle.transform.parent;
                foreach (Transform child in fieldBlock.transform)
                {
                    inputField = child.GetComponent <InputField>();
                    if (inputField)
                    {
                        inputField.OpenKeyboard();
                        break;
                    }
                }

                foreach (var field in m_InputFields)
                {
                    field.CloseKeyboard(inputField == null);
                }

                if (inputField)
                {
                    inputField.OpenKeyboard();
                }
            }

            base.OnDragEnded(handle, eventData);
        }
        protected override void OnDragStarted(BaseHandle baseHandle, HandleEventData eventData)
        {
            base.OnDragStarted(baseHandle, eventData);
            m_DragObject = null;

            var fieldBlock = baseHandle.transform.parent;

            if (fieldBlock)
            {
                if (m_ClickCount == 0)
                {
                    // Get RayInputField from direct children
                    foreach (Transform child in fieldBlock.transform)
                    {
                        m_ClickedField = child.GetComponent <InputField>();
                        if (m_ClickedField)
                        {
                            break;
                        }
                    }
                    StartCoroutine(CheckSingleClick());
                }

                m_ClickCount++;
                m_SelectIsHeld = true;
                m_DragStarts[eventData.rayOrigin] = eventData.rayOrigin.position;

                // Grab a field block on double click
                var timeSinceLastClick = Time.realtimeSinceStartup - m_LastClickTime;
                m_LastClickTime = Time.realtimeSinceStartup;
                if (m_ClickCount > 1 && UIUtils.IsDoubleClick(timeSinceLastClick))
                {
                    CancelSingleClick();

                    var clone = Instantiate(fieldBlock.gameObject, fieldBlock.parent) as GameObject;

                    // Re-center pivot
                    clone.GetComponent <RectTransform>().pivot = Vector2.one * 0.5f;

                    //Re-center backing cube
                    foreach (Transform child in clone.transform)
                    {
                        if (child.GetComponent <BaseHandle>())
                        {
                            var localPos = child.localPosition;
                            localPos.x          = 0;
                            localPos.y          = 0;
                            child.localPosition = localPos;
                        }
                    }

                    m_DragObject   = clone.transform;
                    m_ClickedField = null;                     // Clear clicked field so we don't drag the value

                    var graphics = clone.GetComponentsInChildren <Graphic>(true);
                    foreach (var graphic in graphics)
                    {
                        graphic.material = null;
                    }

                    var stencilRef = requestStencilRef();
                    var renderers  = clone.GetComponentsInChildren <Renderer>(true);
                    foreach (var renderer in renderers)
                    {
                        if (renderer.sharedMaterials.Length > 1)
                        {
                            foreach (var material in m_NoClipHighlightMaterials)
                            {
                                material.SetInt("_StencilRef", stencilRef);
                            }
                            renderer.sharedMaterials = m_NoClipHighlightMaterials;
                        }
                        else
                        {
                            renderer.sharedMaterial = m_NoClipBackingCube;
                            m_NoClipBackingCube.SetInt("_StencilRef", stencilRef);
                        }
                    }
                }
            }
        }