Example #1
0
 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");
 }
Example #2
0
        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");
        }
        /// <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;
        }
        public static IDisposable MarkAwakePhase(MonoBehaviour target)
        {
            Count++;
            return Observable.TimerFrame(AnimationSpeed * Count)
                .Subscribe(_ => target.GetComponent<Renderer>().material.color = Color.yellow);

        }
 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();
 }
		/// <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;
		}
		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);
		}
		public static Tag GetTag (MonoBehaviour bh)
		{
			var tag = bh.GetComponent<Tag> ();
			if (tag == null) {
				tag = bh.gameObject.AddComponent<Tag> ();
			}
			return tag;
		}
Example #9
0
 private static bool GetMB(UnityEngine.MonoBehaviour networkView, out Contextual contextual)
 {
     if ((networkView != null) && ((contextual = networkView.GetComponent <Contextual>()) != null))
     {
         return(contextual.exists);
     }
     contextual = null;
     return(false);
 }
Example #10
0
 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));
     }
 }
        /// <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;
        }
Example #12
0
 private static bool GetMB(UnityEngine.MonoBehaviour networkView, out Contextual contextual)
 {
     if (networkView)
     {
         Contextual component   = networkView.GetComponent <Contextual>();
         Contextual contextual1 = component;
         contextual = component;
         if (contextual1)
         {
             return(contextual.exists);
         }
     }
     contextual = null;
     return(false);
 }
Example #13
0
    public bool GetComponent <TComponent>(out TComponent component) where TComponent : Component
    {
        TComponent local;

        UnityEngine.MonoBehaviour view = this.view;
        if (view == null)
        {
            component = null;
            return(false);
        }
        if (view is TComponent)
        {
            component = (TComponent)view;
            return(true);
        }
        component = local = view.GetComponent <TComponent>();
        return(local);
    }
Example #14
0
    public bool GetComponent <TComponent>(out TComponent component)
        where TComponent : Component
    {
        UnityEngine.MonoBehaviour monoBehaviour = this.view;
        if (!monoBehaviour)
        {
            component = (TComponent)null;
            return(false);
        }
        if (monoBehaviour is TComponent)
        {
            component = (TComponent)monoBehaviour;
            return(true);
        }
        TComponent tComponent  = monoBehaviour.GetComponent <TComponent>();
        TComponent tComponent1 = tComponent;

        component = tComponent;
        return(tComponent1);
    }
Example #15
0
 public static FduClusterView GetClusterView(this UnityEngine.MonoBehaviour mono)
 {
     return(mono.GetComponent <FduClusterView>() as FduClusterView);
 }
        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);

        }
        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);
        }
Example #18
0
 public TComponent GetComponent <TComponent>() where TComponent : Component
 {
     UnityEngine.MonoBehaviour view = this.view;
     return((view == null) ? null : view.GetComponent <TComponent>());
 }
		public static void MoveAnchorFromRightToLeft(MonoBehaviour component)
		{
			RectTransform rectTransform = component.GetComponent<RectTransform>();
			rectTransform.anchoredPosition = new Vector2(-rectTransform.anchoredPosition.x, rectTransform.anchoredPosition.y);
		}
Example #20
0
 public TComponent GetComponent <TComponent>()
     where TComponent : Component
 {
     UnityEngine.MonoBehaviour monoBehaviour = this.view;
     return(!monoBehaviour ? (TComponent)null : monoBehaviour.GetComponent <TComponent>());
 }