To move a control animation for a stroke to a position, you can use thetweenposition, but this can only be used when the position is fixed, and cannot be moved according to the resolution adaptation. Example scenario with NguiExample 1-anchors"For example, let's say" left "is moved to" Top right ", and this effect needs to be achieved regardless of any resolution. The method here is to modifytweenpositionCode to support the transform of the incoming target, which is the control that is also being traced.
Open itTweenPosition.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));
} |
ModifyOnUpdateThe functions are as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
|
protectedOverridevoidOnUpdate (floatFactorBOOLisfinished)
{ 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;
} |
OpenTweenPositionEditor.cs, modifyOninspectorguithe functions are as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21st
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.to); Transform Targetto = Editorguilayout.objectfield ("Or to", Tw.targetto, typeof (Transform), true) as Transform;
if (gui.changed)
{
Nguieditortools.registerundo ("Tween change", TW);
Tw.from = from;
Tw.to = to; tw.sourcefrom = Sourcefrom;
Tw.targetto = Targetto;
Nguitools.setdirty (TW);
}
Drawcommonproperties ();
}
} |
The following configuration can now be seen in the viewer:
Set its "Or fromandOr to, and then run to see the displacement animation as follows:
Usually can useUiplaytweenTo control the animation of the control, but it only supports actions that require interaction, such as click, select, and so on, where you can automatically play the animation when it is joined. Open itAnimationOrTween.cs, for enumerationTriggerAdd one of the enumeration values, as follows:
1
2
3
4
5
6 / td> |
|
public enum trigger
{
onclick,
onenabletrue ,
} |
Open itUIPlayTween.cs, in itsonenableAt the end of the function, add the following code:
1
2
3
4
5
6
7
8
9
|
|
void Onenable ()
{
......
if (trigger = = Trigger.onenabletrue)
{
Play (TRUE);
}
} |
SuchUiplaytweenYou can play the animation directly when you turn it on.
Unity NGUI Displacement Animation for a stroke control