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


C# Bounds.Intersects方法代码示例

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


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

示例1: BoundsQuery

        public List<DBVHNode> BoundsQuery(Bounds bounds)
        {
            List<DBVHNode> results = new List<DBVHNode>();

            if (nodes.Count > 0){

            Stack<DBVHNode> stack = new Stack<DBVHNode>();
            stack.Push(nodes[0]);
            while(stack.Count > 0)
            {

                DBVHNode node = stack.Pop();

                if (node.content != null){ //leaf node

                    if (bounds.Intersects(node.content.bounds))
                        results.Add(node);

                }else{

                    if (NodeExists(node.Left) && bounds.Intersects(nodes[node.Left].bounds))
                        stack.Push(nodes[node.Left]);

                    if (NodeExists(node.Right) && bounds.Intersects(nodes[node.Right].bounds))
                        stack.Push(nodes[node.Right]);

                }

            }
            }

            return results;
        }
开发者ID:Fabbseh,项目名称:CuteHorrorGame,代码行数:33,代码来源:DBVH.cs

示例2: CheckIfHitDodgeButton

    private void CheckIfHitDodgeButton()
    {
        /*
        if (Mathf.Abs(Input.mousePosition.x - Camera.main.WorldToScreenPoint (uiInterface.transform.GetChild (0).transform.position).x) < 35 &&
            Mathf.Abs(Input.mousePosition.y - Camera.main.WorldToScreenPoint (uiInterface.transform.GetChild (0).transform.position).y) < 35)
        {
            playerObj.Dodge (false);
        }
        if (Mathf.Abs(Input.mousePosition.x - Camera.main.WorldToScreenPoint (uiInterface.transform.GetChild (1).transform.position).x) < 35 &&
            Mathf.Abs(Input.mousePosition.y - Camera.main.WorldToScreenPoint (uiInterface.transform.GetChild (1).transform.position).y) < 35)
        {
            playerObj.Dodge (true);
        } */

        Bounds mouseBounds = new Bounds (Input.mousePosition, new Vector3 (65.2f, 65.2f, 65.2f));
        Bounds debugBounds_0 = new Bounds (Camera.main.WorldToScreenPoint (uiInterface.transform.GetChild (0).transform.localPosition), new Vector3 (65.2f, 65.2f, 65.2f));
        Bounds debugBounds_1 = new Bounds (Camera.main.WorldToScreenPoint (uiInterface.transform.GetChild (1).transform.localPosition), new Vector3 (65.2f, 65.2f, 65.2f));

        if (debugBounds_0.Intersects(mouseBounds))
        {
            playerObj.Dodge (false);
        }
        else if (debugBounds_1.Intersects(mouseBounds))
        {
            playerObj.Dodge (true);
        }
    }
开发者ID:TheMetabug,项目名称:RendelGame,代码行数:27,代码来源:GameScript.cs

示例3: update

    public override void update()
    {
        if (!helper.success) {
            return;
        }
        float angle = Mathf.Atan2(helper.screenspace_position.y, helper.screenspace_position.x - Camera.main.pixelWidth / 2);
        float percent = angle / Mathf.PI;
        foreach (GameObject wall in walls) {
            wall.transform.Translate((percent - 0.5f) * speed, 0, -0.1f * speed);
            Bounds wallBounds = new Bounds();
            wallBounds.center = wall.transform.position;
            wallBounds.size = wall.transform.localScale;
            helper.success = helper.success && !wallBounds.Intersects(bounds);
            if (wallBounds.Intersects(bounds))
            {
                helper.end();
            }
        }

        if (helper.success && walls[walls.Count - 1].transform.position.z < 60) {
            addWall ();
        }
    }
开发者ID:dsesclei,项目名称:DS501,代码行数:23,代码来源:avoid_game.cs

示例4: GetAffectedObjects

    private static GameObject[] GetAffectedObjects(Bounds bounds, LayerMask affectedLayers)
    {
        MeshRenderer[] renderers = (MeshRenderer[]) GameObject.FindObjectsOfType<MeshRenderer>();
        List<GameObject> objects = new List<GameObject>();
        foreach(Renderer r in renderers) {
            if( !r.enabled ) continue;
            if( !IsLayerContains(affectedLayers, r.gameObject.layer) ) continue;
            if( r.GetComponent<CausticDecal>() != null ) continue;

            if( bounds.Intersects(r.bounds) ) {
                objects.Add(r.gameObject);
            }
        }
        return objects.ToArray();
    }
开发者ID:OSW-team,项目名称:Project-4,代码行数:15,代码来源:CausticDecalEditor.cs

示例5: GenerateDungeon

    IEnumerator GenerateDungeon()
    {
        GameObject firstRoom = (GameObject)Instantiate (startingRoom, Vector3.zero, Quaternion.identity);
        EnqueueRoom (firstRoom.GetComponent<Room> ());
        currentRooms.Add (firstRoom.GetComponent<Room> ());

        int numRooms = 1;
        int curChecks = 0;

        for (int i = 0; i < roomPrefabs.Length; i++) {
            NavMeshObstacle[] obstacles = roomPrefabs[i].GetComponentsInChildren<NavMeshObstacle> ();
            for (int j = 0; j < obstacles.Length; j++) {
                obstacles[j].carving = false;
            }
        }

        GameObject bp = new GameObject ("BuildPointer");
        Transform buildPointer = bp.transform;

        while (numRooms < maxRooms && remainingRooms.Count > 0) {
            Room curRoom = remainingRooms.Dequeue ();

            for (int j = 0; j < curRoom.doors.Length; j++) {

                if (!curRoom.doors [j].isConnected) {
                    GameObject newRoomGO = roomPrefabs [Random.Range (0, roomPrefabs.Length)];
                    if (curRoom.doors [j].forcedRoom) {
                        newRoomGO = curRoom.doors [j].forcedRoom;
                    }
                    Room newRoom = newRoomGO.GetComponent<Room> ();

                    Transform door = curRoom.doors [j].transform;
                    Vector3 spawnPos = door.position + door.forward * (newRoom.Size ().z / 2f);
                    spawnPos = new Vector3 (spawnPos.x, 0f, spawnPos.z);

                    buildPointer.position = spawnPos;
                    buildPointer.LookAt (door);

                    buildPointer.rotation = Quaternion.Euler (0, buildPointer.eulerAngles.y, 0);

                    bool allowBuild = true;

                    for (int i = 0; i < currentRooms.Count; i++) {
                        currentBounds = AbsBounds (currentRooms [i].GetBounds ());
                        checkingBounds = AbsBounds (new Bounds (spawnPos, buildPointer.rotation * newRoom.size * 0.9f));

                        if (curChecks >= checksPerTick) {
                            yield return new WaitForFixedUpdate ();
                            curChecks = 0;
                        } else {
                            curChecks++;
                        }

                        if (checkingBounds.Intersects (currentBounds)) {
                            curRoom.doors [j].isConnected = true;
                            allowBuild = false;
                        }
                    }

                    if (allowBuild) {
                        numRooms++;
                        curRoom.doors [j].isConnected = true;
                        GameObject spawnedRoom = (GameObject)Instantiate (newRoomGO, buildPointer.position, buildPointer.rotation);

                        curRoom = null;
                        Room r = spawnedRoom.GetComponent<Room> ();
                        r.doors [0].isConnected = true;
                        currentRooms.Add (r);
                        EnqueueRoom (r);

                        break;
                    }
                }
            }
        }

        // Check all doors to find out if a door is nearby, and then removed one of the doors based on priority.
        Transform survivingDoor = null;
        bool noNearby = true;

        List<GameObject> toDestroy = new List<GameObject> ();
        List<Transform> toEnd = new List<Transform> ();

        for (int i = 0; i < allDoors.Count; i++) {
            survivingDoor = allDoors [i].transform;
            noNearby = true;
            Door t = allDoors [i];
            if (toDestroy.Contains(t.transform.gameObject))
                continue;

            for (int j = 0; j < allDoors.Count; j++) {
                Door d = allDoors [j];

                if (t.transform == d.transform)
                    continue;

                if (Vector3.Distance (t.transform.position, d.transform.position) < 0.5f) {
                    if (t.priority > d.priority) {
                        toDestroy.Add (d.transform.gameObject);
                        survivingDoor = t.transform;
//.........这里部分代码省略.........
开发者ID:Lomztein,项目名称:Microsquad,代码行数:101,代码来源:Dungeon.cs

示例6: UpdateBuildingsPosition

    private void UpdateBuildingsPosition()
    {
        Bounds bounds = new Bounds();
        Vector2 topLeftPosition = OnlineMaps.instance.topLeftPosition;
        Vector2 bottomRightPosition = OnlineMaps.instance.bottomRightPosition;

        bounds.min = new Vector3(topLeftPosition.x, bottomRightPosition.y);
        bounds.max = new Vector3(bottomRightPosition.x, topLeftPosition.y);

        List<string> unusedKeys = new List<string>();

        bool useElevation = OnlineMapsTileSetControl.instance.useElevation;

        foreach (KeyValuePair<string, OnlineMapsBuildingBase> building in buildings)
        {
            if (!bounds.Intersects(building.Value.boundsCoords)) unusedKeys.Add(building.Key);
            else
            {
                if (useElevation)
                {
                    Vector3 newPosition = OnlineMapsTileSetControl.instance.GetWorldPositionWithElevation(building.Value.centerCoordinates, topLeftPosition, bottomRightPosition);
                    building.Value.transform.position = newPosition;
                }
                else
                {
                    Vector3 newPosition = OnlineMapsTileSetControl.instance.GetWorldPosition(building.Value.centerCoordinates);
                    building.Value.transform.position = newPosition;
                }
            }
        }

        List<string> usedKeys = new List<string>();
        List<string> destroyKeys = new List<string>();

        double px, py;
        api.GetPosition(out px, out py);
        OnlineMapsUtils.LatLongToTiled(px, py, api.zoom, out px, out py);

        float maxDistance = Mathf.Sqrt(Mathf.Pow(api.width / 2 / OnlineMapsUtils.tileSize, 2) + Mathf.Pow(api.height / 2 / OnlineMapsUtils.tileSize, 2)) * 2;

        foreach (KeyValuePair<string, OnlineMapsBuildingBase> building in unusedBuildings)
        {
            OnlineMapsBuildingBase value = building.Value;
            if (bounds.Intersects(value.boundsCoords))
            {
                usedKeys.Add(building.Key);
                Vector3 newPosition =
                    OnlineMapsTileSetControl.instance.GetWorldPosition(value.centerCoordinates);
                value.transform.position = newPosition;
            }
            else
            {
                Vector2 buildingTilePos = OnlineMapsUtils.LatLongToTilef(value.centerCoordinates, api.zoom);
                if ((buildingTilePos - new Vector2((float)px, (float)py)).magnitude > maxDistance) destroyKeys.Add(building.Key);
            }
        }

        foreach (string key in unusedKeys)
        {
            OnlineMapsBuildingBase value = buildings[key];
            value.gameObject.SetActive(false);
            unusedBuildings.Add(key, value);
            buildings.Remove(key);
        }

        foreach (string key in usedKeys)
        {
            OnlineMapsBuildingBase value = unusedBuildings[key];
            value.gameObject.SetActive(true);
            buildings.Add(key, value);
            unusedBuildings.Remove(key);
        }

        foreach (string key in destroyKeys)
        {
            OnlineMapsBuildingBase value = unusedBuildings[key];
            if (OnBuildingDispose != null) OnBuildingDispose(value);
            DestroyImmediate(value.gameObject);
            unusedBuildings.Remove(key);
        }

        if (destroyKeys.Count > 0) OnlineMaps.instance.needGC = true;
    }
开发者ID:JorgenNyborg,项目名称:Fishualizer,代码行数:83,代码来源:OnlineMapsBuildings.cs

示例7: OnMouseUp

    void OnMouseUp()
    {
        SpriteRenderer[] subImages = GetComponentsInChildren<SpriteRenderer>();
        foreach (SpriteRenderer sr in subImages)
        {
            sr.sortingLayerName = "Front";
        }

        if (dragging && (mainController.statusCode == 1 || mainController.statusCode == 0 || mainController.statusCode != 7) && mainController.statusCode != 50 && mainController.statusCode != 6)
        {
            staffAttributePanel.SetActive(false);

            Bounds staffBounds = new Bounds(transform.position, new Vector3(1, 1, 1));

            Bounds b = GameObject.Find("Box Office").GetComponent<Renderer>().bounds;

            Bounds boxOfficeBounds = new Bounds(b.center - new Vector3(0, 0.5f, 0), b.extents);

            Bounds newStaffBounds = new Bounds(staffBounds.center + new Vector3(0, 0.5f, 0), staffBounds.extents - new Vector3(0, 0.25f, 0));

            if (boxOfficeBounds.Intersects(newStaffBounds))
            {
                float xPos = transform.position.x;
                transform.position = new Vector2(xPos, 8f);
            }

            this.transform.localScale = new Vector3(1, 1, 1);
            animator.SetTrigger("land");

            Animator handimator = GetComponentsInChildren<Animator>()[1];
            handimator.SetTrigger("land");

            // check if in an invalid place - in middle of screen or object - sort layer accordingly
            GameObject hidden = CheckHiddenBehind(staffBounds, shopController.gameObjectList, shopController.screenObjectList);

            for (int i = 0; i < mainController.staffSlot.Count; i++)
            {
                SpriteRenderer[] srs = mainController.staffSlot[i].GetComponentsInChildren<SpriteRenderer>();
                foreach (SpriteRenderer sr in srs) { sr.enabled = false; }
            }

            triggerSet = false;
            this.transform.position = new Vector3(transform.position.x, transform.position.y + 0.4f, 0);

            float x = this.transform.position.x;
            float y = this.transform.position.y;

            this.staffMember.SetVector(x, y);

            for (int i = 0; i < mainController.staffSlot.Count; i++)
            {
                Bounds b1 = mainController.staffSlot[i].GetComponent<Renderer>().bounds;

                Bounds newStaff = new Bounds(staffBounds.center + new Vector3(0, 1.25f, 0), staffBounds.extents);

                if (b1.Intersects(newStaff))
                {
                    if (ValidDrop(i))
                    {
                        // get the level required to use this slot
                        int levReq = TileManager.GetAccessLevelForSlot(mainController.staffSlot[i].tag);
                        int currLev = staffMember.GetLevel();

                        // change color
                        if (currLev >= levReq)
                        {
                            // add to list of staff at ticket booth
                            if (changeStaffJob != null)
                            {
                                int target = 0;

                                if (mainController.staffSlot[i].tag.Contains("1"))
                                {
                                    // a ticket slot
                                    target = 1;
                                }
                                else
                                {
                                    target = 2;
                                }

                                mainController.slotState[i] = true;

                                GameObject[] slots = GameObject.FindGameObjectsWithTag("Slot Type " + target);

                                int posInPost = -1;
                                for (int j = 0; j < slots.Length; j++)
                                {
                                    if (slots[j].name.Equals(mainController.staffSlot[i].name))
                                    {
                                        posInPost = j;
                                        break;
                                    }
                                }

                                if (target == 2)
                                {
                                    transform.Translate(0, 0.27f, 0);
                                }

//.........这里部分代码省略.........
开发者ID:andrewdavis1995,项目名称:Cinema-Game,代码行数:101,代码来源:mouseDrag.cs

示例8: CollectMeshes

		bool CollectMeshes (out List<ExtraMesh> extraMeshes, Bounds bounds) {
			List<ExtraMesh> extraMeshesList = new List<ExtraMesh> ();
			if (rasterizeMeshes) {
				extraMeshesList = GetSceneMeshes (bounds);
			}
			
			GetRecastMeshObjs (bounds, extraMeshesList);
			
			Terrain[] terrains = MonoBehaviour.FindObjectsOfType(typeof(Terrain)) as Terrain[];
			
			if (rasterizeTerrain && terrains.Length > 0) {
				
				for (int j=0;j<terrains.Length;j++) {
					
					TerrainData terrainData = terrains[j].terrainData;
					
					if (terrainData == null) continue;
					
					Vector3 offset = terrains[j].GetPosition ();
					Vector3 center = offset + terrainData.size * 0.5F;
					Bounds b = new Bounds (center, terrainData.size);
					
					
					//Only include terrains which intersects the graph
					if (!b.Intersects (bounds)) continue;
					
					float[,] heights = terrainData.GetHeights (0,0,terrainData.heightmapWidth,terrainData.heightmapHeight);
					
					terrainSampleSize = terrainSampleSize < 1 ? 1 : terrainSampleSize;//Clamp to at least 1
					
					int hWidth = terrainData.heightmapWidth / terrainSampleSize;
					int hHeight = terrainData.heightmapHeight / terrainSampleSize;
					Vector3[] terrainVertices = new Vector3[hWidth*hHeight];
					
					Vector3 hSampleSize = terrainData.heightmapScale;
					float heightScale = terrainData.size.y;
					
					for (int z = 0, nz = 0;nz < hHeight;z+= terrainSampleSize, nz++) {
						for (int x = 0, nx = 0; nx < hWidth;x+= terrainSampleSize, nx++) {
							terrainVertices[nz*hWidth + nx] = new Vector3 (z * hSampleSize.z,heights[x,z]*heightScale, x * hSampleSize.x) + offset;
						}
					}
					
					int[] tris = new int[(hWidth-1)*(hHeight-1)*2*3];
					int c = 0;
					for (int z = 0;z < hHeight-1;z++) {
						for (int x = 0; x < hWidth-1;x++) {
							tris[c] = z*hWidth + x;
							tris[c+1] = z*hWidth + x+1;
							tris[c+2] = (z+1)*hWidth + x+1;
							c += 3;
							tris[c] = z*hWidth + x;
							tris[c+1] = (z+1)*hWidth + x+1;
							tris[c+2] = (z+1)*hWidth + x;
							c += 3;
						}
					}
					
	#if ASTARDEBUG
					for (int i=0;i<tris.Length;i+=3) {
						Debug.DrawLine (terrainVertices[tris[i]],terrainVertices[tris[i+1]],Color.red);
						Debug.DrawLine (terrainVertices[tris[i+1]],terrainVertices[tris[i+2]],Color.red);
						Debug.DrawLine (terrainVertices[tris[i+2]],terrainVertices[tris[i]],Color.red);
					}
	#endif
					
					
					extraMeshesList.Add (new ExtraMesh (terrainVertices,tris,b));
					
					if (rasterizeTrees) {
						//Rasterize all tree colliders on this terrain object
						CollectTreeMeshes (extraMeshesList, terrains[j]);
					}
				}
			}
			
			if (rasterizeColliders) {
				Collider[] colls = MonoBehaviour.FindObjectsOfType (typeof(Collider)) as Collider[];
				foreach (Collider col in colls) {
					if (((1 << col.gameObject.layer) & mask) == (1 << col.gameObject.layer) && col.enabled && !col.isTrigger && col.bounds.Intersects (bounds)) {
						ExtraMesh emesh = RasterizeCollider (col);
						//Make sure a valid ExtraMesh was returned
						if (emesh.vertices != null) extraMeshesList.Add (emesh);
					}
				}
				
				//Clear cache to avoid memory leak
				capsuleCache.Clear();
			}
			
			extraMeshes = extraMeshesList;
			
			if (extraMeshesList.Count == 0) {
				Debug.LogWarning ("No MeshFilters where found contained in the layers specified by the 'mask' variable");
				
				return false;
			}
			
			return true;
		}
开发者ID:JoseRego,项目名称:summer-rush,代码行数:100,代码来源:RecastGenerator.cs

示例9: UpdateMarkersMesh


//.........这里部分代码省略.........
            float rx2 = (fx + markerWidth) * cx;
            float ry2 = (fy + markerHeight) * cy;

            Vector3 center = new Vector3((fx + offset.x) * cx, 0, (fy + offset.y) * cy);

            Vector3 p1 = new Vector3(rx1 - center.x, 0, ry1 - center.z);
            Vector3 p2 = new Vector3(rx2 - center.x, 0, ry1 - center.z);
            Vector3 p3 = new Vector3(rx2 - center.x, 0, ry2 - center.z);
            Vector3 p4 = new Vector3(rx1 - center.x, 0, ry2 - center.z);

            float angle = Mathf.Repeat(marker.rotation, 1) * 360;

            if (angle != 0)
            {
                matrix.SetTRS(Vector3.zero, Quaternion.Euler(0, angle, 0), Vector3.one);

                p1 = matrix.MultiplyPoint(p1) + center;
                p2 = matrix.MultiplyPoint(p2) + center;
                p3 = matrix.MultiplyPoint(p3) + center;
                p4 = matrix.MultiplyPoint(p4) + center;
            }
            else
            {
                p1 += center;
                p2 += center;
                p3 += center;
                p4 += center;
            }

            if (checkMarker2DVisibility == OnlineMapsTilesetCheckMarker2DVisibility.bounds)
            {
                Vector3 markerCenter = (p2 + p4) / 2;
                Vector3 markerSize = p4 - p2;
                if (!tilesetBounds.Intersects(new Bounds(markerCenter, markerSize))) continue;
            }

            float y = GetElevationValue((rx1 + rx2) / 2, (ry1 + ry2) / 2, yScale, tlx, tly, brx, bry);
            float yOffset = (useOffsetY) ? offsets[i] : 0;

            p1.y = p2.y = p3.y = p4.y = y + yOffset;

            markersVerticles.Add(p1);
            markersVerticles.Add(p2);
            markersVerticles.Add(p3);
            markersVerticles.Add(p4);

            usedMarkers.Add(new TilesetFlatMarker(marker, p1 + transform.position, p3 + transform.position));

            if (marker.texture == api.defaultMarkerTexture)
                usedTexturesMarkerIndex[0].Add(usedMarkersCount);
            else
            {
                int textureIndex = usedTextures.IndexOf(marker.texture);
                if (textureIndex != -1) usedTexturesMarkerIndex[textureIndex].Add(usedMarkersCount);
                else
                {
                    usedTextures.Add(marker.texture);
                    usedTexturesMarkerIndex.Add(new List<int>());
                    usedTexturesMarkerIndex[usedTexturesMarkerIndex.Count - 1].Add(usedMarkersCount);
                }
            }

            usedMarkersCount++;
        }

        Vector2[] markersUV = new Vector2[markersVerticles.Count];
开发者ID:Ronnie619,项目名称:TouchScreenKiosk,代码行数:67,代码来源:OnlineMapsTileSetControl.cs

示例10: CheckRecycleObjectBounds

		/// <summary>
		/// Checks the recycle object bounds.
		/// </summary>
		/// <returns><c>true</c>, if recycle object bounds was checked, <c>false</c> otherwise.</returns>
		/// <param name="objectBounds">Object bounds.</param>
		/// <param name="destroyDistance">Destroy distance.</param>
		public virtual bool CheckRecycleObjectBounds (Bounds objectBounds, float destroyDistance)
		{
			tempRecycleBounds = RecycleBounds;
			tempRecycleBounds.extents += Vector3.one * destroyDistance;

			if (objectBounds.Intersects (tempRecycleBounds)) {
				return false;
			} else {
				return true;
			}
		}
开发者ID:nathantaylor50,项目名称:IndividualProject2016,代码行数:17,代码来源:LevelManager.cs

示例11: multiSelectPenguins

    // Returns a list of the Icicle Penguins within the drawn selection box
    public List<IciclePenguins> multiSelectPenguins(Vector3 startBound, Vector3 endBound)
    {
        List<IciclePenguins> selected = new List<IciclePenguins> ();

        Vector3 center = new Vector3 ((startBound.x+endBound.x)/2.0f, (startBound.y+endBound.y)/2.0f, 0.0f);
        //size.x is the width, size.y is the height and size.z is the depth of the box.
        Vector3 size = new Vector3 (Math.Abs(startBound.x-endBound.x), Math.Abs(startBound.y-endBound.y), 0.0f);

        //create box
        Bounds b = new Bounds (center, size);

        //loop through grid to see what agents are within the box, and on the box's intersecting lines
        for (int i = 0; i < width; i++) {
            for(int j = 0; j < height; j++){
                foreach(Agent a in grid[i,j]){
                    if(a.GetType().Equals(typeof(IciclePenguins)) && b.Intersects(a.renderer.bounds)){
                        selected.Add((IciclePenguins) a);
                    }
                }
            }
        }

        return selected;
    }
开发者ID:jessmay,项目名称:oil-penguins,代码行数:25,代码来源:Grid.cs

示例12: CollectTerrainMeshes

 private void CollectTerrainMeshes(Bounds bounds, bool rasterizeTrees, List<ExtraMesh> extraMeshes)
 {
     Terrain[] array = UnityEngine.Object.FindObjectsOfType(typeof(Terrain)) as Terrain[];
     if (array.Length > 0)
     {
         for (int i = 0; i < array.Length; i++)
         {
             TerrainData terrainData = array[i].terrainData;
             if (!(terrainData == null))
             {
                 Vector3 position = array[i].GetPosition();
                 Vector3 center = position + terrainData.size * 0.5f;
                 Bounds b = new Bounds(center, terrainData.size);
                 if (b.Intersects(bounds))
                 {
                     float[,] heights = terrainData.GetHeights(0, 0, terrainData.heightmapWidth, terrainData.heightmapHeight);
                     this.terrainSampleSize = Math.Max(this.terrainSampleSize, 1);
                     int heightmapWidth = terrainData.heightmapWidth;
                     int heightmapHeight = terrainData.heightmapHeight;
                     int num = (terrainData.heightmapWidth + this.terrainSampleSize - 1) / this.terrainSampleSize + 1;
                     int num2 = (terrainData.heightmapHeight + this.terrainSampleSize - 1) / this.terrainSampleSize + 1;
                     Vector3[] array2 = new Vector3[num * num2];
                     Vector3 heightmapScale = terrainData.heightmapScale;
                     float y = terrainData.size.y;
                     int num3 = 0;
                     for (int j = 0; j < num2; j++)
                     {
                         int num4 = 0;
                         for (int k = 0; k < num; k++)
                         {
                             int num5 = Math.Min(num4, heightmapWidth - 1);
                             int num6 = Math.Min(num3, heightmapHeight - 1);
                             array2[j * num + k] = new Vector3((float)num6 * heightmapScale.x, heights[num5, num6] * y, (float)num5 * heightmapScale.z) + position;
                             num4 += this.terrainSampleSize;
                         }
                         num3 += this.terrainSampleSize;
                     }
                     int[] array3 = new int[(num - 1) * (num2 - 1) * 2 * 3];
                     int num7 = 0;
                     for (int l = 0; l < num2 - 1; l++)
                     {
                         for (int m = 0; m < num - 1; m++)
                         {
                             array3[num7] = l * num + m;
                             array3[num7 + 1] = l * num + m + 1;
                             array3[num7 + 2] = (l + 1) * num + m + 1;
                             num7 += 3;
                             array3[num7] = l * num + m;
                             array3[num7 + 1] = (l + 1) * num + m + 1;
                             array3[num7 + 2] = (l + 1) * num + m;
                             num7 += 3;
                         }
                     }
                     extraMeshes.Add(new ExtraMesh(array2, array3, b));
                     if (rasterizeTrees)
                     {
                         this.CollectTreeMeshes(array[i], extraMeshes);
                     }
                 }
             }
         }
     }
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:63,代码来源:RecastGraph.cs

示例13: GenerateVoxelData

	private void GenerateVoxelData(BoundHierarchy rootNode)
	{
		var gridCubeSize = new Vector3(
			_bounds.size.x / _xDensity,
			_bounds.size.y / _yDensity,
			_bounds.size.z / _zDensity);
		var worldCentre = _bounds.min + gridCubeSize / 2;
		var objectLevelBounds = rootNode.subBounds;
		var cachedGridBounds = new Bounds(Vector3.zero, gridCubeSize);
		var cachedVec = Vector3.zero;
		
		#if UNITY_EDITOR
		EditorUtility.ClearProgressBar();
		var pointsProcessed = 0;
		var totalPoints = (float)(_xDensity * _yDensity * _zDensity);
		#endif
		
		for(int x = 0; x < _xDensity; x++)
		{
			for(int y = 0; y < _yDensity; y++)
			{
				for(int z = 0; z < _zDensity; z++)
				{
					#if UNITY_EDITOR
					pointsProcessed++;
					if (Application.isEditor && !Application.isPlaying)
					{
						if (pointsProcessed % 2000 == 0)
						{
							if(EditorUtility.DisplayCancelableProgressBar("Voxelising", "Voxelising", (float)pointsProcessed / totalPoints))
							{
								EditorUtility.ClearProgressBar();
								return;
							}
						}
					}
					#endif
					
					var didFind = false;
					for(int objectCnt = 0; objectCnt < objectLevelBounds.Length; objectCnt++)
					{
						cachedVec.x = x * gridCubeSize.x + worldCentre.x;
						cachedVec.y = y * gridCubeSize.y + worldCentre.y;
						cachedVec.z = z * gridCubeSize.z + worldCentre.z;
						cachedGridBounds.center = cachedVec;
						
						if(cachedGridBounds.Intersects(objectLevelBounds[objectCnt].bound))
						{
							var triBounds = objectLevelBounds[objectCnt].subBounds;
							for(int triCnt = 0; triCnt < triBounds.Length; triCnt++)
							{
								var triangle = triBounds[triCnt].triList;
								if(TriAABBOverlap.Check(cachedGridBounds, triangle))
								{
									
									_voxelMap[x][y][z] = true;
									didFind = true;
									break;
								}
							}
							if(didFind)
							{
								break;
							}
						}
						if(didFind)
						{
							break;
						}
					}
				}
			}
		}
		
		#if UNITY_EDITOR
		EditorUtility.ClearProgressBar();
		#endif
	}
开发者ID:ArieLeo,项目名称:unity-voxelizer,代码行数:78,代码来源:Voxeliser.cs

示例14: CollectTerrainMeshes

		void CollectTerrainMeshes ( Bounds bounds, bool rasterizeTrees, List<ExtraMesh> extraMeshes ) {

			Terrain[] terrains = MonoBehaviour.FindObjectsOfType(typeof(Terrain)) as Terrain[];
			
			if (terrains.Length > 0) {
				
				for (int j=0;j<terrains.Length;j++) {
					
					TerrainData terrainData = terrains[j].terrainData;
					
					if (terrainData == null) continue;
					
					Vector3 offset = terrains[j].GetPosition ();
					Vector3 center = offset + terrainData.size * 0.5F;
					Bounds b = new Bounds (center, terrainData.size);
					
					
					//Only include terrains which intersects the graph
					if (!b.Intersects (bounds)) continue;
					
					float[,] heights = terrainData.GetHeights (0,0,terrainData.heightmapWidth,terrainData.heightmapHeight);
					
					terrainSampleSize = terrainSampleSize < 1 ? 1 : terrainSampleSize;//Clamp to at least 1
					
					int rwidth = terrainData.heightmapWidth;
					int rheight = terrainData.heightmapHeight;
					
					int hWidth = (terrainData.heightmapWidth+terrainSampleSize-1) / terrainSampleSize + 1;
					int hHeight = (terrainData.heightmapHeight+terrainSampleSize-1) / terrainSampleSize + 1;
					Vector3[] terrainVertices = new Vector3[hWidth*hHeight];
					
					Vector3 hSampleSize = terrainData.heightmapScale;
					float heightScale = terrainData.size.y;
					
					for (int z = 0, nz = 0;nz < hHeight;z+= terrainSampleSize, nz++) {
						for (int x = 0, nx = 0; nx < hWidth;x+= terrainSampleSize, nx++) {
							int rx = System.Math.Min (x,rwidth-1);
							int rz = System.Math.Min (z,rheight-1);
							
							terrainVertices[nz*hWidth + nx] = new Vector3 (rz * hSampleSize.z,heights[rx,rz]*heightScale, rx * hSampleSize.x) + offset;
						}
					}
					
					int[] tris = new int[(hWidth-1)*(hHeight-1)*2*3];
					int c = 0;
					for (int z = 0;z < hHeight-1;z++) {
						for (int x = 0; x < hWidth-1;x++) {
							tris[c] = z*hWidth + x;
							tris[c+1] = z*hWidth + x+1;
							tris[c+2] = (z+1)*hWidth + x+1;
							c += 3;
							tris[c] = z*hWidth + x;
							tris[c+1] = (z+1)*hWidth + x+1;
							tris[c+2] = (z+1)*hWidth + x;
							c += 3;
						}
					}
					
					#if ASTARDEBUG
					for (int i=0;i<tris.Length;i+=3) {
						Debug.DrawLine (terrainVertices[tris[i]],terrainVertices[tris[i+1]],Color.red);
						Debug.DrawLine (terrainVertices[tris[i+1]],terrainVertices[tris[i+2]],Color.red);
						Debug.DrawLine (terrainVertices[tris[i+2]],terrainVertices[tris[i]],Color.red);
					}
					#endif
					
					
					extraMeshes.Add (new ExtraMesh (terrainVertices,tris,b));
					
					if (rasterizeTrees) {
						//Rasterize all tree colliders on this terrain object
						CollectTreeMeshes (terrains[j], extraMeshes);
					}
				}
			}

		}
开发者ID:moderndelta137,项目名称:Shadow_Sword,代码行数:77,代码来源:RecastGenerator.cs

示例15: CheckHiddenBehind

    /// <summary>
    /// check if a staff member is hidden
    /// </summary>
    /// <param name="staffBounds"></param>
    /// <param name="gameObjectList"></param>
    /// <param name="screenObjectList"></param>
    /// <returns></returns>
    public static GameObject CheckHiddenBehind(Bounds staffBounds, List<GameObject> gameObjectList, List<GameObject> screenObjectList)
    {
        GameObject toHideBehind = null;

        for (int i = 0; i < gameObjectList.Count; i++)
        {
            Bounds bTop = GetObjectHiddenBounds(gameObjectList[i]);

            if (bTop.Intersects(staffBounds)) { toHideBehind = gameObjectList[i]; break; }

        }

        if (toHideBehind == null)
        {
            for (int i = 0; i < screenObjectList.Count; i++)
            {

                Bounds b1 = screenObjectList[i].GetComponent<Renderer>().bounds;

                Bounds bTop = new Bounds(new Vector3(b1.center.x, (b1.center.y - b1.extents.y + 8.8f), 0), 2 * new Vector3(b1.extents.x, 1.8f, 0.125f));
                Bounds bBottom = new Bounds(new Vector3(b1.center.x, (b1.center.y - b1.extents.y + 0.9f), 0), 2 * new Vector3(b1.extents.x, 0.65f, 0.1f));

                if (bTop.Intersects(staffBounds)) { toHideBehind = screenObjectList[i]; break; }
                if (bBottom.Intersects(staffBounds)) { toHideBehind = screenObjectList[i]; break; }

                if (b1.Intersects(staffBounds) && ShopController.theScreens[i].ConstructionInProgress())
                {
                    toHideBehind = screenObjectList[i];
                    break;
                }

            }
        }

        return toHideBehind;
    }
开发者ID:andrewdavis1995,项目名称:Cinema-Game,代码行数:43,代码来源:mouseDrag.cs


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