示例#1
0
        /// <summary>
        /// Called by Unity. Blockingly updates <see langword="this"/> on first frame enabled; otherwise tries async update.
        /// </summary>
        private void OnRenderObject()
        {
            // Return unless revived.
            if (!IsRevived)
            {
                return;
            }


            // Return if already ticked this frame.
            if (LastTick == Time.frameCount && Application.isPlaying)
            {
                return;
            }


            LastTick = Time.frameCount;


            // Try to sync parameters and parts (without caring whether task is executing or not).
            TaskableModel.TryWriteParametersAndParts(Parameters, Parts);


            // Return if task is executing.
            if (TaskableModel.IsExecuting)
            {
                return;
            }


            // Force blocking update on first frame enabled.
            if (WasJustEnabled)
            {
                // Force sync update.
                TaskableModel.UpdateNow();


                // Unset condition.
                WasJustEnabled = false;


                // Fetch results by calling own 'Update()'.
                Update();


                return;
            }


            // Enqueue update task.
            TaskableModel.Update();
        }