Beispiel #1
0
            public void AddFrameCallback(Action callback, FrameTiming timing)
            {
                switch (timing)
                {
                case FrameTiming.FixedUpdate:
                    AddFrameCallback(ref _fixedUpdateActions, callback);
                    break;

                case FrameTiming.Update:
                    AddFrameCallback(ref _updateActions, callback);
                    break;

                case FrameTiming.LateUpdate:
                    AddFrameCallback(ref _lateUpdateActions, callback);
                    break;

                case FrameTiming.EndOfFrame:

                    if (_eofCoroutine == null)
                    {
                        _eofCoroutine = StartCoroutine(EofEnumerator());
                    }

                    AddFrameCallback(ref _eofUpdateActions, callback);
                    break;
                }
            }
Beispiel #2
0
        /// <summary>
        /// Register a completion callback that is triggered on a specific time during next frame.
        /// </summary>
        /// <param name="callback">A delegate to be called on the next frame.</param>
        /// <param name="timing">Time to call the <paramref name="callback"/>.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="callback"/> is <see langword="null"/>.</exception>
        public static void AddFrameCallback(Action callback, FrameTiming timing)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            _rootBehaviour.AddFrameCallback(callback, timing);
        }
Beispiel #3
0
 public static void Record(FrameTiming timing, long updateElapsedTicks)
 {
     PushSample(UpdateSamples, (double)updateElapsedTicks / (double)Time.MillisecondInTicks);
     PushSample(WaitSamples, timing.Wait.TotalMilliseconds);
     PushSample(BeginDrawSamples, timing.BeginDraw.TotalMilliseconds);
     PushSample(DrawSamples, timing.Draw.TotalMilliseconds);
     PushSample(BeforePresentSamples, timing.BeforePresent.TotalMilliseconds);
     PushSample(EndDrawSamples, timing.EndDraw.TotalMilliseconds);
     LastBatchCount     = timing.BatchCount;
     LastPrimitiveCount = timing.PrimitiveCount;
 }
Beispiel #4
0
        /// <summary>
        /// Returns an instance of an <see cref="IAsyncUpdateSource"/> for the specified <paramref name="frameTiming"/>.
        /// </summary>
        /// <seealso cref="GetUpdateSource()"/>
        public static IAsyncUpdateSource GetUpdateSource(FrameTiming frameTiming)
        {
            switch (frameTiming)
            {
            case FrameTiming.FixedUpdate:
                return(_rootBehaviour.FixedUpdateSource);

            case FrameTiming.LateUpdate:
                return(_rootBehaviour.LateUpdateSource);

            case FrameTiming.EndOfFrame:
                return(_rootBehaviour.EofUpdateSource);
            }

            return(_rootBehaviour.UpdateSource);
        }
Beispiel #5
0
    public static int constructor(IntPtr l)
    {
        int result;

        try
        {
            FrameTiming frameTiming = default(FrameTiming);
            LuaObject.pushValue(l, true);
            LuaObject.pushValue(l, frameTiming);
            result = 2;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Beispiel #6
0
            public void AddFrameCallback(Action callback, FrameTiming timing)
            {
                switch (timing)
                {
                case FrameTiming.FixedUpdate:
                    AddFrameCallback(ref _fixedUpdateActions, callback);
                    break;

                case FrameTiming.Update:
                    AddFrameCallback(ref _updateActions, callback);
                    break;

                case FrameTiming.LateUpdate:
                    AddFrameCallback(ref _lateUpdateActions, callback);
                    break;
                }
            }
Beispiel #7
0
 /// <summary>
 /// Waits until the specified <paramref name="frameTime"/>.
 /// </summary>
 /// <param name="frameTime">The frame time to await.</param>
 public static FrameAwaitable FrameUpdate(FrameTiming frameTime = FrameTiming.Update)
 {
     return(new FrameAwaitable(frameTime));
 }
Beispiel #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FrameAwaitable"/> struct.
 /// </summary>
 public FrameAwaitable(FrameTiming frameTime)
 {
     _awaiter = new FrameAwaiter(frameTime);
 }
Beispiel #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FrameAwaiter"/> struct.
 /// </summary>
 public FrameAwaiter(FrameTiming frameTiming)
 {
     _frameTiming = frameTiming;
 }
Beispiel #10
0
    void OnGUI()
    {
        int w = Screen.width, h = Screen.height;

        ypos = 0;
        Rect     rect;
        string   text;
        GUIStyle style = new GUIStyle();

        #region defaultPrints
        if (showFPS)
        {
            ypos                  += 20;
            rect                   = new Rect(0, ypos, w, h * 2 / 100);
            style.alignment        = TextAnchor.UpperLeft;
            style.fontSize         = h * 2 / 90;
            style.normal.textColor = flipflopColor ? flipflopColor_1 : flipflopColor_2;
            float msec = deltaTime * 1000.0f;
            float fps  = 1.0f / deltaTime;
            text = string.Format("{0:0.0} ms ({1:0.} fps)", msec, fps);
            GUI.Label(rect, text, style);
            flipflopColor = !flipflopColor;
        }

        if (show_ms)
        {
            ypos                  += 20;
            rect                   = new Rect(0, ypos, w, h * 2 / 100);
            style.alignment        = TextAnchor.UpperLeft;
            style.fontSize         = h * 2 / 90;
            style.normal.textColor = flipflopColor ? flipflopColor_1 : flipflopColor_2;

            FrameTiming[] timing = new FrameTiming[1];
            FrameTimingManager.CaptureFrameTimings();
            uint framesCaptured = FrameTimingManager.GetLatestTimings(1, timing);
            if (framesCaptured > 0)
            {
                text = "cpu: " + timing[0].cpuFrameTime + "ms || gpu: " + timing[0].gpuFrameTime + "ms";
            }
            else
            {
                text = "could not get frame timings";
            }

            GUI.Label(rect, text, style);
            flipflopColor = !flipflopColor;
        }

        if (showSystemLanguage)
        {
            ypos                  += 20;
            rect                   = new Rect(0, ypos, w, h * 2 / 100);
            style.alignment        = TextAnchor.UpperLeft;
            style.fontSize         = h * 2 / 90;
            style.normal.textColor = flipflopColor ? flipflopColor_1 : flipflopColor_2;
            text                   = "System language:  " + Application.systemLanguage.ToString();
            GUI.Label(rect, text, style);
            flipflopColor = !flipflopColor;
        }

        if (showGPU)
        {
            ypos                  += 20;
            rect                   = new Rect(0, ypos, w, h * 2 / 100);
            style.alignment        = TextAnchor.UpperLeft;
            style.fontSize         = h * 2 / 90;
            style.normal.textColor = flipflopColor ? flipflopColor_1 : flipflopColor_2;
            text                   = "graphics Device:  " + SystemInfo.graphicsDeviceName + "  " + SystemInfo.graphicsDeviceVendor + "  " + SystemInfo.graphicsDeviceVersion + "  " + SystemInfo.graphicsMemorySize;
            GUI.Label(rect, text, style);
            flipflopColor = !flipflopColor;
        }

        #endregion

        #region userLists
        if (showCustomMessages)
        {
            if (staticStringMessages.Count > 0)
            {
                foreach (Message message in staticStringMessages)
                {
                    ypos += 20;
                    style.normal.textColor = message.color;
                    rect            = new Rect(0, ypos, w, h * 2 / 100);
                    style.alignment = TextAnchor.UpperLeft;
                    style.fontSize  = h * 2 / 90;
                    text            = message.text;
                    GUI.Label(rect, text, style);
                }
            }

            if (staticMessages.Count > 0)
            {
                foreach (RefMessage message in staticMessages)
                {
                    ypos += 20;
                    style.normal.textColor = message.color;
                    rect            = new Rect(0, ypos, w, h * 2 / 100);
                    style.alignment = TextAnchor.UpperLeft;
                    style.fontSize  = h * 2 / 90;
                    text            = message.prefix;

                    if (message.FieldReferenced)
                    {
                        text += message.fieldInfo.GetValue(message.obj).ToString();
                    }
                    else if (message.PropertyReferenced)
                    {
                        text += message.propertyInfo.GetValue(message.obj).ToString();
                    }
                    else
                    {
                        style.normal.textColor = Color.red;
                        text += "unaccessible variable! make sure it's a public variable and that the name given is written correctly (" + message.parameterName + ")";
                    }

                    GUI.Label(rect, text, style);
                }
            }

            if (tempMessages.Count > 0)
            {
                ypos += 20;
                foreach (Message message in tempMessages)
                {
                    ypos += 20;
                    style.normal.textColor = message.color;
                    rect            = new Rect(0, ypos, w, h * 2 / 100);
                    style.alignment = TextAnchor.UpperLeft;
                    style.fontSize  = h * 2 / 90;
                    text            = message.text;
                    GUI.Label(rect, text, style);
                }
            }

            if (staticStringMessagesAtPosition.Count > 0)
            {
                foreach (System.Tuple <Message, Vector2> message in staticStringMessagesAtPosition)
                {
                    style.normal.textColor = message.Item1.color;
                    rect            = new Rect(message.Item2.x, message.Item2.y, w, h * 2 / 100);
                    style.alignment = TextAnchor.UpperLeft;
                    style.fontSize  = h * 2 / 90;
                    text            = message.Item1.text;
                    GUI.Label(rect, text, style);
                }
            }

            if (staticMessagesAtPosition.Count > 0)
            {
                foreach (System.Tuple <RefMessage, Vector2> message in staticMessagesAtPosition)
                {
                    style.normal.textColor = message.Item1.color;
                    style.alignment        = TextAnchor.UpperLeft;
                    rect           = new Rect(message.Item2.x, message.Item2.y, w, h * 2 / 100);
                    style.fontSize = h * 2 / 90;
                    text           = message.Item1.prefix;

                    if (message.Item1.FieldReferenced)
                    {
                        text += message.Item1.fieldInfo.GetValue(message.Item1.obj).ToString();
                    }
                    else if (message.Item1.PropertyReferenced)
                    {
                        text += message.Item1.propertyInfo.GetValue(message.Item1.obj).ToString();
                    }
                    else
                    {
                        style.normal.textColor = Color.red;
                        text += "unaccessible variable! make sure it's a public variable and that the name given is written correctly (" + message.Item1.parameterName + ")";
                    }
                }
            }

            if (tempMessagesAtPosition.Count > 0)
            {
                ypos += 20;
                foreach (System.Tuple <Message, Vector2> message in tempMessagesAtPosition)
                {
                    style.normal.textColor = message.Item1.color;
                    rect            = new Rect(message.Item2.x, message.Item2.y, w, h * 2 / 100);
                    style.alignment = TextAnchor.UpperLeft;
                    style.fontSize  = h * 2 / 90;
                    text            = message.Item1.text;
                    GUI.Label(rect, text, style);
                }
            }
        }
        #endregion
    }
Beispiel #11
0
        public async UniTask LoadAsync <TBoneSpan>(TBoneSpan bones, FrameTimingPointList timingPoints, FrameTiming timing,
                                                   CancellationToken cancellationToken = default) where TBoneSpan : IReadOnlySpan <Bone>
        {
            if (IsBoneLoaded)
            {
                throw new InvalidOperationException("Already loaded");
            }
            if (timingPoints is null)
            {
                throw new ArgumentNullException(nameof(timingPoints));
            }
            timing.ThrowArgExceptionIfNotSpecified(nameof(timing));

            cancellationToken.ThrowIfCancellationRequested();
            await UniTask.SwitchToThreadPool();

            cancellationToken.ThrowIfCancellationRequested();
            try {
                InitializeSkeletonData(this, bones.AsReadOnlySpan());
                await timingPoints.TimingOf(timing).Next(cancellationToken);

                if (IsBoneLoaded)
                {
                    throw new InvalidOperationException("Already loaded");
                }
                _boneTranslationData.Load(_matrices !.AsSpan().MarshalCast <Matrix4, Color4>());
            }
            catch {
                _posMatrices.Dispose();
                _posInvMatrices.Dispose();
                _tree.Dispose();
                _matrices.Dispose();
                _translations.Dispose();
                throw;
            }

            ContextAssociatedMemorySafety.Register(this, Engine.GetValidCurrentContext());
            return;
        }