UGUI——Canvas

作者:追风剑情 发布于:2019-4-16 16:35 分类:Unity3d

https://docs.unity3d.com/Manual/class-Canvas.html

渲染模式(Render Mode)

Screen Space - Overlay
UI始终显示在3D对象前面。

1111.png

Screen Space - Camera
任何比UI更靠近场景摄像机的对象将显示在UI前面,不存在3D对象与UI之间穿钗显示。

2222.png

World Space
3D对象与UI可以穿钗显示。

3333.png

一个查看Canvas详情的类

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 查看Canvas详情
/// </summary>
[ExecuteInEditMode]
public class CanvasDetail : MonoBehaviour
{
    public Canvas rootCanvas;
    public string sortingLayerName;
    public AdditionalCanvasShaderChannels additionalShaderChannels;
    public int cachedSortingLayerValue;
    public int sortingLayerID;
    public float normalizedSortingGridSize;
    public int targetDisplay;
    public int sortingOrder;
    [Tooltip("是否覆盖父Canvas的sortingOrder")]
    public bool overrideSorting;
    public int renderOrder;
    [Tooltip("摄像机离画布的距离")]
    public float planeDistance;
    [Tooltip("是否覆盖父Canvas的pixelPerfect")]
    public bool overridePixelPerfect;
    public float referencePixelsPerUnit;
    public float scaleFactor;//UI元素渲染尺寸=计算出的尺寸/scaleFactor
    [Tooltip("画布在屏幕上的渲染矩形")]
    public Rect pixelRect;
    public Camera worldCamera;
    public bool isRootCanvas;
    public RenderMode renderMode;
    public bool pixelPerfect;
    public Material defaultCanvasMaterial;
    public Material defaultCanvasTextMaterial;
    public Material ETC1SupportedCanvasMaterial;

    Canvas canvas;

    private void LateUpdate()
    {
        if (!Application.isEditor)
            return;

        if (canvas == null)
            canvas = GetComponent<Canvas>();

        rootCanvas = canvas.rootCanvas;
        sortingLayerName = canvas.sortingLayerName;
        additionalShaderChannels = canvas.additionalShaderChannels;
        cachedSortingLayerValue = canvas.cachedSortingLayerValue;
        sortingLayerID = canvas.sortingLayerID;
        normalizedSortingGridSize = canvas.normalizedSortingGridSize;
        targetDisplay = canvas.targetDisplay;
        sortingOrder = canvas.sortingOrder;
        overrideSorting = canvas.overrideSorting;
        renderOrder = canvas.renderOrder;
        planeDistance = canvas.planeDistance;
        overridePixelPerfect = canvas.overridePixelPerfect;
        referencePixelsPerUnit = canvas.referencePixelsPerUnit;
        scaleFactor = canvas.scaleFactor;
        pixelRect = canvas.pixelRect;
        worldCamera = canvas.worldCamera;
        isRootCanvas = canvas.isRootCanvas;
        renderMode = canvas.renderMode;
        pixelPerfect = canvas.pixelPerfect;
        defaultCanvasMaterial = Canvas.GetDefaultCanvasMaterial();
        defaultCanvasTextMaterial = Canvas.GetDefaultCanvasTextMaterial();
        ETC1SupportedCanvasMaterial = Canvas.GetETC1SupportedCanvasMaterial();
    }
}


效果
111111.png

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号