﻿using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;

[UdonBehaviourSyncMode(BehaviourSyncMode.None)]
public class ReflectionProbeUpdater : UdonSharpBehaviour {
	public ReflectionProbe[] rtProbes;
	public FrameCounter fc;

	private int updateProgress = 0;
	private float a = 3;

	void Start() {
		_UpdateProbes();
	}

	void Update() {
		if(updateProgress > 0) {
			for(int i = 0; i < rtProbes.Length; i++) {
				if(rtProbes[i] == null) continue;
				if(updateProgress == 2 && (i & 1) == 0) continue;
				if(updateProgress == 1 && (i & 1) == 1) continue;
				rtProbes[i].RenderProbe();
			}
			updateProgress--;
		}
		if(a > 0) {
			a -= Time.deltaTime;
			if(a <= 0) {
				_UpdateProbes();
			}
		}
	}

	public void _UpdateProbes() {
		updateProgress = 2;
	}
}
