Last active
September 29, 2016 01:45
-
-
Save dskjal/2647d3f75187ddd41da4f68a2f1f7c48 to your computer and use it in GitHub Desktop.
Unity でヒープにできるごみを減らすコルーチン
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class Coroutine : MonoBehaviour { | |
[SerializeField]float interval = 1; | |
void Start () { | |
StartCoroutine(coroutine()); | |
} | |
/* 一般的な実装 | |
IEnumerator coroutine(){ | |
while(true){ | |
// 実行するコード | |
yield return new WaitForSeconds(interval); | |
} | |
} | |
*/ | |
IEnumerator coroutine() { | |
var oldInterval = interval; | |
var wfs = new WaitForSeconds(interval); | |
while (true) { | |
// 実行するコード | |
if (oldInterval != interval) { | |
wfs = new WaitForSeconds(interval); | |
oldInterval = interval; | |
} | |
yield return wfs; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment