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


C# GameObject.GetPrefabBounds方法代码示例

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


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

示例1: SpawnBuilding

        /// <summary>
        /// Spawn a building on the position
        /// </summary>
        private void SpawnBuilding(Vector3 position, GameObject prefab, BuildingSite building)
        {
            var road = building.ParentRoad;

            //Make the building face the road, make a perpendicular line from the building pos to the road
            var lookAtPos = road.FindPerpendicularPointOnLine(new Point(position.x, position.z)).ToVector3();

            //get correct spawn height from the terrain
            position.y = _terrain.SampleHeight(position);
            lookAtPos.y = position.y;

            //Get bounds of the prefab and store them
            var size = prefab.GetPrefabBounds();
            building.Width = (int)size.x;
            building.Height = (int)size.z;

            //don't spawn when there is a collision
            var colliderPos = position;
            colliderPos.y += size.y / 2;
            if (isOverlapping(prefab, position))
            {
                return;
            }

            //instantiate the building
            var go = (GameObject)Object.Instantiate(prefab, position, prefab.transform.rotation);

            //look at the road
            go.transform.LookAt(lookAtPos);

            //flip on Y
            go.transform.RotateAround(position, go.transform.up, 180);
            go.isStatic = true;
            go.SetParent(_buildingParent);

            building.UserData = go;

            //Remove grass and other details around the object
            //RemoveDetailsAroundGameObject((GameObject)go);

            //Add to the buildings list
            _buildings.Add(building);
        }
开发者ID:TobieD,项目名称:City-Generator,代码行数:46,代码来源:TownBuilder.cs

示例2: isOverlapping

        /// Check if there is an overlap
        private bool isOverlapping(GameObject prefab, Vector3 pos)
        {
            var colliderPos = pos;
            var size = prefab.GetPrefabBounds();
            colliderPos.y += size.y / 2;

            var collisions = Physics.OverlapBox(pos, size/1.5f);
            return collisions.Length > 1;
        }
开发者ID:TobieD,项目名称:City-Generator,代码行数:10,代码来源:TownBuilder.cs


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