本文整理汇总了C#中UnityEngine.Transform.GetComponentInParent方法的典型用法代码示例。如果您正苦于以下问题:C# Transform.GetComponentInParent方法的具体用法?C# Transform.GetComponentInParent怎么用?C# Transform.GetComponentInParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Transform
的用法示例。
在下文中一共展示了Transform.GetComponentInParent方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDoors
// Look for doors on object, then on direct parent
private DaggerfallStaticDoors GetDoors(Transform transform, out Transform owner)
{
owner = null;
DaggerfallStaticDoors doors = transform.GetComponent<DaggerfallStaticDoors>();
if (!doors)
{
doors = transform.GetComponentInParent<DaggerfallStaticDoors>();
if (doors)
owner = doors.transform;
}
else
{
owner = doors.transform;
}
return doors;
}
示例2: MakeRipple
public static GameObject MakeRipple(Vector3 position, Transform parent, int size, float animSpeed, float startAlpha, float endAlpha, Color color, Vector3 endPosition)
{
currentRipple = GameObject.Instantiate (ripplePrefab) as GameObject;
Canvas parentCanvas = parent.GetComponentInParent<Canvas> ();
if (parentCanvas.renderMode == RenderMode.ScreenSpaceOverlay)
currentRipple.GetComponent<RectTransform>().position = position;
else
currentRipple.transform.localPosition = position;
currentRipple.transform.SetParent (parent);
currentRipple.GetComponent<RectTransform> ().localRotation = new Quaternion (0f, 0f, 0f, 0f);
currentRipple.GetComponent<RippleAnim> ().MakeRipple (size, animSpeed, startAlpha, endAlpha, color, endPosition);
return currentRipple;
}
示例3: FindTeleportRoot
/**
* Finds the best transform parent for the given object to use when teleporting.
*/
protected Transform FindTeleportRoot(Transform obj)
{
/*
* Find the rigidbody/character controller we are part of.
* Failing that, find the root collider.
* Failing that, choose {obj}.
*
*/
Transform movementRoot = obj;
var logicalRoot = (Component)obj.GetComponentInParent<Rigidbody>() ?? obj.GetComponentInParent<CharacterController>();
if (logicalRoot) movementRoot = logicalRoot.transform;
else {
Transform current = obj.parent;
while (current) {
Component component = current.GetComponent<Rigidbody>();
if (!component) component = current.GetComponent<Collider>();
if (component) movementRoot = component.transform;
current = current.parent;
}
}
return movementRoot;
}
示例4: GetPanel
/// <summary>
/// Get closest parent panel for transform. if not found - new panel will be created at root GameObject.
/// </summary>
/// <returns>The panel.</returns>
/// <param name="obj">Widget.</param>
public static GuiPanel GetPanel(Transform obj)
{
if (obj == null) {
return null;
}
var panel = obj.GetComponentInParent<GuiPanel> ();
if (panel == null) {
panel = obj.transform.root.gameObject.AddComponent<GuiPanel> ();
}
return panel;
}
示例5: FindCanvas
/// <summary>
/// Finds the canvas.
/// </summary>
/// <returns>The canvas.</returns>
/// <param name="currentObject">Current object.</param>
static public Transform FindCanvas(Transform currentObject)
{
var canvas = currentObject.GetComponentInParent<Canvas>();
if (canvas==null)
{
return null;
}
return canvas.transform;
}
示例6: areGizmosDisabled
protected static bool areGizmosDisabled(Transform transform) {
bool isDisabled = false;
do {
var toggle = transform.GetComponentInParent<RuntimeGizmoToggle>();
if (toggle == null) {
break;
}
if (!toggle.enabled) {
isDisabled = true;
break;
}
transform = transform.parent;
} while (transform != null);
return isDisabled;
}
示例7: Start
// Use this for initialization
void Start()
{
// Get relative variables for script use
_player = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Transform>();
_playerCam = _player.GetComponent<Camera>();
_defaultRot = Moveable.rotation.eulerAngles;
_playerBase = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
_normalisedDefaultRot = new Vector3(0, _defaultRot.y, 0);
_cam = GetComponent<Camera>();
_cam.fieldOfView = _player.GetComponent<Camera>().fieldOfView;
// Get the positions of the area bounds
_bounds = new Vector3[Bounds.Length];
for (int i = 0; i < Bounds.Length; i++) {
_bounds[i] = Bounds[i].position;
}
// If there are requests for additional render depths, create the requirements
_additionalDepthRenderers = new GameObject[Helper.renderDepth];
for (int i = 0; i < Helper.renderDepth; i++) {
_additionalDepthRenderers[i] = Instantiate(Moveable.gameObject);
_additionalDepthRenderers[i].GetComponentInChildren<CameraRenderPosition>().enabled = false;
_additionalDepthRenderers[i].GetComponentInChildren<Camera>().depth = -(i + 2);
_additionalDepthRenderers[i].transform.parent = Moveable.parent;
}
// Get rotation Quaternions between the two points
_relativePlayerRot = Quaternion.FromToRotation(RenderPosition.forward, -PointOfView.forward);
_relativePortalRot = Quaternion.FromToRotation(RenderPosition.forward, PointOfView.forward);
// Get external script references
_linkedScript = PointOfView.GetComponentInChildren<CameraRenderPosition>();
_playerControl = _player.GetComponentInParent<OVRPlayerController>();
}