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


C# MonoBehaviour.GetComponent方法代碼示例

本文整理匯總了C#中UnityEngine.MonoBehaviour.GetComponent方法的典型用法代碼示例。如果您正苦於以下問題:C# MonoBehaviour.GetComponent方法的具體用法?C# MonoBehaviour.GetComponent怎麽用?C# MonoBehaviour.GetComponent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UnityEngine.MonoBehaviour的用法示例。


在下文中一共展示了MonoBehaviour.GetComponent方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: RotateToVelocity

 public static void RotateToVelocity(MonoBehaviour behaviour, float duration)
 {
     if (behaviour != null && behaviour.GetComponent<Rigidbody2D>() != null)
     {
         _instance.StopAllCoroutines();
         _instance.StartCoroutine(_instance.cRotateToVelocity(behaviour.GetComponent<Rigidbody2D>(), duration));
     }
     else
         Debug.LogError("[VelocityShake] cant find rigidbody2D on gameobject");
 }
開發者ID:Badeye,項目名稱:impulse,代碼行數:10,代碼來源:CamRotation.cs

示例2: VelocityRotation

        public static void VelocityRotation(MonoBehaviour behaviour)
        {
            if (behaviour != null && behaviour.GetComponent<Rigidbody2D>() != null)
            {
                _instance.StopAllCoroutines();

                if (_instance.rotationType == RotationType.minToMax)
                    _instance.StartCoroutine(_instance.cVelocityRotationMinMax(behaviour.GetComponent<Rigidbody2D>()));
                else
                    _instance.StartCoroutine(_instance.cVelocityRotationDefMax(behaviour.GetComponent<Rigidbody2D>()));
            }
            else
                Debug.LogError("[VelocityShake] cant find rigidbody2D on gameobject");
        }
開發者ID:Badeye,項目名稱:impulse,代碼行數:14,代碼來源:CamRotation.cs

示例3: CheckCollider

        /// <summary>
        /// Validates collider settings.
        /// </summary>
        protected List<ValidationResult> CheckCollider(MonoBehaviour m)
        {
            List<ValidationResult> result = new List<ValidationResult> ();

            if (m.GetComponent<Collider2D>() == null)
            {
                result.Add (new ValidationResult("Found a  " + m.GetType().Name + " but it did not have a Collider2D attached.",  MessageType.Warning));
            }
            else if (!m.GetComponent<Collider2D>().isTrigger)
            {
                result.Add (new ValidationResult("Found a  " + m.GetType().Name  + " but the collider2D was not a trigger.", MessageType.Info));
            }
            return result;
        }
開發者ID:Connorlc,項目名稱:UnityProjects,代碼行數:17,代碼來源:ValidateRigidbodies.cs

示例4: HollywoodMVCSContext

 public HollywoodMVCSContext(MonoBehaviour view) : base(view, ContextStartupFlags.MANUAL_MAPPING)
 {
     _hollywoodContextView = view.GetComponent<IHollywoodContextView>();
     if (_hollywoodContextView == null)
         throw (new Exception("HollywoodMVCSContext constructor error, there's no IHollywoodContextView instance on context's view !!!"));
     Start();
 }
開發者ID:flow38,項目名稱:StrangeIoC-Hollywood-extension,代碼行數:7,代碼來源:HollywoodMVCSContext.cs

示例5: MarkAwakePhase

        public static IDisposable MarkAwakePhase(MonoBehaviour target)
        {
            Count++;
            return Observable.TimerFrame(AnimationSpeed * Count)
                .Subscribe(_ => target.GetComponent<Renderer>().material.color = Color.yellow);

        }
開發者ID:ClusterVR,項目名稱:teleportation_for_vive,代碼行數:7,代碼來源:Sample14_PresenterBase.cs

示例6: FlipXScale

		/// <summary>
		/// just sets the x scale to -x
		/// </summary>
		/// <param name="component"></param>
		public static void FlipXScale(MonoBehaviour component)
		{
			RectTransform rectTransform = component.GetComponent<RectTransform>();
			Vector3 scale = rectTransform.localScale;
			scale.x *= -1f;
			rectTransform.localScale = scale;
		}
開發者ID:paveltimofeev,項目名稱:GameJamFramework,代碼行數:11,代碼來源:UIUtilities.cs

示例7: MoveAlignmentFromRightToLeft

		public static void MoveAlignmentFromRightToLeft(MonoBehaviour component)
		{
			RectTransform rectTransform = component.GetComponent<RectTransform>();
			rectTransform.anchorMin = new Vector2(0f, 1f);
			rectTransform.anchorMax = new Vector2(0f, 1f);
			rectTransform.anchoredPosition = new Vector2(-rectTransform.anchoredPosition.x + rectTransform.rect.width, rectTransform.anchoredPosition.y);
		}
開發者ID:paveltimofeev,項目名稱:GameJamFramework,代碼行數:7,代碼來源:UIUtilities.cs

示例8: GetTag

		public static Tag GetTag (MonoBehaviour bh)
		{
			var tag = bh.GetComponent<Tag> ();
			if (tag == null) {
				tag = bh.gameObject.AddComponent<Tag> ();
			}
			return tag;
		}
開發者ID:pandaboy,項目名稱:Village,代碼行數:8,代碼來源:MonoBehaviourExtensions.cs

示例9: ReflectRotationSwitch

 public static void ReflectRotationSwitch(MonoBehaviour behaviour, float duration)
 {
     Debug.Log("Reflect");
     if (behaviour != null && behaviour.GetComponent<Rigidbody2D>() != null)
     {
         _instance.StopAllCoroutines();
         Quaternion memoryRotation = _instance.minRotation;
         _instance.minRotation = _instance.maxRotation;
         _instance.maxRotation = memoryRotation;
         _instance.StartCoroutine(_instance.cRotateToVelocity(behaviour.GetComponent<Rigidbody2D>(), duration));
     }
 }
開發者ID:Badeye,項目名稱:impulse,代碼行數:12,代碼來源:CamRotation.cs

示例10: CheckRigidbody

        /// <summary>
        /// Validates  rigidbody settings.
        /// </summary>
        protected List<ValidationResult> CheckRigidbody(MonoBehaviour m, bool isWarning)
        {
            List<ValidationResult> result = new List<ValidationResult> ();

            if (m.GetComponent<Rigidbody2D>() == null)
            {
                result.Add (new ValidationResult("Found a  " + m.GetType().Name + " but it did not have a rigidbody attached.", isWarning ? MessageType.Warning : MessageType.Info));
            }
            else if (!m.GetComponent<Rigidbody2D>().isKinematic)
            {
                result.Add (new ValidationResult("Found a  " + m.GetType().Name  + " but the rigidboy was not kinematic.", isWarning ? MessageType.Warning : MessageType.Info));
            }
            return result;
        }
開發者ID:Connorlc,項目名稱:UnityProjects,代碼行數:17,代碼來源:ValidateRigidbodies.cs

示例11: 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

示例12: 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

示例13: MoveAnchorFromRightToLeft

		public static void MoveAnchorFromRightToLeft(MonoBehaviour component)
		{
			RectTransform rectTransform = component.GetComponent<RectTransform>();
			rectTransform.anchoredPosition = new Vector2(-rectTransform.anchoredPosition.x, rectTransform.anchoredPosition.y);
		}
開發者ID:paveltimofeev,項目名稱:GameJamFramework,代碼行數:5,代碼來源:UIUtilities.cs


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