コード例 #1
0
        /// <summary>
        /// Adds a decor provider to a given cell.
        /// </summary>
        /// <param name="cell">The cell.</param>
        /// <param name="provider">The object providing decor.</param>
        /// <param name="decor">The quantity of decor to add or subtract.</param>
        public void AddDecorProvider(int cell, DecorProvider provider, float decor)
        {
            var  parent          = provider.gameObject;
            bool allowForCritter = (parent == null) ? false : (!noCritterDecor ||
                                                               parent.GetComponent <CreatureBrain>() == null);

            // Must be a valid cell, and the object must be either not a critter or critter
            // decor enabled
            if (Grid.IsValidCell(cell) && cell < size && cell >= 0 && allowForCritter)
            {
                lock (decorGrid) {
                    AddOrGet(cell).AddDecorProvider(provider.PrefabID(), provider, decor);
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Removes a decor provider from a given cell.
 /// </summary>
 /// <param name="cell">The cell.</param>
 /// <param name="provider">The object providing decor.</param>
 /// <param name="decor">The quantity of decor to add or subtract.</param>
 public void RemoveDecorProvider(int cell, DecorProvider provider, float decor)
 {
     if (Grid.IsValidCell(cell) && cell < size && cell >= 0)
     {
         lock (decorGrid) {
             var dc = decorGrid[cell];
             if (dc != null)
             {
                 dc.RemoveDecorProvider(provider.PrefabID(), provider, decor);
                 if (dc.Count == 0)
                 {
                     decorGrid[cell] = null;
                 }
             }
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// Retrieves the decor score provided by the provider.
        /// </summary>
        /// <param name="provider">The decor provider to check.</param>
        /// <returns>The score provided by that provider, or 0 if it does not provide decor there.</returns>
        public float GetDecorProvidedBy(DecorProvider provider)
        {
            BestDecorList values;
            float         decor = 0.0f;

            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            lock (decorProviders) {
                decorProviders.TryGetValue(provider.PrefabID(), out values);
            }
            if (values != null && provider == values.BestProvider)
            {
                decor = values.BestDecor;
            }
            return(decor);
        }