本文整理汇总了C#中UnityEngine.MonoBehaviour.AddOrGetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# MonoBehaviour.AddOrGetComponent方法的具体用法?C# MonoBehaviour.AddOrGetComponent怎么用?C# MonoBehaviour.AddOrGetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.MonoBehaviour
的用法示例。
在下文中一共展示了MonoBehaviour.AddOrGetComponent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Resume
internal void Resume(MonoBehaviour behaviour)
{
if (_state != RadicalCoroutineOperatingState.Inactive && _state != RadicalCoroutineOperatingState.Paused) throw new System.InvalidOperationException("Failed to start RadicalCoroutine. The Coroutine is already being processed.");
if (behaviour == null) throw new System.ArgumentNullException("behaviour");
_state = RadicalCoroutineOperatingState.Active;
_owner = behaviour;
if (_stack.CurrentOperation is IPausibleYieldInstruction) (_stack.CurrentOperation as IPausibleYieldInstruction).OnResume();
#if SP_LIB
var manager = behaviour.AddOrGetComponent<RadicalCoroutineManager>();
#else
var manager = behaviour.GetComponent<RadicalCoroutineManager>();
if (manager == null) manager = behaviour.gameObject.AddComponent<RadicalCoroutineManager>();
#endif
_manager = manager;
_manager.RegisterCoroutine(this);
_token = behaviour.StartCoroutine(this);
}
示例2: Start
/// <summary>
/// Starts the coroutine, one should always call this method or the StartRadicalCoroutine extension method. Never pass the RadicalCoroutine into the 'StartCoroutine' method.
/// </summary>
/// <param name="behaviour">A reference to the MonoBehaviour that should be handling the coroutine.</param>
/// <param name="disableMode">A disableMode other than Default is only supported if the behaviour is an SPComponent.</param>
/// <remarks>
/// Disable modes allow you to decide how the coroutine is dealt with when the component/gameobject are disabled. Note that 'CancelOnDeactivate' is a specical case flag,
/// it only takes effect if NO OTHER flag is set (it's a 0 flag actually). What this results in is that Deactivate and Disable are pausible... but a routine can only play
/// through Disable, not Deactivate. This is due to the default behaviour of coroutine in unity. In default mode, coroutines continue playing when a component gets disabled,
/// but when deactivated the coroutine gets cancelled. This means we can not play through a deactivation.
/// </remarks>
public void Start(MonoBehaviour behaviour, RadicalCoroutineDisableMode disableMode = RadicalCoroutineDisableMode.Default)
{
if (_state != RadicalCoroutineOperatingState.Inactive) throw new System.InvalidOperationException("Failed to start RadicalCoroutine. The Coroutine is already being processed.");
if (behaviour == null) throw new System.ArgumentNullException("behaviour");
_state = RadicalCoroutineOperatingState.Active;
_owner = behaviour;
_token = behaviour.StartCoroutine(this);
_disableMode = disableMode;
if (_disableMode > RadicalCoroutineDisableMode.Default && _disableMode != RadicalCoroutineDisableMode.ResumeOnEnable)
{
//no point in managing the routine if it acts in default mode... a flag of 'ResumeOnEnable' is a redundant mode to default
var manager = behaviour.AddOrGetComponent<RadicalCoroutineManager>();
manager.RegisterCoroutine(behaviour, this);
}
if (_stack.Count > 0 && _stack.Peek() is IPausibleYieldInstruction) (_stack.Peek() as IPausibleYieldInstruction).OnResume();
}
示例3: StartAsync
public void StartAsync(MonoBehaviour behaviour, RadicalCoroutineDisableMode disableMode = RadicalCoroutineDisableMode.Default)
{
if (_state != RadicalCoroutineOperatingState.Inactive) throw new System.InvalidOperationException("Failed to start RadicalCoroutine. The Coroutine is already being processed.");
if (behaviour == null) throw new System.ArgumentNullException("behaviour");
_state = RadicalCoroutineOperatingState.Active;
_owner = behaviour;
_disableMode = disableMode;
if (_stack.CurrentOperation is IPausibleYieldInstruction) (_stack.CurrentOperation as IPausibleYieldInstruction).OnResume();
_stack.Push(com.spacepuppy.Async.RadicalTask.Create(this)); //we start the task as an async operation
#if SP_LIB
var manager = behaviour.AddOrGetComponent<RadicalCoroutineManager>();
#else
var manager = behaviour.GetComponent<RadicalCoroutineManager>();
if (manager == null) manager = behaviour.gameObject.AddComponent<RadicalCoroutineManager>();
#endif
_manager = manager;
_manager.RegisterCoroutine(this);
_token = behaviour.StartCoroutine(this);
}