Example #1
0
    static int CalculateRaycastDepth(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        GameObject arg0 = (GameObject)LuaScriptMgr.GetUnityObject(L, 1, typeof(GameObject));
        int        o    = NGUITools.CalculateRaycastDepth(arg0);

        LuaScriptMgr.Push(L, o);
        return(1);
    }
Example #2
0
	static public int CalculateRaycastDepth_s(IntPtr l) {
		try {
			UnityEngine.GameObject a1;
			checkType(l,1,out a1);
			var ret=NGUITools.CalculateRaycastDepth(a1);
			pushValue(l,true);
			pushValue(l,ret);
			return 2;
		}
		catch(Exception e) {
			return error(l,e);
		}
	}
Example #3
0
        private void ShieldSendHelp(string fuctionName, object param = null)
        {
            this.CloseView();
            UICamera.currentTouch.clickNotification = UICamera.ClickNotification.BasedOnDelta;
            Ray ray = UICamera.currentCamera.ScreenPointToRay(UICamera.currentTouch.pos);

            RaycastHit[] hits = Physics.RaycastAll(ray);

            HitGo hitGo;

            hitGoList.Clear();
            if (hits.Length > 0)
            {
                for (int b = 0; b < hits.Length; ++b)
                {
                    GameObject go = hits[b].collider.gameObject;
                    UIWidget   w  = go.GetComponent <UIWidget>();
                    hitGo = new HitGo();
                    if (w != null)
                    {
                        if (!w.isVisible)
                        {
                            continue;
                        }
                        if (w.hitCheck != null && !w.hitCheck(hits[b].point))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        UIRect rect = NGUITools.FindInParents <UIRect>(go);
                        if (rect != null && rect.finalAlpha < 0.001f)
                        {
                            continue;
                        }
                    }

                    hitGo.depth = NGUITools.CalculateRaycastDepth(go);
                    hitGo.go    = go;
                    if (hitGo.depth != int.MaxValue)
                    {
                        hitGoList.Add(hitGo);
                    }
                }
                hitGoList.Sort(delegate(HitGo r1, HitGo r2) { return(r2.depth.CompareTo(r1.depth)); });
                (AppMap.Instance.me.Controller as ActionControler).StopWalk();
                hitGoList[0].go.SendMessage(fuctionName, param, SendMessageOptions.DontRequireReceiver);
            }
        }
Example #4
0
 static int CalculateRaycastDepth(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         UnityEngine.GameObject arg0 = (UnityEngine.GameObject)ToLua.CheckUnityObject(L, 1, typeof(UnityEngine.GameObject));
         int o = NGUITools.CalculateRaycastDepth(arg0);
         LuaDLL.lua_pushinteger(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #5
0
    private static int CalculateRaycastDepth(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 1);
            GameObject go = (GameObject)ToLua.CheckUnityObject(L, 1, typeof(GameObject));
            int        n  = NGUITools.CalculateRaycastDepth(go);
            LuaDLL.lua_pushinteger(L, n);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
Example #6
0
    /// <summary>
    /// Returns the object under the specified position.
    /// </summary>

    static public bool Raycast(Vector3 inPos, out RaycastHit hit)
    {
        for (int i = 0; i < list.size; ++i)
        {
            UICamera cam = list.buffer[i];

            // Skip inactive scripts
            if (!cam.enabled || !NGUITools.GetActive(cam.gameObject))
            {
                continue;
            }

            // Convert to view space
            currentCamera = cam.cachedCamera;
            Vector3 pos = currentCamera.ScreenToViewportPoint(inPos);
            if (float.IsNaN(pos.x) || float.IsNaN(pos.y))
            {
                continue;
            }

            // If it's outside the camera's viewport, do nothing
            if (pos.x < 0f || pos.x > 1f || pos.y < 0f || pos.y > 1f)
            {
                continue;
            }

            // Cast a ray into the screen
            Ray ray = currentCamera.ScreenPointToRay(inPos);

            // Raycast into the screen
            int   mask = currentCamera.cullingMask & (int)cam.eventReceiverMask;
            float dist = (cam.rangeDistance > 0f) ? cam.rangeDistance : currentCamera.farClipPlane - currentCamera.nearClipPlane;

            if (cam.eventType == EventType.World)
            {
                if (Physics.Raycast(ray, out hit, dist, mask))
                {
                    hoveredObject = hit.collider.gameObject;
                    return(true);
                }
                continue;
            }
            else if (cam.eventType == EventType.UI)
            {
                RaycastHit[] hits = Physics.RaycastAll(ray, dist, mask);

                if (hits.Length > 1)
                {
                    for (int b = 0; b < hits.Length; ++b)
                    {
                        GameObject go = hits[b].collider.gameObject;
                        mHit.depth = NGUITools.CalculateRaycastDepth(go);

                        if (mHit.depth != int.MaxValue)
                        {
                            mHit.hit = hits[b];
                            mHits.Add(mHit);
                        }
                    }

                    mHits.Sort(delegate(DepthEntry r1, DepthEntry r2) { return(r2.depth.CompareTo(r1.depth)); });

                    for (int b = 0; b < mHits.size; ++b)
                    {
#if UNITY_FLASH
                        if (IsVisible(mHits.buffer[b]))
#else
                        if (IsVisible(ref mHits.buffer[b]))
#endif
                        {
                            hit           = mHits[b].hit;
                            hoveredObject = hit.collider.gameObject;
                            mHits.Clear();
                            return(true);
                        }
                    }
                    mHits.Clear();
                }
                else if (hits.Length == 1 && IsVisible(ref hits[0]))
                {
                    hit           = hits[0];
                    hoveredObject = hit.collider.gameObject;
                    return(true);
                }
                continue;
            }
        }
        hit = mEmpty;
        return(false);
    }
Example #7
0
    bool IsUIVisible(string uiName, string checkCoverButton = "")
    {
        Transform ui = basePanel.FindChild(uiName);

        if (ui != null && NGUITools.GetActive(ui.gameObject))
        {
            if (checkCoverButton != "")
            {
                Transform button = basePanel.FindChild(checkCoverButton);
                if (button == null)
                {
                    Debug.Log("Button not found: " + checkCoverButton);
                    return(false);
                }
                Camera cam = UICamera.currentCamera;
                if (cam == null)
                {
                    return(true);
                }
                Vector3 viewPoint = cam.WorldToViewportPoint(button.transform.position);
                //是否在屏幕外
                if (viewPoint.x < 0f || viewPoint.x > 1f || viewPoint.y < 0f || viewPoint.y > 1f)
                {
                    return(true);
                }
                //检测是否正在播动画
                Animator animator = button.GetComponentInParent <Animator>();
                if (animator != null)
                {
                    // The position of GameObject that controlled by animation is 0 at animation's beginning. Consider it as invisible.
                    if (AtBeginning(animator))
                    {
                        return(false);
                    }
                    // No ray cast test when animating.
                    if (IsAnimating(animator))
                    {
                        return(true);
                    }
                }
                //射线检测
                Vector3 screenPoint = cam.WorldToScreenPoint(button.transform.position);
                if (shutter == null)
                {
                    RaycastHit hit;
                    if (UICamera.Raycast(screenPoint, out hit))
                    {
                        if (hit.collider.transform == button)
                        {
                            return(true);
                        }
                        else
                        {
                            shutter = hit.collider;
                            Debug.Log("Guide, shuttered by " + shutter.name);
                            return(false);
                        }
                    }
                    else
                    {
                        //Debug.LogError("Guide, ray cast failed on highlight button: " + checkCoverButton);
                        return(false);
                    }
                }
                else
                {
                    Ray ray = cam.ScreenPointToRay(screenPoint);
                    if (shutter.bounds.IntersectRay(ray) &&
                        NGUITools.CalculateRaycastDepth(shutter.gameObject) > NGUITools.CalculateRaycastDepth(button.gameObject))
                    {
                        return(false);
                    }
                    else
                    {
                        shutter = null;
                        return(true);
                    }
                }
            }
            return(true);
        }

        if (!uiName.EndsWith("(Clone)"))
        {
            return(IsUIVisible(uiName + "(Clone)", checkCoverButton));
        }
        return(false);
    }
Example #8
0
        public void ClickCenter()
        {
            var mHit  = new DepthEntry();
            var mHits = new BetterList <DepthEntry>();

            var cam = UIManager.Instance.UICamera.GetComponent <UICamera>();

            UIEventTrigger.current = null;

            // Convert to view space
            var currentCamera = cam.cachedCamera;

            // Cast a ray into the screen
            var p = Hollow.transform.position;

            p.z = currentCamera.nearClipPlane;
            var ray = new Ray(p, Vector3.forward);

            // Raycast into the screen
            var mask = currentCamera.cullingMask & cam.eventReceiverMask;
            var dist = (cam.rangeDistance > 0f)
                    ? cam.rangeDistance
                    : currentCamera.farClipPlane - currentCamera.nearClipPlane;

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

            if (hits.Length > 1)
            {
                for (var b = 0; b < hits.Length; ++b)
                {
                    var go = hits[b].collider.gameObject;

                    if (go == Hollow.gameObject)
                    {
                        continue;
                    }

                    var w = go.GetComponent <UIWidget>();

                    if (w != null)
                    {
                        if (!w.isVisible)
                        {
                            continue;
                        }
                        if (w.hitCheck != null && !w.hitCheck(hits[b].point))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        var rect = NGUITools.FindInParents <UIRect>(go);
                        if (rect != null && rect.finalAlpha < 0.001f)
                        {
                            continue;
                        }
                    }

                    mHit.depth = NGUITools.CalculateRaycastDepth(go);

                    if (mHit.depth != int.MaxValue)
                    {
                        mHit.hit   = hits[b];
                        mHit.point = hits[b].point;
                        mHit.go    = hits[b].collider.gameObject;
                        mHits.Add(mHit);
                    }
                }

                mHits.Sort(delegate(DepthEntry r1, DepthEntry r2) { return(r2.depth.CompareTo(r1.depth)); });

                for (var b = 0; b < mHits.size; ++b)
                {
        #if UNITY_FLASH
                    if (IsShowing(mHits.buffer[b]))
        #else
                    if (IsShowing(ref mHits.buffer[b]))
        #endif
                    {
                        MessageNotify(mHits.buffer[b].go, "OnClick", null);
                        return;
                    }
                }
                mHits.Clear();
            }
            else if (hits.Length == 1)
            {
                var go = hits[0].collider.gameObject;

                if (go == Hollow.gameObject)
                {
                    return;
                }

                var w = go.GetComponent <UIWidget>();

                if (w != null)
                {
                    if (!w.isVisible)
                    {
                        return;
                    }
                    if (w.hitCheck != null && !w.hitCheck(hits[0].point))
                    {
                        return;
                    }
                }
                else
                {
                    var rect = NGUITools.FindInParents <UIRect>(go);
                    if (rect != null && rect.finalAlpha < 0.001f)
                    {
                        return;
                    }
                }

                if (IsShowing(hits[0].point, hits[0].collider.gameObject))
                {
                    MessageNotify(hits[0].collider.gameObject, "OnClick", null);
                }
            }
        }
Example #9
0
	/// <summary>
	/// Returns the object under the specified position.
	/// </summary>

	static public bool Raycast (Vector3 inPos)
	{
		for (int i = 0; i < list.size; ++i)
		{
			UICamera cam = list.buffer[i];
			
			// Skip inactive scripts
			if (!cam.enabled || !NGUITools.GetActive(cam.gameObject)) continue;

			// Convert to view space
			currentCamera = cam.cachedCamera;
			Vector3 pos = currentCamera.ScreenToViewportPoint(inPos);
			if (float.IsNaN(pos.x) || float.IsNaN(pos.y)) continue;

			// If it's outside the camera's viewport, do nothing
			if (pos.x < 0f || pos.x > 1f || pos.y < 0f || pos.y > 1f) continue;

			// Cast a ray into the screen
			Ray ray = currentCamera.ScreenPointToRay(inPos);

			// Raycast into the screen
			int mask = currentCamera.cullingMask & (int)cam.eventReceiverMask;
			float dist = (cam.rangeDistance > 0f) ? cam.rangeDistance : currentCamera.farClipPlane - currentCamera.nearClipPlane;

			if (cam.eventType == EventType.World_3D)
			{
				if (Physics.Raycast(ray, out lastHit, dist, mask))
				{
					lastWorldPosition = lastHit.point;
					hoveredObject = lastHit.collider.gameObject;
					return true;
				}
				continue;
			}
			else if (cam.eventType == EventType.UI_3D)
			{
				RaycastHit[] hits = Physics.RaycastAll(ray, dist, mask);

				if (hits.Length > 1)
				{
					for (int b = 0; b < hits.Length; ++b)
					{
						GameObject go = hits[b].collider.gameObject;
						UIWidget w = go.GetComponent<UIWidget>();

						if (w != null)
						{
							if (!w.isVisible) continue;
							if (w.hitCheck != null && !w.hitCheck(hits[b].point)) continue;
						}
						else
						{
							UIRect rect = NGUITools.FindInParents<UIRect>(go);
							if (rect != null && rect.finalAlpha < 0.001f) continue;
						}

						mHit.depth = NGUITools.CalculateRaycastDepth(go);

						if (mHit.depth != int.MaxValue)
						{
							mHit.hit = hits[b];
							mHit.go = hits[b].collider.gameObject;
							mHits.Add(mHit);
						}
					}

					mHits.Sort(delegate(DepthEntry r1, DepthEntry r2) { return r2.depth.CompareTo(r1.depth); });

					for (int b = 0; b < mHits.size; ++b)
					{
#if UNITY_FLASH
						if (IsVisible(mHits.buffer[b]))
#else
						if (IsVisible(ref mHits.buffer[b]))
#endif
						{
							lastHit = mHits[b].hit;
							hoveredObject = mHits[b].go;
							lastWorldPosition = hits[b].point;
							mHits.Clear();
							return true;
						}
					}
					mHits.Clear();
				}
				else if (hits.Length == 1)
				{
					GameObject go = hits[0].collider.gameObject;
					UIWidget w = go.GetComponent<UIWidget>();

					if (w != null)
					{
						if (!w.isVisible) continue;
						if (w.hitCheck != null && !w.hitCheck(hits[0].point)) continue;
					}
					else
					{
						UIRect rect = NGUITools.FindInParents<UIRect>(go);
						if (rect != null && rect.finalAlpha < 0.001f) continue;
					}

					if (IsVisible(hits[0].point, hits[0].collider.gameObject))
					{
						lastHit = hits[0];
						lastWorldPosition = hits[0].point;
						hoveredObject = lastHit.collider.gameObject;
						return true;
					}
				}
				continue;
			}
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2
			else if (cam.eventType == EventType.World_2D)
			{
				if (m2DPlane.Raycast(ray, out dist))
				{
					Vector3 point = ray.GetPoint(dist);
					Collider2D c2d = Physics2D.OverlapPoint(point, mask);

					if (c2d)
					{
						lastWorldPosition = point;
						hoveredObject = c2d.gameObject;
						return true;
					}
				}
				continue;
			}
			else if (cam.eventType == EventType.UI_2D)
			{
				if (m2DPlane.Raycast(ray, out dist))
				{
					lastWorldPosition = ray.GetPoint(dist);
					Collider2D[] hits = Physics2D.OverlapPointAll(lastWorldPosition, mask);

					if (hits.Length > 1)
					{
						for (int b = 0; b < hits.Length; ++b)
						{
							GameObject go = hits[b].gameObject;
							UIWidget w = go.GetComponent<UIWidget>();

							if (w != null)
							{
								if (!w.isVisible) continue;
								if (w.hitCheck != null && !w.hitCheck(lastWorldPosition)) continue;
							}
							else
							{
								UIRect rect = NGUITools.FindInParents<UIRect>(go);
								if (rect != null && rect.finalAlpha < 0.001f) continue;
							}

							mHit.depth = NGUITools.CalculateRaycastDepth(go);

							if (mHit.depth != int.MaxValue)
							{
								mHit.go = go;
								mHits.Add(mHit);
							}
						}

						mHits.Sort(delegate(DepthEntry r1, DepthEntry r2) { return r2.depth.CompareTo(r1.depth); });

						for (int b = 0; b < mHits.size; ++b)
						{
#if UNITY_FLASH
							if (IsVisible(mHits.buffer[b]))
#else
							if (IsVisible(ref mHits.buffer[b]))
#endif
							{
								hoveredObject = mHits[b].go;
								mHits.Clear();
								return true;
							}
						}
						mHits.Clear();
					}
					else if (hits.Length == 1)
					{
						GameObject go = hits[0].gameObject;
						UIWidget w = go.GetComponent<UIWidget>();

						if (w != null)
						{
							if (!w.isVisible) continue;
							if (w.hitCheck != null && !w.hitCheck(lastWorldPosition)) continue;
						}
						else
						{
							UIRect rect = NGUITools.FindInParents<UIRect>(go);
							if (rect != null && rect.finalAlpha < 0.001f) continue;
						}

						if (IsVisible(lastWorldPosition, go))
						{
							hoveredObject = go;
							return true;
						}
					}
				}
				continue;
			}
#endif
		}
		return false;
	}
Example #10
0
 public static bool Raycast(Vector3 inPos)
 {
     for (int i = 0; i < list.size; i++)
     {
         UICamera uICamera = list.buffer[i];
         if (!uICamera.enabled || !NGUITools.GetActive(uICamera.gameObject))
         {
             continue;
         }
         currentCamera = uICamera.cachedCamera;
         Vector3 vector = currentCamera.ScreenToViewportPoint(inPos);
         if (float.IsNaN(vector.x) || float.IsNaN(vector.y) || vector.x < 0f || vector.x > 1f || vector.y < 0f || vector.y > 1f)
         {
             continue;
         }
         Ray   ray       = currentCamera.ScreenPointToRay(inPos);
         int   layerMask = currentCamera.cullingMask & (int)uICamera.eventReceiverMask;
         float enter     = ((uICamera.rangeDistance > 0f) ? uICamera.rangeDistance : (currentCamera.farClipPlane - currentCamera.nearClipPlane));
         if (uICamera.eventType == EventType.World_3D)
         {
             if (Physics.Raycast(ray, out lastHit, enter, layerMask))
             {
                 hoveredObject = lastHit.collider.gameObject;
                 return(true);
             }
         }
         else if (uICamera.eventType == EventType.UI_3D)
         {
             RaycastHit[] array = Physics.RaycastAll(ray, enter, layerMask);
             if (array.Length > 1)
             {
                 for (int j = 0; j < array.Length; j++)
                 {
                     GameObject gameObject = array[j].collider.gameObject;
                     UIWidget   component  = gameObject.GetComponent <UIWidget>();
                     if (component != null)
                     {
                         if (!component.isVisible || (component.hitCheck != null && !component.hitCheck(array[j].point)))
                         {
                             continue;
                         }
                     }
                     else
                     {
                         UIRect uIRect = NGUITools.FindInParents <UIRect>(gameObject);
                         if (uIRect != null && uIRect.finalAlpha < 0.001f)
                         {
                             continue;
                         }
                     }
                     mHit.depth = NGUITools.CalculateRaycastDepth(gameObject);
                     if (mHit.depth != int.MaxValue)
                     {
                         mHit.hit = array[j];
                         mHit.go  = array[j].collider.gameObject;
                         mHits.Add(mHit);
                     }
                 }
                 mHits.Sort((DepthEntry r1, DepthEntry r2) => r2.depth.CompareTo(r1.depth));
                 for (int j = 0; j < mHits.size; j++)
                 {
                     if (IsVisible(ref mHits.buffer[j]))
                     {
                         lastHit           = mHits[j].hit;
                         hoveredObject     = mHits[j].go;
                         lastWorldPosition = array[j].point;
                         mHits.Clear();
                         return(true);
                     }
                 }
                 mHits.Clear();
             }
             else
             {
                 if (array.Length != 1)
                 {
                     continue;
                 }
                 GameObject gameObject = array[0].collider.gameObject;
                 UIWidget   component  = gameObject.GetComponent <UIWidget>();
                 if (component != null)
                 {
                     if (!component.isVisible || (component.hitCheck != null && !component.hitCheck(array[0].point)))
                     {
                         continue;
                     }
                 }
                 else
                 {
                     UIRect uIRect = NGUITools.FindInParents <UIRect>(gameObject);
                     if (uIRect != null && uIRect.finalAlpha < 0.001f)
                     {
                         continue;
                     }
                 }
                 if (IsVisible(array[0].point, array[0].collider.gameObject))
                 {
                     lastHit           = array[0];
                     lastWorldPosition = array[0].point;
                     hoveredObject     = lastHit.collider.gameObject;
                     return(true);
                 }
             }
         }
         else if (uICamera.eventType == EventType.World_2D)
         {
             if (m2DPlane.Raycast(ray, out enter))
             {
                 Vector3    point      = ray.GetPoint(enter);
                 Collider2D collider2D = Physics2D.OverlapPoint(point, layerMask);
                 if ((bool)collider2D)
                 {
                     lastWorldPosition = point;
                     hoveredObject     = collider2D.gameObject;
                     return(true);
                 }
             }
         }
         else
         {
             if (uICamera.eventType != EventType.UI_2D || !m2DPlane.Raycast(ray, out enter))
             {
                 continue;
             }
             lastWorldPosition = ray.GetPoint(enter);
             Collider2D[] array2 = Physics2D.OverlapPointAll(lastWorldPosition, layerMask);
             if (array2.Length > 1)
             {
                 for (int j = 0; j < array2.Length; j++)
                 {
                     GameObject gameObject = array2[j].gameObject;
                     UIWidget   component  = gameObject.GetComponent <UIWidget>();
                     if (component != null)
                     {
                         if (!component.isVisible || (component.hitCheck != null && !component.hitCheck(lastWorldPosition)))
                         {
                             continue;
                         }
                     }
                     else
                     {
                         UIRect uIRect = NGUITools.FindInParents <UIRect>(gameObject);
                         if (uIRect != null && uIRect.finalAlpha < 0.001f)
                         {
                             continue;
                         }
                     }
                     mHit.depth = NGUITools.CalculateRaycastDepth(gameObject);
                     if (mHit.depth != int.MaxValue)
                     {
                         mHit.go = gameObject;
                         mHits.Add(mHit);
                     }
                 }
                 mHits.Sort((DepthEntry r1, DepthEntry r2) => r2.depth.CompareTo(r1.depth));
                 for (int j = 0; j < mHits.size; j++)
                 {
                     if (IsVisible(ref mHits.buffer[j]))
                     {
                         hoveredObject = mHits[j].go;
                         mHits.Clear();
                         return(true);
                     }
                 }
                 mHits.Clear();
             }
             else
             {
                 if (array2.Length != 1)
                 {
                     continue;
                 }
                 GameObject gameObject = array2[0].gameObject;
                 UIWidget   component  = gameObject.GetComponent <UIWidget>();
                 if (component != null)
                 {
                     if (!component.isVisible || (component.hitCheck != null && !component.hitCheck(lastWorldPosition)))
                     {
                         continue;
                     }
                 }
                 else
                 {
                     UIRect uIRect = NGUITools.FindInParents <UIRect>(gameObject);
                     if (uIRect != null && uIRect.finalAlpha < 0.001f)
                     {
                         continue;
                     }
                 }
                 if (IsVisible(lastWorldPosition, gameObject))
                 {
                     hoveredObject = gameObject;
                     return(true);
                 }
             }
         }
     }
     return(false);
 }