123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using System.Collections;
- using UnityEngine;
- public class GameLoader : MonoBehaviour
- {
- public string SceneName;
- public Texture2D Back;
- public Texture2D whitePixel;
- private void Start()
- {
- ImageFit(Back);
- StartCoroutine(LoadLevel());
- }
- public void OnGUI()
- {
- GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), whitePixel, ScaleMode.StretchToFill);
- GUI.DrawTexture(new Rect(x,y,width,height), Back,ScaleMode.StretchToFill);
- }
- private IEnumerator LoadLevel()
- {
- yield return new WaitForSeconds(5);
- Application.LoadLevelAsync(SceneName);
- }
- /*private AsyncOperation operation;
- [SerializeField]
- private UISprite progress;
- internal void Start ()
- {
- operation = Application.LoadLevelAsync(SceneName);
- }
- internal void Update()
- {
- if (operation != null)
- {
- progress.fillAmount = operation.progress;
- }
- }*/
- private float width;
- private float height;
- private float x;
- private float y;
- private void ImageFit(Texture2D texture, Vector2? placeSize = null)
- {
- var size = placeSize == null ? new Vector2(Screen.width, Screen.height) : placeSize.Value;
- //texture.MakePixelPerfect();
- var widthPercent = texture.width / (size.x / 100f);
- var heightPercent = texture.height / (size.y / 100f);
- if (widthPercent > heightPercent)
- {
- width = (int)((texture.width * 100) / widthPercent) * 0.8f;
- height = (int)((texture.height * 100) / widthPercent) * 0.8f;
- x = Screen.width * 0.1f;
- y = size.y/2f - height/2f;
- }
- else
- {
- width = (int)((texture.width * 100) / heightPercent) * 0.8f;
- height = (int)((texture.height * 100) / heightPercent) * 0.8f;
- x = (size.x / 2f - width / 2f) + Screen.width * 0.1f;;
- y = 0;
- }
- }
- }
|