using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; [ExecuteInEditMode] public class ButtomUICheck : MonoBehaviour { // Update is called once per frame void Update() { RawImage raw = this.transform.parent.GetComponent(); RawImage raw2 = this.transform.GetComponent(); this.GetComponent().sizeDelta = new Vector2(raw2.texture.width, raw2.texture.height); float bl2 = 0; if (Screen.width<= Screen.height) { if ((raw.texture.width * this.transform.parent.localScale.x)> Screen.width) { // Debug.Log("44444"); bl2 = (float)Screen.width/((float)(raw2.texture.width) * this.transform.parent.localScale.x) ; } else { // Debug.Log("33333"); bl2 = (float)raw.texture.width / ((float)(raw2.texture.width * this.transform.parent.localScale.x)); } } else { if ((raw.texture.width * this.transform.parent.localScale.x) > Screen.width) { // Debug.Log("22222"); bl2 = (float)Screen.width / ((float)(raw2.texture.width) * this.transform.parent.localScale.x); } else { // Debug.Log("11111"); bl2 = (float)raw.texture.width / ((float)(raw2.texture.width)); } } float bz = Screen.height / ((raw2.texture.height * bl2 * this.transform.parent.localScale.x)); if(bz<3) { float js = 3 * ((raw2.texture.height * this.transform.parent.localScale.x)); bl2 = Screen.height/ js; } this.transform.localScale = new Vector3(bl2, bl2, bl2); } }