LogoZoom.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using UnityEngine.UI;
  6. public class LogoZoom : MonoBehaviour
  7. {
  8. public bool isDark=true;
  9. GameObject logo;
  10. public Sprite darkSp;
  11. ScreenOrientation orientation;
  12. int width = Screen.width;
  13. void Start()
  14. {
  15. orientation = Screen.orientation;
  16. logo= GameObject.Find("PottingLogo");
  17. if (isDark) {
  18. Image bg = GameObject.Find("PottingBg").GetComponent<Image>();
  19. logo.GetComponent<Image>().sprite = darkSp;
  20. bg.color = new Color((18 / 255f), (18 / 255f), (18/ 255f), (255 / 255f));
  21. }
  22. if (orientation == ScreenOrientation.LandscapeLeft) {
  23. width = Screen.height;
  24. }
  25. Zoom();
  26. Invoke("NextScene", 3f);
  27. }
  28. void Zoom()
  29. {
  30. if (orientation == ScreenOrientation.Portrait || orientation == ScreenOrientation.PortraitUpsideDown)
  31. {
  32. float logow = width / 3;
  33. float zoom = 1.4238f;
  34. float logoh = logow / zoom;
  35. logo.transform.GetComponent<RectTransform>().sizeDelta = new Vector2(logow, logoh);
  36. }
  37. else
  38. {
  39. float logoh = width / 5;
  40. float zoom = 1.4238f;
  41. float logow = logoh * zoom;
  42. logo.transform.GetComponent<RectTransform>().sizeDelta = new Vector2(logow, logoh);
  43. }
  44. }
  45. /// <summary>
  46. /// 加载游戏场景
  47. /// </summary>
  48. void NextScene() {
  49. SceneManager.LoadScene("PottingMobScene");
  50. }
  51. // Update is called once per frame
  52. void Update()
  53. {
  54. if (orientation!= Screen.orientation) {
  55. orientation = Screen.orientation;
  56. Zoom();
  57. }
  58. }
  59. }