UIBGP.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using UnityEngine.UI;
  6. public class UIBGP : MonoBehaviour
  7. {
  8. public GameObject topGame;
  9. public bool isCenter=false;
  10. Vector3 initV3;
  11. // Start is called before the first frame update
  12. void Awake()
  13. {
  14. initV3 = this.GetComponent<RectTransform>().anchoredPosition;
  15. }
  16. // Update is called once per frame
  17. void Update()
  18. {
  19. if(topGame)
  20. {
  21. initV3 = new Vector3(initV3.x,-topGame.GetComponent<RectTransform>().sizeDelta.y,initV3.z);
  22. }
  23. float bl = (float)Screen.width / 430f;
  24. float bl2 = (float)Screen.height / 932f;
  25. if(bl>bl2)
  26. {
  27. this.transform.localScale = new Vector3(bl2,bl2,bl2);
  28. }else
  29. {
  30. this.transform.localScale = new Vector3(bl, bl, bl);
  31. }
  32. this.GetComponent<RectTransform>().anchoredPosition= new Vector2(initV3.x,initV3.y* this.transform.localScale.x);
  33. if(isCenter)
  34. {
  35. this.GetComponent<RectTransform>().sizeDelta =new Vector2(430, ((float)Screen.height - (-this.GetComponent<RectTransform>().anchoredPosition.y+100*this.transform.localScale.x))/this.transform.localScale.x);
  36. }
  37. }
  38. }