本文整理汇总了C#中Camera.GetComponentInParent方法的典型用法代码示例。如果您正苦于以下问题:C# Camera.GetComponentInParent方法的具体用法?C# Camera.GetComponentInParent怎么用?C# Camera.GetComponentInParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Camera
的用法示例。
在下文中一共展示了Camera.GetComponentInParent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
// Use this for initialization
IEnumerator Start () {
// initialize cameras
setupCam = GameObject.Find ("Main Camera").GetComponent<Camera>();
playCam = GameObject.Find ("PlayCam").GetComponent<Camera>();
playCam.enabled = false;
playCam.GetComponent<AudioListener>().enabled = false;
// find the spawnpoint. if it exists create a player and put it there.
GameObject spawnPoint = GameObject.Find ("SpawnPoint");
if (null != spawnPoint) {
Transform spawnPointTransform = GameObject.Find ("SpawnPoint").GetComponent<Transform> ();
this.player = (GameObject)Instantiate(Resources.Load ("BubbleBoy"));
Rigidbody playerBody = player.GetComponent<Rigidbody> ();
playerBody.position = spawnPointTransform.position;
playerBody.velocity = Vector3.zero;
CamFollow follow = playCam.GetComponentInParent<CamFollow> ();
follow.target = this.player.transform;
follow.body = playerBody;
} else {
Debug.LogWarning ("Failed to get spawnpoint");
}
GameManager.Active = false;
AsyncOperation async = Application.LoadLevelAdditiveAsync("UI_Scene");
yield return async;
Debug.Log("Loading complete");
}
示例2: AsymmetricBalance
public static float AsymmetricBalance(GameObject subject, List<GameObject> visibleObjects, Camera cam) {
float heuristicWeight = 0f;
float percentageLeft = 0f;
float percentageRight = 0f;
List<Vector3> camSpaceCoords = new List<Vector3>();
List<Vector3> leftMostCoords = new List<Vector3>();
List<Vector3> rightMostCoords = new List<Vector3>();
List<GameObject> leftMostGameObjs = new List<GameObject>();
List<GameObject> rightMostGameObjs = new List<GameObject>();
for(int i = 0; i < visibleObjects.Count; i++) {
Vector3 viewportCoord = visibleObjects[i].transform.TransformPoint(visibleObjects [i].transform.position);
viewportCoord = cam.WorldToViewportPoint (viewportCoord);
camSpaceCoords.Add (viewportCoord);
}
for(int j = 0; j < camSpaceCoords.Count; j++) {
if (camSpaceCoords[j].x > 1.0f &&
camSpaceCoords[j].y >= 0.0f &&
camSpaceCoords[j].y <= 1.0f) {
rightMostCoords.Add(camSpaceCoords[j]);
} else {
leftMostCoords.Add(camSpaceCoords[j]);
}
}
if (rightMostCoords.Count > 0) {
for (int ii = 0; ii < rightMostCoords.Count; ii++) {
rightMostGameObjs.Add (visibleObjects [ii]);
}
}
for (int jj = 0; jj < visibleObjects.Count; jj++) {
if (rightMostGameObjs.Contains(visibleObjects[jj])) {
continue;
} else {
leftMostGameObjs.Add(visibleObjects[jj]);
}
}
if (leftMostGameObjs.Count > 0 && rightMostGameObjs.Count > 0) {
for (int kk = 0; kk < leftMostGameObjs.Count; kk++) {
if (percentageLeft + cam.GetComponentInParent<PhotoEval> ().CalcScreenPercentage (leftMostGameObjs [kk]) <= 100f) {
percentageLeft += cam.GetComponentInParent<PhotoEval> ().CalcScreenPercentage (leftMostGameObjs [kk]);
} else {
break;
}
}
for (int kk2 = 0; kk2 < rightMostGameObjs.Count; kk2++) {
if (percentageRight + cam.GetComponentInParent<PhotoEval> ().CalcScreenPercentage (rightMostGameObjs [kk2]) <= 100f) {
percentageRight += cam.GetComponentInParent<PhotoEval> ().CalcScreenPercentage (rightMostGameObjs [kk2]);
} else {
break;
}
}
float score = 10f;
if (percentageLeft == percentageRight) {
return 100f;
} else if (Mathf.Approximately (percentageLeft, percentageRight)) {
heuristicWeight = 0.8f;
score = score * heuristicWeight;
//Debug.Log("percents: " + percentageLeft + ", " + percentageRight);
score = Mathf.Max(Mathf.Min(score, 100),0);
Debug.Log ("Asym score: " + score);
return score;
} else {
float difference = Mathf.Abs ((percentageLeft - percentageRight));
score = 100;
//difference = 100f * difference;
score -= difference;
// Debug.Log("percents: " + percentageLeft + ", " + percentageRight);
Debug.Log ("Balance B(Asym) score: " + score);
score = Mathf.Max(Mathf.Min(score, 100),0);
return score;
}
} else if (leftMostGameObjs.Count > 0 && rightMostGameObjs.Count == 0) {
for (int iii = 0; iii < leftMostGameObjs.Count; iii++) {
if (percentageLeft + cam.GetComponentInParent<PhotoEval>().CalcScreenPercentage (leftMostGameObjs [iii]) <= 100f) {
percentageLeft += cam.GetComponentInParent<PhotoEval>().CalcScreenPercentage (leftMostGameObjs [iii]);
} else {
break;
}
}
//Debug.Log ("percentage: " + percentageLeft);
float score = 100f;
heuristicWeight = percentageLeft * 0.1f;
float difference = 100f * heuristicWeight;
score -= difference;
if (score < 0f) {
return 0f;
}
Debug.Log ("Asym score: " + score);
//.........这里部分代码省略.........