Skip to content

Instantly share code, notes, and snippets.

@ronyx69
Last active November 29, 2020 07:25
Show Gist options
  • Save ronyx69/8071d41a135cdb5d1f1f0627b5806b6d to your computer and use it in GitHub Desktop.
Save ronyx69/8071d41a135cdb5d1f1f0627b5806b6d to your computer and use it in GitHub Desktop.
Sets amount of prop variations and calculates equal probability.
//----------------------------------------------------------------
// Prop Variation Amount Changer
//Set amount of prop 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 PropInfo;
if(variations!=asset.m_variations.Length)
{
PropInfo.Variation[] temp = new PropInfo.Variation[variations];
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());
//----------------------------------------------------------------
// Prop 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 PropInfo;
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();
@hgb0607
Copy link

hgb0607 commented Nov 29, 2020

bug:Can only be random between the main prop and the first variations prop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment