Skip to content
DucNV_2000 edited this page Mar 11, 2024 · 33 revisions

Common

  • IsInteger checks the input value is an integer or not
static bool IsInteger(float value)
  • GetNumberInAString Gets the first number that appears in the input string
static int GetNumberInAString(string str)
// exp: str = ab234dc => result: 234
// exp: str = ab23df45 => result: 23
  • CallActionAndClean execute the call action and remove the original reference
static void CallActionAndClean(ref Action action)

Example CallActionAndClean:

    public Action completed;
    public void Handle()
    {
        Common.CallActionAndClean(ref completed);
    }
  • IsNullOrEmpty check null or empty
static bool IsNullOrEmpty<T>(this List<T> source) // Check for null or empty list
static bool IsNullOrEmpty<T>(this T[] source) // Check for null or empty array
static bool IsNullOrEmpty<TKey, TValue>(this Dictionary<TKey, TValue> source) // Check for null or empty dictionary

Example IsNullOrEmpty:

    public List<int> listInt;
    public int[] arrayInt;
    public Dictionary<int, string> dict;

    public void CheckNullOrEmpty()
    {
        bool isListNull = listInt.IsNullOrEmpty();
        bool isArrayNull = arrayInt.IsNullOrEmpty();
        bool isDictNull = dict.IsNullOrEmpty();
    }
  • Shuffle
static void Shuffle<T>(this T[] source) // shuffle the elements in the array
static void Shuffle<T>(this List<T> source) // shuffle the elements in the list
static IDictionary<T1, T2> Shuffle<T1, T2>(this IDictionary<T1, T2> source) // shuffle the elements in the dictionary

Example Shuffle:

    public List<int> listInt;
    public int[] arrayInt;
    public Dictionary<int, string> dict;

    public void HandleShuffle()
    {
        // shuffle list
        listInt.Shuffle();
        //shuffle array
        arrayInt.Shuffle();
        // shuffle dict
        dict.Shuffle();
    }
  • MakeDictionary
static IDictionary<TKey, TValue> MakeDictionary<TKey, TValue>(this TKey[] keys, TValue[] values) // Make a dictionary from an array of keys and an array of values
static IDictionary<TKey, TValue> MakeDictionary<TKey, TValue>(this IList<TKey> keys, IList<TValue> values) // Make a dictionary from a list of keys and an array of values
  • PickRandom
static T PickRandom<T>(this T[] collection) // Randomly select an element of the array
static T PickRandom<T>(this List<T> collection) // Randomly select an element of the list
  • PickRandomAndIndex
static (T, int) PickRandomAndIndex<T>(this T[] collection) //  Randomly select an element and index of the array
(T, int) PickRandomWithIndex<T>(this List<T> collection) // Randomly select an element and index of the list
  • InternetConnection
static IEnumerator InternetConnection(Action<bool> action)
// if request internet success => action(true)
// if request internet fail => action(false)
static void CheckInternetConnection(Action actionConnected, Action actionDisconnected)
// actionConnected => Action when connected to the internet
// actionDisconnected => Action when losing internet connection

Common.Animancer

  • PlayAnim
static AnimancerComponent PlayAnim(this AnimancerComponent animancerComponent, ClipTransition clip,Action _endAnim = null, float _durationFade = .2f, FadeMode mode = default)
  • PauseClip
// Freeze a single animation on its current frame:
static AnimancerComponent PauseClip(this AnimancerComponent animancerComponent, ClipTransition clip)
  • PauseAll
// Freeze all animations on their current frame
static AnimancerComponent PauseAll(this AnimancerComponent animancerComponent)
  • StopClip
// Stop a single animation from affecting the character and rewind it to the start
static AnimancerComponent StopClip(this AnimancerComponent animancerComponent, ClipTransition clip)
  • StopAll
// Stop all animations from affecting the character and rewind them to the start
static AnimancerComponent StopAll(this AnimancerComponent animancerComponent)

Example

   public AnimancerComponent animancerComponent;
   public ClipTransition clip;

   public void PlayAnimation()
   {
       animancerComponent.PlayAnim(clip);
   }
   public void PauseAnimation()
   {
       animancerComponent.PauseClip(clip);
   }

   public void PauseAllAnimation()
   {
       animancerComponent.PauseAll();
   }

   public void StopAnimation()
   {
       animancerComponent.StopClip(clip);
   }

   public void StopAllAnimation()
   {
       animancerComponent.StopAll();
   }

Common.Physic

  • IgnoreCollisionListColliderWithCollider Ignore Collision between a Collider and a list of Collider
static void IgnoreCollisionListColliderWithCollider(List<Collider> _listCollider, Collider _collider)
static void IgnoreCollisionListColliderWithCollider(Collider _collider, List<Collider> _listCollider)
  • IgnoreCollisionListColliderWithListCollider Ignore Collision between a list of Collider and a list of Collider
static void IgnoreCollisionListColliderWithListCollider(List<Collider> _listCollider1, List<Collider> _listCollider2)
  • IgnoreCollision2DListColliderWithCollider Ignore Collision 2D between a Collider and a list of Collider
static void IgnoreCollision2DListColliderWithCollider(List<Collider2D> _listCollider, Collider2D _collider)
static void IgnoreCollision2DListColliderWithCollider(Collider2D _collider, List<Collider2D> _listCollider)
  • IgnoreCollision2DListColliderWithListCollider Ignore Collision 2D between a list of Collider and a list of Collider
static void IgnoreCollision2DListColliderWithListCollider(List<Collider2D> _listCollider1, List<Collider2D> _listCollider2)

Common.Tag

  • FindComponentInChildWithTag Find component by tag
static T FindComponentInChildWithTag<T>(this GameObject parent, string tag)

Example

   public GameObject player;
   private BoxCollider _boxCollider;

   public void GetBoxColliderPlayer()
   {
       _boxCollider = player.FindComponentInChildWithTag<BoxCollider>("Player");
   }
  • SetLayer Set layer for this game object
static GameObject SetLayer(this GameObject obj, int layerIndex)
  • SetLayerForAllChildObject Set layer for this game object and all child of game object
static GameObject SetLayerForAllChildObject(this GameObject obj, int layerIndex)

Example

    public GameObject player;
    public void SetLayerForAllChildPlayer()
    {
        player.SetLayerForAllChildObject(LayerMask.NameToLayer("Layer_Player"));
    }
  • SetTag Set tag for this game object
static GameObject SetTag(this GameObject obj, string tag)
  • SetTagForAllChildObject Set tag for this game object and all child of game object
static GameObject SetTagForAllChildObject(this GameObject obj, string tag)

Example

    public GameObject player;
    public void SetTagForAllChildPlayer()
    {
        player.SetTagForAllChildObject("Tag_Player");
    }

Common.Transform

  • ClearTransform clear all child game object of transform
static Transform ClearTransform(this Transform transform)

Example

    public GameObject container;
    public void ClearContainer()
    {
        container.transform.ClearTransform();
    }

Common.SkeletonAnimation & Common.SkeletonGraphic

  • Duration Get duration animation
static float Duration(this SkeletonAnimation skeletonAnimation, string animationName) // For skeleton animation
static float Duration(this SkeletonGraphic skeletonGraphic, string animationName) // For skeleton graphic
  • Play Clear state, play and initialize skeleton
static SkeletonAnimation Play(this SkeletonAnimation skeletonAnimation, string animationName, bool loop = false) //for skeleton animation
static SkeletonGraphic Play(this SkeletonGraphic skeletonGraphic, string animationName, bool loop = false) //for skeleton graphic
  • PlayOnly Play only skeleton not clear state and not initialize skeleton
static SkeletonAnimation PlayOnly(this SkeletonAnimation skeletonAnimation, string animationName, bool loop = false) //for skeleton animation
static SkeletonGraphic PlayOnly(this SkeletonGraphic skeletonGraphic, string animationName, bool loop = false) //for skeleton graphic
  • SetSkin Set new skin for skeleton
static SkeletonAnimation SetSkin(this SkeletonAnimation skeletonAnimation, string skinName) //for skeleton animation
static SkeletonAnimation SetSkin(this SkeletonAnimation skeletonAnimation, List<string> skinNames) //for skeleton animation
static SkeletonGraphic SetSkin(this SkeletonGraphic skeletonGraphic, string skinName) //for skeleton graphic
static SkeletonGraphic SetSkin(this SkeletonGraphic skeletonGraphic, List<string> skinNames) //for skeleton graphic
  • ChangeAttachment
static SkeletonAnimation ChangeAttachment(this SkeletonAnimation skeletonAnimation, string slotName, string attachmentName) //for skeleton animation
static SkeletonAnimation ChangeAttachment(this SkeletonAnimation skeletonAnimation, string slotName, List<string> attachmentNames) //for skeleton animation
static SkeletonGraphic ChangeAttachment(this SkeletonGraphic skeletonGraphic, string slotName, string attachmentName) //for skeleton graphic
static SkeletonGraphic ChangeAttachment(this SkeletonGraphic skeletonGraphic, string slotName, List<string> attachmentNames) //for skeleton graphic
  • MixSkin
static SkeletonAnimation MixSkin(this SkeletonAnimation skeletonAnimation, string mixSkinName) //for skeleton animation
static SkeletonAnimation MixSkin(this SkeletonAnimation skeletonAnimation, List<string> mixSkinNames) //for skeleton animation
static SkeletonGraphic MixSkin(this SkeletonGraphic skeletonGraphic, string mixSkinName) //for skeleton graphic
static SkeletonGraphic MixSkin(this SkeletonGraphic skeletonGraphic, List<string> mixSkinNames) //for skeleton graphic
Clone this wiki locally