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


C# Building.AddCollider方法代码示例

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


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

示例1: checkSegment

    /// <summary>
    /// evaluate segment for potential building placement
    /// </summary>
    /// <param name="segment"></param>
    private void checkSegment(RoadSegment segment)
    {
        Vector2 start = segment.PointA.point;
        Vector2 end = segment.PointB.point;
        Vector2 dir = (end - start).normalized;
        float distance = Vector2.Distance (start, end);

        Vector2 current = start;
        bool side = true;
        for(float f=RoadRenderer.RoadWidth;f<distance || side;f+=4.5f)
        {
            //switch side of the road
            if(f > distance && side)
            {
                side = false;
                f=RoadRenderer.RoadWidth;
            }

            Vector2 per = new Vector2(-dir.y, dir.x);
            if(side)
                per *=-1;

            //try to put some building into the spot
            for(int i=0;i<10;i++)
            {
                //get road level adjustment
                float level = 2.0f - (segment.Level / 3f);//0,0.33,0.66,1

                //get building dimensions
                float width = Random.Range(1.75f,2f) * level;
                float length = Random.Range(1.75f,2f) * level;
                float height = Random.Range(2.5f,10f) * level;

                //get building center
                Vector2 roadOffset = per.normalized * (RoadRenderer.RoadWidth * 1.25f + length);
                Vector2 tc = start + (dir * f) + roadOffset;

                if(f - width < 0 || f + width > distance)
                    continue;

                Vector3 center = new Vector3(tc.x,0,tc.y);

                //get building size
                Vector3 size = new Vector3(length,width,height);

                //set building
                GameObject buildingObj = GameObject.Instantiate(this.BuildingStatic);
                buildingObj.transform.parent = this.Instances.transform;
                buildingObj.transform.name = "building_" + this.BuildingsList.Count.ToString("D5");

                Building building = new Building(center,size,this.GetRotation(dir) - (side ? 180 : 0));
                building.AddMyGameObject(buildingObj);
                this.AddBuildingMesh(building);
                building.AddCollider();

                if(this.CheckValidPlacement(building))
                {
                    this.BuildingsList.Add(building);
                    break;
                }
                else
                    GameObject.DestroyImmediate(buildingObj);
            }
        }
    }
开发者ID:cybercritic,项目名称:City-Generator,代码行数:69,代码来源:Buildings.cs


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