Skip to content

Instantly share code, notes, and snippets.

@ronyx69
Created May 22, 2018 15:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronyx69/5fc7e20afe73888e220165caad8c904f to your computer and use it in GitHub Desktop.
Save ronyx69/5fc7e20afe73888e220165caad8c904f to your computer and use it in GitHub Desktop.
Sets amount of tree variations and calculates equal probability. Thanks to TPB for making it work.
//----------------------------------------------------------------
// Tree Variation Amount Changer
// Set amount of Tree variations.
// If you are increasing the amount, previous variations will be preserved.
// If decreasing, all variations will be removed!
var variations = 12; //CHANGE THIS
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as TreeInfo;
if(variations!=asset.m_variations.Length) {
TreeInfo.Variation[] temp = new TreeInfo.Variation[variations];
for(int i = 0; i < temp.Length; i++) temp[i] = new TreeInfo.Variation();
if(asset.m_variations.Length<variations) asset.m_variations.CopyTo(temp, 0);
asset.m_variations = temp;
UnityEngine.Object.FindObjectOfType<DecorationPropertiesPanel>().Refresh(); }
else Debug.LogWarning("Amount of variations already is " + variations.ToString());
//----------------------------------------------------------------
// Tree Variation Equal Probability Calculator
// Automatically calculate equal probability for all variations.
// The formula is 100 divided by (variation amount + 1), then rounded down.
// Empty variations can't have probability,
// so run this after you have added all your variations.
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as TreeInfo;
var variations = asset.m_variations.Length;
var probability = (int)Math.Floor(100f/(variations+1));
for(uint i = 0; i < variations; i++) asset.m_variations[i].m_probability=probability;
UnityEngine.Object.FindObjectOfType<DecorationPropertiesPanel>().Refresh();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment