当前位置: 首页>>代码示例>>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;未经允许,请勿转载。