AutoGenerate Flags (monsters, chests, any)
💡
4
Just add [ExecuteInEditMode] on top of the class, and create a function called OnValidate which the unity executes automatically.
`csharp
using UnityEngine;
namespace Gyvr.Mythril2D
{
[ExecuteInEditMode]
public class YourClass:MonoBehaviour
{
[SerializeField] private string m_gameFlagID = "";
// Only generate the flagId if it's empty or null
private void OnValidate()
{
// Get the current date and time in the format yymmddhhmmss
if(m_gameFlagID.IsNullOrEmpty())
m_gameFlagID = "CLASS_NAME_OR_SOMETHING_CLEAR" + System.DateTime.Now.ToString("yyMMddHHmmss");
// Make the flagId persist by marking the object as dirty
UnityEditor.EditorUtility.SetDirty(this);
}
}
}

💬 Comments (3)
Want to continue the conversation?