Example #1
0
        private void Start()
        {
            _instance = this;
            Screen.SetResolution(600, 600, false);
            var path = Path.Combine(Application.dataPath, "background.jpg");

            if (File.Exists(path)) //file doesnt exist, abort mission!
            {
                //read the contents.
                byte[] data = File.ReadAllBytes(path);
                // get the texture
                Texture2D tex = new Texture2D(1, 1);
                tex.LoadImage(data);
                //www.LoadImageIntoTexture(tex);
                mainBackground.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.one / 2f, 100);
                //todo ?? adjust the height of the image in the UI:
                //float correctHeight = ((float)tex.height / (float)tex.width )* mainBackground.rectTransform.rect.width;
                //mainBackground.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, correctHeight);
            }
            //setup reset n such:
            resDropdown.onValueChanged.AddListener(ResetGameFor);

            currentRes = gameSizes[defaultSize];
            InitGame(true);
        }
Example #2
0
        /// <summary>
        /// Reset the game using the resolution and the given index.
        /// </summary>
        /// <param name="index">index of the resolution</param>
        void ResetGameFor(int index)
        {
            //do this first.
            var  res    = gameSizes[index];
            bool change = res != currentRes;

            if (change)
            {
                //adjust the window size:
                int width = (int)Mathf.Max(minWidth, res.width * (tileSize + tileOffset));
                print(width);
                int height = res.height * (int)(tileSize + tileOffset) + marginTop + marginBottom;
                print(height);
                Screen.SetResolution(width, height, false);
            }

            //init the game last.
            currentRes = res;
            InitGame(change);
        }