コード例 #1
0
//	protected List<RaycastResult> raycastResults = new List<RaycastResult>();

        protected override Vector2 MapPointerToBrowser(Vector2 screenPosition, int pointerId)
        {
            if (!raycaster)
            {
                raycaster = GetComponentInParent <BaseRaycaster>();
            }

            Vector2 pos;

            RectTransformUtility.ScreenPointToLocalPointInRectangle(
                (RectTransform)transform, screenPosition, raycaster.eventCamera, out pos
                );
            pos.x = pos.x / rTransform.rect.width + rTransform.pivot.x;
            pos.y = pos.y / rTransform.rect.height + rTransform.pivot.y;

            if (pos.x < 0 || pos.x > 1)
            {
                pos.x = float.NaN;
            }
            if (pos.y < 0 || pos.y > 1)
            {
                pos.x = float.NaN;
            }
            return(pos);
        }
コード例 #2
0
        public void Init()
        {
            if (this.canvas != null && this.windowObject != null && this.windowObject.GetWindow() == null)
            {
                WindowSystem.GetEvents().Register(this.windowObject, WindowEventType.OnShowBegin, this.Init);
                WindowSystem.GetEvents().Register(this.windowObject, WindowEventType.OnWindowActive, this.Init);
                return;
            }

            WindowSystem.GetEvents().Unregister(this.windowObject, WindowEventType.OnShowBegin, this.Init);
            WindowSystem.GetEvents().Unregister(this.windowObject, WindowEventType.OnWindowActive, this.Init);

            var raycasterTemp = false;

            if (this.canvas != null && this.windowObject != null)
            {
                var window = this.windowObject.GetWindow();
                if (window == null)
                {
                                        #if UNITY_EDITOR
                    Debug.LogWarning("[ CanvasLinker ] WindowObject::GetWindow() is null", this);
                                        #endif
                    return;
                }

                //Debug.Log("[ CanvasLinker ] Initialized", this);

                this.canvas.overrideSorting  = true;
                this.canvas.sortingLayerName = window.GetSortingLayerName();
                this.canvas.sortingOrder     = window.GetSortingOrder() + this.orderDelta;

                if (this.overridePixelPerfect == true)
                {
                    this.canvas.overridePixelPerfect = true;
                    this.canvas.pixelPerfect         = this.pixelPrefect;
                }

                if (this.raycasterSource == null)
                {
                    this.raycasterSource = (window as LayoutWindowType).GetCurrentLayout().GetLayoutInstance().GetComponent <BaseRaycaster>();
                    raycasterTemp        = true;
                }
            }

            if (this.raycaster != null && this.raycasterSource != null)
            {
                var graphicRaycaster       = this.raycaster as GraphicRaycaster;
                var graphicRaycasterSource = this.raycasterSource as GraphicRaycaster;
                if (graphicRaycaster != null && graphicRaycasterSource != null)
                {
                    graphicRaycaster.blockingObjects        = graphicRaycasterSource.blockingObjects;
                    graphicRaycaster.ignoreReversedGraphics = graphicRaycasterSource.ignoreReversedGraphics;
                }

                if (raycasterTemp == true)
                {
                    this.raycasterSource = null;
                }
            }
        }
コード例 #3
0
        public void Init()
        {
            if (this.canvas != null && this.windowObject != null)
            {
                var window = this.windowObject.GetWindow();
                if (window == null)
                {
                                        #if UNITY_EDITOR
                    Debug.LogWarning("[ CanvasLinker ] WindowObject::GetWindow() is null", this);
                                        #endif
                    return;
                }

                this.canvas.overrideSorting  = true;
                this.canvas.sortingLayerName = window.GetSortingLayerName();
                this.canvas.sortingOrder     = window.GetSortingOrder() + this.orderDelta;

                if (this.raycasterSource == null)
                {
                    this.raycasterSource = (window as LayoutWindowType).layout.GetLayoutInstance().GetComponent <BaseRaycaster>();
                }
            }

            if (this.raycaster != null && this.raycasterSource != null)
            {
                var graphicRaycaster       = this.raycaster as GraphicRaycaster;
                var graphicRaycasterSource = this.raycasterSource as GraphicRaycaster;
                if (graphicRaycaster != null && graphicRaycasterSource != null)
                {
                    graphicRaycaster.blockingObjects        = graphicRaycasterSource.blockingObjects;
                    graphicRaycaster.ignoreReversedGraphics = graphicRaycasterSource.ignoreReversedGraphics;
                }
            }
        }
コード例 #4
0
        public static void Raycast(Canvas canvas, bool ignoreReversedGraphics, BaseRaycaster module, Vector2 position, Camera eventCamera, List <RaycastResult> raycastResults)
        {
            if (canvas == null)
            {
                return;
            }

            var ray      = eventCamera.ScreenPointToRay(position);
            var distance = eventCamera.farClipPlane - eventCamera.nearClipPlane;

            var graphics = GraphicRegistry.GetGraphicsForCanvas(canvas);

            for (int i = 0; i < graphics.Count; ++i)
            {
                var graphic = graphics[i];

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

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

                if (ignoreReversedGraphics && Vector3.Dot(eventCamera.transform.forward, graphic.transform.forward) <= 0f)
                {
                    continue;
                }

                if (!graphic.Raycast(position, eventCamera))
                {
                    continue;
                }

                float dist;
                new Plane(graphic.transform.forward, graphic.transform.position).Raycast(ray, out dist);
                if (dist > distance)
                {
                    continue;
                }

                raycastResults.Add(new RaycastResult
                {
                    gameObject     = graphic.gameObject,
                    module         = module,
                    distance       = dist,
                    worldPosition  = ray.GetPoint(dist),
                    worldNormal    = graphic.transform.forward,
                    screenPosition = position,
                    index          = raycastResults.Count,
                    depth          = graphic.depth,
                    sortingLayer   = canvas.sortingLayerID,
                    sortingOrder   = canvas.sortingOrder
                });
            }
        }
コード例 #5
0
 public void Clear()
 {
     gameObject = null;
     module     = null;
     distance   = 0;
     index      = 0;
     depth      = 0;
 }
コード例 #6
0
ファイル: RaycastResult.cs プロジェクト: aammfe/unity3d-ui
 public void Clear()
 {
     gameObject = null;
     module = null;
     distance = 0;
     index = 0;
     depth = 0;
 }
コード例 #7
0
 public static void RemoveRaycasters(BaseRaycaster baseRaycaster)
 {
     if (!s_Raycasters.Contains(baseRaycaster))
     {
         return;
     }
     s_Raycasters.Remove(baseRaycaster);
 }
コード例 #8
0
        protected override void ProcessMove(PointerEventData pointerEvent)
        {
            // process pointer move
            if (DpnManager.DPVRPointer)
            {
                GameObject gameObject = pointerEvent.pointerCurrentRaycast.gameObject;
                if (gameObject)
                {
                    BaseRaycaster raycaster       = pointerEvent.pointerCurrentRaycast.module;
                    Ray           intersectionRay = new Ray();
                    if (raycaster != null)
                    {
                        DpnBasePointer pointer = DpnPointerManager.Pointer as DpnBasePointer;
                        intersectionRay = pointer.GetRay();
                    }
                    else if (pointerEvent.enterEventCamera != null)
                    {
                        Camera cam = pointerEvent.enterEventCamera;
                        intersectionRay = new Ray(cam.transform.position, cam.transform.forward);
                    }

                    Vector3 intersectionPos = pointerEvent.pointerCurrentRaycast.worldPosition;
                    if (intersectionPos == Vector3.zero)
                    {
                        Camera camera = pointerEvent.enterEventCamera;
                        if (camera != null)
                        {
                            float intersectionDistance = pointerEvent.pointerCurrentRaycast.distance + camera.nearClipPlane;
                            intersectionPos = camera.transform.position + intersectionRay.direction * intersectionDistance;
                        }
                    }

                    bool interactived = pointerEvent.pointerPress != null ||
                                        ExecuteEvents.GetEventHandler <IPointerEnterHandler>(gameObject) != null;

                    if (_lastGameObejct == null)
                    {
                        DpnPointerManager.Pointer.OnPointerEnter(gameObject, intersectionPos, intersectionRay, interactived);

                        _lastGameObejct = gameObject;
                    }
                    else
                    {
                        DpnPointerManager.Pointer.OnPointerHover(gameObject, intersectionPos, intersectionRay, interactived);
                    }
                }
                else
                {
                    if (_lastGameObejct != null)
                    {
                        DpnPointerManager.Pointer.OnPointerExit(gameObject);
                        _lastGameObejct = null;
                    }
                }
            }

            base.ProcessMove(pointerEvent);
        }
コード例 #9
0
        public static void AddRaycaster(BaseRaycaster baseRaycaster)
        {
            if (s_Raycasters.Contains(baseRaycaster))
            {
                return;
            }

            s_Raycasters.Add(baseRaycaster);
        }
コード例 #10
0
        public virtual void InputUpdate()
        {
            List <Event> list = keyEvents;

            keyEvents     = keyEventsLast;
            keyEventsLast = list;
            keyEvents.Clear();
            if (MouseHasFocus)
            {
                if (!raycaster)
                {
                    raycaster = GetComponentInParent <BaseRaycaster>();
                }
                RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)base.transform, Input.mousePosition, raycaster.eventCamera, out var localPoint);
                localPoint.x  = localPoint.x / rTransform.rect.width + 0.5f;
                localPoint.y  = localPoint.y / rTransform.rect.height + 0.5f;
                MousePosition = localPoint;
                MouseButton mouseButton = (MouseButton)0;
                if (Input.GetMouseButton(0))
                {
                    mouseButton |= MouseButton.Left;
                }
                if (Input.GetMouseButton(1))
                {
                    mouseButton |= MouseButton.Right;
                }
                if (Input.GetMouseButton(2))
                {
                    mouseButton |= MouseButton.Middle;
                }
                MouseButtons = mouseButton;
                MouseScroll  = Input.mouseScrollDelta;
            }
            else
            {
                MouseButtons = (MouseButton)0;
            }
            if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift))
            {
                keyEventsLast.Insert(0, new Event
                {
                    type    = EventType.KeyDown,
                    keyCode = KeyCode.LeftShift
                });
            }
            if (Input.GetKeyUp(KeyCode.LeftShift) || Input.GetKeyUp(KeyCode.RightShift))
            {
                keyEventsLast.Add(new Event
                {
                    type    = EventType.KeyUp,
                    keyCode = KeyCode.LeftShift
                });
            }
        }
コード例 #11
0
 public void Clear()
 {
     gameObject    = null;
     module        = null;
     distance      = 0;
     index         = 0;
     depth         = 0;
     sortingLayer  = 0;
     sortingOrder  = 0;
     worldNormal   = Vector3.up;
     worldPosition = Vector3.zero;
 }
コード例 #12
0
        /// <summary>
        /// Returns a Canvas for a raycaster.
        /// </summary>
        /// <param name="raycaster">The raycaster.</param>
        /// <returns> The Canvas this raycaster is on. </returns>
        public Canvas GetCanvasForRaycaster(BaseRaycaster raycaster)
        {
            var    id = raycaster.GetInstanceID();
            Canvas canvas;

            if (!raycasterCanvasCache.TryGetValue(id, out canvas))
            {
                canvas = canvasProp.GetValue(raycaster, null) as Canvas;
                raycasterCanvasCache.Add(id, canvas);
            }
            return(canvas);
        }
コード例 #13
0
 private void Awake()
 {
     m_raycaster = GetComponentInParent <BaseRaycaster>();
     if (m_raycaster == null)
     {
         Canvas canvas = GetComponentInParent <Canvas>();
         if (canvas != null)
         {
             m_raycaster = canvas.gameObject.AddComponent <BaseRaycaster>();
         }
     }
 }
コード例 #14
0
 /// <summary>
 ///   <para>Reset the result.</para>
 /// </summary>
 public void Clear()
 {
     this.gameObject     = (GameObject)null;
     this.module         = (BaseRaycaster)null;
     this.distance       = 0.0f;
     this.index          = 0.0f;
     this.depth          = 0;
     this.sortingLayer   = 0;
     this.sortingOrder   = 0;
     this.worldNormal    = Vector3.up;
     this.worldPosition  = Vector3.zero;
     this.screenPosition = Vector2.zero;
 }
コード例 #15
0
ファイル: RaycastResult.cs プロジェクト: gdzzzyyy/UGUIlok
 public void Clear()
 {
     gameObject = null;
     module = null;
     distance = 0;
     index = 0;
     depth = 0;
     sortingLayer = 0;
     sortingOrder = 0;
     worldNormal = Vector3.up;
     worldPosition = Vector3.zero;
     screenPosition = Vector2.zero;
 }
コード例 #16
0
 /// <summary>
 ///   <para>Reset the result.</para>
 /// </summary>
 public void Clear()
 {
   this.gameObject = (GameObject) null;
   this.module = (BaseRaycaster) null;
   this.distance = 0.0f;
   this.index = 0.0f;
   this.depth = 0;
   this.sortingLayer = 0;
   this.sortingOrder = 0;
   this.worldNormal = Vector3.up;
   this.worldPosition = Vector3.zero;
   this.screenPosition = Vector2.zero;
 }
コード例 #17
0
        private void Awake()
        {
            if (m_raycaster == null)
            {
                m_raycaster = GetComponentInParent <BaseRaycaster>();
                if (m_raycaster == null)
                {
                    Canvas canvas = GetComponentInParent <Canvas>();
                    if (canvas)
                    {
                        m_raycaster = canvas.gameObject.AddComponent <GraphicRaycaster>();
                    }
                }
            }
            Region.Selected           += OnRegionSelected;
            Region.Unselected         += OnRegionUnselected;
            Region.Created            += OnRegionCreated;
            Region.BeforeDepthChanged += OnRegionBeforeDepthChanged;
            Region.DepthChanged       += OnRegionDepthChanged;
            Region.Destroyed          += OnRegionDestroyed;
            Region.Enabled            += OnRegionEnabled;
            Region.Disabled           += OnRegionDisabled;
            Region.Maximized          += OnRegionMaximized;

            Region.BeforeBeginDrag  += OnRegionBeforeBeginDrag;
            Region.BeginDrag        += OnRegionBeginDrag;
            Region.Drag             += OnRegionDrag;
            Region.EndDrag          += OnRegionEndDrag;
            Region.TransformChanged += OnRegionTranformChanged;

            Resizer.BeginResize += OnRegionBeginResize;
            Resizer.Resize      += OnRegionResize;
            Resizer.EndResize   += OnRegionEndResize;

            Region.TabActivated   += OnTabActivated;
            Region.TabDeactivated += OnTabDeactivated;
            Region.TabClosed      += OnTabClosed;
            Region.TabBeginDrag   += OnTabBeginDrag;
            Region.TabEndDrag     += OnTabEndDrag;

            if (m_rootRegion == null)
            {
                m_rootRegion = GetComponentInChildren <Region>();
            }

            if (m_rootRegion == null)
            {
                m_rootRegion      = Instantiate(m_regionPrefab, m_docked);
                m_rootRegion.name = "Root Region";
            }
        }
コード例 #18
0
    public void OnDrag(PointerEventData eventData)
    {
        BaseRaycaster raycaster = eventData.pointerCurrentRaycast.module;

        if (raycaster == null)
        {
            return;
        }
        Vector3 currentPosition = eventData.pointerCurrentRaycast.worldPosition;
        Vector3 deltaPosition   = currentPosition - m_LastPosition;

        transform.Translate(deltaPosition);
        m_LastPosition = currentPosition;
        Debug.Log("Drag: " + currentPosition);
    }
コード例 #19
0
        public override void Raycast(BaseRaycaster module, Vector2 position, Camera eventCamera, List <RaycastResult> raycastResults)
        {
            var tempCanvases = ListPool <ICanvasRaycastTarget> .Get();

            tempCanvases.AddRange(canvases);
            for (int i = tempCanvases.Count - 1; i >= 0; --i)
            {
                var target = tempCanvases[i];
                if (target == null || !target.enabled)
                {
                    continue;
                }
                Raycast(target.canvas, target.ignoreReversedGraphics, module, position, eventCamera, raycastResults);
            }
            ListPool <ICanvasRaycastTarget> .Release(tempCanvases);
        }
    public static int get_eventCamera(IntPtr l)
    {
        int result;

        try
        {
            BaseRaycaster baseRaycaster = (BaseRaycaster)LuaObject.checkSelf(l);
            LuaObject.pushValue(l, true);
            LuaObject.pushValue(l, baseRaycaster.eventCamera);
            result = 2;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
コード例 #21
0
        private void Awake()
        {
            m_editor = IOC.Resolve <IRTE>();
            m_input  = m_editor.Input;
            if (m_raycaster == null)
            {
                m_raycaster = gameObject.GetComponent <BaseRaycaster>();
                if (m_raycaster == null)
                {
                    GraphicRaycaster raycaster = gameObject.AddComponent <GraphicRaycaster>();
                    raycaster.blockingObjects = GraphicRaycaster.BlockingObjects.None;
                    //raycaster.mask => ?

                    m_raycaster = raycaster;
                }
            }
        }
    public static int get_renderOrderPriority(IntPtr l)
    {
        int result;

        try
        {
            BaseRaycaster baseRaycaster = (BaseRaycaster)LuaObject.checkSelf(l);
            LuaObject.pushValue(l, true);
            LuaObject.pushValue(l, baseRaycaster.renderOrderPriority);
            result = 2;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
コード例 #23
0
    private static int ToString(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 1);
            BaseRaycaster baseRaycaster = (BaseRaycaster)ToLua.CheckObject(L, 1, typeof(BaseRaycaster));
            string        str           = baseRaycaster.ToString();
            LuaDLL.lua_pushstring(L, str);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
コード例 #24
0
    private static int get_renderOrderPriority(IntPtr L)
    {
        object obj = null;
        int    result;

        try
        {
            obj = ToLua.ToObject(L, 1);
            BaseRaycaster baseRaycaster       = (BaseRaycaster)obj;
            int           renderOrderPriority = baseRaycaster.renderOrderPriority;
            LuaDLL.lua_pushinteger(L, renderOrderPriority);
            result = 1;
        }
        catch (Exception ex)
        {
            result = LuaDLL.toluaL_exception(L, ex, (obj != null) ? ex.Message : "attempt to index renderOrderPriority on a nil value");
        }
        return(result);
    }
コード例 #25
0
    private static int Raycast(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 3);
            BaseRaycaster        baseRaycaster    = (BaseRaycaster)ToLua.CheckObject(L, 1, typeof(BaseRaycaster));
            PointerEventData     eventData        = (PointerEventData)ToLua.CheckObject(L, 2, typeof(PointerEventData));
            List <RaycastResult> resultAppendList = (List <RaycastResult>)ToLua.CheckObject(L, 3, typeof(List <RaycastResult>));
            baseRaycaster.Raycast(eventData, resultAppendList);
            result = 0;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
コード例 #26
0
    private static int get_eventCamera(IntPtr L)
    {
        object obj = null;
        int    result;

        try
        {
            obj = ToLua.ToObject(L, 1);
            BaseRaycaster baseRaycaster = (BaseRaycaster)obj;
            Camera        eventCamera   = baseRaycaster.eventCamera;
            ToLua.Push(L, eventCamera);
            result = 1;
        }
        catch (Exception ex)
        {
            result = LuaDLL.toluaL_exception(L, ex, (obj != null) ? ex.Message : "attempt to index eventCamera on a nil value");
        }
        return(result);
    }
コード例 #27
0
ファイル: Util.cs プロジェクト: hamtol2/D2EEditor
        // UI RayCaster.
        public static bool GetRaycastResult(BaseRaycaster raycaster, EventSystem eventSystem, Vector2 mousePosition, out RaycastResult result)
        {
            result = new RaycastResult();
            PointerEventData data = new PointerEventData(eventSystem);

            data.position = Input.mousePosition;
            List <RaycastResult> results = new List <RaycastResult>();

            raycaster.Raycast(data, results);

            if (results.Count > 0)
            {
                result = results[0];
                return(true);
            }

            else
            {
                return(false);
            }
        }
    public static int Raycast(IntPtr l)
    {
        int result;

        try
        {
            BaseRaycaster    baseRaycaster = (BaseRaycaster)LuaObject.checkSelf(l);
            PointerEventData eventData;
            LuaObject.checkType <PointerEventData>(l, 2, out eventData);
            List <RaycastResult> resultAppendList;
            LuaObject.checkType <List <RaycastResult> >(l, 3, out resultAppendList);
            baseRaycaster.Raycast(eventData, resultAppendList);
            LuaObject.pushValue(l, true);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
コード例 #29
0
        public override void Raycast(BaseRaycaster module, Vector2 position, Camera eventCamera, List <RaycastResult> raycastResults)
        {
            var ray      = eventCamera.ScreenPointToRay(position);
            var distance = eventCamera.farClipPlane - eventCamera.nearClipPlane;
            var hitCount = Physics.RaycastNonAlloc(ray, hits, distance, RaycastMask);

            for (int i = 0; i < hitCount; ++i)
            {
                raycastResults.Add(new RaycastResult
                {
                    gameObject     = hits[i].collider.gameObject,
                    module         = module,
                    distance       = hits[i].distance,
                    worldPosition  = hits[i].point,
                    worldNormal    = hits[i].normal,
                    screenPosition = position,
                    index          = raycastResults.Count,
                    sortingLayer   = 0,
                    sortingOrder   = 0
                });
            }
        }
コード例 #30
0
        public override void Raycast(BaseRaycaster module, Vector2 position, Camera eventCamera, List <RaycastResult> raycastResults)
        {
            var ray      = eventCamera.ScreenPointToRay(position);
            var distance = eventCamera.farClipPlane - eventCamera.nearClipPlane;
            var hitCount = Physics2D.GetRayIntersectionNonAlloc(ray, hits, distance, RaycastMask);

            for (int i = 0; i < hitCount; ++i)
            {
                var sr = hits[i].collider.gameObject.GetComponent <SpriteRenderer>();

                raycastResults.Add(new RaycastResult
                {
                    gameObject     = hits[i].collider.gameObject,
                    module         = module,
                    distance       = Vector3.Distance(eventCamera.transform.position, hits[i].transform.position),
                    worldPosition  = hits[i].point,
                    worldNormal    = hits[i].normal,
                    screenPosition = position,
                    index          = raycastResults.Count,
                    sortingLayer   = sr != null ? sr.sortingLayerID : 0,
                    sortingOrder   = sr != null ? sr.sortingOrder : 0
                });
            }
        }
コード例 #31
0
        public static VRRaycaster TryRaycastAll(string name, PointerEventData eventData, List <RaycastResult> raycastResults)
        {
            raycastResults.Clear();
            VRRaycaster raycaster = null;

            if (s_InstanceMap.TryGetValue(name, out raycaster))
            {
                int i = 0, imax = s_AllCanvases.Count;
                if (imax == 0)
                {
                    s_AllCanvases.AddRange(FindObjectsOfType <Canvas>());
                    s_AllCanvases.RemoveAll((x) => {
                        BaseRaycaster br = x.GetComponent <BaseRaycaster>();
                        return(br == null || br is VRRaycaster);
                    });
                    imax = s_AllCanvases.Count;
                }
                if (imax == 0)
                {
                    raycaster.PhysicsRaycast(eventData, raycastResults);
                }
                else
                {
                    for (; i < imax; ++i)
                    {
                        raycaster.SetCanvas(s_AllCanvases[i]);
                        raycaster.Raycast(eventData, raycastResults);
                    }
                }
            }
            else
            {
                //Log.w("VRRaycaster","No such a VRRaycaster(name="+name+") at TryRaycastAll().");
            }
            return(raycaster);
        }
コード例 #32
0
//	protected List<RaycastResult> raycastResults = new List<RaycastResult>();

        public virtual void InputUpdate()
        {
            var tmp = keyEvents;

            keyEvents     = keyEventsLast;
            keyEventsLast = tmp;
            keyEvents.Clear();

            if (MouseHasFocus)
            {
                if (!raycaster)
                {
                    raycaster = GetComponentInParent <BaseRaycaster>();
                }

//			raycastResults.Clear();

//			raycaster.Raycast(data, raycastResults);

//			if (raycastResults.Count != 0) {
//				Vector2 pos = raycastResults[0].stuff
                Vector2 pos;
                RectTransformUtility.ScreenPointToLocalPointInRectangle(
                    (RectTransform)transform, Input.mousePosition, raycaster.eventCamera, out pos
                    );
                pos.x         = pos.x / rTransform.rect.width + .5f;
                pos.y         = pos.y / rTransform.rect.height + .5f;
                MousePosition = pos;


                var buttons = (MouseButton)0;
                if (Input.GetMouseButton(0))
                {
                    buttons |= MouseButton.Left;
                }
                if (Input.GetMouseButton(1))
                {
                    buttons |= MouseButton.Right;
                }
                if (Input.GetMouseButton(2))
                {
                    buttons |= MouseButton.Middle;
                }
                MouseButtons = buttons;



                MouseScroll = Input.mouseScrollDelta;
            }
            else
            {
                MouseButtons = 0;
            }


            //Unity doesn't include events for some keys, so fake it.
            if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift))
            {
                //Note: doesn't matter if left or right shift, the browser can't tell.
                //(Prepend event. We don't know what happened first, but pressing shift usually precedes other key presses)
                keyEventsLast.Insert(0, new Event()
                {
                    type = EventType.KeyDown, keyCode = KeyCode.LeftShift
                });
            }

            if (Input.GetKeyUp(KeyCode.LeftShift) || Input.GetKeyUp(KeyCode.RightShift))
            {
                //Note: doesn't matter if left or right shift, the browser can't tell.
                keyEventsLast.Add(new Event()
                {
                    type = EventType.KeyUp, keyCode = KeyCode.LeftShift
                });
            }
        }
コード例 #33
0
 public override void Raycast(BaseRaycaster module, Vector2 position, Camera eventCamera, List <RaycastResult> raycastResults)
 {
     CanvasRaycastMethod.Raycast(canvas, ignoreReversedGraphics, module, position, eventCamera, raycastResults);
 }