本文整理汇总了C#中Connector.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Connector.GetComponent方法的具体用法?C# Connector.GetComponent怎么用?C# Connector.GetComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connector
的用法示例。
在下文中一共展示了Connector.GetComponent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
// Update is called once per frame
void Update()
{
#region find real districts
//if (!split)
if (split > 0) { --split; } else if (split == 0)
{
districts.Sort(delegate (DistrictCollider2 a, DistrictCollider2 b) {
return a.NumUnits.CompareTo(b.NumUnits);
});
for (int i = 0; i < districts.Count; ++i)
{
districts[i].transform.position += Vector3.down * (5.0f + 1.5f * i);
}
split = -1;
//check for districts underneath units
List<string> saveDistricts = new List<string>();
foreach (Unit u in units)
{
RaycastHit unitHit;
Transform unitObjectHit = null;
Ray unitRay = new Ray(u.transform.position + 2.0f*Vector3.down, Vector3.down);//Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(unitRay, out unitHit) && unitHit.transform.gameObject.GetComponent<DistrictCollider2>() != null)
{
unitObjectHit = unitHit.transform;
//Debug.Log("hit " + unitObjectHit.name);
//unitHit.transform.position = new Vector3(unitHit.transform.position.x, 0.0f, unitHit.transform.position.z);
}
else {
unitObjectHit = u.transform;
}
if (unitObjectHit != u.transform)
{
if (!saveDistricts.Contains(unitObjectHit.name))
{
saveDistricts.Add(unitObjectHit.name);
}
}
}
//clear districts not to save
for (int i = 0; i < districts.Count; ++i)
{
if (!saveDistricts.Contains(districts[i].name))
//if (districts[i].transform.position.y < -1.0f)
{
//Debug.Log("removed " + districts[i].name);
Destroy(districts[i].gameObject);
districts.RemoveAt(i--);
}
}
//move meshes back into xz plane
for (int i = 0; i < districts.Count; ++i)
{
districts[i].transform.position = new Vector3(districts[i].transform.position.x, 0.0f, districts[i].transform.position.z);
districts[i].GetComponent<Renderer>().enabled = true;
if (districts[i].NumUnits != units.Count / goalDistricts)
{
districts[i].GetComponent<Renderer>().material.color *= 0.25f;
}
}
//Debug.Log("districts to save: " + saveDistricts.Count + "\tDistricts remaining: "+districts.Count);
}
#endregion
for (int i = 0; i < partyDistricts.Length; i++)
{
partyDistricts[i] = 0;
}
#region mouse raycast
RaycastHit hit;
Transform objectHit = null;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
objectHit = hit.transform;
}
else {
objectHit = this.transform;
}
hit.point = new Vector3(hit.point.x, 0.0f, hit.point.z);
#endregion
#region left click
if (Input.GetMouseButtonDown(0))
{ //left click down
//Debug.Log("click");
if ((startNode = objectHit.GetComponent<Node>()) != null)
{
tempConnector = (Connector)Instantiate(connectorPrefab);
tempConnector.transform.localScale = Vector3.zero;
tempConnector.transform.SetParent(this.transform);
tempConnector.name = "dragged connector";
tempConnector.GetComponent<Renderer>().material.color = Color.green;
}
}
else if (Input.GetMouseButton(0))
{ // left click drag
bool validConnector = true;
if (startNode != null)
{
//.........这里部分代码省略.........