Unity NGUI, unityngui
You can useTweenPositionBut this can only be used when the Position is fixed and cannot be moved based on resolution adaptation. Take the Example scenario "Example 1-Anchors" that comes with NGUI as an Example. If you want to move "Left" to "Top Right", you can achieve this regardless of any resolution. The method here is to modifyTweenPositionCode to allow it to pass in the target's Transform, and this target is also the control of the points to be drawn.
OpenTweenPosition. cs, Add the following code:
1 2 3 4 5 6 7 |
|
Public Transform sourceFrom; Public Transform targetTo;
Static public TweenPosition Begin (GameObject go, float duration, Transform targetTo) { Return Begin (go, duration, go. transform. parent. InverseTransformPoint (targetTo. position )); } |
Modify
OnUpdateThe function is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Protected override void OnUpdate (float factor, bool isFinished) { If (sourceFrom! = Null) { From = cachedTransform. parent. InverseTransformPoint (sourceFrom. position ); SourceFrom = null; } If (targetTo! = Null) { To = cachedTransform. parent. InverseTransformPoint (targetTo. position ); TargetTo = null; } Value = from * (1f-factor) + to * factor; } |
Open
TweenPositionEditor. cs, Modify the OnInspectorGUI function as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
Public class TweenPositionEditor: UITweenerEditor { Public override void OnInspectorGUI () { GUILayout. Space (6f ); NGUIEditorTools. SetLabelWidth (120f );
TweenPosition tw = target as TweenPosition; GUI. changed = false;
Vector3 from = EditorGUILayout. Vector3Field ("From", tw. from ); Transform sourceFrom = EditorGUILayout. ObjectField ("Or From", tw. sourceFrom, typeof (Transform), true) as Transform; Vector3 to = EditorGUILayout. Vector3Field ("To", tw. ); Transform targetTo = EditorGUILayout. ObjectField ("Or To", tw.tar getTo, typeof (Transform), true) as Transform;
If (GUI. changed) { NGUIEditorTools. RegisterUndo ("Tween Change", tw ); Tw. from = from; Tw. to =; Tw. sourceFrom = sourceFrom; Tw.tar getTo = targetTo; NGUITools. SetDirty (tw ); }
DrawCommonProperties (); } } |
Now you can see the following configuration in the viewer:
Set "Or From" and "Or To", and then run the command To see the displacement animation, as shown below:
Can be used at ordinary times
UIPlayTweenTo control the animation playback of the control, but it only supports the click, select, and other actions that need to be interacted. Here, when it is enabled, the animation can be automatically played. Open
AnimationOrTween. cs, For enumeration
TriggerAdd an enumerated value as follows:
1 2 3 4 5 6 |
|
Public enum Trigger { OnClick, ...... OnEnableTrue, } |
Open
UIPlayTween. cs, In its
OnEnableAdd the following code to the end of the function:
1 2 3 4 5 6 7 8 9 |
|
Void OnEnable () { ......
If (trigger = Trigger. OnEnableTrue) { Play (true ); } } |
This way
UIPlayTweenYou can directly play the animation when enabling it.
Who has Unity3d login verification implemented using the Ngui control? How should I obtain the Ngui input control value in the source code script? Details
Associate the label of the Input and obtain the text of the label. This is your Input.
How to use code to control NGUI controls such as Button, Lable, and SlicedSprite in Unity3d?
Very easy.
Public UILabel text;
Declaration, and then the script to an object, directly drag the label, and then directly use text. text = "Chinese" When referencing ";
This is the label.
As for the button event, do you want to ask?
Add the script buttonmessage and drag the script with the event to the target. Enter your method name for the function name below.