當前位置: 首頁>>代碼示例>>C#>>正文


C# MonoBehaviour.AddOrGetComponent方法代碼示例

本文整理匯總了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);
        }
開發者ID:Gege00,項目名稱:spacepuppy-unity-framework,代碼行數:20,代碼來源:RadicalCoroutine.cs

示例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();
        }
開發者ID:yuanchunfa,項目名稱:spacepuppy-unity-framework,代碼行數:30,代碼來源:RadicalCoroutine.cs

示例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);

        }
開發者ID:Gege00,項目名稱:spacepuppy-unity-framework,代碼行數:23,代碼來源:RadicalCoroutine.cs


注:本文中的UnityEngine.MonoBehaviour.AddOrGetComponent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。