summaryrefslogtreecommitdiff
path: root/Valheim_v0.141.2_r202102/Valheim/assembly_valheim/SlowUpdater.cs
blob: b97b1ee0acb5c7af642d6b9aa4d4286c0729ac68 (plain)
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
41
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SlowUpdater : MonoBehaviour
{
	private const int m_updatesPerFrame = 100;

	private void Awake()
	{
		StartCoroutine("UpdateLoop");
	}

	private IEnumerator UpdateLoop()
	{
		while (true)
		{
			List<SlowUpdate> instances = SlowUpdate.GetAllInstaces();
			int index = 0;
			while (index < instances.Count)
			{
				for (int i = 0; i < 100; i++)
				{
					if (instances.Count == 0)
					{
						break;
					}
					if (index >= instances.Count)
					{
						break;
					}
					instances[index].SUpdate();
					int num = index + 1;
					index = num;
				}
				yield return null;
			}
			yield return new WaitForSeconds(0.1f);
		}
	}
}