Unity Auto-Generate Component Index class tool

Source: Internet
Author: User

Unity Auto-generated Component Index class tool requirements origin

We need to get the components in the presets when we write the UI class

joystick = transform.Find("joystick");background = transform.Find("joystick/background");stick = transform.Find("joystick/stick");direction = transform.Find("joystick/direction");


  1. Requires handwritten code
  2. Modifying game object names requires manual code modification
  3. Modifying levels requires manual code modification
  4. Handwriting is prone to problems
Solution Solutions

Use the editor to automatically generate the following index classes

public class MianBase : MonoBehaviour{    protected UISprite Left_Sprite;    protected UITexture Right_Texture;    protected UISprite Bottom_Sprite;    protected UILabel Top_Label;    public void InitBase()    {        Left_Sprite = transform.Find("Left/Sprite").GetComponent<UISprite>();        Right_Texture = transform.Find("Right/Texture").GetComponent<UITexture>();        Bottom_Sprite = transform.Find("Bottom/Sprite").GetComponent<UISprite>();        Top_Label = transform.Find("Top/Label").GetComponent<UILabel>();    }}

The UI code then inherits this class
You can use these components very conveniently.

Tool making


The core idea of tool making

  • Select a preset Parent
  • Iterating over the script on the Child and child objects
  • Index variable names can be automatically populated with customizable
  • Serialization classes
How to Use Tools
    1. Select a preset Parent
    2. Top left menu bar zouqiang/ui/Create Preset index class (shortcut key ctrl+alt+1) Open window
    3. Custom variable name or auto-fill variable name
    4. Click the Generate Code button

If you have a better solution, please do not hesitate to enlighten, thank you endless!

Source: Https://github.com/QiangZou/ZouQiang/blob/master/Assets/ZouQiang/Editor/AssetBundlesTool.cs

Unity Auto-Generate Component Index class tool

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.