예제 #1
0
        public void OnDrop(PointerEventData eventData)
        {
            if (uiCharacterItem == null)
            {
                Debug.LogWarning("[UIEquipItemSlotDropHandler] `uicharacterItem` is empty");
                return;
            }
            if (RectTransformUtility.RectangleContainsScreenPoint(DropRect, Input.mousePosition))
            {
                UIDragHandler dragHandler = eventData.pointerDrag.GetComponent <UIDragHandler>();
                if (dragHandler != null && !dragHandler.isDropped)
                {
                    dragHandler.isDropped = true;
                    // Get owing character
                    BasePlayerCharacterEntity owningCharacter = BasePlayerCharacterController.OwningCharacter;
                    if (owningCharacter == null)
                    {
                        return;
                    }
                    UICharacterItemDragHandler draggedItemUI = dragHandler as UICharacterItemDragHandler;
                    if (draggedItemUI != null)
                    {
                        switch (draggedItemUI.sourceLocation)
                        {
                        case UICharacterItemDragHandler.SourceLocation.EquipItems:
                            break;

                        case UICharacterItemDragHandler.SourceLocation.NonEquipItems:
                            // If dropped non equip item to equip slot, equip it
                            owningCharacter.RequestEquipItem((short)draggedItemUI.uiCharacterItem.IndexOfData, (byte)uiCharacterItem.InventoryType, (short)uiCharacterItem.IndexOfData);
                            break;
                        }
                    }
                }
            }
        }
예제 #2
0
        public virtual void OnBeginDrag(PointerEventData eventData)
        {
            isPointerDownAndNotDragging = false;

            if (!MayDrag(eventData))
            {
                return;
            }

            if (m_ContainerRect == null)
            {
                return;
            }

            m_Offset = Vector2.zero;
            if (RectTransformUtility.RectangleContainsScreenPoint(m_HandleRect, eventData.position, eventData.enterEventCamera))
            {
                Vector2 localMousePos;
                if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_HandleRect, eventData.position, eventData.pressEventCamera, out localMousePos))
                {
                    m_Offset = localMousePos - m_HandleRect.rect.center;
                }
            }
        }
        public void OnBeginDrag(PointerEventData eventData)
        {
            if (rectTransform == null)
            {
                rectTransform = GetComponent <RectTransform>();
            }

            if (MayDrag(eventData) == true)
            {
                var target = TargetTransform;

                if (RectTransformUtility.RectangleContainsScreenPoint(rectTransform, eventData.position, eventData.enterEventCamera) == true)
                {
                    var vector = default(Vector2);

                    if (RectTransformUtility.ScreenPointToLocalPointInRectangle(target, eventData.position, eventData.pressEventCamera, out vector) == true)
                    {
                        dragging    = true;
                        startSize   = target.sizeDelta;
                        startOffset = vector - target.anchoredPosition;
                    }
                }
            }
        }
예제 #4
0
    protected override bool HitTest()
    {
        Vector2 inputPosition = GetInputPosition();


#if CURVEDUI
        if (curvedUI != null)
        {
            Camera activeCamera = image.canvas.renderMode == RenderMode.ScreenSpaceOverlay ? Camera.main : image.canvas.worldCamera;
            return(curvedUI.RaycastToCanvasSpace(activeCamera.ScreenPointToRay(inputPosition), out inputPosition));
        }
#endif

        PointerEventData pe = new PointerEventData(EventSystem.current);
        pe.position = inputPosition;
        List <RaycastResult> hits = new List <RaycastResult>();
        EventSystem.current.RaycastAll(pe, hits);

        if (hits.Count > 0 && hits[0].gameObject != gameObject)
        {
            return(false);
        }
        return(RectTransformUtility.RectangleContainsScreenPoint(image.rectTransform, inputPosition, worldCamera));
    }
예제 #5
0
        /// <summary>
        /// 스크린 좌표가 Rect안에 포함되는지 확인
        /// </summary>
        public static bool inScreenRect(this RectTransform self, Vector2 screenPos)
        {
            var canvas = self.GetComponentInParent <Canvas>();

            switch (canvas.renderMode)
            {
            case RenderMode.ScreenSpaceCamera:
            {
                var camera = canvas.worldCamera;
                if (camera != null)
                {
                    return(RectTransformUtility.RectangleContainsScreenPoint(self, screenPos, camera));
                }
            }
            break;

            case RenderMode.ScreenSpaceOverlay:
                return(RectTransformUtility.RectangleContainsScreenPoint(self, screenPos));

            case RenderMode.WorldSpace:
                return(RectTransformUtility.RectangleContainsScreenPoint(self, screenPos));
            }
            return(false);
        }
예제 #6
0
    /// <summary>
    /// 拖拽开始
    /// </summary>
    /// <param name="eventData"></param>
    public void OnBeginDrag(PointerEventData eventData)
    {
        if (IsOpened || !CanHandle)
        {
            return;
        }
        m_StartDragLocalPoint = ScreenToLocal(eventData) - lastDragSpace;
        if (isStarted)
        {
            interactable = true;
            return;
        }

        if (RectTransformUtility.RectangleContainsScreenPoint(m_PagePlane, eventData.position, eventData.pressEventCamera))
        {
            isStarted        = true;
            m_LastMoveSpace  = MoveSpace;
            m_LastUpdateTime = Time.realtimeSinceStartup;
        }
        else
        {
            isStarted = false;
        }
    }
예제 #7
0
    public void OnDrop(PointerEventData eventData)
    {
        if (EventSystem.current.currentSelectedGameObject != null)
        {
            Vector3 mousePosition = Input.mousePosition;

            RectTransform invEntry = transform as RectTransform;

            Debug.Log("Dropped at " + mousePosition);
            if (RectTransformUtility.RectangleContainsScreenPoint(invEntry, mousePosition))
            {
                gun         = EventSystem.current.currentSelectedGameObject.GetComponent <Draggable>().gun;
                icon.sprite = gun.icon;
                if (gun.name != "Pistol" && gun.name != "Laser" && gun.name != "Shuriken")
                {
                    icon.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 80);
                    icon.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 40);
                    icon.transform.rotation = Quaternion.Euler(0f, 0f, 45f);
                }
                switch (id)
                {
                case 1:
                    SelectedGuns.gun1 = gun;
                    break;

                case 2:
                    SelectedGuns.gun2 = gun;
                    break;

                case 3:
                    SelectedGuns.gun3 = gun;
                    break;
                }
            }
        }
    }
예제 #8
0
    public static bool IsCursorInUIBounds(RectTransform rt, Vector2 cursorPos)
    {
        return(RectTransformUtility.RectangleContainsScreenPoint(rt, cursorPos));

        //Vector2 rMin = new Vector2(rt.rect.xMin, rt.rect.yMin);
        //Vector2 rMax = new Vector2(rt.rect.xMax, rt.rect.yMax);

        //rMin = RectTransformUtility.WorldToScreenPoint(Camera.main, rMin);
        //rMax = RectTransformUtility.WorldToScreenPoint(Camera.main, rMax);

        //if(
        //    cursorPos.x > rt.rect.xMin &&
        //    cursorPos.x < rt.rect.xMax &&
        //    cursorPos.y > rt.rect.yMin &&
        //    cursorPos.y < rt.rect.yMax
        //    )
        //{
        //    return true;
        //}
        //else
        //{
        //    return false;
        //}
    }
예제 #9
0
        private static void Raycast(Canvas canvas, Camera eventCamera, Vector2 pointerPosition, List <Graphic> results)
        {
            // Debug.Log("ttt" + pointerPoision + ":::" + camera);
            // Necessary for the event system
            var foundGraphics = GraphicRegistry.GetGraphicsForCanvas(canvas);

            s_SortedGraphics.Clear();
            for (int i = 0; i < foundGraphics.Count; ++i)
            {
                Graphic graphic = foundGraphics[i];

                // -1 means it hasn't been processed by the canvas, which means it isn't actually drawn
                if (graphic.depth == -1)
                {
                    continue;
                }

                if (!RectTransformUtility.RectangleContainsScreenPoint(graphic.rectTransform, pointerPosition, eventCamera))
                {
                    continue;
                }

                if (graphic.Raycast(pointerPosition, eventCamera))
                {
                    s_SortedGraphics.Add(graphic);
                }
            }

            s_SortedGraphics.Sort((g1, g2) => g2.depth.CompareTo(g1.depth));
            //      StringBuilder cast = new StringBuilder();
            for (int i = 0; i < s_SortedGraphics.Count; ++i)
            {
                results.Add(s_SortedGraphics[i]);
            }
            //      Debug.Log (cast.ToString());
        }
예제 #10
0
    void Update()
    {
        DoUpdate();

        if (Input.GetMouseButtonDown(0))
        {
            var     pos = Input.mousePosition;
            Vector2 uiPos;
            if (RectTransformUtility.RectangleContainsScreenPoint(img.rectTransform, pos))
            {
                RectTransformUtility.ScreenPointToLocalPointInRectangle(img.rectTransform,
                                                                        pos, null, out uiPos);

                uiPos.x += width;
                lastPos  = uiPos;

                tracer.PixelDebug(cameraWrap, uiPos.x / width, uiPos.y / height);
            }
        }
        else if (Input.GetKeyDown(KeyCode.R))
        {
            tracer.PixelDebug(cameraWrap, lastPos.x / width, lastPos.y / height);
        }
    }
예제 #11
0
        /// <summary>
        ///  Use normalized mouse position inside ScrollRect to scroll
        /// </summary>
        void Update()
        {
            if (!m_OverrideScrolling)
            {
                return;
            }
            Vector3 mousePosition = UnityInput.mousePosition;

            // only scroll if mouse is inside ScrollRect
            bool inside = RectTransformUtility.RectangleContainsScreenPoint(m_ScrollRectTransform, mousePosition);

            if (!inside)
            {
                return;
            }

            Rect  rect        = m_ScrollRectTransform.rect;
            float adjustmentX = rect.width * scrollXBuffer,
                  adjustmentY = rect.height * scrollYBuffer;

            Vector2 localPoint;

            RectTransformUtility.ScreenPointToLocalPointInRectangle(m_ScrollRectTransform, mousePosition, null, out localPoint);

            Vector2 pivot = m_ScrollRectTransform.pivot;
            float   x     = (localPoint.x + (rect.width - adjustmentX) * pivot.x) / (rect.width - 2 * adjustmentX);
            float   y     = (localPoint.y + (rect.height - adjustmentY) * pivot.y) / (rect.height - 2 * adjustmentY);

            if (clampScroll)
            {
                x = Mathf.Clamp01(x);
                y = Mathf.Clamp01(y);
            }

            m_ScrollRect.normalizedPosition = new Vector2(x, y);
        }
예제 #12
0
    void Update()
    {
        if (!isPaused)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            foreach (var touch in Input.touches)
            {
                if (touch.phase == TouchPhase.Began &&
                    !RectTransformUtility.RectangleContainsScreenPoint(pauseButton, touch.position))
                {
                    Jump();
                }
            }
#else
            if (Input.GetKeyDown(KeyCode.Space))
            {
                Jump();
            }
#endif
        }

        //optional
        ClampPosition();
    }
예제 #13
0
    public void OnPointerUp(PointerEventData eventData)
    {
        if (!wasDown)
        {
            return;
        }
        text.color = oldTextColor;
        int i = 0;

        foreach (Transform x in objects)
        {
            SpriteRenderer sp = x.GetComponent <SpriteRenderer>();
            sp.color = oldColors[i];
            i++;
        }
        if (!activ)
        {
            return;
        }
        if (RectTransformUtility.RectangleContainsScreenPoint(GetComponent <RectTransform>(), eventData.position, eventData.pressEventCamera))
        {
            buttonUnityEvent.Invoke();
        }
    }
예제 #14
0
        public void OnPointerDown(PointerEventData eventData)
        {
            MapEditorInputMgr.ins.uiCamera = eventData.pressEventCamera;

            if (RectTransformUtility.RectangleContainsScreenPoint(maskRecTran, eventData.position, eventData.pressEventCamera))
            {
                if (MapEditorMgr.ins.touchBehaviour == TouchBehaviour.Added)
                {
                    MapEditorInputMgr.ins.UpdateWithAdded(eventData.position);
                }
                else if (MapEditorMgr.ins.touchBehaviour == TouchBehaviour.Deleted)
                {
                    MapEditorInputMgr.ins.UpdateWithDelete(eventData.position);
                }
                else if (MapEditorMgr.ins.touchBehaviour == TouchBehaviour.Select)
                {
                    MapEditorInputMgr.ins.UpdateWithSelected(eventData.position);
                }
            }
            else
            {
                Debug.Log("OnPointerDown out");
            }
        }
예제 #15
0
        public override void OnPointerDown(PointerEventData eventData)
        {
            if (!CanDrag())
            {
                return;
            }

            base.OnPointerDown(eventData);

            handleOffset = Vector2.zero;
            if (handleContainerRect != null && RectTransformUtility.RectangleContainsScreenPoint(handleRect, eventData.position, eventData.enterEventCamera))
            {
                Vector2 localMousePos;
                if (RectTransformUtility.ScreenPointToLocalPointInRectangle(handleRect, eventData.position, eventData.pressEventCamera, out localMousePos))
                {
                    handleOffset = localMousePos;
                }
                handleOffset.y = -handleOffset.y;
            }
            else
            {
                UpdateDrag(eventData, eventData.pressEventCamera);
            }
        }
예제 #16
0
    void Update()
    {
        for (var i = 0; i < files.Count; i++)
        {
            var file     = files[i];
            var listItem = file.listItem;

            if (RectTransformUtility.RectangleContainsScreenPoint(listItem.GetComponent <RectTransform>(), Input.mousePosition))
            {
                listItem.GetComponent <Image>().color = new Color(210 / 255f, 210 / 255f, 210 / 255f);
            }
            else
            {
                listItem.GetComponent <Image>().color = new Color(239 / 255f, 239 / 255f, 239 / 255f);
            }

            if (i == selectedIndex)
            {
                listItem.GetComponent <Image>().color = new Color(210 / 255f, 210 / 255f, 210 / 255f);
            }

            if (RectTransformUtility.RectangleContainsScreenPoint(listItem.GetComponent <RectTransform>(), Input.mousePosition) &&
                Input.GetMouseButtonDown(0))
            {
                if (lastClickIndex == i && lastClickDelta < .5)
                {
                    Answer();
                }

                SetIndex(i);
                lastClickIndex = i;
                lastClickDelta = 0;
            }
        }
        lastClickDelta += Time.deltaTime;
    }
    public bool FrameContainsPosition(Frame ignoredFrame, Vector3 screenPosition, out Frame frame)
    {
        for (int i = 0; i < m_Frames.Length; i++)
        {
            if (m_Frames[i] == ignoredFrame)
            {
                continue;
            }

            RectTransform rect = m_Frames[i].GetComponent <RectTransform>();


            if (RectTransformUtility.RectangleContainsScreenPoint(rect, screenPosition, Camera.main))
            {
                frame = m_Frames[i];
                PreviousBeingHoverOnFrame = m_Frames[i];
                return(true);
            }
        }

        frame = null;

        return(false);
    }
예제 #18
0
 protected override void Update()
 {
     base.Update();
     this.UpdateAnimations();
     this.UpdateColor();
     this.UpdateEquippedIcon();
     this.m_PadQuitHint.SetActive(GreenHellGame.IsPadControllerActive() && !BodyInspectionController.Get().IsActive());
     this.m_PadSortHint.SetActive(GreenHellGame.IsPadControllerActive() && !BodyInspectionController.Get().IsActive());
     this.m_IsHovered = RectTransformUtility.RectangleContainsScreenPoint(this.m_BG.rectTransform, Input.mousePosition);
     if (this.m_IsHovered)
     {
         PocketImageData pocketImageData = null;
         foreach (PocketImageData pocketImageData2 in this.m_PocketImages)
         {
             if (pocketImageData2.selection.gameObject.activeSelf)
             {
                 pocketImageData = pocketImageData2;
                 break;
             }
         }
         CursorManager.Get().SetCursor((pocketImageData != null) ? CursorManager.TYPE.MouseOver : CursorManager.TYPE.Normal);
         if (pocketImageData != null && Input.GetKeyDown(InputHelpers.PadButton.Button_X.KeyFromPad()))
         {
             this.OnPocketClick(pocketImageData.pocket.ToString());
         }
     }
     foreach (Image image in this.m_PADChangeTabs)
     {
         if (image.gameObject.activeSelf)
         {
             Color color = image.color;
             color.a     = (Inventory3DManager.Get().m_CarriedItem ? (this.m_PADChangeTabDefaultAlpha * 0.5f) : this.m_PADChangeTabDefaultAlpha);
             image.color = color;
         }
     }
 }
    void Update()
    {
        UpdateSelection();

        if (!RectTransformUtility.RectangleContainsScreenPoint(selectionTrans, Input.mousePosition))
        {
            if (Input.GetMouseButtonUp(0))
            {
                // Hovered
                if (!hasSelected)
                {
                    if (curHovered != new Vector2Int(-1, -1))
                    {
                        curSelected            = curHovered;
                        selectorPlane.position = new Vector3((curSelected.x + 0.5f) * 0.125f - 0.5f, (curSelected.y + 0.5f) * 0.125f - 0.5f, raycastHit.point.z);

                        // Update selection menu here
                        selectionFieldUI.EnableMenu(curSelected, currentMana);
                    }
                }
                else
                {
                    if (moveHover)
                    {
                        InvokeAction(1, curHovered);
                    }
                    else
                    {
                        curSelected            = new Vector2Int(-1, -1);
                        selectorPlane.position = new Vector3(0f, -100f, 0f);
                        selectionFieldUI.DisableMenu();
                    }
                }
            }
        }
    }
예제 #20
0
    private void Update()
    {
        Vector3 pointerPosition;
        bool    sprayed;

        if (WiimoteInput.isConnected)
        {
            Vector2 wiiPointerPos = WiimoteInput.GetPointerPosition();
            pointerPosition = new Vector3(wiiPointerPos.x, wiiPointerPos.y, 0f);
            sprayed         = WiimoteInput.isSprayButtonPressed;
        }
        else
        {
            pointerPosition = Input.mousePosition;
            sprayed         = Input.GetButtonDown("Spray");
        }

        Vector2 sprayScreenPos = new Vector2(pointerPosition.x, pointerPosition.y);


        RectTransform rectTransform = GetComponent <RectTransform>();
        bool          isHovering    = RectTransformUtility.RectangleContainsScreenPoint(rectTransform, sprayScreenPos);

        Highlight(isHovering);

        if (isHovering && sprayed)
        {
            SelectUI();
        }


        if (startMenu.StartExitTransition)
        {
            anim.SetBool("doTransition", true);
        }
    }
예제 #21
0
 /// <summary>
 /// Coroutine function for handling continual press during Scrollbar.OnPointerDown.
 /// </summary>
 protected IEnumerator ClickRepeat(PointerEventData eventData)
 {
     while (isPointerDownAndNotDragging)
     {
         if (!RectTransformUtility.RectangleContainsScreenPoint(m_HandleRect, eventData.position, eventData.enterEventCamera))
         {
             Vector2 localMousePos;
             if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_HandleRect, eventData.position, eventData.pressEventCamera, out localMousePos))
             {
                 var axisCoordinate = axis == 0 ? localMousePos.x : localMousePos.y;
                 if (axisCoordinate < 0)
                 {
                     value -= size;
                 }
                 else
                 {
                     value += size;
                 }
             }
         }
         yield return(new WaitForEndOfFrame());
     }
     StopCoroutine(m_PointerDownRepeat);
 }
    public void OnEndDrag(PointerEventData eventData)
    {
        if (canCarryItemIcon)
        {
            getHitIconPanel();
            RectTransform invPanel = transform.parent.parent.GetComponent <RectTransform>();

            if (hitIconPanel != null)
            {
                changeItemIconsDatas(hitIconPanel);
            }
            else if (!RectTransformUtility.RectangleContainsScreenPoint(invPanel, Input.mousePosition))
            {
                Inventory.instance.dropItem(carriedItemIcon);
                transform.localPosition = Vector3.zero;
                resetCarriedItemIconSettings();
            }
            else
            {
                carriedItemIcon_T.localPosition = Vector3.zero;
                resetCarriedItemIconSettings();
            }
        }
    }
예제 #23
0
        // Update is called once per frame
        void Update()
        {
            if (Input.GetMouseButton(0))
            {
                var previewRect = LargePreviewImage.GetComponent <RectTransform>();
                var mapRect     = MapFull.GetComponent <RectTransform>();

                if (_state == State.Preview)
                {
                    if (RectTransformUtility.RectangleContainsScreenPoint(previewRect, Input.mousePosition))
                    {
                        var point = GetRectPosition(previewRect);
                    }
                }
                else if (_state == State.Map)
                {
                    if (RectTransformUtility.RectangleContainsScreenPoint(mapRect, Input.mousePosition))
                    {
                        var point = GetRectPosition(mapRect);
                        Debug.Log(point);
                    }
                }
            }
        }
예제 #24
0
    void Update()
    {
        if (Input.GetMouseButtonUp(0) &&
            !RectTransformUtility.RectangleContainsScreenPoint(Panel, Input.mousePosition))
        {
            warpMenuEnabled = false;
        }

        Panel.gameObject.SetActive(warpMenuEnabled);

        if (GetComponent <DosBox>().ProcessReader != null)
        {
            if (!Panel.GetComponentsInChildren <InputField>().Any(x => x.isFocused) && warpActor != null)
            {
                MoveOrRotateActor(warpActor);
            }

            //warp to mouse position
            if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && Input.GetKeyDown(KeyCode.W))
            {
                WarpActor(warpActor);
            }
        }
    }
예제 #25
0
        public override void OnPointerDown(PointerEventData eventData)
        {
            if (!MayDrag(eventData))
            {
                return;
            }

            base.OnPointerDown(eventData);

            m_Offset = Vector2.zero;
            if (m_HandleContainerRect != null && RectTransformUtility.RectangleContainsScreenPoint(m_HandleRect, eventData.position, eventData.enterEventCamera))
            {
                Vector2 localMousePos;
                if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_HandleRect, eventData.position, eventData.pressEventCamera, out localMousePos))
                {
                    m_Offset = localMousePos;
                }
            }
            else
            {
                // Outside the slider handle - jump to this point instead
                UpdateDrag(eventData, eventData.pressEventCamera);
            }
        }
예제 #26
0
        /// <summary>
        /// Coroutine function for handling continual press during Scrollbar.OnPointerDown.
        /// </summary>
        protected IEnumerator ClickRepeat(Vector2 screenPosition, Camera camera)
        {
            while (isPointerDownAndNotDragging)
            {
                if (!RectTransformUtility.RectangleContainsScreenPoint(m_HandleRect, screenPosition, camera))
                {
                    Vector2 localMousePos;
                    if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_HandleRect, screenPosition, camera, out localMousePos))
                    {
                        var axisCoordinate = axis == 0 ? localMousePos.x : localMousePos.y;

                        // modifying value depending on direction, fixes (case 925824)

                        float change = axisCoordinate < 0 ? size : -size;
                        value += reverseValue ? change : -change;
                        value  = Mathf.Clamp01(value);
                        // Only keep 4 decimals of precision
                        value = Mathf.Round(value * 10000f) / 10000f;
                    }
                }
                yield return(new WaitForEndOfFrame());
            }
            StopCoroutine(m_PointerDownRepeat);
        }
예제 #27
0
    void Update()
    {
        if (!RectTransformUtility.RectangleContainsScreenPoint(toolBar.GetComponent <RectTransform>(),
                                                               Input.mousePosition))
        {
            if (Input.GetMouseButton(0))
            {
                switch (this.cursorType)
                {
                case CursorType.Empty:
                    break;

                case CursorType.Brush:
                    changeBlock();
                    break;
                }
            }
            else if (Input.GetMouseButtonDown(1))
            {
                this.cursorType = CursorType.Empty;
            }
        }
        cameraKeyboardControler();
    }
예제 #28
0
    //public GameObject[] Panels;		//Rishabh
    //public Transform[] WT=new Transform[Panels.Length];		//Rishabh
    void Update()
    {
        //mouse touch testing
//		if (Input.GetMouseButton (0)) {
//			nowOnPanel1 = RectTransformUtility.RectangleContainsScreenPoint (panel, new Vector2 (Input.mousePosition.x, Input.mousePosition.y), cam);
//
//			if (nowOnPanel1) {
//				int SI = transform.GetSiblingIndex ();
//				Debug.Log ("cpi: " + PanelIndex.currentPanelIndex);
//				if (SI < PanelIndex.currentPanelIndex)
//					return;
//				Debug.Log ("SI value : " + SI);
//				PanelIndex.SetIndex (SI);
//
//				if (PanelIndex.currentPanelIndex == SI) {
//					Debug.Log ("scaling index " + SI);
//					Vector3 origScale1 = this.transform.localScale;
//					origScale1.x += 0.01f;
//					origScale1.y += 0.01f;
//					this.transform.localScale = origScale1;
//				}
//
//			}
//		} else {
//			PanelIndex.currentPanelIndex = -1;
//		}
        //input touch testing
        if (Input.touchCount == 2)
        {
            // Store both touches.
            Touch touchZero = Input.GetTouch(0);
            Touch touchOne  = Input.GetTouch(1);

            //nowOnPanel1 = RectTransformUtility.RectangleContainsScreenPoint (panel, new Vector2 (Input.mousePosition.x,Input.mousePosition.y), cam);
            nowOnPanel1 = RectTransformUtility.RectangleContainsScreenPoint(panel, new Vector2(touchZero.position.x, touchZero.position.y), cam);
            nowOnPanel2 = RectTransformUtility.RectangleContainsScreenPoint(panel, new Vector2(touchOne.position.x, touchOne.position.y), cam);

            if (nowOnPanel1 && nowOnPanel2)
            {
                // Find the position in the previous frame of each touch.
                Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
                Vector2 touchOnePrevPos  = touchOne.position - touchOne.deltaPosition;

                // Find the magnitude of the vector (the distance) between the touches in each frame.
                float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
                float touchDeltaMag     = (touchZero.position - touchOne.position).magnitude;

                // Find the difference in the distances between each frame.
                float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;

                int SI = transform.GetSiblingIndex();
                Debug.Log("SI value : " + SI);
                if (SI < PanelIndex.currentPanelIndex)
                {
                    return;
                }
                PanelIndex.SetIndex(SI);

                if (PanelIndex.currentPanelIndex == SI)
                {
                    Vector3 origScale1 = this.transform.localScale;
                    //origScale *= deltaMagnitudeDiff;
                    origScale1.x -= deltaMagnitudeDiff * 0.01f;
                    origScale1.x  = Mathf.Max(origScale1.x, 0.4f);

                    origScale1.y -= deltaMagnitudeDiff * 0.01f;
                    origScale1.y  = Mathf.Max(origScale1.y, 0.4f);

                    this.transform.localScale = origScale1;
                }
            }
        }
        else
        {
            PanelIndex.currentPanelIndex = -1;
        }
//		Debug.Log (nowOnPanel);


//		if (Input.GetMouseButton(0)) {
//			Debug.Log ("touching");
//			Vector3 origScale = featurePanel.transform.localScale;
//			origScale.x -= 0.01f;
//			origScale.y -= 0.01f;
//			featurePanel.transform.localScale = origScale;
//		}

        //Rishabh
//		for (int i = 0; i < Panels.Length; i++) {
//			if (Input.GetMouseButtonDown (0)) {
//				Vector3[] origScale = new Vector3[Panels [i].gameObject.transform.localScale] ;
//				origScale[i].x += 0.01f;
//				origScale[i].y += 0.01f;
//				Panels [i].gameObject.transform.localScale = origScale [i];
//			}
//		}
//		// If there are two touches on the device...
//		if (Input.touchCount == 2)
//		{
//			// Store both touches.
//			Touch touchZero = Input.GetTouch(0);
//			Touch touchOne = Input.GetTouch(1);
//
//
//
//			// Find the position in the previous frame of each touch.
//			Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
//			Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;
//
//			// Find the magnitude of the vector (the distance) between the touches in each frame.
//			float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
//			float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;
//
//			// Find the difference in the distances between each frame.
//			float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;
//
//			// If the camera is orthographic...
//
////			if(Camera.main.orthographic)
////			{
//				// ... change the orthographic size based on the change in distance between the touches.
//				//Camera.main.orthographicSize += deltaMagnitudeDiff * orthoZoomSpeed;
//
//
//				// Make sure the orthographic size never drops below zero.
//				//Camera.main.orthographicSize = Mathf.Max(Camera.main.orthographicSize, 0.1f);
//
//				//OVERVIEW PANEL
//				Vector3 origScale1 = this.transform.localScale;
//				//origScale *= deltaMagnitudeDiff;
//				origScale1.x-=deltaMagnitudeDiff*0.01f;
//				origScale1.x = Mathf.Max (origScale1.x,0.4f);
//
//				origScale1.y -= deltaMagnitudeDiff * 0.01f;
//				origScale1.y = Mathf.Max (origScale1.y,0.4f);
//
//				this.transform.localScale = origScale1;

//				//FEATURES PANEL
//				Vector3 origScale2 = featurePanel.transform.localScale;
//				//origScale *= deltaMagnitudeDiff;
//				origScale2.x-=deltaMagnitudeDiff*0.01f;
//				origScale2.x = Mathf.Max (origScale2.x,0.4f);
//
//				origScale2.y -= deltaMagnitudeDiff * 0.01f;
//				origScale2.y = Mathf.Max (origScale2.y,0.4f);
//
//				featurePanel.transform.localScale = origScale2;
//
//				//GALLERY PANEL
//				Vector3 origScale3 = galleryPanel.transform.localScale;
//				//origScale *= deltaMagnitudeDiff;
//				origScale3.x-=deltaMagnitudeDiff*0.01f;
//				origScale3.x = Mathf.Max (origScale3.x,0.4f);
//
//				origScale3.y -= deltaMagnitudeDiff * 0.01f;
//				origScale3.y = Mathf.Max (origScale3.y,0.4f);
//
//				galleryPanel.transform.localScale = origScale3;
//
//				//PERFORMANCE PANEL
//				Vector3 origScale4 = performancePanel.transform.localScale;
//				//origScale *= deltaMagnitudeDiff;
//				origScale4.x-=deltaMagnitudeDiff*0.01f;
//				origScale4.x = Mathf.Max (origScale4.x,0.4f);
//
//				origScale4.y -= deltaMagnitudeDiff * 0.01f;
//				origScale4.y = Mathf.Max (origScale4.y,0.4f);
//
//				performancePanel.transform.localScale = origScale4;
//
//				//MODEL PANEL
//				Vector3 origScale5 = modelPanel.transform.localScale;
//				//origScale *= deltaMagnitudeDiff;
//				origScale5.x-=deltaMagnitudeDiff*0.01f;
//				origScale5.x = Mathf.Max (origScale5.x,0.4f);
//
//				origScale5.y -= deltaMagnitudeDiff * 0.01f;
//				origScale5.y = Mathf.Max (origScale5.y,0.4f);
//
//				modelPanel.transform.localScale = origScale5;
//			}
//			else
//			{
//				// Otherwise change the field of view based on the change in distance between the touches.
//				Camera.main.fieldOfView += deltaMagnitudeDiff * perspectiveZoomSpeed;
//
//				// Clamp the field of view to make sure it's between 0 and 180.
//				Camera.main.fieldOfView = Mathf.Clamp(Camera.main.fieldOfView, 0.1f, 179.9f);
//			}
//		}
    }
예제 #29
0
 public void OnPointerUp(PointerEventData eventData)
 {
     if (onClick != null)
     {
         if (Vector2.Distance(eventData.pressPosition, eventData.position) < 10)
         {
             if (m_click >= 1000)
             {
                 onClick();
                 return;
             }
             Canvas canvas = GetComponentInParent <Canvas>();
             if (RectTransformUtility.RectangleContainsScreenPoint(Box.GetComponent <RectTransform>(), eventData.position, canvas.worldCamera))
             {
                 if (NeedPass)
                 {
                     eventData.position      = Box.transform.position;
                     eventData.pressPosition = Box.transform.position;
                     if (PassEvent(eventData, ExecuteEvents.submitHandler) &&
                         PassEvent(eventData, ExecuteEvents.pointerDownHandler) &&
                         PassEvent(eventData, ExecuteEvents.pointerUpHandler))
                     {
                         onClick();
                     }
                 }
                 else
                 {
                     if (onClick2 != null)
                     {
                         onClick2();
                     }
                     onClick();
                 }
             }
             m_click += 1;
         }
     }
     else if (onPress != null)
     {
         Canvas canvas = GetComponentInParent <Canvas>();
         if (RectTransformUtility.RectangleContainsScreenPoint(Box.GetComponent <RectTransform>(), eventData.position, canvas.worldCamera))
         {
             if (NeedPass)
             {
                 eventData.position      = Box.transform.position;
                 eventData.pressPosition = Box.transform.position;
                 if (PassEvent(eventData, ExecuteEvents.pointerUpHandler))
                 {
                     if (_pressTime >= pressTime)
                     {
                         onPress();
                     }
                 }
             }
             else
             {
                 if (_pressTime >= pressTime)
                 {
                     onPress();
                 }
             }
         }
     }
     isPressing = false;
     _pressTime = 0;
 }
예제 #30
0
    void OnEndDrag(GameObject go)
    {
        AudioManager.instance.PlayEffect(ConstConfig.DropRole);
        //先判断原本在哪个队列
        var listType = goItems[go].listType;

        var mousePosition = Input.mousePosition;

        //RectTransformUtility.ScreenPointToWorldPointInRectangle(rect, Input.mousePosition, Camera.main, out v);

        if (listType == EnumType.RoleListType.Fight)
        {
            //如果停在fight里
            if (RectTransformUtility.RectangleContainsScreenPoint
                    (fightList, mousePosition))
            {
                for (int i = 0; i < fightPositions.Length; i++)
                {
                    bool isHere = RectTransformUtility.RectangleContainsScreenPoint(fightPositions[i], Input.mousePosition);
                    if (isHere)
                    {
                        //我拖的这个东西的索引
                        int orIndex = goItems[go].index;

                        //int newIndex = i;
                        playerModel.ExChangeRolesBetFight(orIndex, i);
                        break;
                    }
                }
            }
            //如果停在准备列表
            else if (RectTransformUtility.RectangleContainsScreenPoint(preList, mousePosition))
            {
                for (int i = 0; i < prePositions.Length; i++)
                {
                    bool isHere = RectTransformUtility.RectangleContainsScreenPoint(prePositions[i], Input.mousePosition);
                    if (isHere)
                    {
                        int orIndex = goItems[go].index;
                        playerModel.ExChangeRolesBetPreAndFight(orIndex, i);


                        break;
                    }
                }
            }
        }
        //如果原本是在准备列表
        else if (listType == EnumType.RoleListType.Pre)
        {
            //如果停在fight里
            if (RectTransformUtility.RectangleContainsScreenPoint
                    (fightList, mousePosition))
            {
                for (int i = 0; i < fightPositions.Length; i++)
                {
                    bool isHere = RectTransformUtility.RectangleContainsScreenPoint(fightPositions[i], Input.mousePosition);
                    if (isHere)
                    {
                        int orIndex = goItems[go].index;
                        playerModel.ExChangeRolesBetPreAndFight(i, orIndex);

                        break;
                    }
                }
            }
            //如果停在准备列表
            else if (RectTransformUtility.RectangleContainsScreenPoint(preList, mousePosition))
            {
                for (int i = 0; i < prePositions.Length; i++)
                {
                    bool isHere = RectTransformUtility.RectangleContainsScreenPoint(prePositions[i], Input.mousePosition);
                    if (isHere)
                    {
                        int orIndex = goItems[go].index;

                        playerModel.ExChangeRolesBetPre(i, orIndex);

                        break;
                    }
                }
            }
        }

        go.transform.position = orPosition;
    }