public static descr ( int uniqueId ) : LTDescr, | ||
uniqueId | int | |
return | LTDescr, |
public void GoTowards(Vector3 dir, int parentId) { ParentId = parentId; DamageDealer.ParentId = ParentId; if (_moveTwid.HasValue) { LeanTween.cancel(_moveTwid.Value); _moveTwid = null; } var newPos = transform.position + (dir * 50f); _moveTwid = LeanTween.move(gameObject, newPos, 3f).id; LeanTween.descr(_moveTwid.Value).setEase(LeanTweenType.linear); LeanTween.descr(_moveTwid.Value).setOnComplete(() => { LeanTween.cancel(_moveTwid.Value); _moveTwid = null; Destroy(gameObject); }); }
/// <summary> /// Resetting the salad combo /// </summary> /// <param name="status"></param> public void ResetTheCombo(bool status) { if (status) { saladCombo = string.Empty; CustomerLeaves(transform.parent); LTDescr d = LeanTween.descr(leanTweenId); if (d != null) { LeanTween.cancel(leanTweenId); } isAngry = false; } else { waitTimeBarImage.color = angryWaitTimeColor; isAngry = true; } }
public void TweenScale(AnimationDirection direction) { if (gameObject.activeSelf == false || Direction == direction) { return; } float timePassed; float tweenDirection; if (direction == AnimationDirection.Forward) { timePassed = 0f; tweenDirection = 1f; } else { timePassed = Direction == AnimationDirection.None ? 0f : 1f; tweenDirection = -1f; } if (TweenID.HasValue) { var descr = LeanTween.descr(TweenID.Value); if (descr != null && LeanTween.isTweening(TweenID.Value)) { timePassed = descr.passed; } LeanTween.cancel(TweenID.Value); } Direction = direction; TweenID = LeanTween.scale(gameObject, scaleEnd, duration) .setFrom(scaleStart) .setDirection(tweenDirection) .setPassed(timePassed) .setEase(tweenType) .id; }
private void Scroll(float value) { var initialSetting = ScrollRect.verticalNormalizedPosition; // Debug.Log("initialSetting: " + initialSetting + ", value: " + value); var distance = (Mathf.Abs(Mathf.Abs(value) - Mathf.Abs(initialSetting)) * 100) + 50; distance = distance > 100 ? 100 : distance; LeanTweenType easing = LeanTweenType.linear; // scrollTime = (distance / 100); // Debug.Log("scrollTime: " + scrollTime); scrollTime = scrollTimeSlow; if (distance > 60) { easing = LeanTweenType.easeOutCirc; scrollTime = scrollTimeFast; } // Debug.Log("distance: " + distance); if (_scrollAnimationId.HasValue) { LeanTween.cancel(_scrollAnimationId.Value); _scrollAnimationId = null; } _scrollAnimationId = LeanTween.value(gameObject, initialSetting, value, scrollTime).id; LeanTween.descr(_scrollAnimationId.Value).setEase(easing); LeanTween.descr(_scrollAnimationId.Value).setOnUpdate((float val) => { ScrollRect.verticalNormalizedPosition = val; }); LeanTween.descr(_scrollAnimationId.Value).setOnComplete(() => { LeanTween.cancel(_scrollAnimationId.Value); _scrollAnimationId = null; }); }
public void Transition(OverlayTransition overlayTransition, float time = 1f, MiddleTransition onMiddleTransition = null) { if (_animationId.HasValue) { Debug.LogWarning("Overlay Transition in progress."); return; // LeanTween.cancel(_animationId.Value); // _animationId = null; } if (onMiddleTransition != null) { _onMiddleTransition = onMiddleTransition; time = time - 0.1f; } _overlayTransition = overlayTransition; _time = overlayTransition == OverlayTransition.Complete ? (time / 2) : time; var fromColor = GameHiddenOptions.Instance.BlackTransparentColor; var toColor = GameHiddenOptions.Instance.BlackColor; if (overlayTransition == OverlayTransition.Black) { fromColor = GameHiddenOptions.Instance.BlackColor; toColor = GameHiddenOptions.Instance.BlackTransparentColor; } _panel.color = fromColor; _animationId = LeanTween.color( _panel.GetComponent <RectTransform>(), toColor, time ).id; LeanTween.descr(_animationId.Value).setEase(LeanTweenType.linear); LeanTween.descr(_animationId.Value).setOnComplete(OnTransitionEnd); Debug.Log("Play transition"); }
public void TransitionOverlay(bool show = true, bool instant = false, OnTransitionEnd onTransitionEnd = null) { _isFadeIn = show; if (_overlay == null) { return; } if (instant == false) { _onTransitionEnd = onTransitionEnd; _overlay.color = show ? HiddenSettings._.BlackColor : HiddenSettings._.TransparentColor; _fadeAnimationId = LeanTween.color(_overlay.gameObject.GetComponent <RectTransform>(), show ? HiddenSettings._.TransparentColor : HiddenSettings._.BlackColor, _timeBetweenFadings).id; LeanTween.descr(_fadeAnimationId.Value).setEase(LeanTweenType.linear); if (_onTransitionEnd != null) { LeanTween.descr(_fadeAnimationId.Value).setOnComplete(() => { _onTransitionEnd(); }); } return; } _overlay.color = show ? HiddenSettings._.TransparentColor : HiddenSettings._.BlackColor; }
IEnumerator GoDiscardedDeck() { yield return(new WaitForSeconds(Game.Instance.InGameOptions.ByGameSpeed(_goToDiscardedDeckWaitTime))); var position = new Vector3( Game.Instance.InGameOptions.DiscardedDeckTransform.position.x, Game.Instance.InGameOptions.DiscardedDeckTransform.position.y + (Game.Instance.InGameOptions.DeckYAddition * Game.Instance.CardManager.CardsInDescardedDeck), Game.Instance.InGameOptions.DiscardedDeckTransform.position.z ); if (_moveTweenId.HasValue) { LeanTween.cancel(_moveTweenId.Value); _moveTweenId = null; } if (_rotateTweenId.HasValue) { LeanTween.cancel(_rotateTweenId.Value); _rotateTweenId = null; } _moveTweenId = LeanTween.move(gameObject, position, Game.Instance.InGameOptions.ByGameSpeed(_animationTime)).id; LeanTween.descr(_moveTweenId.Value).setOnComplete(() => { LeanTween.cancel(_moveTweenId.Value); _moveTweenId = null; }); _rotateTweenId = LeanTween.rotate(gameObject, Game.Instance.InGameOptions.DiscardedDeckTransform.eulerAngles, Game.Instance.InGameOptions.ByGameSpeed(_animationTime)).setEase(_animationType).id; LeanTween.descr(_rotateTweenId.Value).setOnComplete(() => { LeanTween.cancel(_rotateTweenId.Value); _rotateTweenId = null; }); Game.Instance.CardManager.CardsInDescardedDeck++; CardPlace = CardPlace.InDiscardedDeck; }
public void Windup(float windupTime, AfterWindup afterWindup) { _windupTime = percent.Find(80f, windupTime); _fadeoutTime = percent.Find(20f, windupTime); _originalSpriteAlpha = utils.GetRGBAAlphaValue(Sprite.color.a); _afterWindup = afterWindup; ResetWindup(); if (_maskSliderTweenId.HasValue) { LeanTween.cancel(_maskSliderTweenId.Value); } _maskSliderTweenId = LeanTween.scaleZ(WindupMaskSlider.gameObject, MaskSliderActivePoint, _windupTime).id; LeanTween.descr(_maskSliderTweenId.Value).setEase(LeanTweenType.linear); LeanTween.descr(_maskSliderTweenId.Value).setOnComplete(() => { _maskSliderTweenId = null; ResetWindup(); Show(false, overtime: true); _afterWindup(); }); }
void Start() { // Time.timeScale = 0.25f; LeanTest.timeout = 46f; LeanTest.expected = 56; LeanTween.init(15 + 1200); // add a listener LeanTween.addListener(cube1, 0, eventGameObjectCalled); LeanTest.expect(LeanTween.isTweening() == false, "NOTHING TWEEENING AT BEGINNING"); LeanTest.expect(LeanTween.isTweening(cube1) == false, "OBJECT NOT TWEEENING AT BEGINNING"); LeanTween.scaleX(cube4, 2f, 0f).setOnComplete(() => { LeanTest.expect(cube4.transform.localScale.x == 2f, "TWEENED WITH ZERO TIME"); }); // dispatch event that is received LeanTween.dispatchEvent(0); LeanTest.expect(eventGameObjectWasCalled, "EVENT GAMEOBJECT RECEIVED"); // do not remove listener LeanTest.expect(LeanTween.removeListener(cube2, 0, eventGameObjectCalled) == false, "EVENT GAMEOBJECT NOT REMOVED"); // remove listener LeanTest.expect(LeanTween.removeListener(cube1, 0, eventGameObjectCalled), "EVENT GAMEOBJECT REMOVED"); // add a listener LeanTween.addListener(1, eventGeneralCalled); // dispatch event that is received LeanTween.dispatchEvent(1); LeanTest.expect(eventGeneralWasCalled, "EVENT ALL RECEIVED"); // remove listener LeanTest.expect(LeanTween.removeListener(1, eventGeneralCalled), "EVENT ALL REMOVED"); lt1Id = LeanTween.move(cube1, new Vector3(3f, 2f, 0.5f), 1.1f).id; LeanTween.move(cube2, new Vector3(-3f, -2f, -0.5f), 1.1f); LeanTween.reset(); // Queue up a bunch of tweens, cancel some of them but expect the remainder to finish GameObject[] cubes = new GameObject[99]; int[] tweenIds = new int[cubes.Length]; for (int i = 0; i < cubes.Length; i++) { GameObject c = cubeNamed("cancel" + i); tweenIds[i] = LeanTween.moveX(c, 100f, 1f).id; cubes [i] = c; } int onCompleteCount = 0; LeanTween.delayedCall(cubes[0], 0.2f, () => { for (int i = 0; i < cubes.Length; i++) { if (i % 3 == 0) { LeanTween.cancel(cubes [i]); } else if (i % 3 == 1) { LeanTween.cancel(tweenIds[i]); } else if (i % 3 == 2) { LTDescr descr = LeanTween.descr(tweenIds[i]); // Debug.Log("descr:"+descr); descr.setOnComplete(() => { onCompleteCount++; // Debug.Log("onCompleteCount:"+onCompleteCount); if (onCompleteCount >= 33) { LeanTest.expect(true, "CANCELS DO NOT EFFECT FINISHING"); } }); } } }); Vector3[] splineArr = new Vector3[] { new Vector3(-1f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(4f, 0f, 0f), new Vector3(20f, 0f, 0f), new Vector3(30f, 0f, 0f) }; LTSpline cr = new LTSpline(splineArr); cr.place(cube4.transform, 0.5f); LeanTest.expect((Vector3.Distance(cube4.transform.position, new Vector3(10f, 0f, 0f)) <= 0.7f), "SPLINE POSITIONING AT HALFWAY", "position is:" + cube4.transform.position + " but should be:(10f,0f,0f)"); LeanTween.color(cube4, Color.green, 0.01f); // Debug.Log("Point 2:"+cr.ratioAtPoint(splineArr[2])); // OnStart Speed Test for ignoreTimeScale vs normal timeScale GameObject cubeDest = cubeNamed("cubeDest"); Vector3 cubeDestEnd = new Vector3(100f, 20f, 0f); LeanTween.move(cubeDest, cubeDestEnd, 0.7f); GameObject cubeToTrans = cubeNamed("cubeToTrans"); LeanTween.move(cubeToTrans, cubeDest.transform, 1.2f).setEase(LeanTweenType.easeOutQuad).setOnComplete(() => { LeanTest.expect(cubeToTrans.transform.position == cubeDestEnd, "MOVE TO TRANSFORM WORKS"); }); GameObject cubeDestroy = cubeNamed("cubeDestroy"); LeanTween.moveX(cubeDestroy, 200f, 0.05f).setDelay(0.02f).setDestroyOnComplete(true); LeanTween.moveX(cubeDestroy, 200f, 0.1f).setDestroyOnComplete(true).setOnComplete(() => { LeanTest.expect(true, "TWO DESTROY ON COMPLETE'S SUCCEED"); }); GameObject cubeSpline = cubeNamed("cubeSpline"); LeanTween.moveSpline(cubeSpline, new Vector3[] { new Vector3(0.5f, 0f, 0.5f), new Vector3(0.75f, 0f, 0.75f), new Vector3(1f, 0f, 1f), new Vector3(1f, 0f, 1f) }, 0.1f).setOnComplete(() => { LeanTest.expect(Vector3.Distance(new Vector3(1f, 0f, 1f), cubeSpline.transform.position) < 0.01f, "SPLINE WITH TWO POINTS SUCCEEDS"); }); // This test works when it is positioned last in the test queue (probably worth fixing when you have time) GameObject jumpCube = cubeNamed("jumpTime"); jumpCube.transform.position = new Vector3(100f, 0f, 0f); jumpCube.transform.localScale *= 100f; int jumpTimeId = LeanTween.moveX(jumpCube, 200f, 1f).id; LeanTween.delayedCall(gameObject, 0.2f, () => { LTDescr d = LeanTween.descr(jumpTimeId); float beforeX = jumpCube.transform.position.x; d.setTime(0.5f); LeanTween.delayedCall(0.0f, () => { }).setOnStart(() => { float diffAmt = 1f; // This variable is dependent on a good frame-rate because it evalutes at the next Update beforeX += Time.deltaTime * 100f * 2f; LeanTest.expect(Mathf.Abs(jumpCube.transform.position.x - beforeX) < diffAmt, "CHANGING TIME DOESN'T JUMP AHEAD", "Difference:" + Mathf.Abs(jumpCube.transform.position.x - beforeX) + " beforeX:" + beforeX + " now:" + jumpCube.transform.position.x + " dt:" + Time.deltaTime); }); }); // Tween with time of zero is needs to be set to it's final value GameObject zeroCube = cubeNamed("zeroCube"); LeanTween.moveX(zeroCube, 10f, 0f).setOnComplete(() => { LeanTest.expect(zeroCube.transform.position.x == 10f, "ZERO TIME FINSHES CORRECTLY", "final x:" + zeroCube.transform.position.x); }); // Scale, and OnStart GameObject cubeScale = cubeNamed("cubeScale"); LeanTween.scale(cubeScale, new Vector3(5f, 5f, 5f), 0.01f).setOnStart(() => { LeanTest.expect(true, "ON START WAS CALLED"); }).setOnComplete(() => { LeanTest.expect(cubeScale.transform.localScale.z == 5f, "SCALE", "expected scale z:" + 5f + " returned:" + cubeScale.transform.localScale.z); }); // Rotate GameObject cubeRotate = cubeNamed("cubeRotate"); LeanTween.rotate(cubeRotate, new Vector3(0f, 180f, 0f), 0.02f).setOnComplete(() => { LeanTest.expect(cubeRotate.transform.eulerAngles.y == 180f, "ROTATE", "expected rotate y:" + 180f + " returned:" + cubeRotate.transform.eulerAngles.y); }); // RotateAround GameObject cubeRotateA = cubeNamed("cubeRotateA"); LeanTween.rotateAround(cubeRotateA, Vector3.forward, 90f, 0.3f).setOnComplete(() => { LeanTest.expect(cubeRotateA.transform.eulerAngles.z == 90f, "ROTATE AROUND", "expected rotate z:" + 90f + " returned:" + cubeRotateA.transform.eulerAngles.z); }); // RotateAround 360 GameObject cubeRotateB = cubeNamed("cubeRotateB"); cubeRotateB.transform.position = new Vector3(200f, 10f, 8f); LeanTween.rotateAround(cubeRotateB, Vector3.forward, 360f, 0.3f).setPoint(new Vector3(5f, 3f, 2f)).setOnComplete(() => { LeanTest.expect(cubeRotateB.transform.position.ToString() == (new Vector3(200f, 10f, 8f)).ToString(), "ROTATE AROUND 360", "expected rotate pos:" + (new Vector3(200f, 10f, 8f)) + " returned:" + cubeRotateB.transform.position); }); // Alpha, onUpdate with passing value, onComplete value LeanTween.alpha(cubeAlpha1, 0.5f, 0.1f).setOnUpdate((float val) => { LeanTest.expect(val != 0f, "ON UPDATE VAL"); }).setOnCompleteParam("Hi!").setOnComplete((object completeObj) => { LeanTest.expect(((string)completeObj) == "Hi!", "ONCOMPLETE OBJECT"); LeanTest.expect(cubeAlpha1.GetComponent <Renderer>().material.color.a == 0.5f, "ALPHA"); }); // Color float onStartTime = -1f; LeanTween.color(cubeAlpha2, Color.cyan, 0.3f).setOnComplete(() => { LeanTest.expect(cubeAlpha2.GetComponent <Renderer>().material.color == Color.cyan, "COLOR"); LeanTest.expect(onStartTime >= 0f && onStartTime < Time.time, "ON START", "onStartTime:" + onStartTime + " time:" + Time.time); }).setOnStart(() => { onStartTime = Time.time; }); // moveLocalY (make sure uses y values) Vector3 beforePos = cubeAlpha1.transform.position; LeanTween.moveY(cubeAlpha1, 3f, 0.2f).setOnComplete(() => { LeanTest.expect(cubeAlpha1.transform.position.x == beforePos.x && cubeAlpha1.transform.position.z == beforePos.z, "MOVE Y"); }); Vector3 beforePos2 = cubeAlpha2.transform.localPosition; LeanTween.moveLocalZ(cubeAlpha2, 12f, 0.2f).setOnComplete(() => { LeanTest.expect(cubeAlpha2.transform.localPosition.x == beforePos2.x && cubeAlpha2.transform.localPosition.y == beforePos2.y, "MOVE LOCAL Z", "ax:" + cubeAlpha2.transform.localPosition.x + " bx:" + beforePos.x + " ay:" + cubeAlpha2.transform.localPosition.y + " by:" + beforePos2.y); }); AudioClip audioClip = LeanAudio.createAudio(new AnimationCurve(new Keyframe(0f, 1f, 0f, -1f), new Keyframe(1f, 0f, -1f, 0f)), new AnimationCurve(new Keyframe(0f, 0.001f, 0f, 0f), new Keyframe(1f, 0.001f, 0f, 0f)), LeanAudio.options()); LeanTween.delayedSound(gameObject, audioClip, new Vector3(0f, 0f, 0f), 0.1f).setDelay(0.2f).setOnComplete(() => { LeanTest.expect(Time.time > 0, "DELAYED SOUND"); }); // Easing Methods int totalEasingCheck = 0; int totalEasingCheckSuccess = 0; for (int j = 0; j < 2; j++) { bool isCheckingFrom = j == 1; int totalTweenTypeLength = (int)LeanTweenType.easeShake; for (int i = (int)LeanTweenType.notUsed; i < totalTweenTypeLength; i++) { LeanTweenType easeType = (LeanTweenType)i; GameObject cube = cubeNamed("cube" + easeType); LTDescr descr = LeanTween.moveLocalX(cube, 5, 0.1f).setOnComplete((object obj) => { GameObject cubeIn = obj as GameObject; totalEasingCheck++; if (cubeIn.transform.position.x == 5f) { totalEasingCheckSuccess++; } if (totalEasingCheck == (2 * totalTweenTypeLength)) { LeanTest.expect(totalEasingCheck == totalEasingCheckSuccess, "EASING TYPES"); } }).setOnCompleteParam(cube); if (isCheckingFrom) { descr.setFrom(-5f); } } } // value2 bool value2UpdateCalled = false; LeanTween.value(gameObject, new Vector2(0, 0), new Vector2(256, 96), 0.1f).setOnUpdate((Vector2 value) => { value2UpdateCalled = true; }); LeanTween.delayedCall(0.2f, () => { LeanTest.expect(value2UpdateCalled, "VALUE2 UPDATE"); }); // check descr // LTDescr descr2 = LeanTween.descr( descrId ); // LeanTest.expect(descr2 == null,"DESCRIPTION STARTS AS NULL"); StartCoroutine(timeBasedTesting()); }
public override void Setup() { ctrler = ExperimentController.Instance(); trial = ctrler.Session.CurrentTrial; Cursor.visible = false; reachPrefab = Instantiate(ctrler.GetPrefab("ReachPrefab")); reachPrefab.transform.SetParent(ctrler.transform); reachPrefab.transform.localPosition = Vector3.zero; reachCam = GameObject.Find("ReachCamera"); reachSurface = GameObject.Find("Surface"); waterBowl = GameObject.Find("Bowl"); water = GameObject.Find("Water"); timerIndicator = GameObject.Find("TimerIndicator").GetComponent <TimerIndicator>(); scoreboard = GameObject.Find("Scoreboard").GetComponent <Scoreboard>(); timerIndicator.Timer = ctrler.Session.CurrentBlock.settings.GetFloat("per_block_timerTime"); // Whether or not this is a practice trial // replaces scoreboard with 'Practice Round', doesn't record score trackScore = (ctrler.Session.CurrentBlock.settings.GetBool("per_block_track_score")); if (!trackScore) { // Scoreboard is now updated by the reach class scoreboard.AllowManualSet = true; scoreboard.ScorePrefix = false; scoreboard.ManualScoreText = "Practice Round"; } Enum.TryParse(ctrler.Session.CurrentTrial.settings.GetString("per_block_type"), out MovementType rType); reachType = new MovementType[3]; reachType[2] = rType; maxSteps = 3; // Set up hand and cursor ctrler.CursorController.SetHandVisibility(false); ctrler.CursorController.SetCursorVisibility(true); // Set up the dock position targets[0] = GameObject.Find("Dock"); targets[0].transform.position = ctrler.TargetContainer.transform.position; // Set up the home position targets[1] = GameObject.Find("Home"); targets[1].transform.position = ctrler.TargetContainer.transform.position + ctrler.transform.forward * 0.05f; targets[1].SetActive(false); Home = targets[1]; // Set up the target // Takes a target angle from the list and removes it float targetAngle = Convert.ToSingle(ctrler.PollPseudorandomList("per_block_targetListToUse")); targets[2] = GameObject.Find("Target"); targets[2].transform.rotation = Quaternion.Euler( 0f, -targetAngle + 90f, 0f); targets[2].transform.position = targets[1].transform.position + targets[2].transform.forward.normalized * (trial.settings.GetFloat("per_block_distance") / 100f); // Disable collision detection for nocursor task if (trial.settings.GetString("per_block_type") == "nocursor") { targets[2].GetComponent <BaseTarget>().enabled = false; } targets[2].SetActive(false); Target = targets[2]; // Use static camera for non-vr version if (ctrler.Session.settings.GetString("experiment_mode") == "target") { reachSurface.SetActive(false); reachCam.SetActive(false); ctrler.CursorController.UseVR = true; } else { ctrler.CursorController.SetVRCamera(false); } // sets up the water in the level if (ctrler.Session.CurrentBlock.settings.GetString("per_block_waterPresent") == "wp1") { float waterLevel = Convert.ToSingle(ctrler.PollPseudorandomList("per_block_waterPresent")); waterBowl.SetActive(true); water.SetActive(true); // If previous trial had a water level, animate water level rising/falling from that level try { if (ctrler.Session.PrevTrial.result.ContainsKey("per_block_waterPresent")) { water.transform.localPosition = new Vector3(water.transform.localPosition.x, Convert.ToSingle(ctrler.Session.PrevTrial.result["per_block_waterPresent"]) / 10, water.transform.localPosition.z); id = LeanTween.moveLocalY(water, waterLevel / 10, speed).id; d = LeanTween.descr(id); } else { water.transform.localPosition = new Vector3(0, -0.03f, 0); id = LeanTween.moveLocalY(water, waterLevel / 10, speed).id; d = LeanTween.descr(id); } } catch (NoSuchTrialException e) { water.transform.localPosition = new Vector3(0, -0.03f, 0); id = LeanTween.moveLocalY(water, waterLevel / 10, speed).id; d = LeanTween.descr(id); } } else { waterBowl.SetActive(false); water.SetActive(false); } }
void Start() { LeanTest.timeout = 46f; LeanTest.expected = 35; LeanTween.init(14 + 1200); // add a listener LeanTween.addListener(cube1, 0, eventGameObjectCalled); LeanTest.expect(LeanTween.isTweening() == false, "NOTHING TWEEENING AT BEGINNING"); LeanTest.expect(LeanTween.isTweening(cube1) == false, "OBJECT NOT TWEEENING AT BEGINNING"); LeanTween.scaleX(cube4, 2f, 0f).setOnComplete(() => { LeanTest.expect(cube4.transform.localScale.x == 2f, "TWEENED WITH ZERO TIME"); }); // dispatch event that is received LeanTween.dispatchEvent(0); LeanTest.expect(eventGameObjectWasCalled, "EVENT GAMEOBJECT RECEIVED"); // do not remove listener LeanTest.expect(LeanTween.removeListener(cube2, 0, eventGameObjectCalled) == false, "EVENT GAMEOBJECT NOT REMOVED"); // remove listener LeanTest.expect(LeanTween.removeListener(cube1, 0, eventGameObjectCalled), "EVENT GAMEOBJECT REMOVED"); // add a listener LeanTween.addListener(1, eventGeneralCalled); // dispatch event that is received LeanTween.dispatchEvent(1); LeanTest.expect(eventGeneralWasCalled, "EVENT ALL RECEIVED"); // remove listener LeanTest.expect(LeanTween.removeListener(1, eventGeneralCalled), "EVENT ALL REMOVED"); lt1Id = LeanTween.move(cube1, new Vector3(3f, 2f, 0.5f), 1.1f).id; LeanTween.move(cube2, new Vector3(-3f, -2f, -0.5f), 1.1f); LeanTween.reset(); LTSpline cr = new LTSpline(new Vector3[] { new Vector3(-1f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(4f, 0f, 0f), new Vector3(20f, 0f, 0f), new Vector3(30f, 0f, 0f) }); cr.place(cube4.transform, 0.5f); LeanTest.expect((Vector3.Distance(cube4.transform.position, new Vector3(10f, 0f, 0f)) <= 0.7f), "SPLINE POSITIONING AT HALFWAY", "position is:" + cube4.transform.position + " but should be:(10f,0f,0f)"); LeanTween.color(cube4, Color.green, 0.01f); // OnStart Speed Test for ignoreTimeScale vs normal timeScale GameObject cube = Instantiate(boxNoCollider) as GameObject; cube.name = "normalTimeScale"; // float timeElapsedNormal = Time.time; LeanTween.moveX(cube, 12f, 1f).setIgnoreTimeScale(false).setOnComplete(() => { timeElapsedNormalTimeScale = Time.time; }); LTDescr[] descr = LeanTween.descriptions(cube); LeanTest.expect(descr.Length >= 0 && descr[0].to.x == 12f, "WE CAN RETRIEVE A DESCRIPTION"); cube = Instantiate(boxNoCollider) as GameObject; cube.name = "ignoreTimeScale"; LeanTween.moveX(cube, 5f, 1f).setIgnoreTimeScale(true).setOnComplete(() => { timeElapsedIgnoreTimeScale = Time.time; }); GameObject cubeDest = Instantiate(boxNoCollider) as GameObject; cubeDest.name = "cubeDest"; Vector3 cubeDestEnd = new Vector3(100f, 20f, 0f); LeanTween.move(cubeDest, cubeDestEnd, 0.7f); GameObject cubeToTrans = Instantiate(boxNoCollider) as GameObject; cubeToTrans.name = "cubeToTrans"; LeanTween.move(cubeToTrans, cubeDest.transform, 1.2f).setEase(LeanTweenType.easeOutQuad).setOnComplete(() => { LeanTest.expect(cubeToTrans.transform.position == cubeDestEnd, "MOVE TO TRANSFORM WORKS"); }); GameObject cubeDestroy = Instantiate(boxNoCollider) as GameObject; cubeDestroy.name = "cubeDestroy"; LeanTween.moveX(cubeDestroy, 200f, 0.05f).setDelay(0.02f).setDestroyOnComplete(true); LeanTween.moveX(cubeDestroy, 200f, 0.1f).setDestroyOnComplete(true).setOnComplete(() => { LeanTest.expect(true, "TWO DESTROY ON COMPLETE'S SUCCEED"); }); GameObject cubeSpline = Instantiate(boxNoCollider) as GameObject; cubeSpline.name = "cubeSpline"; LeanTween.moveSpline(cubeSpline, new Vector3[] { new Vector3(0.5f, 0f, 0.5f), new Vector3(0.75f, 0f, 0.75f), new Vector3(1f, 0f, 1f), new Vector3(1f, 0f, 1f) }, 0.1f).setOnComplete(() => { LeanTest.expect(Vector3.Distance(new Vector3(1f, 0f, 1f), cubeSpline.transform.position) < 0.01f, "SPLINE WITH TWO POINTS SUCCEEDS"); }); // This test works when it is positioned last in the test queue (probably worth fixing when you have time) GameObject jumpCube = Instantiate(boxNoCollider) as GameObject; jumpCube.name = "jumpTime"; int jumpTimeId = LeanTween.moveX(jumpCube, 1f, 1f).id; LeanTween.delayedCall(jumpCube, 0.2f, () => { LTDescr d = LeanTween.descr(jumpTimeId); float beforeX = jumpCube.transform.position.x; d.setTime(0.5f); LeanTween.delayedCall(0.01f, () => { }).setOnStart(() => { LeanTest.expect(Mathf.Abs(jumpCube.transform.position.x - beforeX) < 0.01f, "CHANGING TIME DOESN'T JUMP AHEAD", "Difference:" + Mathf.Abs(jumpCube.transform.position.x - beforeX)); }); }); StartCoroutine(timeBasedTesting()); }
void Start() { // Time.timeScale = 0.25f; LeanTest.timeout = 46f; LeanTest.expected = 50; LeanTween.init(15 + 1200); // add a listener LeanTween.addListener(cube1, 0, eventGameObjectCalled); LeanTest.expect(LeanTween.isTweening() == false, "NOTHING TWEEENING AT BEGINNING"); LeanTest.expect(LeanTween.isTweening(cube1) == false, "OBJECT NOT TWEEENING AT BEGINNING"); LeanTween.scaleX(cube4, 2f, 0f).setOnComplete(() => { LeanTest.expect(cube4.transform.localScale.x == 2f, "TWEENED WITH ZERO TIME"); }); // dispatch event that is received LeanTween.dispatchEvent(0); LeanTest.expect(eventGameObjectWasCalled, "EVENT GAMEOBJECT RECEIVED"); // do not remove listener LeanTest.expect(LeanTween.removeListener(cube2, 0, eventGameObjectCalled) == false, "EVENT GAMEOBJECT NOT REMOVED"); // remove listener LeanTest.expect(LeanTween.removeListener(cube1, 0, eventGameObjectCalled), "EVENT GAMEOBJECT REMOVED"); // add a listener LeanTween.addListener(1, eventGeneralCalled); // dispatch event that is received LeanTween.dispatchEvent(1); LeanTest.expect(eventGeneralWasCalled, "EVENT ALL RECEIVED"); // remove listener LeanTest.expect(LeanTween.removeListener(1, eventGeneralCalled), "EVENT ALL REMOVED"); lt1Id = LeanTween.move(cube1, new Vector3(3f, 2f, 0.5f), 1.1f).id; LeanTween.move(cube2, new Vector3(-3f, -2f, -0.5f), 1.1f); LeanTween.reset(); Vector3[] splineArr = new Vector3[] { new Vector3(-1f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(4f, 0f, 0f), new Vector3(20f, 0f, 0f), new Vector3(30f, 0f, 0f) }; LTSpline cr = new LTSpline(splineArr); cr.place(cube4.transform, 0.5f); LeanTest.expect((Vector3.Distance(cube4.transform.position, new Vector3(10f, 0f, 0f)) <= 0.7f), "SPLINE POSITIONING AT HALFWAY", "position is:" + cube4.transform.position + " but should be:(10f,0f,0f)"); LeanTween.color(cube4, Color.green, 0.01f); // Debug.Log("Point 2:"+cr.ratioAtPoint(splineArr[2])); // OnStart Speed Test for ignoreTimeScale vs normal timeScale GameObject cubeDest = cubeNamed("cubeDest"); Vector3 cubeDestEnd = new Vector3(100f, 20f, 0f); LeanTween.move(cubeDest, cubeDestEnd, 0.7f); GameObject cubeToTrans = cubeNamed("cubeToTrans"); LeanTween.move(cubeToTrans, cubeDest.transform, 1.2f).setEase(LeanTweenType.easeOutQuad).setOnComplete(() => { LeanTest.expect(cubeToTrans.transform.position == cubeDestEnd, "MOVE TO TRANSFORM WORKS"); }); GameObject cubeDestroy = cubeNamed("cubeDestroy"); LeanTween.moveX(cubeDestroy, 200f, 0.05f).setDelay(0.02f).setDestroyOnComplete(true); LeanTween.moveX(cubeDestroy, 200f, 0.1f).setDestroyOnComplete(true).setOnComplete(() => { LeanTest.expect(true, "TWO DESTROY ON COMPLETE'S SUCCEED"); }); GameObject cubeSpline = cubeNamed("cubeSpline"); LeanTween.moveSpline(cubeSpline, new Vector3[] { new Vector3(0.5f, 0f, 0.5f), new Vector3(0.75f, 0f, 0.75f), new Vector3(1f, 0f, 1f), new Vector3(1f, 0f, 1f) }, 0.1f).setOnComplete(() => { LeanTest.expect(Vector3.Distance(new Vector3(1f, 0f, 1f), cubeSpline.transform.position) < 0.01f, "SPLINE WITH TWO POINTS SUCCEEDS"); }); // This test works when it is positioned last in the test queue (probably worth fixing when you have time) GameObject jumpCube = cubeNamed("jumpTime"); jumpCube.transform.position = new Vector3(100f, 0f, 0f); jumpCube.transform.localScale *= 100f; int jumpTimeId = LeanTween.moveX(jumpCube, 200f, 1f).id; LeanTween.delayedCall(gameObject, 0.2f, () => { LTDescr d = LeanTween.descr(jumpTimeId); float beforeX = jumpCube.transform.position.x; d.setTime(0.5f); LeanTween.delayedCall(0.0f, () => { }).setOnStart(() => { float diffAmt = 1f; // This variable is dependent on a good frame-rate because it evalutes at the next Update beforeX += Time.deltaTime * 100f * 2f; LeanTest.expect(Mathf.Abs(jumpCube.transform.position.x - beforeX) < diffAmt, "CHANGING TIME DOESN'T JUMP AHEAD", "Difference:" + Mathf.Abs(jumpCube.transform.position.x - beforeX) + " beforeX:" + beforeX + " now:" + jumpCube.transform.position.x + " dt:" + Time.deltaTime); }); }); // Tween with time of zero is needs to be set to it's final value GameObject zeroCube = cubeNamed("zeroCube"); LeanTween.moveX(zeroCube, 10f, 0f).setOnComplete(() => { LeanTest.expect(zeroCube.transform.position.x == 10f, "ZERO TIME FINSHES CORRECTLY", "final x:" + zeroCube.transform.position.x); }); // Scale, and OnStart GameObject cubeScale = cubeNamed("cubeScale"); LeanTween.scale(cubeScale, new Vector3(5f, 5f, 5f), 0.01f).setOnStart(() => { LeanTest.expect(true, "ON START WAS CALLED"); }).setOnComplete(() => { LeanTest.expect(cubeScale.transform.localScale.z == 5f, "SCALE", "expected scale z:" + 5f + " returned:" + cubeScale.transform.localScale.z); }); // Rotate GameObject cubeRotate = cubeNamed("cubeRotate"); LeanTween.rotate(cubeRotate, new Vector3(0f, 180f, 0f), 0.02f).setOnComplete(() => { LeanTest.expect(cubeRotate.transform.eulerAngles.y == 180f, "ROTATE", "expected rotate y:" + 180f + " returned:" + cubeRotate.transform.eulerAngles.y); }); // RotateAround GameObject cubeRotateA = cubeNamed("cubeRotateA"); LeanTween.rotateAround(cubeRotateA, Vector3.forward, 90f, 0.3f).setOnComplete(() => { LeanTest.expect(cubeRotateA.transform.eulerAngles.z == 90f, "ROTATE AROUND", "expected rotate z:" + 90f + " returned:" + cubeRotateA.transform.eulerAngles.z); }); // Alpha, onUpdate with passing value, onComplete value LeanTween.alpha(cubeAlpha1, 0.5f, 0.1f).setOnUpdate((float val) => { LeanTest.expect(val != 0f, "ON UPDATE VAL"); }).setOnCompleteParam("Hi!").setOnComplete((object completeObj) => { LeanTest.expect(((string)completeObj) == "Hi!", "ONCOMPLETE OBJECT"); LeanTest.expect(cubeAlpha1.GetComponent <Renderer>().material.color.a == 0.5f, "ALPHA"); }); // Color float onStartTime = -1f; LeanTween.color(cubeAlpha2, Color.cyan, 0.3f).setOnComplete(() => { LeanTest.expect(cubeAlpha2.GetComponent <Renderer>().material.color == Color.cyan, "COLOR"); LeanTest.expect(onStartTime >= 0f && onStartTime < Time.time, "ON START", "onStartTime:" + onStartTime + " time:" + Time.time); }).setOnStart(() => { onStartTime = Time.time; }); // moveLocalY (make sure uses y values) Vector3 beforePos = cubeAlpha1.transform.position; LeanTween.moveY(cubeAlpha1, 3f, 0.2f).setOnComplete(() => { LeanTest.expect(cubeAlpha1.transform.position.x == beforePos.x && cubeAlpha1.transform.position.z == beforePos.z, "MOVE Y"); }); Vector3 beforePos2 = cubeAlpha2.transform.localPosition; LeanTween.moveLocalZ(cubeAlpha2, 12f, 0.2f).setOnComplete(() => { LeanTest.expect(cubeAlpha2.transform.localPosition.x == beforePos2.x && cubeAlpha2.transform.localPosition.y == beforePos2.y, "MOVE LOCAL Z", "ax:" + cubeAlpha2.transform.localPosition.x + " bx:" + beforePos.x + " ay:" + cubeAlpha2.transform.localPosition.y + " by:" + beforePos2.y); }); AudioClip audioClip = LeanAudio.createAudio(new AnimationCurve(new Keyframe(0f, 1f, 0f, -1f), new Keyframe(1f, 0f, -1f, 0f)), new AnimationCurve(new Keyframe(0f, 0.001f, 0f, 0f), new Keyframe(1f, 0.001f, 0f, 0f)), LeanAudio.options()); LeanTween.delayedSound(gameObject, audioClip, new Vector3(0f, 0f, 0f), 0.1f).setDelay(0.2f).setOnComplete(() => { LeanTest.expect(Time.time > 0, "DELAYED SOUND"); }); StartCoroutine(timeBasedTesting()); }
internal void DisableAppering() { Disappear(); LeanTween.descr(_LTdisappearing).setOnComplete(() => enabled = false); }
void moveNext() { if (route_.Count == 0) { if (prevNode_ != null && prevNode_ != currentNode_) { graph_.GetConnection(prevNode_, currentNode_).SetOnPath(false, false); } moving_ = false; return; } moving_ = true; Node nextNode = route_ [0]; route_.RemoveAt(0); Connection conn = graph_.GetConnection(currentNode_, nextNode); if (conn == null) { Debug.LogError("Trying to move without connection", nextNode); return; } conn.SetOnPath(true, conn.m_Node2 == currentNode_); float routeSpeed = conn.TravelTime * Vector2.Distance(transform.position, nextNode.gameObject.transform.position); //Debug.Log("Setting travel time to: " + routeSpeed); if (conn.m_Type == ConnectionType.Path) { moveTweenId = LeanTween.move(gameObject, nextNode.gameObject.transform, routeSpeed).setEase(LeanTweenType.linear).id; } else { moveTweenId = LeanTween.move(gameObject, nextNode.gameObject.transform, routeSpeed).setEase(LeanTweenType.easeInOutSine).id; } LTDescr d = LeanTween.descr(moveTweenId); // if the tween has already finished it will return null if (d != null) { // change some parameters d.setOnComplete(HandleMovementComplete); } if (prevNode_ != null && currentNode_ != prevNode_) { graph_.GetConnection(prevNode_, currentNode_).SetOnPath(false, false); } prevNode_ = currentNode_; currentNode_ = nextNode; switch (conn.m_Type) { case ConnectionType.Path: vehicleRenderer.sprite = bikeSprite; break; case ConnectionType.Railway: vehicleRenderer.sprite = trainSprite; break; case ConnectionType.Road: vehicleRenderer.sprite = carSprite; break; } disableHighlighted(); highlightRoute(); highlightNeighbours(); }
// Update is called once per frame protected override void Update() { base.Update(); switch (currentStep) { // initlize the scene case 0: ObjectFollowMouse(toolObjects); ToolLookAtBall(); baseObject.GetComponent <Rigidbody>().velocity = Vector3.zero; if (Vector3.Distance(mousePoint, ballObjects.transform.position) <= 0.01f) { Animate(); IncrementStep(); ToolLookAtBall(); } else if (Vector3.Distance(ctrllerPoint, ballObjects.transform.position) <= 0.01f) { Animate(); IncrementStep(); ToolLookAtBall(); } break; // the user triggers the object case 1: ObjectFollowMouse(toolObjects); //Ball follows mouse ObjectFollowMouse(baseObject); d = LeanTween.descr(id); if (d == null) { toolObjects.transform.LookAt(look, toolSpace.transform.up); } pos = toolObjects.transform.position; Vector3 startPos = new Vector3(); Vector3 shotDir = new Vector3(); float time = 0f; //non vr and vr control of the curling if (ctrler.Session.settings.GetString("experiment_mode") == "tool") { if (Vector3.Distance(curlingStone.transform.position, Home.transform.position) > 0.12f) { time += Time.fixedDeltaTime; startPos = mousePoint; } if (Vector3.Distance(curlingStone.transform.position, Home.transform.position) > 0.2f) { shotDir = startPos - mousePoint; shotDir /= time; baseObject.GetComponent <Rigidbody>().AddForce(-shotDir.normalized * FIRE_FORCE); pos = toolObjects.transform.position; IncrementStep(); } } else { if (Vector3.Distance(curlingStone.transform.position, Home.transform.position) > 0.12f) { time += Time.fixedDeltaTime; startPos = ctrllerPoint; } foreach (var device in devices) { UnityEngine.XR.HapticCapabilities capabilities; if (device.TryGetHapticCapabilities(out capabilities)) { if (capabilities.supportsImpulse) { uint channel = 0; float amplitude = 0.2f; float duration = Time.deltaTime; device.SendHapticImpulse(channel, amplitude, duration); } } } if (Vector3.Distance(curlingStone.transform.position, Home.transform.position) > 0.2f) { shotDir = startPos - ctrllerPoint; shotDir /= time; baseObject.GetComponent <Rigidbody>().AddForce(-shotDir.normalized * FIRE_FORCE); pos = toolObjects.transform.position; IncrementStep(); } } break; case 2: toolObjects.transform.position = pos; break; case 3: toolObjects.transform.position = pos; break; } }