Git Product home page Git Product logo

Comments (5)

sansuke05 avatar sansuke05 commented on July 3, 2024

そもそもコルーチンがエディタ拡張で使えなさそう

from quiche-pantie-patch-unity-editor.

sansuke05 avatar sansuke05 commented on July 3, 2024

この辺使えるのでは?
https://www.shibuya24.info/entry/2017/04/18/000000
https://github.com/baobao/EditorImgLoader

from quiche-pantie-patch-unity-editor.

sansuke05 avatar sansuke05 commented on July 3, 2024

そもそもOnUpdateでエディタをフレーム更新する処理が必要だったっぽい

private void OnEnable (){
    EditorApplication.update += Update;
}

...

private static void Update(){
    if(_iEnumerator != null){
        //コルーチンを実行
        _iEnumerator.MoveNext();
    }
}

from quiche-pantie-patch-unity-editor.

sansuke05 avatar sansuke05 commented on July 3, 2024

ここを参考にエディタのフレーム更新処理を追加するも問題直らず😭

In develop branch

Assets/AliceLaboratory/Editor/PantiePatchEditorWindow.cs

private void OnEnable() {
        EditorApplication.update += Update;
    }
    
    /// <summary>
    /// GUI setting
    /// </summary>
    private void OnGUI() {
        using(new GUILayout.VerticalScope()) {
            if(GUILayout.Button("パンツ一括ダウンロード")) {
                Download();
            }
        }
    }

    private void Update() {
        if (_iEnumerator != null) {
            while (_iEnumerator.MoveNext()) { Debug.Log("Running coRoutine..."); }
        }
    }

    private void Download() {
        Debug.Log("Start coRoutine");
        var com = new Communication();
        // コルーチンの作成
        _iEnumerator = com.GetTexture(FinishDownload);
    }

    private void FinishDownload() {
        _iEnumerator = null;
    }

Assets/AliceLaboratory/Editor/Communication.cs

public class Communication {
	private const string URL = "http://pantie-patch.herokuapp.com/api/convert/anna/0101.png?add_sign=true";

	FileCreator creator;

	public IEnumerator GetTexture(Action callback) {
		UnityWebRequest www = UnityWebRequestTexture.GetTexture(URL);
		www.timeout = 5;
		yield return www.SendWebRequest();

		// リクエストが完了するまで待機
		while(!www.isDone) {
			yield return 0;
		}

		if(www.isNetworkError || www.isHttpError) {
			Debug.Log(www.error);
		} else {
			// テクスチャデータを保存
			Texture tex = ((DownloadHandlerTexture)www.downloadHandler).texture;
			creator = new FileCreator();
			creator.Create(tex);
		}

		callback();
	}
}

from quiche-pantie-patch-unity-editor.

sansuke05 avatar sansuke05 commented on July 3, 2024

ここで while ループ使ってたのが問題だったっぽい。
ループさせないようにしたらいけた。

そもそもUpdateで毎フレーム更新してるのにループさせた結果、フレームが更新されなくなってフリーズしたのが原因

// before
    private void Update() {
        if (_iEnumerator != null) {
            while (_iEnumerator.MoveNext()) { Debug.Log("Running coRoutine..."); }
        }
    }

// after
    private void Update() {
        if (_iEnumerator != null) {
            _iEnumerator.MoveNext();
        }
    }

from quiche-pantie-patch-unity-editor.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.