LethalCompany/Lethal Company/ExportedProject/Assets/Scripts/Assembly-CSharp/DunGen/RandomPrefab.cs

42 lines
1.1 KiB
C#
Raw Normal View History

2023-12-22 22:51:17 +00:00
using UnityEngine;
namespace DunGen
{
[AddComponentMenu("DunGen/Random Props/Random Prefab")]
public class RandomPrefab : RandomProp
{
[AcceptGameObjectTypes(GameObjectFilter.Asset)]
public GameObjectChanceTable Props = new GameObjectChanceTable();
public bool ZeroPosition = true;
public bool ZeroRotation = true;
public override void Process(RandomStream randomStream, Tile tile)
{
if (Props.Weights.Count > 0)
{
GameObject value = Props.GetRandom(randomStream, tile.Placement.IsOnMainPath, tile.Placement.NormalizedDepth, null, allowImmediateRepeats: true, removeFromTable: true).Value;
GameObject gameObject = Object.Instantiate(value);
gameObject.transform.parent = base.transform;
if (ZeroPosition)
{
gameObject.transform.localPosition = Vector3.zero;
}
else
{
gameObject.transform.localPosition = value.transform.localPosition;
}
if (ZeroRotation)
{
gameObject.transform.localRotation = Quaternion.identity;
}
else
{
gameObject.transform.localRotation = value.transform.localRotation;
}
}
}
}
}