Official website: https://www.fairygui.com/
basic operation
Add Package: UIPackage.AddPackage(@“Assets/ArtContents\UIAssets\Sprites\homeChatBox\homeChatBox”);
Create Object:
var main = UIPackage.CreateObject(“homeChatBox”, “main”);
Display:
GRoot.inst.AddChild( main);
Element (GObject)
Set hide and show
visible = true/false
set interactive
touchable = true/false.
Set
grayed = true/false.
Set activation
enabled = true/false. The activation state of the component is actually composed of gray + untouchable.
Get gameObject:
aObject.displayObject.gameObject
destroy Dispose.
Destroy the object, it can be called when the object is no longer used, and must be called. Note: Public resources such as textures and sounds are managed by UIPackage, and destroying objects will not reclaim these resources. If you want to reclaim these resources, you should use UIPackage.RemovePackage.
event system
Add:
gObject.Event.Set();//Will not repeatedly add
gObject.Event.Add();//Add repeatedly
1. onTouchBegin: start touching
2, onTouchEnd: end touching
3, onTouchMove: touch moving
4, onRemovedFromStage: the component is removed from the stage.
5. onAddedToStage: The component is added to the stage
6. onRightClick: Right click. Bubble event
7, onClick: click. Bubble event
8, onRollOver: the mouse moves into element
9, onRollOut: the mouse moves out of element
10, onKeyDown: the element receives a key event. Key events can only be received when the key is focused. Bubble event
11, onClickLink: the link in the text is clicked
12, onPositionChanged: the position of the component changes
13, onSizeChanged: the size of the component changes
14, onDragStart/onDragEnd/onDragMove: drag start and end events, drag and drop movement, need to The draggable of the element = true
When onDragStart, call EventContext.PreventDefault() to cancel the dragging immediately. No event data.
15, onDrop: Note that it is different from ordinary dragging. After an element is dragged and released, the Drop event will not be triggered. The Drop event needs to be used with DragDropManager. When the icon dragged by DragDropManager is released on a component, the component will trigger onDrop. The event data is the source value passed in DragDropManager.StartDrag.
GList: Manage List Contents
Inherited from GComponent,
when the list is added, deleted or modified, it will be automatically arranged and refreshed without calling any API.
Automatic arrangement will set the coordinates, size and depth of the item according to the layout of the list, so do not set the position of the item by yourself, and do not set the sortingOrder to try to control the depth of the item.
The y coordinate of the item is automatically set after the vertically laid out list. same horizontal layout
This arrangement and refresh occurs before the frame is drawn. If you want to access the correct coordinates of the item immediately, you can call EnsureBoundsCorrect to notify GList to rearrange immediately
Use the built-in object pool in the list
RemoveChildrenToPool
takes it from the pool (if any) or creates a new object and adds it to the list. If no parameter is used, the setting of the "item resource" of the list is used; a URL can also be specified to create the specified object.
RemoveChildToPoolAt
removes an object from the pool (if any) or creates a new one.
RemoveChildToPool
returns the object to the pool.
ReturnToPool
deletes an item and returns the object to the pool.
GetFromPool
deletes an item at a specified location and returns the object to the pool.
AddItemFromPool
deletes a range of items, or deletes them all, and returns all deleted objects to the pool
Use the callback function to modify the list
If you add a large number of items, in addition to calling AddChild or AddItemFromPool, you can also use
aList.itemRenderer = itemRendererCB;
void itemRendererCB(int index, GObject gObj)
{ } Change the number of lists by aList.numItems = 100;
virtual list
Similar to infinite scrolling, hundreds or thousands of items do not need to be created each.
Conditions for starting a virtual list:
1. ItemRenderer needs to be defined
2. Scrolling needs to be enabled. Lists with overflow handling that are not scrollable cannot be virtualized.
3. It is necessary to set up the "project resource" of the list. You can also call GList.defaultItem to set it.
After the conditions are met, call aList.SetVirtual
In the virtual list, the number of display objects and items is inconsistent in quantity and order. The number of items can be obtained through numItems, and the number of display objects can be obtained through the API numChildren of the component.
Jump to the first few positions, for example: jump to the 500th
//It should be noted here that because we need to immediately access the object of the new scroll position, the second parameter scrollItToView cannot be true, that is, the animation effect is not used
aList.ScrollToView(500);
//转换到显示对象索引
int index = aList.ItemIndexToChildIndex(500);
//这就是你要的第500个对象
GObject obj = aList.GetChildAt(index);
Refresh list
1, use numItems to reset quantity
2, GList.RefreshVirtualList
Cannot use AddChild and RemoveChild to add or delete objects to the virtual list
Popup: pop up, click blank to close
Open:
GRoot.inst:ShowPopup(gComponent);
Closed event:
gComponent.onRemoveFromStage
Precautions
1. FairyBatching problem
If there are multiple input boxes, after FairyBatching is checked, the input box may lose focus and the content will not be visible
list and inputFiled problem
When the input box and list exist at the same time, it must be ensured that the input box is under the list, otherwise the list will flicker when the input box gets the focus
The problem of displaying multiple lists at the same time
If multiple lists are displayed at the same time, it may be the same as the Mask range, and
the processing method: make the overflow different