예제 #1
0
        /// <summary>
        /// Initializes the grid. This is only intended for use if <see cref="automaticInitialization"/> is set to <c>false</c>.
        /// The grid will be initialized over a number of frames, as to smooth out the initialization.
        /// </summary>
        /// <param name="maxMillisecondsUsedPerFrame">The maximum milliseconds used per frame while initializing.</param>
        /// <param name="callback">Callback that will be called once initialization is complete. The callback will receive a reference to this component for convenience.</param>
        public void Initialize(int maxMillisecondsUsedPerFrame, Action<GridComponent> callback)
        {
            if (this.grid != null)
            {
                return;
            }

            var builder = GetBuilder();

            //This is the callback used for posting the final status message
            Action msgCallback = () =>
            {
                if (callback != null)
                {
                    callback(this);
                }
            };

            //This is the callback for the initialization routine
            Action<IGrid> cb = (g) =>
            {
                this.grid = g;
                RegisterWithManagers();

                this.enabled = true;

                var msg = new GridStatusMessage
                {
                    gridBounds = g.bounds,
                    status = GridStatusMessage.StatusCode.InitializationComplete
                };

                GameServices.messageBus.PostBalanced(msg, maxMillisecondsUsedPerFrame, msgCallback);
            };

            if (this.bakedData != null)
            {
                builder.Create(this.bakedData, maxMillisecondsUsedPerFrame, cb);
            }
            else
            {
                builder.Create(maxMillisecondsUsedPerFrame, cb);
            }
        }
예제 #2
0
        /// <summary>
        /// Disables the grid and releases all memory. If <see cref="automaticInitialization"/> is <c>true</c>, the grid will be reinitialized if re-enabled, otherwise <see cref="Initialize(int, Action&lt;GridComponent&gt;)"/> must be called to re-enable and re-initialize the grid.
        /// <param name="maxMillisecondsUsedPerFrame">The maximum milliseconds used per frame while disabling</param>
        /// </summary>
        public void Disable(int maxMillisecondsUsedPerFrame)
        {
            if (this.grid == null)
            {
                return;
            }

            this.enabled = false;
            this.grid = null;

            var msg = new GridStatusMessage
            {
                gridBounds = this.bounds,
                status = GridStatusMessage.StatusCode.DisableComplete
            };

            GameServices.messageBus.PostBalanced(msg, maxMillisecondsUsedPerFrame);
        }