-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGameManager.cs
More file actions
40 lines (34 loc) · 1.15 KB
/
Copy pathGameManager.cs
File metadata and controls
40 lines (34 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using UnityEngine;
using System.Net.Http;
using System.Threading.Tasks;
using UnityEngine.SceneManagement;
using System.Collections;
using System.Diagnostics;
public class GameManager : MonoBehaviour
{
public string url = "http://localhost:5000/stop_timer"; // Python服务器的URL
public bool sendPost = true; // 是否发送POST请求
private static readonly HttpClient client = new HttpClient();
private void Awake() {
DontDestroyOnLoad(gameObject);
}
void Start()
{
//告诉python启动完成了
if(sendPost)client.PostAsync(url, null).Wait();
//加载main场景
// SceneManager.LoadScene("Main");
// StartCoroutine(LoadSceneCo("Main"));
}
public void StartLoad(){
StartCoroutine(LoadSceneCo("Main"));
}
//协程加载场景
public IEnumerator LoadSceneCo(string sceneName)
{
var stopwatch = Stopwatch.StartNew();
var op = SceneManager.LoadSceneAsync(sceneName);
yield return op;
GameObject.Find("Text").GetComponent<UnityEngine.UI.Text>().text = "加载场景耗时:" + stopwatch.ElapsedMilliseconds + "ms";
}
}