/// <summary> /// Updates the given RuntimeGraph's params to be consistent with the given GPUGraph. /// </summary> private void LoadParams(RuntimeGraph gR, Graph gE) { GraphParamCollection paramSet = new GraphParamCollection(gE); //Get all float params for the graph. var newFloatParams = new List <RuntimeGraph._SerializableFloatParamKVP>(); foreach (FloatParamInfo fp in paramSet.FloatParams) { RuntimeGraph._SerializableFloatParamKVP sfp = new RuntimeGraph._SerializableFloatParamKVP(); sfp.Key = fp.Name; sfp.Value = new RuntimeGraph._SerializableFloatParamInfo(); sfp.Value.IsSlider = fp.IsSlider; sfp.Value.SliderMin = fp.SliderMin; sfp.Value.SliderMax = fp.SliderMax; sfp.Value.DefaultValue = fp.DefaultValue; newFloatParams.Add(sfp); } //Remove vestigial params from the RuntimeGraph. for (int i = 0; i < gR.FloatParams.Count; ++i) { if (!newFloatParams.Any((kvp) => kvp.Key == gR.FloatParams[i].Key)) { gR.FloatParams.RemoveAt(i); gR._FloatParams.RemoveAt(i); i -= 1; } } //Update/add the params to the RuntimeGraph. for (int i = 0; i < newFloatParams.Count; ++i) { var param = new FloatParamKVP(newFloatParams[i].Key, (newFloatParams[i].Value.IsSlider ? Mathf.Lerp(newFloatParams[i].Value.SliderMin, newFloatParams[i].Value.SliderMax, newFloatParams[i].Value.DefaultValue) : newFloatParams[i].Value.DefaultValue)); int found = gR.FloatParams.IndexOf(p => p.Key == newFloatParams[i].Key); if (found == -1) { gR.FloatParams.Add(param); gR._FloatParams.Add(newFloatParams[i]); } else { param.Value = gR.FloatParams[found].Value; gR.FloatParams[found] = param; gR._FloatParams[found] = newFloatParams[i]; } } //Get all Tex2D params for the graph. var newTex2DParams = new List <RuntimeGraph._SerializableTex2DParamKVP>(); foreach (Texture2DParamInfo tp in paramSet.Tex2DParams) { RuntimeGraph._SerializableTex2DParamKVP stp = new RuntimeGraph._SerializableTex2DParamKVP(); stp.Key = tp.Name; stp.Value = new RuntimeGraph._SerializableTex2DParamInfo(); stp.Value.DefaultValue = tp.DefaultVal; newTex2DParams.Add(stp); } //Remove vestigial params from the RuntimeGraph. for (int i = 0; i < gR.Tex2DParams.Count; ++i) { if (!newTex2DParams.Any((kvp) => kvp.Key == gR.Tex2DParams[i].Key)) { gR.Tex2DParams.RemoveAt(i); gR._Tex2DParams.RemoveAt(i); i -= 1; } } //Update/add new params to the RuntimeGraph. for (int i = 0; i < newTex2DParams.Count; ++i) { var param = new Tex2DParamKVP(newTex2DParams[i].Key, newTex2DParams[i].Value.DefaultValue); int found = gR.Tex2DParams.IndexOf(p => p.Key == newTex2DParams[i].Key); if (found == -1) { gR.Tex2DParams.Add(param); gR._Tex2DParams.Add(newTex2DParams[i]); } else { param.Value = gR.Tex2DParams[found].Value; gR.Tex2DParams[found] = param; gR._Tex2DParams[found] = newTex2DParams[i]; } } }