static Tile GetRandomClearTile(int size, int avoidCenterDistance, Tile[,] tiles) { while (true) { var x = Random.Range(1, size - 1); var y = Random.Range(1, size - 1); // Don't return positions too close to the center. var distanceToCenter = ManhattanDistanceFromCenter(x, y, size); if (distanceToCenter < avoidCenterDistance) { continue; } // Don't return positions with an obstacle or pickup that is too close. var someTiles = new[] { tiles[x, y], tiles[x - 1, y], tiles[x + 1, y], tiles[x, y - 1], tiles[x, y + 1] }; if (someTiles.Any(t => t.IsObstacle || t.IsPickup || t.IsRitualPoint)) { continue; } return tiles[x, y]; } }
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); }
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(); // 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(); // 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.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(); }
void Start() { return; Vector3[] path = new[] { new Vector3(0,1,0), new Vector3(1,2,0), new Vector3(2,1,0), new Vector3(2,0,0) }; TweenParams tp = new TweenParams() .SetEase(ease) .SetLoops(-1, loopType); AxisConstraint lockRotation = lockRotation0 | lockRotation1; // Relative VS non relative controller = targets[0].DOPath(path, 3, PathType.CatmullRom, pathMode, pathResolution, pathsColors[0]) .SetOptions(closePaths, lockPosition, lockRotation) .SetLookAt(0.1f, forward) .SetAs(tp) .SetRelative() .Pause(); targets[1].DOPath(path, 3, PathType.CatmullRom, pathMode, pathResolution, pathsColors[1]) .SetOptions(closePaths, lockPosition, lockRotation) .SetLookAt(targets[2], forward) .SetAs(tp) .Pause(); // Linear VS curved targets[2].DOPath(path, 3, PathType.CatmullRom, pathMode, pathResolution, pathsColors[0]) .SetOptions(closePaths, lockPosition, lockRotation) .SetLookAt(new Vector3(3, 0, 0), forward) .SetAs(tp) .SetRelative() .Pause(); targets[3].DOPath(path, 3, PathType.Linear, pathMode, pathResolution, pathsColors[1]) .SetOptions(closePaths, lockPosition, lockRotation) .SetLookAt(0.1f, forward) .SetAs(tp) .SetRelative() .Pause(); // Linear VS curved no lookAt targets[4].DOPath(path, 3, PathType.CatmullRom, pathMode, pathResolution, pathsColors[0]) .SetOptions(closePaths, lockPosition, lockRotation) .SetAs(tp) .SetRelative() .Pause(); targets[5].DOPath(path, 3, PathType.Linear, pathMode, pathResolution, pathsColors[1]) .SetOptions(closePaths, lockPosition, lockRotation) .SetAs(tp) .SetRelative() .Pause(); // Linear VS curved top-down path = new[] { new Vector3(0,0,1), new Vector3(1,0,2), new Vector3(2,0,1), new Vector3(2,0,0) }; targets[6].DOPath(path, 3, PathType.CatmullRom, pathMode, pathResolution, pathsColors[0]) .SetOptions(closePaths, lockPosition, lockRotation) .SetLookAt(0.1f, forward) .SetAs(tp) .SetRelative() .Pause(); targets[7].DOPath(path, 3, PathType.Linear, pathMode, pathResolution, pathsColors[1]) .SetOptions(closePaths, lockPosition, lockRotation) .SetLookAt(0.1f, forward) .SetAs(tp) .SetRelative() .Pause(); // Log lengths controller.ForceInit(); Debug.Log("Controller path length: " + controller.PathLength()); }