private void Update()
        {
            objectRenderer.enabled = this.mouseStateData != null;
            if (!objectRenderer.enabled)
            {
                return;
            }

            Camera gazeCamera = InputStateManager.Instance.gazeCamera;

            var lastPosition = gameObject.transform.position;

            UnityEngine.EventSystems.RaycastResult result = this.mouseStateData.RaycastResult;

            var forward  = -gazeCamera.transform.forward;
            var position = this.mouseStateData.WorldPosition;

            if (result.gameObject != null)
            {
                forward  = result.worldNormal;
                position = result.worldPosition;

                this.distance = (result.distance > 1.0f) ? result.distance : 1.0f;
            }
            else
            {
                var direction = (position - gazeCamera.transform.position).normalized;
                position = gazeCamera.transform.position + (direction * distance);
            }

            var t = Time.deltaTime * 20.0f;

            gameObject.transform.position = Vector3.Lerp(this.transform.position, position, t);
            gameObject.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(forward), t);
        }
Beispiel #2
0
		public static HtmlDocument MapToUIPanel(ref Vector2 screenPos){
			
			//Create the PointerEventData with null for the EventSystem
			UnityEngine.EventSystems.PointerEventData ed = new UnityEngine.EventSystems.PointerEventData(null);
			
			// Set pos:
			ed.position=screenPos;
			
			//Create list to receive all results
			List<UnityEngine.EventSystems.RaycastResult> results = new List<UnityEngine.EventSystems.RaycastResult>();
			
			//Raycast it
			UnityUICaster.Raycast(ed,results);
			
			if(results.Count==0){
				return null;
			}
			
			// Look for a hit with a HtmlUIPanel component:
			for(int i=results.Count-1;i>=0;i--){
				
				// Get the result:
				UnityEngine.EventSystems.RaycastResult rayRes=results[i];
				
				// Get the panel:
				HtmlUIBase panel=rayRes.gameObject.GetComponent<HtmlUIBase>();
				
				if(panel!=null){
					
					// Got one!
					
					Vector2 localPoint;
					
					RectTransform rectTrans=panel.screenRect;
					
					UnityEngine.RectTransformUtility.ScreenPointToLocalPointInRectangle(
						rectTrans,
						screenPos,
						UnityUICaster.eventCamera,
						out localPoint
					);
					
					// Map the point (relative to the pivot):
					Rect rectangle=rectTrans.rect;
					
					localPoint.x+=rectangle.width*rectTrans.pivot.x;
					localPoint.y+=rectangle.height*rectTrans.pivot.y;
					
					screenPos.x=localPoint.x;
					screenPos.y=( rectangle.height-1-localPoint.y);
					
					return panel.document;
					
				}
				
			}
			
			return null;
			
		}
Beispiel #3
0
        static object PerformMemberwiseClone(ref object o)
        {
            var ins = new UnityEngine.EventSystems.RaycastResult();

            ins = (UnityEngine.EventSystems.RaycastResult)o;
            return(ins);
        }
        /// <summary>
        /// Perform a raycast using the worldSpaceRay in eventData.
        /// </summary>
        /// <param name="eventData"></param>
        /// <param name="resultAppendList"></param>
        public override void Raycast(UnityEngine.EventSystems.PointerEventData eventData, List <UnityEngine.EventSystems.RaycastResult> resultAppendList)
        {
            // This function is closely based on PhysicsRaycaster.Raycast

            if (eventCamera == null)
            {
                return;
            }

            OVRRayPointerEventData rayPointerEventData = eventData as OVRRayPointerEventData;

            if (rayPointerEventData == null)
            {
                return;
            }

            var ray = rayPointerEventData.worldSpaceRay;

            //float dist = eventCamera.farClipPlane - eventCamera.nearClipPlane;
            float      dist = 10.0f;
            RaycastHit hit;

            Physics.Raycast(ray.origin, ray.direction, out hit, dist, finalEventMask);
            PointerVisualizer.instance.SetPointer(hit);
            if (hit.collider != null && Controller.instance.pointerMode == PointerMode.SELECT)
            {
                // var hit = Physics.RaycastAll(ray, dist, finalEventMask);

                // if (hits.Length > 1)
                //     System.Array.Sort(hits, (r1, r2) => r1.distance.CompareTo(r2.distance));

                // lastHitDistance = 0;
                // if (hits.Length != 0)
                // {
                //     lastHitDistance = hits[0].distance;
                //     for (int b = 0, bmax = hits.Length; b < bmax; ++b)
                //     {
                var result = new UnityEngine.EventSystems.RaycastResult
                {
                    gameObject    = hit.collider.gameObject,
                    module        = this,
                    distance      = hit.distance,
                    index         = resultAppendList.Count,
                    worldPosition = hit.point,
                    worldNormal   = hit.normal,
                };
                resultAppendList.Add(result);
                //     }
                // }
            }
        }
Beispiel #5
0
        static void WriteBackInstance(CSHotFix.Runtime.Enviorment.AppDomain __domain, StackObject *ptr_of_this_method, IList <object> __mStack, ref UnityEngine.EventSystems.RaycastResult instance_of_this_method)
        {
            ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method);
            switch (ptr_of_this_method->ObjectType)
            {
            case ObjectTypes.Object:
            {
                __mStack[ptr_of_this_method->Value] = instance_of_this_method;
            }
            break;

            case ObjectTypes.FieldReference:
            {
                var ___obj = __mStack[ptr_of_this_method->Value];
                if (___obj is ILTypeInstance)
                {
                    ((ILTypeInstance)___obj)[ptr_of_this_method->ValueLow] = instance_of_this_method;
                }
                else
                {
                    var t = __domain.GetType(___obj.GetType()) as CLRType;
                    t.SetFieldValue(ptr_of_this_method->ValueLow, ref ___obj, instance_of_this_method);
                }
            }
            break;

            case ObjectTypes.StaticFieldReference:
            {
                var t = __domain.GetType(ptr_of_this_method->Value);
                if (t is ILType)
                {
                    ((ILType)t).StaticInstance[ptr_of_this_method->ValueLow] = instance_of_this_method;
                }
                else
                {
                    ((CLRType)t).SetStaticFieldValue(ptr_of_this_method->ValueLow, instance_of_this_method);
                }
            }
            break;

            case ObjectTypes.ArrayReference:
            {
                var instance_of_arrayReference = __mStack[ptr_of_this_method->Value] as UnityEngine.EventSystems.RaycastResult[];
                instance_of_arrayReference[ptr_of_this_method->ValueLow] = instance_of_this_method;
            }
            break;
            }
        }
Beispiel #6
0
        static StackObject *set_pointerPressRaycast_10(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            UnityEngine.EventSystems.RaycastResult value = (UnityEngine.EventSystems.RaycastResult) typeof(UnityEngine.EventSystems.RaycastResult).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);
            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            UnityEngine.EventSystems.PointerEventData instance_of_this_method;
            instance_of_this_method = (UnityEngine.EventSystems.PointerEventData) typeof(UnityEngine.EventSystems.PointerEventData).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.pointerPressRaycast = value;

            return(__ret);
        }
        static StackObject *get_gameObject_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method);
            UnityEngine.EventSystems.RaycastResult instance_of_this_method = (UnityEngine.EventSystems.RaycastResult) typeof(UnityEngine.EventSystems.RaycastResult).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));

            var result_of_this_method = instance_of_this_method.gameObject;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            WriteBackInstance(__domain, ptr_of_this_method, __mStack, ref instance_of_this_method);

            __intp.Free(ptr_of_this_method);
            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
        /// <summary>
        /// Perform a raycast using the worldSpaceRay in eventData.
        /// </summary>
        /// <param name="eventData"></param>
        /// <param name="resultAppendList"></param>
        public override void Raycast(UnityEngine.EventSystems.PointerEventData eventData, List <UnityEngine.EventSystems.RaycastResult> resultAppendList)
        {
            // This function is closely based on PhysicsRaycaster.Raycast

            if (eventCamera == null)
            {
                return;
            }

            OVRRayPointerEventData rayPointerEventData = eventData as OVRRayPointerEventData;

            if (rayPointerEventData == null)
            {
                return;
            }

            var ray = rayPointerEventData.worldSpaceRay;

            float dist = eventCamera.farClipPlane - eventCamera.nearClipPlane;

            var hits = Physics.RaycastAll(ray, dist, finalEventMask);

            if (hits.Length > 1)
            {
                System.Array.Sort(hits, (r1, r2) => r1.distance.CompareTo(r2.distance));
            }

            if (hits.Length != 0)
            {
                for (int b = 0, bmax = hits.Length; b < bmax; ++b)
                {
                    var result = new UnityEngine.EventSystems.RaycastResult
                    {
                        gameObject    = hits[b].collider.gameObject,
                        module        = this,
                        distance      = hits[b].distance,
                        index         = resultAppendList.Count,
                        worldPosition = hits[0].point,
                        worldNormal   = hits[0].normal,
                    };
                    resultAppendList.Add(result);
                }
            }
        }
        static StackObject *get_isValid_2(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method);
            UnityEngine.EventSystems.RaycastResult instance_of_this_method = (UnityEngine.EventSystems.RaycastResult) typeof(UnityEngine.EventSystems.RaycastResult).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));

            var result_of_this_method = instance_of_this_method.isValid;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            WriteBackInstance(__domain, ptr_of_this_method, __mStack, ref instance_of_this_method);

            __intp.Free(ptr_of_this_method);
            __ret->ObjectType = ObjectTypes.Integer;
            __ret->Value      = result_of_this_method ? 1 : 0;
            return(__ret + 1);
        }
Beispiel #10
0
 internal void SetUI(
     GameObject nGameObject,
     bool nIsUI,
     float nUiIndex,
     float nDistance,
     Vector3 nPoint,
     Vector3 nNormal,
     Transform nTransform,
     Vector2 nTextureCoord,
     UnityEngine.EventSystems.RaycastResult nRaycastResult)
 {
     this.gameObject    = nGameObject;
     this.isUI          = nIsUI;
     this.uiIndex       = nUiIndex;
     this.distance      = nDistance;
     this.point         = nPoint;
     this.normal        = nNormal;
     this.transform     = nTransform;
     this.textureCoord  = nTextureCoord;
     this.raycastResult = nRaycastResult;
 }
Beispiel #11
0
 static void set_worldPosition_6(ref object o, object v)
 {
     UnityEngine.EventSystems.RaycastResult _o = (UnityEngine.EventSystems.RaycastResult)o;
     _o.worldPosition = (UnityEngine.Vector3)v;
 }
Beispiel #12
0
        static internal int Lua_System_Comparison_1_UnityEngine_EventSystems_RaycastResult(LuaFunction ld, UnityEngine.EventSystems.RaycastResult a1, UnityEngine.EventSystems.RaycastResult a2)
        {
            IntPtr l     = ld.L;
            int    error = pushTry(l);

            pushValue(l, a1);
            pushValue(l, a2);
            ld.pcall(2, error);
            int ret;

            checkType(l, error + 1, out ret);
            LuaDLL.lua_settop(l, error - 1);
            return(ret);
        }
Beispiel #13
0
 /// <summary>
 /// Get screen position of worldPosition contained in this RaycastResult
 /// </summary>
 /// <param name="worldPosition"></param>
 /// <returns></returns>
 public Vector2 GetScreenPosition(UnityEngine.EventSystems.RaycastResult raycastResult)
 {
     // In future versions of Uinty RaycastResult will contain screenPosition so this will not be necessary
     return(eventCamera.WorldToScreenPoint(raycastResult.worldPosition));
 }
Beispiel #14
0
        private void Raycast(UnityEngine.EventSystems.PointerEventData eventData, List <UnityEngine.EventSystems.RaycastResult> resultAppendList, Ray ray, bool checkForBlocking)
        {
            //This function is closely based on
            //void GraphicRaycaster.Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList)

            if (canvas == null)
            {
                return;
            }

            float hitDistance = float.MaxValue;

            if (checkForBlocking && blockingObjects != BlockingObjects.None)
            {
                float dist = eventCamera.farClipPlane;

                if (blockingObjects == BlockingObjects.ThreeD || blockingObjects == BlockingObjects.All)
                {
                    var hits = Physics.RaycastAll(ray, dist, m_BlockingMask);

                    if (hits.Length > 0 && hits[0].distance < hitDistance)
                    {
                        hitDistance = hits[0].distance;
                    }
                }

                if (blockingObjects == BlockingObjects.TwoD || blockingObjects == BlockingObjects.All)
                {
                    var hits = Physics2D.GetRayIntersectionAll(ray, dist, m_BlockingMask);

                    if (hits.Length > 0 && hits[0].fraction * dist < hitDistance)
                    {
                        hitDistance = hits[0].fraction * dist;
                    }
                }
            }

            m_RaycastResults.Clear();

            GraphicRaycast(canvas, ray, m_RaycastResults);

            for (var index = 0; index < m_RaycastResults.Count; index++)
            {
                var  go            = m_RaycastResults[index].graphic.gameObject;
                bool appendGraphic = true;

                if (ignoreReversedGraphics)
                {
                    // If we have a camera compare the direction against the cameras forward.
                    var cameraFoward = ray.direction;
                    var dir          = go.transform.rotation * Vector3.forward;
                    appendGraphic = Vector3.Dot(cameraFoward, dir) > 0;
                }

                // Ignore points behind us (can happen with a canvas pointer)
                if (eventCamera.transform.InverseTransformPoint(m_RaycastResults[index].worldPos).z <= 0)
                {
                    appendGraphic = false;
                }

                if (appendGraphic)
                {
                    float distance = Vector3.Distance(ray.origin, m_RaycastResults[index].worldPos);

                    if (distance >= hitDistance)
                    {
                        continue;
                    }

                    var castResult = new UnityEngine.EventSystems.RaycastResult {
                        gameObject = go,
                        module     = this,
                        distance   = distance,
                        index      = resultAppendList.Count,
                        depth      = m_RaycastResults[index].graphic.depth,

                        worldPosition = m_RaycastResults[index].worldPos
                    };
                    resultAppendList.Add(castResult);
                }
            }
        }
Beispiel #15
0
 static void set_module_0(ref object o, object v)
 {
     UnityEngine.EventSystems.RaycastResult _o = (UnityEngine.EventSystems.RaycastResult)o;
     _o.module = (UnityEngine.EventSystems.BaseRaycaster)v;
 }
        static internal bool Lua_System_Predicate_1_UnityEngine_EventSystems_RaycastResult(LuaFunction ld, UnityEngine.EventSystems.RaycastResult a1)
        {
            IntPtr l     = ld.L;
            int    error = pushTry(l);

            pushValue(l, a1);
            ld.pcall(1, error);
            bool ret;

            checkType(l, error + 1, out ret);
            LuaDLL.lua_settop(l, error - 1);
            return(ret);
        }
Beispiel #17
0
 static void set_index_2(ref object o, object v)
 {
     UnityEngine.EventSystems.RaycastResult _o = (UnityEngine.EventSystems.RaycastResult)o;
     _o.index = (System.Single)v;
 }
Beispiel #18
0
 static void set_distance_1(ref object o, object v)
 {
     UnityEngine.EventSystems.RaycastResult _o = (UnityEngine.EventSystems.RaycastResult)o;
     _o.distance = (System.Single)v;
 }
Beispiel #19
0
 static void set_screenPosition_8(ref object o, object v)
 {
     UnityEngine.EventSystems.RaycastResult _o = (UnityEngine.EventSystems.RaycastResult)o;
     _o.screenPosition = (UnityEngine.Vector2)v;
 }
Beispiel #20
0
 static void set_worldNormal_7(ref object o, object v)
 {
     UnityEngine.EventSystems.RaycastResult _o = (UnityEngine.EventSystems.RaycastResult)o;
     _o.worldNormal = (UnityEngine.Vector3)v;
 }
        static internal void Lua_System_Action_1_UnityEngine_EventSystems_RaycastResult(LuaFunction ld, UnityEngine.EventSystems.RaycastResult a1)
        {
            IntPtr l     = ld.L;
            int    error = pushTry(l);

            pushValue(l, a1);
            ld.pcall(1, error);
            LuaDLL.lua_settop(l, error - 1);
        }
Beispiel #22
0
 static void set_sortingOrder_5(ref object o, object v)
 {
     UnityEngine.EventSystems.RaycastResult _o = (UnityEngine.EventSystems.RaycastResult)o;
     _o.sortingOrder = (System.Int32)v;
 }
Beispiel #23
0
 static void set_depth_3(ref object o, object v)
 {
     UnityEngine.EventSystems.RaycastResult _o = (UnityEngine.EventSystems.RaycastResult)o;
     _o.depth = (System.Int32)v;
 }