Untitled

 avatar
unknown
csharp
4 years ago
2.1 kB
9
Indexable
using System;
using System.Collections.Generic;
using UnityEngine;

namespace FlowReactor {  
	 
	[AddComponentMenu("FlowReactor/FlowReactorDeferredComponent")]
	public class FlowReactorDeferredComponent : FlowReactorComponent {

        private bool didStart = false;

        public override void Awake() {

            if (this.graph == null) { return; }
            _SetupGraph();

        }

        public override void Start() {
            
            if (this.graph != null) {
                _StartGraph();
            }

            this.didStart = true;

        }

        public void StartGraph(Graph graph) {

            this.graph = graph;
            _SetupGraph();

            if (this.didStart) {
                _StartGraph();
            }

        }

        private void _SetupGraph() {

			isSerializing = false;
			
			executingCoroutines = new Dictionary<int, CoroutineNodes>();
			
			// Make sure exposed variable dictionary is up to date
			CollectAndUpdateAllExposedVariables();
			
			if (runUniqueInstance)
			{
				originalGraph = graph;
				
				var _uniqueGraph = graph.Copy(null, null, null);	
			
				graph = _uniqueGraph;
			}
			
			// Register this component to graph
			graph.flowReactorComponents.Add(this.GetInstanceID(), this);
		
			if (graph.flowReactorComponents.Keys.Count > 1)
			{
				Debug.LogWarning("FlowReactor: Multiple FlowReactor components are running the same graph. Please set it to unique instance to prevent errors. This graph will not run!", this.gameObject);
			}
			else
			{
				if (graph != null)
				{
					graph.CallOnInitialize(this);
				}
			}

		}

        private void _StartGraph() {

			currentFrameCount = Time.frameCount;
			
			if (graph != null && graph.isActive)
			{
				for (int n = 0; n < graph.nodes.Count; n ++)
				{
					graph.nodes[n].OnGraphStart(this);
				}
			}
			
			if (useGlobalUpdateLoop)
			{
				FlowReactorGlobalUpdate.Instance.Register(this);
			}

        }

    }

}
Editor is loading...