Coder Social home page Coder Social logo

xavierarpa / x.common Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 1.0 463 KB

Lib to get Common Code Scenarios, Extensor way

library unity csharp extension-methods extensions unity-3d utils game-development game-developmen game game-dev gamedev awesome awesome-list awesome-unity csharp-code csharp-game csharp-library csharp-script

x.common's Introduction

CommonX

Helper to handle Unity code scenarios

~ CommonX it's a DLL where you'll find methods to handle a variety of situations based of what you expect to when we are making games on Unity

How to Install

  • You must have a Unity Project
  • You must have to install Git (https://git-scm.com/downloads) (Maybe you'll have to reboot after install)
  • Go to the Package Manager Window
  • Click in the '+' icon
  • Click on the option Add package from git URL...
  • Paste the git link: https://github.com/kingdox/x-common on it
  • Wait some seconds...
  • Installed ๐Ÿ˜Ž ๐Ÿ‘

Helper Classes

  • Supply

    General class, this includes the most common methods. Frequently used methods:
    • T Component<C, T>: Get the Component and set on a ref variable, also allows you can chain methods, if it can't find it, you can add it too. Instead of: Button btn_back = gameObject.GetComponent<Button>(); btn_back.interactable = true; btn_back.onClick.AddListener(Back); Why not:
          // Look you're not typing any type, because is implicit on the variable 'btn_back'
          this.Component(out btn_back).interactable = true; 
          btn_back.onClick.AddListener(Back);
    • T[] Components: Get the same Component of every child of a Transform (Excluding itself) example:
          //Where 'btn_buyItems' represent a Button[]
          this.Components(out btn_buyItems);
    • void ClearChilds: Destroy every GameObject child of a Transform parent example:
          transform_parentItems.ClearChilds();
    • void Singleton: Apply the Singleton Pattern, also can include a Object.DontDestroyOnLoad example:
          //'this' means the class to be unique and instance means the static variable of the Type
          this.Singleton(ref instance);
    • Lenght(): Returns the Qty of key elements on a Enum
      enum WordType{
          A = -1,
          B = 2,
          C = 0
      }
      //returns 3
      Supply.Lenght<WordType>(); 
    • T Print(): One of the most useful Methods, Used to debug whenever you want, adding a Color if you want (or a random)
      int a = 1;
      int b = 2;
      int c = 3;
      //Look that you can add it in each part of your code, this is useful when you whant to debug each piece of code on a specified moment without any alteration of the formula
      int result = ((2*b).Print("red") / (a-c).Print("blue"));
      string displayedResult = $"on a:{a},b:{b} and c:{c}, \n the result is {result}".Print("magenta");
      return displayedResult;
  • Get.Get

    Class based on obtention of data Frequently used methods:
    • T Any(): Returns any item of an Array
     Transform tr_target = tr_targets.Any();
    • int ZeroMax(): Returns a random value betweeen 0 and the specified int
    100.ZeroMax();
    100f.ZeroMax();
    array.ZeroMax();
    • float Max(): returns a value clamped on the Max value
    int percent = value.Max(100);
    • float Min(): returns a value clamped on the Min value
    int life = (life - damage).Min(0);

x.common's People

Contributors

xavierarpa avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

game-challenge

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.