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