From 68dc7e80eb82ec6aadc0fce0bc3054bc267d7f89 Mon Sep 17 00:00:00 2001 From: hyskai <2545507770@qq.com> Date: Fri, 18 Oct 2024 23:16:30 +0800 Subject: [PATCH] add --- meng_yao/Assets/Bgmain.cs | 38 ------------------- meng_yao/Assets/Scenes/SampleScene.unity.meta | 2 +- meng_yao/Assets/Scenes/main_scene.unity.meta | 7 ++++ meng_yao/Assets/communal.meta | 8 ++++ 4 files changed, 16 insertions(+), 39 deletions(-) delete mode 100644 meng_yao/Assets/Bgmain.cs create mode 100644 meng_yao/Assets/Scenes/main_scene.unity.meta create mode 100644 meng_yao/Assets/communal.meta diff --git a/meng_yao/Assets/Bgmain.cs b/meng_yao/Assets/Bgmain.cs deleted file mode 100644 index aa37ef25..00000000 --- a/meng_yao/Assets/Bgmain.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.UI; - -public class Bgmain : MonoBehaviour -{ - public RawImage rawImage; // 使用RawImage组件展示纹理 - public RectTransform boundaryRect; // 代表边界矩形的RectTransform - - void Start() - { - ScaleAndCropTexture(); - } - - void ScaleAndCropTexture() - { - Texture texture = rawImage.texture; - float textureWidth = texture.width; - float textureHeight = texture.height; - - float boundaryWidth = boundaryRect.rect.width; - float boundaryHeight = boundaryRect.rect.height; - - // 计算缩放比例,确保较短的一边适应边界矩形 - float scaleFactor = Mathf.Max(boundaryWidth / textureWidth, boundaryHeight / textureHeight); - - // 设置缩放后的尺寸 - float newWidth = textureWidth * scaleFactor; - float newHeight = textureHeight * scaleFactor; - - // 设置RawImage的RectTransform尺寸,使其居中并覆盖边界矩形 - rawImage.rectTransform.sizeDelta = new Vector2(newWidth, newHeight); - - // 裁剪超出的部分 - rawImage.rectTransform.anchoredPosition = Vector2.zero; // 确保居中 - } -} diff --git a/meng_yao/Assets/Scenes/SampleScene.unity.meta b/meng_yao/Assets/Scenes/SampleScene.unity.meta index 952bd1e9..f0d720c4 100644 --- a/meng_yao/Assets/Scenes/SampleScene.unity.meta +++ b/meng_yao/Assets/Scenes/SampleScene.unity.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 9fc0d4010bbf28b4594072e72b8655ab +guid: e823ef15a3569cd47b2e7db73fe85fc5 DefaultImporter: externalObjects: {} userData: diff --git a/meng_yao/Assets/Scenes/main_scene.unity.meta b/meng_yao/Assets/Scenes/main_scene.unity.meta new file mode 100644 index 00000000..5983e570 --- /dev/null +++ b/meng_yao/Assets/Scenes/main_scene.unity.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 0223a40190e85bb49b6ee6e282d9181f +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/meng_yao/Assets/communal.meta b/meng_yao/Assets/communal.meta new file mode 100644 index 00000000..49bed704 --- /dev/null +++ b/meng_yao/Assets/communal.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f15a3d4fb0133904b8ead85bcffdc587 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: