コード例 #1
0
ファイル: ComponentService.cs プロジェクト: thurn/tarkin
        CanvasScaler UpdateCanvasScaler(ZCanvasScaler zCanvasScaler, GameObject gameObject)
        {
            CanvasScaler canvasScaler = GetOrAddComponent <CanvasScaler>(gameObject);

            switch (zCanvasScaler.UiScaleMode)
            {
            case ZCanvasScaler.Types.ScaleMode.ConstantPixelSize:
                canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ConstantPixelSize;
                break;

            case ZCanvasScaler.Types.ScaleMode.ScaleWithScreenSize:
                canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
                break;

            case ZCanvasScaler.Types.ScaleMode.ConstantPhysicalSize:
                canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ConstantPhysicalSize;
                break;
            }

            if (zCanvasScaler.ScaleFactor.HasValue)
            {
                canvasScaler.scaleFactor = zCanvasScaler.ScaleFactor.Value;
            }

            if (zCanvasScaler.ReferencePixelsPerUnit.HasValue)
            {
                canvasScaler.referencePixelsPerUnit = zCanvasScaler.ReferencePixelsPerUnit.Value;
            }

            if (zCanvasScaler.ReferenceResolution != null)
            {
                canvasScaler.referenceResolution = ZUtils.Vector2(zCanvasScaler.ReferenceResolution);
            }

            switch (zCanvasScaler.ScreenMatchMode)
            {
            case ZCanvasScaler.Types.ScreenMatchMode.MatchWidthOrHeight:
                canvasScaler.screenMatchMode = CanvasScaler.ScreenMatchMode.MatchWidthOrHeight;
                break;

            case ZCanvasScaler.Types.ScreenMatchMode.Expand:
                canvasScaler.screenMatchMode = CanvasScaler.ScreenMatchMode.Expand;
                break;

            case ZCanvasScaler.Types.ScreenMatchMode.Shrink:
                canvasScaler.screenMatchMode = CanvasScaler.ScreenMatchMode.Shrink;
                break;
            }

            if (zCanvasScaler.MatchWidthOrHeight.HasValue)
            {
                canvasScaler.matchWidthOrHeight = zCanvasScaler.MatchWidthOrHeight.Value;
            }

            return(canvasScaler);
        }