using UnityEngine; namespace Unity.Tutorials.Core.Editor { /// /// Future Object Reference is a reference to a Unity Object that might not exist yet (prefab instance). /// public class FutureObjectReference : ScriptableObject { [SerializeField] SceneObjectReferenceHolder m_ReferenceHolder; [SerializeField] Criterion m_Criterion; [SerializeField] string m_ReferenceName; /// /// Returns the SceneObjectReferenceHolder for this FutureObjectReference. /// Creates the SceneObjectReferenceHolder instance if it does not exist. /// SceneObjectReferenceHolder ReferenceHolder { get { if (m_ReferenceHolder == null) { m_ReferenceHolder = CreateInstance(); m_ReferenceHolder.hideFlags = HideFlags.HideAndDontSave; } return m_ReferenceHolder; } } /// /// The SceneObjectReference of this FutureObjectReference. /// public SceneObjectReference SceneObjectReference { get { if (ReferenceHolder.SceneObjectReference == null) ReferenceHolder.SceneObjectReference = new SceneObjectReference(); return ReferenceHolder.SceneObjectReference; } set { ReferenceHolder.SceneObjectReference = value; } } /// /// The Criterion this FutureObjectReference belongs to. /// public Criterion Criterion { get => m_Criterion; set => m_Criterion = value; } /// /// The name used to refer the Unity Object. /// public string ReferenceName { get => m_ReferenceName; set => m_ReferenceName = value; } void OnDestroy() { if (m_ReferenceHolder != null) DestroyImmediate(m_ReferenceHolder); } } /// /// SceneObjectReference holder. /// public class SceneObjectReferenceHolder : ScriptableObject { /// /// The ScenObjectReference. /// public SceneObjectReference SceneObjectReference { get => m_SceneObjectReference; set => m_SceneObjectReference = value; } [SerializeField] SceneObjectReference m_SceneObjectReference; } }