Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Summary of problems encountered in using UGUI

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Image component: dynamically change Source Image.

1.gameObject.GetComponent (). P_w_picpath.sprite = YourSprite; (the way to get YourSPrite is that I defined the Spites array before, and pulled the picture in. If there is a better way, please let me know.

2.gameObject.GetComponent () .sprite= Resources.Load ("img/test/short/short_run_right", typeof (Sprite))

Resources.Load is to read files in the Resources folder

Really troublesome, ask unity to come up with a more convenient way.

I believe everyone will encounter this [color=rgb (85,85,85)! important] problem at the beginning.

The task system clicks the Button button and the character executes the move command. The solution is as follows

If (EventSystem.current.IsPointerOverGameObject ())

Debug.Log ("current touch on UI")

Else Debug.Log ("currently no touch on UI")

The above methods of Android phone are invalid, detailed method

Http://forum.[color=rgb(85, 85, 85)! important] unity3d.com/threads/ispointerovereventsystemobject-always-returns-false-on-mobile.265372/

I copied it over:

Void Update ()

{

If (Input.touchCount > 0 & Input.GetTouch (0). Phase = = TouchPhase.Began) {

If (IsPointerOverGameObject (Input.GetTouch (0) .roomId)) {

Debug.Log ("Hit UI, Ignore Touch")

} else {

Debug.Log ("Handle Touch")

}

}

}

Bool IsPointerOverGameObject (int fingerId)

{

EventSystem eventSystem = EventSystem.current

Return (eventSystem.IsPointerOverGameObject (fingerId))

& & eventSystem.currentSelectedGameObject! = null)

}

Event Trigger handles various click-and-drop events

Canvas processing level

Graphic Raycaster handles event responses in sequence. Two canvas components must be used, otherwise a canvas will not respond to mouse events.

Render hierarchy order:

Camera

Softing Layer

Softing order

Ugui knapsack system

X-ray inspection: the components that need to be added to the item itself: Graphic Raycaster, Canvas Group, Canvas, code for moving items

Graphic Raycaster is used to detect mouse rays to determine whether an item has been clicked.

Canvas Group sets the value of the parameter Blocks Raycasts in the code that moves the item. Let event trigger ignore itself so that event trigger can detect the objects in the layer below it, such as parcels or item squares, etc.

Canvas, you can't use Canvas Group without this.

Public void OnBeginDrag (PointerEventData eventData) eventData is what X-ray inspection encounters.

Layermask enables only one layer to receive it.

Insert a graph between two pictures

GameObject button = GameObject.Instantiate (Resources.Load ("button")) as GameObject

Button.transform.parent = transform

Button.transform.localPosition = Vector3.zero

Button.transform.localScale = Vector3.one

GameObject AObj = transform.Find ("A") .gameObject

GameObject BObj = transform.Find ("B") .gameObject

Button.transform.SetSiblingIndex (AObj.transform.GetSiblingIndex ())

Double-click to use items indirectly

The first two methods must be used, otherwise the third method cannot be used properly. OnPointerEnter executes code at the moment of mouse entry. Set blocksRaycasts to false when the mouse ray penetration, and then change the true for the mouse ray again hit the object, and then click on the item.

Public void OnPointerDown (PointerEventData eventData)

{

CanvasGroup.blocksRaycasts = false

}

Public void OnPointerUp (PointerEventData eventData)

{

CanvasGroup.blocksRaycasts = true

}

Public void OnPointerEnter (PointerEventData eventData) {

If (Input.GetMouseButtonDown (1))

{

Code used

}

}

Of course, this method is a little strange, and I found it by accident.. You'd better write one for yourself. Provide the next idea, use bool to determine whether to click the first time, get a delay parameter as the interval between the first click and the second click.

Sliding frame

1. Create an Image named Mask and add ScrollRect and Mask to the Mask.

two。 Create an empty GameObject named ScrollContent in Mask and pull it into ScrollRect's Content. Add control Vertical Layout Group (vertical distribution, automatic processing). But ScrollContent does not automatically expand. Call GetComponent (). SizeDelta in the code to change its width and height dynamically.

3. Create a Prefab that is dynamically added to the ScrollDetails through code.

The Nine Miyagi sliced frame in p_w_picpath is set in the original SpriteEditor.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report