private void Update() { timer += Time.deltaTime; if (!isTransitioning && timer >= changeDuration) { isTransitioning = true; timer = 0f; ChangeFunctionRandomly(); } if (isTransitioning) { DrawGraphTransition(); if (timer >= transitionDuration) { timer = 0f; func3D = nextFunction; isTransitioning = false; } } else { DrawGraph(); // 画图,在Update里调用让图像能根据数据的变化实时改变 } }
private void Start() { nextFunction = func3D; // 获取点列表长度并实例化点 length = (int)Mathf.Pow(pointNum * 2, 2); for (int i = 0; i < length; i++) { points.Add(Instantiate(pointPrefabs, transform)); } }
public GraphFunction GetFunction(Func3DEnum func) { if (!funcDic.ContainsKey(func)) { try { // 动态生成枚举对应的函数委托,并添加到字典中 GraphFunction function = (GraphFunction)Delegate.CreateDelegate(typeof(GraphFunction), this, func.ToString()); funcDic.Add(func, function); } catch (ArgumentException) { Debug.Log("无法加载函数:" + func); } } return(funcDic[func]); }
/* * 三维函数调用接口,生成三维图形 */ public Vector3 Func3D(float u, float v, Func3DEnum func) { // 用委托的方法实现根据枚举执行对应函数,函数可以是静态的,还可以是私有的 if (!funcDic.ContainsKey(func)) { try { // 动态生成枚举对应的函数委托,并添加到字典中 GraphFunction function = (GraphFunction)Delegate.CreateDelegate(typeof(GraphFunction), this, func.ToString()); funcDic.Add(func, function); } catch (ArgumentException) { Debug.Log("无法加载函数:" + func); } } return(funcDic[func](u, v)); }
private void ChangeFunctionRandomly() { nextFunction = (Func3DEnum)UnityEngine.Random.Range(0, 8); }