Example #1
0
        private void OnGUI()
        {
            GUILayout.BeginArea(new Rect(10, 10, 600, 1000));
            GUILayout.BeginHorizontal();
            GUILayout.Space(10f);
            GUILayout.BeginVertical();

            GUILayout.Label("This example will load an image into a texture from either a local file or a screenshot," +
                            " and enable user to upload the image to Drive as JPG or PNG file, as well as later retrieve the image back by its reported Drive id.",
                            GUILayout.MaxWidth(600f));

            GUILayout.Space(10f);

            if (GUILayout.Button("Load PNG from local file", GUILayout.MinHeight(20f), GUILayout.MaxWidth(200f)))
            {
                LoadPNGFromFile(Application.dataPath + _imagePath);
            }

            if (GUILayout.Button("Take Screenshot", GUILayout.MinHeight(20f), GUILayout.MaxWidth(200f)))
            {
                TakeScreenshot();
            }

            GUILayout.Space(10f);

            if (GUILayout.Button("Save Image to Cloud as PNG", GUILayout.MinHeight(20f), GUILayout.MaxWidth(200f)))
            {
                if (_text2d == null)
                {
                    Debug.Log("Cannot upload image: please load a file or take a screenshot first.");
                }
                else
                {
                    Drive.CreateImageFile(_text2d, "TextureFile", true);
                }
            }

            if (GUILayout.Button("Save Image to Cloud as JPG", GUILayout.MinHeight(20f), GUILayout.MaxWidth(200f)))
            {
                if (_text2d == null)
                {
                    Debug.Log("Cannot upload image: please load a file or take a screenshot first.");
                }
                else
                {
                    Drive.CreateImageFile(_text2d, "TextureFile", false, 90, null, null, true);
                }
            }

            GUILayout.Space(10f);

            GUILayout.Label("Google Drive file id:");
            _cloudFileID = GUILayout.TextField(_cloudFileID, GUILayout.MaxWidth(200f));
            if (GUILayout.Button("Get From Cloud", GUILayout.MinHeight(20f), GUILayout.MaxWidth(200f)))
            {
                if (string.IsNullOrEmpty(_cloudFileID))
                {
                    Debug.Log("Cannot retrieve a file: please provide an id for the image file on Google Drive.");
                }
                else
                {
                    Drive.GetImageFile(_cloudFileID);
                }
            }

            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            GUILayout.EndArea();

            if (_text2d != null)
            {
                GUI.DrawTexture(_texturePos, _text2d);
            }
        }