Unity3d object-oriented design ideas (5) (game backpack processing ii)

Source: Internet
Author: User

Continued:

In Unity3d, the idea of dealing with backpacks in the game is that each lattice of a backpack is a clickable object, and a single lattice can be made into one

Prefabs is then added to the game, and each grid has a logic judgment, whether there are items in the current grid, whether the current grid is empty

My approach is not to dynamically generate objects, but to manually load backpack objects one by one, and then name each backpack. In this way, you can check the current backpack

After the object is loaded, the name of the Current Grid Object is distributed.


The ICOn of the current backpack is only an empty UISprite that has been adjusted


A. Define an object group to store all ICON objects

B. Load the background image to be displayed in the current backpack one by one.

Void SetIcon (int I ){
If (obj [I])
NGUITools. AddSprite (obj [I], atlax, "Orc Armor-Shoulders ");

If (! String. IsNullOrEmpty (obj [I]. GetComponent <UISprite> (). spriteName )){
NGUITools. Broadcast ("OnDetailsResult", "rc" + I );
} Else {
// Reload
}
}

C. Use the NGUI tool class to dynamically load image objects to the UISprite of the ICON

D. Then broadcast the event for logic processing.

Void OnDetailsResult (string rc ){
BetterList <string> entrtys = new BetterList <string> ();

If (! String. IsNullOrEmpty (rc )){
Entrtys. Add (rc );
//If(Entrtys.Size>0)
//TiledController.Index=Entrtys.Size;
}

TiledController. index ++;

Print ("size" + entrtys. size );
}


In this way, the backpack can be loaded. It is also a backpack for static display. You can add display items.


:)

Related Article

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.