Пример #1
0
        /// <summary>
        /// Applies scaling to trees and updates the dictionary records.
        /// </summary>
        /// <param name="prop">Tree prefab</param>
        /// <param name="minScale">Minimum scale</param>
        /// <param name="maxScale">Maximum scale</param>
        private void TreeScale(TreeInfo tree, float minScale, float maxScale)
        {
            // If we don't have an existing record, create one.
            if (!treeScales.ContainsKey(tree.name))
            {
                // Record original values.
                treeScales.Add(tree.name, new BOBScalingElement
                {
                    prefabName  = tree.name,
                    prefab      = tree,
                    originalMin = tree.m_minScale,
                    originalMax = tree.m_maxScale
                });
            }

            // Local reference.
            BOBScalingElement element = treeScales[tree.name];

            // Update record with new scale values.
            element.minScale = minScale;
            element.maxScale = maxScale;

            // Remove record if minimum and maximum scales both match the default.
            if (element.minScale == element.originalMin && element.maxScale == element.originalMax)
            {
                propScales.Remove(tree.name);
            }

            // Apply new scales and save updated configuration.
            tree.m_minScale = minScale;
            tree.m_maxScale = maxScale;
            ConfigurationUtils.SaveConfig();
        }
Пример #2
0
        /// <summary>
        /// Revert a prefab to original scaling.
        /// </summary>
        /// <param name="prefab">Prefab to revert</param>
        /// <param name="removeEntries">True to remove the reverted entries from the list of replacements, false to leave the list unchanged</param>
        internal void Revert(PrefabInfo prefab, bool removeEntries)
        {
            // Prop or tree?
            if (prefab is PropInfo prop)
            {
                // Prop - check if we have a record.
                if (propScales.ContainsKey(prop.name))
                {
                    // Local reference.
                    BOBScalingElement element = propScales[prop.name];

                    // Reset prop scale.
                    prop.m_minScale = element.originalMin;
                    prop.m_maxScale = element.originalMax;

                    // Remove record from dictionary, if we're doing so.
                    if (removeEntries)
                    {
                        propScales.Remove(prop.name);
                    }

                    // Save configuration file.
                    ConfigurationUtils.SaveConfig();
                }
            }
            else if (prefab is TreeInfo tree)
            {
                // Tree - check if we have a record.
                if (treeScales.ContainsKey(tree.name))
                {
                    // Local reference.
                    BOBScalingElement element = treeScales[tree.name];

                    // Reset prop scale.
                    tree.m_minScale = element.originalMin;
                    tree.m_maxScale = element.originalMax;

                    // Remove record from dictionary, if we're doing so.
                    if (removeEntries)
                    {
                        treeScales.Remove(tree.name);
                    }

                    // Save configuration file.
                    ConfigurationUtils.SaveConfig();
                }
            }
        }