예제 #1
0
        /// <summary>
        /// Adds multiple buildables to the base. This method does not spawn in any of the buildables.
        /// </summary>
        /// <param name="builds">The <see cref="IEnumerable{Buildable}"/> of <see cref="Buildable"/>s to add to the base.</param>
        public void AddBuildables(IEnumerable <Buildable> builds)
        {
            var consolidate = builds.ToList();

            m_Buildables.AddRange(consolidate);
            OnBuildablesAdded?.Invoke(consolidate);
        }
예제 #2
0
        /// <summary>
        /// Adds a buildable to the base. This method does not spawn in a buildable.
        /// </summary>
        /// <param name="build">The buildable to add to the base.</param>
        public void AddBuildable(Buildable build)
        {
            var isStruct = build is StructureBuildable;

            if (IsGlobalCluster && isStruct)
            {
                throw new NotSupportedException("StructureBuildables are not supported by global clusters.");
            }

            m_Buildables.Add(build);
            var gCluster      = m_BaseClusterDirectory.GetOrCreateGlobalCluster();
            var buildsInRange = gCluster.Buildables.Where(IsWithinRange).ToList();

            AddBuildables(buildsInRange);
            gCluster.RemoveBuildables(buildsInRange);
            // Include the buildables from the global cluster that got added.
            OnBuildablesAdded?.Invoke(buildsInRange.Concat(new[] { build }));
        }
        private void InternalHandleDeferred()
        {
            var deferredAdd = new List <Buildable>();

            while (m_DeferredAdd.TryDequeue(out var element))
            {
                deferredAdd.Add(element);
            }

            var deferredRemove = new List <Buildable>();

            while (m_DeferredRemove.TryDequeue(out var element))
            {
                deferredRemove.Add(element);
            }

            OnBuildablesAdded?.Invoke(deferredAdd);
            OnBuildablesRemoved?.Invoke(deferredRemove);
        }