当前位置: 首页>>代码示例>>C#>>正文


C# Camera.ScreenToViewportPoint方法代码示例

本文整理汇总了C#中UnityEngine.Camera.ScreenToViewportPoint方法的典型用法代码示例。如果您正苦于以下问题:C# Camera.ScreenToViewportPoint方法的具体用法?C# Camera.ScreenToViewportPoint怎么用?C# Camera.ScreenToViewportPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Camera的用法示例。


在下文中一共展示了Camera.ScreenToViewportPoint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetViewportBounds

    //This returns the boudns to detect units inside the rect.
    public static Bounds GetViewportBounds( Camera camera, Vector3 screenPosition1, Vector3 screenPosition2 )
    {
        var v1 = camera.ScreenToViewportPoint( screenPosition1 );
        var v2 = camera.ScreenToViewportPoint( screenPosition2 );
        var min = Vector3.Min( v1, v2 );
        var max = Vector3.Max( v1, v2 );
        min.z = camera.nearClipPlane;
        max.z = camera.farClipPlane;

        var bounds = new Bounds();
        bounds.SetMinMax( min, max );
        return bounds;
    }
开发者ID:jgirald,项目名称:ES2015F,代码行数:14,代码来源:RectDrawer.cs

示例2: GetViewportBounds

        public static Bounds GetViewportBounds(Vector3 originViewportPoint, Camera currentCamera, Vector3 currentScreenPosition)
        {
            Vector3 v1 = originViewportPoint;
            Vector3 v2 = currentCamera.ScreenToViewportPoint(currentScreenPosition);

            Vector3 min = Vector3.Min(v1, v2);
            Vector3 max = Vector3.Max(v1, v2);
            min.z = currentCamera.nearClipPlane;
            max.z = currentCamera.farClipPlane;

            Bounds bounds = new Bounds();
            bounds.SetMinMax(min, max);
            return bounds;
        }
开发者ID:HyroVitalyProtago,项目名称:KingdomsRebellion,代码行数:14,代码来源:BoxTools.cs

示例3: Raycast

	/// <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;
#if !UNITY_4_7 && !UNITY_5_0 && !UNITY_5_1 && !UNITY_5_2
			if (currentCamera.targetDisplay != 0) continue;
#endif
			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;
					mRayHitObject = lastHit.collider.gameObject;

					if (!cam.eventsGoToColliders)
					{
						Rigidbody rb = FindRootRigidbody(mRayHitObject.transform);
						if (rb != null) mRayHitObject = rb.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;
						Profiler.BeginSample("Editor-only GC allocation (GetComponent)");
						UIWidget w = go.GetComponent<UIWidget>();
						Profiler.EndSample();

						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.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 (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;
							mRayHitObject = mHits[b].go;
							lastWorldPosition = mHits[b].point;
							mHits.Clear();
							return true;
						}
					}
					mHits.Clear();
//.........这里部分代码省略.........
开发者ID:OvertimeStudios,项目名称:CreepyBuster,代码行数:101,代码来源:UICamera.cs

示例4: Raycast

	/// <summary>
	/// Returns the object under the specified position.
	/// </summary>

	static public bool Raycast (Vector3 inPos, out RaycastHit hit)
	{
		for (int i = 0; i < list.Count; ++i)
		{
			UICamera cam = list[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);
						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 (IsVisible(ref mHits.buffer[b]))
						{
							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;
	}
开发者ID:sundayliu,项目名称:HelloWorld-unity3d,代码行数:77,代码来源:UICamera.cs

示例5: Raycast

    /// <summary>
    /// Returns the object under the specified position.
    /// </summary>
    static bool Raycast(Vector3 inPos, ref RaycastHit hit)
    {
        for (int i = 0; i < mList.Count; ++i)
        {
            UICamera cam = mList[i];

            // Skip inactive scripts
            if (!cam.enabled || !cam.gameObject.active) continue;

            // Convert to view space
            currentCamera = cam.cachedCamera;
            Vector3 pos = currentCamera.ScreenToViewportPoint(inPos);

            // 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 (Physics.Raycast(ray, out hit, dist, mask)) return true;
        }
        return false;
    }
开发者ID:zhangcy269,项目名称:workspace,代码行数:29,代码来源:UICamera.cs

示例6: Raycast

	/// <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;
						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];
							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)
				{
					Collider c = hits[0].collider;
					UIWidget w = c.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>(c.gameObject);
						if (rect != null && rect.finalAlpha < 0.001f) continue;
//.........这里部分代码省略.........
开发者ID:Nomex13,项目名称:PingPong,代码行数:101,代码来源:UICamera.cs

示例7: Raycast

    /// <summary>
    /// Returns the object under the specified position.
    /// </summary>
    public static bool Raycast(Vector3 inPos, out RaycastHit hit)
    {
        for (int i = 0; i < mList.Count; ++i)
        {
            UICamera cam = mList[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 raycasts should be clipped by panels, we need to find a panel for each hit
            if (cam.clipRaycasts)
            {
                RaycastHit[] hits = Physics.RaycastAll(ray, dist, mask);

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

                    for (int b = 0, bmax = hits.Length; b < bmax; ++b)
                    {
                        if (IsVisible(ref hits[b]))
                        {
                            hit = hits[b];
                            return true;
                        }
                    }
                }
                else if (hits.Length == 1 && IsVisible(ref hits[0]))
                {
                    hit = hits[0];
                    return true;
                }
                continue;
            }
            if (Physics.Raycast(ray, out hit, dist, mask)) return true;
        }
        hit = mEmpty;
        return false;
    }
开发者ID:mortl,项目名称:AuroraTD,代码行数:57,代码来源:UICamera.cs

示例8: FindPlane

    /// <summary>
    /// Given a screen coordinate, find a plane that most closely fits depth values in that area.
    /// 
    /// This assumes you are using this in an AR context.
    /// </summary>
    /// <returns><c>true</c>, if plane was found, <c>false</c> otherwise.</returns>
    /// <param name="cam">The Unity camera.</param>
    /// <param name="pos">The point in screen space to perform detection on.</param>
    /// <param name="planeCenter">Filled in with the center of the plane in Unity world space.</param>
    /// <param name="plane">Filled in with a model of the plane in Unity world space.</param>
    public bool FindPlane(Camera cam, Vector2 pos, out Vector3 planeCenter, out Plane plane)
    {
        Matrix4x4 unityWorldTColorCamera = m_unityWorldTStartService * m_startServiceTDevice * Matrix4x4.Inverse(m_imuTDevice) * m_imuTColorCamera;
        Matrix4x4 colorCameraTUnityWorld = unityWorldTColorCamera.inverse;

        Vector2 normalizedPos = cam.ScreenToViewportPoint(pos);

        int returnValue = TangoSupport.FitPlaneModelNearClick(
            m_points, m_pointsCount, m_pointsTimestamp, m_colorCameraIntrinsics, ref colorCameraTUnityWorld, normalizedPos,
            out planeCenter, out plane);

        if (returnValue == Common.ErrorType.TANGO_SUCCESS)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
开发者ID:wertkh32,项目名称:project-moonfish,代码行数:30,代码来源:TangoPointCloud.cs

示例9: Raycast

    /// <summary>
    /// Returns the object under the specified position.
    /// </summary>
    static bool Raycast(Vector3 inPos, ref RaycastHit hit)
    {
        foreach (UICamera cam in mList)
        {
            // Skip inactive scripts
            if (!cam.enabled || !cam.gameObject.active) continue;

            // Convert to view space
            lastCamera = cam.cachedCamera;
            Vector3 pos = lastCamera.ScreenToViewportPoint(inPos);

            // 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 = lastCamera.ScreenPointToRay(inPos);

            // Raycast into the screen
            int mask = lastCamera.cullingMask & (int)cam.eventReceiverMask;
            if (Physics.Raycast(ray, out hit, lastCamera.farClipPlane - lastCamera.nearClipPlane, mask)) return true;
        }
        return false;
    }
开发者ID:eonaranas,项目名称:piggiesgame,代码行数:26,代码来源:UICamera.cs

示例10: FindPlane

    /// <summary>
    /// Given a screen coordinate, find a plane that most closely fits depth values in that area.
    /// 
    /// This assumes you are using this in an AR context.
    /// </summary>
    /// <returns><c>true</c>, if plane was found, <c>false</c> otherwise.</returns>
    /// <param name="cam">The Unity camera.</param>
    /// <param name="pos">The point in screen space to perform detection on.</param>
    /// <param name="planeCenter">Filled in with the center of the plane in Unity world space.</param>
    /// <param name="plane">Filled in with a model of the plane in Unity world space.</param>
    public bool FindPlane(Camera cam, Vector2 pos, out Vector3 planeCenter, out Plane plane)
    {
        Matrix4x4 colorCameraTUnityWorld = m_colorCameraTUnityCamera * cam.transform.worldToLocalMatrix;
        Vector2 normalizedPos = cam.ScreenToViewportPoint(pos);

        // If the camera has a TangoARScreen attached, it is not displaying the entire color camera image.  Correct
        // the normalized coordinates by taking the clipping into account.
        TangoARScreen arScreen = cam.gameObject.GetComponent<TangoARScreen>();
        if (arScreen != null)
        {
            normalizedPos = arScreen.ViewportPointToCameraImagePoint(normalizedPos);
        }

        int returnValue = TangoSupport.FitPlaneModelNearClick(
            m_points, m_pointsCount, m_depthTimestamp, m_colorCameraIntrinsics, ref colorCameraTUnityWorld, normalizedPos,
            out planeCenter, out plane);

        if (returnValue == Common.ErrorType.TANGO_SUCCESS)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
开发者ID:tsi25,项目名称:Zen,代码行数:36,代码来源:TangoPointCloud.cs

示例11: CalcViewPort

 public Vector2 CalcViewPort(Vector2 pos,Camera cam)
 {
     return cam.ScreenToViewportPoint(new Vector3(pos.x,pos.y,0f));
 }
开发者ID:justdude,项目名称:SpinTheBall,代码行数:4,代码来源:InputHandler.cs

示例12: FindPlane

    /// <summary>
    /// Given a screen coordinate, finds a plane that most closely fits the
    /// depth values in that area.
    /// 
    /// This function is slow, as it looks at every single point in the point
    /// cloud. Avoid calling this more than once a frame. This also assumes the
    /// Unity camera intrinsics match the device's color camera.
    /// </summary>
    /// <returns><c>true</c>, if a plane was found; <c>false</c> otherwise.</returns>
    /// <param name="cam">The Unity camera.</param>
    /// <param name="pos">The point in screen space to perform detection on.</param>
    /// <param name="planeCenter">Filled in with the center of the plane in Unity world space.</param>
    /// <param name="plane">Filled in with a model of the plane in Unity world space.</param>
    public bool FindPlane(Camera cam, Vector2 pos, out Vector3 planeCenter, out Plane plane)
    {
        if (m_pointsCount == 0)
        {
            // No points to check, maybe not connected to the service yet
            planeCenter = Vector3.zero;
            plane = new Plane();
            return false;
        }

        Matrix4x4 colorCameraTUnityWorld = m_colorCameraTUnityCamera * cam.transform.worldToLocalMatrix;
        Vector2 normalizedPos = cam.ScreenToViewportPoint(pos);

        // If the camera has a TangoARScreen attached, it is not displaying the entire color camera image.  Correct
        // the normalized coordinates by taking the clipping into account.
        TangoARScreen arScreen = cam.gameObject.GetComponent<TangoARScreen>();
        if (arScreen != null)
        {
            normalizedPos = arScreen.ViewportPointToCameraImagePoint(normalizedPos);
        }

        TangoCameraIntrinsics alignedIntrinsics = new TangoCameraIntrinsics();
        VideoOverlayProvider.GetDeviceOientationAlignedIntrinsics(TangoEnums.TangoCameraId.TANGO_CAMERA_COLOR,
                                                                  alignedIntrinsics);
        int returnValue = TangoSupport.FitPlaneModelNearClick(
                m_points, m_pointsCount, m_depthTimestamp, alignedIntrinsics, ref colorCameraTUnityWorld,
                normalizedPos, out planeCenter, out plane);

        if (returnValue == Common.ErrorType.TANGO_SUCCESS)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
开发者ID:kyr7,项目名称:tango-examples-unity,代码行数:50,代码来源:TangoPointCloud.cs

示例13: Start

        // Use this for initialization
        void Start()
        {
            //initialize the player character
            Vector3 charPos = new Vector3(25.5f, -1.8f, 2.0f);
            characters.Add((GameObject)Instantiate(Character, charPos, Quaternion.identity));

            //set camera to follow the Camera Target
            Vector3 camPos = new Vector3(25.5f, -1.8f, 0.0f);
            cameraTargets.Add((GameObject)Instantiate(CamTarget, camPos, Quaternion.identity));

            Transform targetTransform = cameraTargets[0].transform;
            mainCam = Camera.allCameras[0];
            mainCam.GetComponent<SmoothFollow>().target = targetTransform;

            //Find the light
            light = GameObject.Find("Directional Light");

            //initialize the front wall
            Vector3 wallPos = mainCam.ViewportToWorldPoint(new Vector3(1.0f, 0.0f, 0.0f));
            wallPos.z = 2.0f; // resets to platform Z
            wallPos.y = -3.0f; // brings wall to ground
            wallPos.x *= 1.6f; // moves wall half of screen width away from camera
            frontWalls.Add((GameObject)Instantiate(FrontWall, wallPos, Quaternion.identity));
            frontWalls[0].transform.Rotate(0.0f, 0.0f, 90.0f);

            //initialize the kill zone
            Vector3 killZonePos = mainCam.ScreenToViewportPoint(new Vector3(0.0f, 0.0f, 2.0f));
            killZonePos.x += 7.0f; // move slightly right from current lock location
            KillZones.Add((GameObject)Instantiate(KillZone, killZonePos, Quaternion.identity));
            killZones[0].transform.Rotate(0.0f, 0.0f, 90.0f);

            // create bottom killzone
            Vector3 underworld = new Vector3(0.0f, -11.5f, 2.0f);
            killZones.Add((GameObject)Instantiate(KillZone, underworld, Quaternion.identity));

            // create knife
            knifeSpawn = new Vector3(killZonePos.x, killZonePos.y, killZonePos.z);
            knifeSpawn.x += 2.0f; // move slightly right from current lock location
            knife = (GameObject)Instantiate(Knife, knifeSpawn, Quaternion.identity);
            knife.transform.localScale = new Vector3(0.6f, 0.6f, 0.6f);
            thrown = false;

            // create chef
            chefSpawn = new Vector3(killZonePos.x, killZonePos.y, killZonePos.z);
            chefSpawn.x += 2.0f; // move slightly right from current lock location
            Chef = (GameObject)Instantiate(Chef, chefSpawn, Quaternion.identity);
            chefOnScreen = false;
            chefMovingOut = false;

            mainCam.aspect = (1920f / 910f);

            //initialize the game fragments
            for (int i = 0; i < numFrags; i++)
            {
                Vector3 fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                //make the first two fragments flat
                if (i == 0 || i == 1) fragments.Add((GameObject)Instantiate(GameFragments[0], fragPos, Quaternion.identity));
                else
                {
                    float fragType = Random.Range(0.0f, (float)GameFragments.Count);
                    if (fragType >= 0 && fragType < 1)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[0], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 1 && fragType < 2)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[1], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 2 && fragType < 3)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[2], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 3 && fragType < 4)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[3], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 4 && fragType < 5)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[4], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 5 && fragType < 6)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[5], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 6 && fragType < 7)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[6], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 7 && fragType < 8)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[7], fragPos, Quaternion.identity));
//.........这里部分代码省略.........
开发者ID:mfasman95,项目名称:WildPotatoGDD2Digital,代码行数:101,代码来源:GameManager.cs

示例14: Raycast

	/// <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;

					if (!list[0].eventsGoToColliders)
					{
						Rigidbody rb = FindRootRigidbody(hoveredObject.transform);
						if (rb != null) hoveredObject = rb.gameObject;
					}
					return true;
				}
				continue;
			}
		}
		return false;
	}
开发者ID:zhutaorun,项目名称:unitygame,代码行数:47,代码来源:UICamera.cs

示例15: RayCast

    public GameObject RayCast(Camera cam, Vector3 inPos)
    {
        Vector3 pos = cam.ScreenToViewportPoint(inPos);
        if (float.IsNaN(pos.x) || float.IsNaN(pos.y))
            return null;
        if (pos.x < 0f || pos.x > 1f || pos.y < 0f || pos.y > 1f) return null;

        Ray ray = cam.ScreenPointToRay(inPos);
        float dis = 100f;
        RaycastHit[] hits = Physics.RaycastAll(ray, dis, rayCastMask);
        if (hits.Length > 0)
        {
            for (int i = 0; i < hits.Length; i++)
            {
                GameObject go = hits[i].collider.gameObject;
                DragEnhanceView dragView = go.GetComponent<DragEnhanceView>();
                if (dragView == null)
                    continue;
                else
                {
                    // just return current hover object our drag target
                    return go;
                }
            }
        }
        return null;
    }
开发者ID:tinyantstudio,项目名称:EnhancedScrollView,代码行数:27,代码来源:EnhanceScrollViewDragController.cs


注:本文中的UnityEngine.Camera.ScreenToViewportPoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。