This commit is contained in:
SoulliesOfficial
2026-06-09 11:21:59 -04:00
parent 7c60c40d6b
commit 021e76efe7
493 changed files with 50500 additions and 2211 deletions

View File

@@ -0,0 +1,66 @@
/*
Yarn Spinner is licensed to you under the terms found in the file LICENSE.md.
*/
using UnityEngine;
#nullable enable
namespace Yarn.Unity
{
[System.Serializable]
public class InterfaceContainer<TContainedType> : ISerializationCallbackReceiver where TContainedType : class
{
public UnityEngine.Object? targetObject;
public TContainedType? Interface
{
get
{
return targetObject as TContainedType;
}
}
public static implicit operator TContainedType?(InterfaceContainer<TContainedType> value)
{
return value.Interface;
}
// basically if we find a component that is our interface we override the target to be that
// and otherwise we null it out, also wiping the connection in the inspector
void OnValidate()
{
if (targetObject == null)
{
return;
}
if (this.Interface != null)
{
return;
}
if (targetObject is GameObject gameObject)
{
foreach (var component in gameObject.GetComponents<Component>())
{
if (component is TContainedType)
{
targetObject = component;
return;
}
}
}
targetObject = null;
}
public void OnBeforeSerialize()
{
OnValidate();
}
public void OnAfterDeserialize()
{
return;
}
}
}