I've never used Archimatix but looking at the manual I see online, it looks like this will work. In c#, lambdas capture variables by reference, so you can have the params read the result from a lambda to get an up-to-date variable.
public class ParamUpdater: MonoBehaviour {
[SerializeField] AXModel model;
List<AXParameter> params;
List<Func<float>> paramGetters;
// Use this for initialization
void Awake () {
// Establish refernces to AXModel parameters.
Params = new List<AXParameter>();
if (model != null)
{
Params.Add(model.getParameter("Engine.Param0"));
Params.Add(model.getParameter("Engine.Param1"));
// add more params here
}
paramGetters = new List<Func<float>>();
// create default getters
for (int i = 0 ; i < Params.Count ; i++)
{
paramGetters.Add(()=>0f);
}
}
public void ConfigureParamGetter(int index, Func<float> getter)
{
paramGetters[index] = getter;
}
public void Recalculate()
{
for(int i = 0 ; i < Params.Count ; i++)
{
float curVal = paramGetters[i]();
// Maybe a different method would be better?
// online API is very lacking...
Params[i].initiatePARAMETER_Ripple_setFloatValueFromGUIChange(curVal);
}
model.autobuild();
recalculate();
}
}
And then for example in a class where a float of interest lives, call ConfigureParamGetter
with a Func
that returns the variable. As mentioned before, the capture is done by reference, so it will always be up to date when called in ParamUpdater
.
public class ImportantClass: MonoBehaviour
{
[SerializeField] ParamUpdater paramUpdater;
float importantFloat;
// Use Start to call after ParamUpdater initializes in Awake
void Start()
{
paramUpdater.ConfigureParamGetter(0, ()=>importantFloat);
}
// for example
void Update() { importantFloat = Time.time; }
// called whenever
void DoRecalculate()
{
paramUpdater.Recalculate();
}
}
Let me know if I made any syntax errors or any other problems, I can try and fix 'em.