本文整理汇总了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");
}
示例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");
}
示例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;
}
示例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();
}
示例5: MarkAwakePhase
public static IDisposable MarkAwakePhase(MonoBehaviour target)
{
Count++;
return Observable.TimerFrame(AnimationSpeed * Count)
.Subscribe(_ => target.GetComponent<Renderer>().material.color = Color.yellow);
}
示例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;
}
示例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);
}
示例8: GetTag
public static Tag GetTag (MonoBehaviour bh)
{
var tag = bh.GetComponent<Tag> ();
if (tag == null) {
tag = bh.gameObject.AddComponent<Tag> ();
}
return tag;
}
示例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));
}
}
示例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;
}
示例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);
}
示例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);
}
示例13: MoveAnchorFromRightToLeft
public static void MoveAnchorFromRightToLeft(MonoBehaviour component)
{
RectTransform rectTransform = component.GetComponent<RectTransform>();
rectTransform.anchoredPosition = new Vector2(-rectTransform.anchoredPosition.x, rectTransform.anchoredPosition.y);
}