Exemplo n.º 1
0
        /// <summary>
        /// 延迟指定帧数后调用
        /// </summary>
        /// <param name="a">回调</param>
        /// <param name="delayFrame">延迟帧数</param>
        public static FrameCall DelayFrame(Action a, int delayFrame)
        {
            int       currFrame    = 0;
            FrameCall addComponent = ParasiticComponent.parasiteHost.AddComponent <FrameCall>();

            addComponent.CallAction(() =>
            {
                bool b = ++currFrame < delayFrame;
                if (!b)
                {
                    a();
                }
                return(b);
            });
            return(addComponent);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 下一帧调用
        /// </summary>
        /// <param name="a">回调</param>
        public static FrameCall DelayFrame(Action a)
        {
            FrameCall addComponent = ParasiticComponent.parasiteHost.AddComponent <FrameCall>();

            addComponent.CallAction(() =>
            {
                try
                {
                    a();
                }
                catch (Exception e)
                {
                    DebugConsole.Log(e);
                }
                return(false);
            });
            return(addComponent);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 执行frame*times次方法,并记录时间
        /// 这些执行会被分散在frame个帧数内
        /// </summary>
        /// <param name="testFunctions">被检测的方法</param>
        /// <param name="times">一帧内运行次数</param>
        /// <param name="frame">执行帧数</param>
        public static void RunAndPrintInDisperseFrame(Action[] testFunctions, int times, int frame)
        {
            double[] totalMilliseconds = new double[testFunctions.Length];
            double   currFrame         = 0;

            FrameCall.Call(() =>
            {
                for (int i = 0; i < testFunctions.Length; i++)
                {
                    totalMilliseconds[i] += Run(testFunctions[i], times);
                }

                currFrame++;
                bool b = currFrame < frame;
                if (!b)
                {
                    for (int i = 0; i < testFunctions.Length; i++)
                    {
                        DebugConsole.Log(i + ":RunningTime ", totalMilliseconds[i]);
                    }
                }
                return(b);
            });
        }