using System;
using AceLand.Library.Attribute;
using AceLand.Library.Extensions;
using UnityEngine;
[CreateAssetMenu(fileName = "MyItem", menuName = "Profiles/MyItem")]
public class ItemProfile : ScriptableObject
{
// id will be a non-editable field in Inspector window
[ReadOnlyField] public string id;
public Texture2D preview;
public int effectValue;
// value on create
private void OnEnable()
{
id ??= Guid.NewGuid().ToString();
}
// initial readonly field
// this can apply change on existing ScriptableObject
private void OnValidate()
{
if (id.IsNullOrEmptyOrWhiteSpace())
id = Guid.NewGuid().ToString();
}
#if UNITY_EDITOR
// add a button to renew the non-editable field
[InspectorButton]
private void RenewId() =>
id = Guid.NewGuid().ToString();
#endif
}
With attribute , it will be more flexible on editing to non-editable fields.