上海虹口龙之梦项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

56 lines
1.4 KiB

using UnityEngine;
using UnityEngine.UI;
using UniRx;
using System.Collections;
public class ScreenshotPanel : UIView
{
public InputField NameInput;
public Button SetButton;
public Button CloseButton;
public override void Awake()
{
base.Awake();
CloseButton.OnClickAsObservable()
.Subscribe(_ => HidePanel());
SetButton.OnClickAsObservable()
.Subscribe(_ => OnGetScreenshot(NameInput.text));
}
private void OnGetScreenshot(string texName)
{
HidePanel();
StartCoroutine(GetScreenshot(texName));
}
private IEnumerator GetScreenshot(string texName)
{
yield return new WaitForEndOfFrame();
int width = Screen.width;
int height = Screen.height;
Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0, true);
HttpManager.Instance.PostScreenshot(texName, tex);
yield return new WaitForSeconds(0.5f);
MessageBox.Show("截屏成功,是否打开目录?", Color.white, OpenFolder);
Destroy(gameObject);
}
public void HidePanel()
{
CanvasGroup group = GetComponent<CanvasGroup>();
group.alpha = 0;
group.interactable = false;
group.blocksRaycasts = false;
}
private void OpenFolder()
{
Application.OpenURL(HttpManager.Instance.ScreenshotPath);
}
}