// Use this for initialization void Start() { DOTween.defaultAutoPlay = AutoPlay.None; positions = new Vector3[10]; for (int i = 0; i < 5; i++) { positions[i] = new Vector3(0, i, 0); } positions[5] = new Vector3(0, 4, 1); positions[6] = new Vector3(0, 4, 5); positions[7] = new Vector3(0, 5, 3); positions[8] = new Vector3(0, 2, 4); positions[9] = new Vector3(0, 1, 6); obj = GameObject.Find("Cube"); myVector = obj.transform.position; mVector = obj.transform.position; Vector3[] endValues = positions; float[] durations = new[] { 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f }; Vsequence = DOTween.ToArray(() => myVector, x => myVector = x, endValues, durations); sequence = DOTween.ToArray(() => mVector, x => mVector = x, endValues, durations); Vsequence.SetAutoKill(false).SetEase(Ease.Linear); sequence.SetAutoKill(false).SetEase(Ease.Linear); Vsequence.Pause(); sequence.Pause(); }
public static XTween ToArray(LuaFunction getter, LuaFunction setter, Vector3[] to, float[] duration) { return(new XTween(DOTween.ToArray( () => { return (Vector3)getter.call(); }, (v) => { setter.call(v); }, to, duration))); }
void Start() { Vector3[] points = new[] { new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0) }; float[] durations = new[] { 0.5f, 0.5f, 1.5f, 0.5f }; DOTween.ToArray(() => target.position, x => target.localPosition = x, points, durations) // .SetEase(Ease.Linear) .SetRelative() // .SetSpeedBased() .SetEase(Ease.OutQuart) .SetLoops(-1, LoopType.Yoyo) .SetAutoKill(false); }
public static Tweener ToArray(GObject target, Vector3 targetPoint, Vector3[] pathList, float[] durationsList) { return(DOTween.ToArray(() => { if (target != null && !target.isDisposed) { return target.position; } else { return targetPoint; } }, (Vector3 pos) => { if (target != null && !target.isDisposed) { target.position = pos; } }, pathList, durationsList)); }
// Use this for initialization public Drawer(GameObject objPrefab, Track track, float duration) { obj = objPrefab; //send obj to its first place obj.transform.position = track.WfirstPosition.worldPosition; myPosition = obj.transform.position; this.duration = duration; WfirstPosition = track.WfirstPosition; WlastPosition = track.WlastPosition; List <Vector3> positions = new List <Vector3>(); List <float> durations = new List <float>(); //avoid first duration time durations.Add(0.01f); for (int i = 0; i < track.worldPositions.Count; i++) { positions.Add(track.worldPositions[i].worldPosition); if (i != 0) { durations.Add(getDuration(track.worldPositions[i - 1].time.totalTime, track.worldPositions[i].time.totalTime)); } } tweener = DOTween.ToArray(() => myPosition, x => myPosition = x, positions.ToArray(), durations.ToArray()); tweener.SetAutoKill(false).SetEase(Ease.Linear).Pause(); //release positions.Clear(); positions = null; durations.Clear(); durations = null; }
void Start() { DOTween.logBehaviour = LogBehaviour.ErrorsOnly; txtInfo.text = txtInfo.text.Replace("#N", loops.ToString("N0")); // Set RectOffset since it can't be set before rectOffsetToTween = new RectOffset(0, 0, 0, 0); TweenParams tp = new TweenParams(); tp.SetLoops(loops, loopType).SetAutoKill(false); if (ease == Ease.INTERNAL_Custom) { tp.SetEase(easeCurve); } else { tp.SetEase(ease); } // Transform tweens tweens = new Tween[targets.Length - 1]; for (int i = 0; i < targets.Length; ++i) { Transform t = targets[i]; switch (i) { case 0: tweens[i] = DOTween.To(() => t.position, x => t.position = x, new Vector3(0, 5f, 0), 1.5f).SetAs(tp).SetRelative().SetUpdate(true).SetAutoKill(true); break; case 1: // Red cube (rotation) tweens[i] = DOTween.To(() => t.rotation, x => t.rotation = x, toRotation, 1.5f).SetAs(tp).SetRelative(); break; case 2: tweens[i] = DOTween.To(() => t.position, x => t.position = x, new Vector3(0, 5f, 0), 1.5f).SetAs(tp).SetOptions(true).SetRelative().SetAutoKill(true); break; case 3: // Vector3Array (not stored) Vector3[] path = new[] { new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(1, 0, 0), new Vector3(0, -1, 0) }; float[] durations = new[] { 0.5f, 0.5f, 0.5f, 0.5f }; DOTween.ToArray(() => t.position, x => t.position = x, path, durations) .SetAs(tp).SetRelative().Pause(); continue; } Tween tween = tweens[i]; tween.OnStart(() => Debug.Log("OnStart: " + t.name)) .OnPlay(() => Debug.Log("OnPlay: " + t.name)) .OnPause(() => Debug.Log("OnPause: " + t.name)) .OnComplete(() => Debug.Log("OnComplete: " + t.name)) .Pause(); switch (i) { case 0: tween.SetId(intId); // tween.OnStart(()=>tweens[2].Kill()); break; case 1: tween.SetId(stringId); break; case 2: tween.SetId(this); break; } } // Additional tweens ////////////////////////// // Float DOTween.To(() => floatToTween, x => floatToTween = x, 100, 1.5f).SetAs(tp).Pause(); // Double DOTween.To(() => doubleToTween, x => doubleToTween = x, 100, 1.5f).SetAs(tp).Pause(); // Int DOTween.To(() => intToTween, x => intToTween = x, 100, 1.5f).SetAs(tp).Pause(); // Uint DOTween.To(() => uintToTween, x => uintToTween = x, 50, 1.5f).SetAs(tp).Pause(); // Long DOTween.To(() => longToTween, x => longToTween = x, 9223372036854775807L, 1.5f).SetAs(tp).Pause(); // Ulong DOTween.To(() => ulongToTween, x => ulongToTween = x, 18446744073709551615UL, 1.5f).SetAs(tp).Pause(); // Vector2 DOTween.To(() => vector2toTween, x => vector2toTween = x, new Vector2(50, 100), 1.5f).SetAs(tp).Pause(); // Vector4 DOTween.To(() => vector4toTween, x => vector4toTween = x, new Vector4(50, 100, 150, 200), 1.5f).SetAs(tp).Pause(); // Rect DOTween.To(() => rectToTween, x => rectToTween = x, new Rect(10, 20, 50, 100), 1.5f).SetAs(tp).Pause(); // RectOffset DOTween.To(() => rectOffsetToTween, x => rectOffsetToTween = x, new RectOffset(10, 20, 50, 100), 1.5f).SetAs(tp).Pause(); // Color DOTween.To(() => guiTexColor.color, x => guiTexColor.color = x, Color.green, 1.5f).SetAs(tp).Pause(); // Alpha DOTween.ToAlpha(() => guiTexAlpha.color, x => guiTexAlpha.color = x, 0f, 1.5f).SetAs(tp).Pause(); // String DOTween.To(() => stringToTween0, x => stringToTween0 = x, "Hello I'm a new string!", 1.5f).SetAs(tp).Pause(); // String DOTween.To(() => stringToTween1, x => stringToTween1 = x, "Hello I'm a new string!", 1.5f).SetAs(tp).Pause(); // String (relative) DOTween.To(() => stringToTween2, x => stringToTween2 = x, "Hello I'm a new string!", 1.5f).SetAs(tp).SetRelative().Pause(); if (tweenLightAndCam) { // Camera Camera.main.DOColor(toCamColor, 1.5f).SetAs(tp).Pause(); // Light mainLight.DOColor(toLightColor, 1.5f).SetAs(tp).Pause(); mainLight.DOIntensity(4, 1.5f).SetAs(tp).Pause(); } // SpriteRenderer spriteRenderer.DOColor(toSpriteColor, 1.5f).SetAs(tp).Pause(); // Specular material tween specularSphere.GetComponent <Renderer>().material.DOColor(Color.green, "_SpecColor", 1.5f).SetAs(tp).Pause(); // Rotate towards targetToDoLookAt.DOLookAt(specularSphere.transform.position, 1.5f).SetAs(tp).Pause(); targetToDoLookFrom.DOLookAt(specularSphere.transform.position, 1.5f).From().SetAs(tp).Pause(); }
// Use this for initialization public Drawer(GameObject objPrefab, Track track, float duration, bool isCompanion) { obj = objPrefab; //send obj to its first place obj.transform.position = track.WfirstPosition.worldPosition; if (isCompanion) { obj.transform.position += companionHeight; } myPosition = obj.transform.position; //obj.GetComponent<Renderer>().enabled = false; //this.track = track; this.duration = duration; WfirstPosition = track.WfirstPosition; if (isCompanion) { //WfirstPosition.worldPosition += companionHeight; } WlastPosition = track.WlastPosition; if (isCompanion) { // WlastPosition.worldPosition += companionHeight; } List <Vector3> positions = new List <Vector3>(); List <float> durations = new List <float>(); //avoid first duration time durations.Add(0.01f); for (int i = 0; i < track.worldPositions.Count; i++) { if (isCompanion) { positions.Add(track.worldPositions[i].worldPosition + companionHeight); } else { positions.Add(track.worldPositions[i].worldPosition); } if (i != 0) { durations.Add(getDuration(track.worldPositions[i - 1].time.totalTime, track.worldPositions[i].time.totalTime)); //Debug.Log(track.name + ",firstPosition " + track.worldPositions[i - 1].worldPosition + "," + // track.worldPositions[i - 1].time + ",lastPosition " + // track.worldPositions[i].worldPosition + "," + track.worldPositions[i].time+ // ",true time is "+ getDuration(track.worldPositions[i - 1].time.totalTime, track.worldPositions[i].time.totalTime)); } } tweener = DOTween.ToArray(() => myPosition, x => myPosition = x, positions.ToArray(), durations.ToArray()); //tweener = obj.transform.DOPath(positions.ToArray(), duration, PathType.CatmullRom, PathMode.Full3D, 5, null); tweener.SetAutoKill(false).SetEase(Ease.Linear); if (isCompanion) { obj.GetComponent <MeshRenderer>().material.SetColor("_Color", new Color(1, 0, 0, 0)); obj.GetComponent <MeshRenderer>().material.SetColor("_OutlineColor", new Color(3f / 255f, 225f / 255f, 115f / 255f, 0)); } //release positions.Clear(); positions = null; durations.Clear(); durations = null; //this.track.positions.Clear(); //this.track.positions = null; //this.track.worldPositions.Clear(); //this.track.worldPositions = null; }
public static void animVec3CallbackU(DOGetter <Vector3> getter, DOSetter <Vector3> setter, float duration, Vector3 animTo, TweenCallback onUpd, Ease easeType = Ease.Linear) { Vector3[] tempAnim = { animTo }; float[] tempDur = { duration }; DOTween.ToArray(getter, setter, tempAnim, tempDur).SetEase(easeType).SetUpdate(false).OnUpdate(onUpd); }