当前位置: 首页>>代码示例>>C#>>正文


C# Canvas.GetComponent方法代码示例

本文整理汇总了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();
 }
开发者ID:Dawnwoodgames,项目名称:LotsOfTowers,代码行数:13,代码来源:UIComponent.cs

示例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);
 }
开发者ID:NetherDrk,项目名称:Eternal-Empire,代码行数:8,代码来源:RectangularVertexClipper.cs

示例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>();
 }
开发者ID:gary600,项目名称:minimize,代码行数:9,代码来源:AchievementsCustomRendererUnityUI.cs

示例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);
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:14,代码来源:RectangularVertexClipper.cs

示例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;
            }
        }
开发者ID:xiaopanCode,项目名称:SteamVR_Unity_Toolkit,代码行数:37,代码来源:VRTK_UIPointer.cs

示例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;

		}
开发者ID:Cyberbanan,项目名称:Unity3d.UI.Windows,代码行数:40,代码来源:DevicePreviewCamera.cs

示例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;
        }
开发者ID:cpvrlab,项目名称:UnityCavePlugin,代码行数:21,代码来源:CameraManager.cs

示例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));
        }
开发者ID:patferguson,项目名称:Storms-Project,代码行数:8,代码来源:MinimapRenderer.cs

示例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;
            }
        }
开发者ID:RabitBox,项目名称:FlickBattler,代码行数:18,代码来源:ProjectionParams.cs

示例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>();
 }
开发者ID:AresLee,项目名称:FarmerSimulator,代码行数:10,代码来源:DraggableHandle.cs


注:本文中的UnityEngine.Canvas.GetComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。