Exemple #1
0
        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里调用让图像能根据数据的变化实时改变
            }
        }
Exemple #2
0
        private void Start()
        {
            nextFunction = func3D;

            // 获取点列表长度并实例化点
            length = (int)Mathf.Pow(pointNum * 2, 2);
            for (int i = 0; i < length; i++)
            {
                points.Add(Instantiate(pointPrefabs, transform));
            }
        }
Exemple #3
0
        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]);
        }
Exemple #4
0
        /*
         * 三维函数调用接口,生成三维图形
         */
        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));
        }
Exemple #5
0
 private void ChangeFunctionRandomly()
 {
     nextFunction = (Func3DEnum)UnityEngine.Random.Range(0, 8);
 }