我需要从服务器下载图像,然后将其转换为立方体贴图,最后将此立方体贴图放入我的天空盒中。
我使用 C# 工作。
我想出了这个代码:
public string url = "image/url.jpg";
void Update() {
// When trigger, we start the process
if (Input.GetKeyDown("f")) {
// start Coroutine to handle the WWW asynchronous process
StartCoroutine("setImage");
}
}
IEnumerator setImage () {
Texture2D tex;
tex = new Texture2D(2048, 2048, TextureFormat.RGBA32, false);
WWW www = new WWW(url);
//Texture myGUITexture = Resources.Load("23") as Texture;
Debug.Log (www.bytesDownloaded);
Debug.Log (www.progress);
Debug.Log (www.texture);
yield return www;
// we put the downloaded image into the new texture
www.LoadImageIntoTexture(tex);
// …Run Code Online (Sandbox Code Playgroud) 再生产 :
// @flow
type A = { key: string, value: string};
const a:A = {
key: 'a',
value: 'a'
};
const foo = ():Promise<A> => {
return new Promise(function(resolve, reject){
setTimeout(function(){
resolve(a);
}, 1000);
});
}
const bar = async ():A => {
const res:A = ((await foo()):any);
return res;
}
bar();
Run Code Online (Sandbox Code Playgroud)
背景:
当调用一个名为'foo'的函数返回一个带有await的promise时,变量的类型仍然是Promise.
如果我们只返回变量,Flow会正确解释该值,但如果我们输入名为'bar'的函数的返回值,则会触发错误.
19: return res;
^ Cannot return `res` because property `key` is missing in `Promise` [1] but exists in `A` [2].
References:
[LIB] static/v0.75.0/flowlib/core.js:583: …Run Code Online (Sandbox Code Playgroud) 这是架构:
客户端向服务器 A 发送 POST 请求
服务器 A 处理这个并向服务器 B 发送一个 GET
服务器 B 通过 A 向客户端发送响应
我虽然最好的想法是制作一个管道来读取 GET 的响应,并写入 POST 的响应,但我遇到了很多类型的问题。
func main() {
r := mux.NewRouter()
r.HandleFunc("/test/{hash}", testHandler)
log.Fatal(http.ListenAndServe(":9095", r))
}
func handleErr(err error) {
if err != nil {
log.Fatalf("%s\n", err)
}
}
func testHandler(w http.ResponseWriter, r *http.Request){
fmt.Println("FIRST REQUEST RECEIVED")
vars := mux.Vars(r)
hash := vars["hash"]
read, write := io.Pipe()
// writing without a reader will deadlock so write in a goroutine
go func() {
write, …Run Code Online (Sandbox Code Playgroud) async-await ×1
c# ×1
es6-promise ×1
flowtype ×1
go ×1
http ×1
mux ×1
pipe ×1
skybox ×1
textures ×1