本文整理汇总了C#中UnityEngine.Canvas.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.GetComponent方法的具体用法?C# Canvas.GetComponent怎么用?C# Canvas.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Canvas
的用法示例。
在下文中一共展示了Canvas.GetComponent方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Awake
public void Awake()
{
// Get component references and fix values
this.canvas = GetComponentInParent<Canvas>();
this.height = responsive ? Mathf.Max(0, Mathf.Min(height, 100)) : Mathf.Max(0, height);
this.rectTransform = GetComponent<RectTransform>();
this.width = responsive ? Mathf.Max(0, Mathf.Min(width, 100)) : Mathf.Max(0, width);
// Get reference height and width
this.originHeight = (canvas.renderMode == RenderMode.ScreenSpaceOverlay) ? Screen.height : canvas.GetComponent<RectTransform> ().sizeDelta.y;
this.originWidth = (canvas.renderMode == RenderMode.ScreenSpaceOverlay) ? Screen.width : canvas.GetComponent<RectTransform> ().sizeDelta.x;
// Apply settings
Invalidate();
}
示例2: GetCanvasRect
public Rect GetCanvasRect(RectTransform t, Canvas c)
{
t.GetWorldCorners(this.m_WorldCorners);
Transform component = c.GetComponent<Transform>();
for (int index = 0; index < 4; ++index)
this.m_CanvasCorners[index] = component.InverseTransformPoint(this.m_WorldCorners[index]);
return new Rect(this.m_CanvasCorners[0].x, this.m_CanvasCorners[0].y, this.m_CanvasCorners[2].x - this.m_CanvasCorners[0].x, this.m_CanvasCorners[2].y - this.m_CanvasCorners[0].y);
}
示例3: Start
public void Start() {
// we need the root canvas
Transform t = transform;
while (canvas == null && t != null || !canvas.isRootCanvas) {
canvas = t.GetComponent<Canvas>();
t = t.parent;
}
canvasRT = canvas.GetComponent<RectTransform>();
}
示例4: GetCanvasRect
public Rect GetCanvasRect(RectTransform t, Canvas c)
{
if (c == null)
{
return new Rect();
}
t.GetWorldCorners(this.m_WorldCorners);
Transform component = c.GetComponent<Transform>();
for (int i = 0; i < 4; i++)
{
this.m_CanvasCorners[i] = component.InverseTransformPoint(this.m_WorldCorners[i]);
}
return new Rect(this.m_CanvasCorners[0].x, this.m_CanvasCorners[0].y, this.m_CanvasCorners[2].x - this.m_CanvasCorners[0].x, this.m_CanvasCorners[2].y - this.m_CanvasCorners[0].y);
}
示例5: SetWorldCanvas
public static void SetWorldCanvas(Canvas canvas)
{
if (canvas.renderMode != RenderMode.WorldSpace)
{
return;
}
//copy public params then disable existing graphic raycaster
var defaultRaycaster = canvas.gameObject.GetComponent<GraphicRaycaster>();
var customRaycaster = canvas.gameObject.GetComponent<VRTK_UIGraphicRaycaster>();
//if it doesn't already exist, add the custom raycaster
if (!customRaycaster)
{
customRaycaster = canvas.gameObject.AddComponent<VRTK_UIGraphicRaycaster>();
}
if (defaultRaycaster && defaultRaycaster.enabled)
{
customRaycaster.ignoreReversedGraphics = defaultRaycaster.ignoreReversedGraphics;
customRaycaster.blockingObjects = defaultRaycaster.blockingObjects;
defaultRaycaster.enabled = false;
}
//add a box collider and background image to ensure the rays always hit
var canvasSize = canvas.GetComponent<RectTransform>().sizeDelta;
if (!canvas.gameObject.GetComponent<BoxCollider>())
{
var canvasBoxCollider = canvas.gameObject.AddComponent<BoxCollider>();
canvasBoxCollider.size = new Vector3(canvasSize.x, canvasSize.y, 10f);
canvasBoxCollider.center = new Vector3(0f, 0f, 5f);
}
if (!canvas.gameObject.GetComponent<Image>())
{
canvas.gameObject.AddComponent<Image>().color = Color.clear;
}
}
示例6: ResetRender
public IEnumerator ResetRender(int currentIteration, Camera camera, Canvas canvas) {
var canvasScaler = canvas.GetComponent<CanvasScaler>();
if (canvasScaler != null) {
canvasScaler.SendMessage("Update");
}
var current = Selection.instanceIDs;
Selection.activeGameObject = canvas.gameObject;
Canvas.ForceUpdateCanvases();
var timeout = this.timeout;
var time = UnityEditor.EditorApplication.timeSinceStartup;
while (UnityEditor.EditorApplication.timeSinceStartup < time + timeout) {
yield return false;
}
Canvas.ForceUpdateCanvases();
this.StartCoroutine(this.Render(currentIteration, camera, null));
if (currentIteration == this.currentIteration) {
canvas.renderMode = RenderMode.ScreenSpaceCamera;
} else {
Debug.LogWarning("Out of sync: " + currentIteration + "/" + this.currentIteration);
}
Selection.instanceIDs = current;
}
示例7: Start
void Start()
{
// Disable UI Layer for Maincamera, leave others as-is
int layerUI = LayerMask.NameToLayer("UI");
Camera.main.cullingMask = ~(1 << layerUI);
_canvasMouseCursorDuplicate = GameObject.Find("CanvasMouseCursorDuplicate").GetComponent<Canvas>();
_canvasMouseCursorDuplicateRectTransform = _canvasMouseCursorDuplicate.GetComponent<RectTransform>();
FetchCameras();
CreateSettings();
AdjustCameras();
AdjustSecondaryCameras();
PlaceUIElements();
// After configuring alle cameras, don't render anything with obsolete Main-Camera in order to gain better performance
Camera.main.cullingMask = 0;
Camera.main.clearFlags = CameraClearFlags.Color;
Camera.main.farClipPlane = 1.01f;
Camera.main.nearClipPlane = 1f;
}
示例8: WorldToCanvas
Vector2 WorldToCanvas(Canvas a_canvas, Vector3 a_worldPosition, Camera a_camera)
{
Vector3 viewportPos = a_camera.WorldToViewportPoint(a_worldPosition);
RectTransform canvasRect = a_canvas.GetComponent<RectTransform>();
return new Vector2((viewportPos.x * canvasRect.sizeDelta.x) - (canvasRect.sizeDelta.x * 0.5f),
(viewportPos.y * canvasRect.sizeDelta.y) - (canvasRect.sizeDelta.y * 0.5f));
}
示例9: CanvasProjectionParams
/// <summary>
/// Initializes a new instance of the <see cref="CanvasProjectionParams"/> class.
/// </summary>
/// <param name="canvas"> The canvas. </param>
public CanvasProjectionParams(Canvas canvas)
{
this.canvas = canvas;
mode = canvas.renderMode;
if (mode == RenderMode.ScreenSpaceOverlay)
{
rect = canvas.GetComponent<RectTransform>();
}
else
{
camera = canvas.worldCamera ?? Camera.main;
}
}
示例10: Drag
/// <summary>
/// Set the specified draggable object.
/// </summary>
/// <param name="newDrag">New drag.</param>
public void Drag(RectTransform newDrag)
{
drag = newDrag;
canvas = Utilites.FindCanvas(transform).GetComponent<Canvas>();
canvasRect = canvas.GetComponent<RectTransform>();
}