public static GameObject MessageBoxAnimateIn(this RectTransform background, Action endAction = null) { CanvasGroup canvasGroup = background.gameObject.GetOrAdd <CanvasGroup>(); FloatAnimator floatAnimator = background.gameObject.GetOrAdd <FloatAnimator>(); Vector3Animator scaleAnimator = background.gameObject.GetOrAdd <Vector3Animator>(); floatAnimator.StartAnimation(new FloatAnimationData { StartValue = 0.5f, EndValue = 1, Duration = .15f, AnimationMode = BosAnimationMode.Single, EaseType = EaseType.EaseInOutQuad, Target = background.gameObject, OnStart = canvasGroup.UpdateAlphaFunctor(), OnUpdate = canvasGroup.UpdateAlphaTimedFunctor(), OnEnd = canvasGroup.UpdateAlphaFunctor(() => endAction?.Invoke()) }); /* * scaleAnimator.StartAnimation( * background.ConstructScaleAnimationData( * startValue: new Vector3(0.5f, 0.5f, 1f), * endValue: Vector3.one, * duration: .15f, * mode: BosAnimationMode.Single, * easeType: EaseType.EaseInOutQuad, * endAction: () => endAction?.Invoke()) * );*/ return(background.gameObject); }
public static void AnimateModuleToInvisibleState(this FloatAnimator animator, Image image, float duration = 1.0f) { Material imageMaterial = image.material; if (imageMaterial == null) { Debug.LogError($"image: {image.name} doesn't have any material"); return; } int propertyId = Shader.PropertyToID(COLOR_SUM_PROP); animator.StartAnimation(new FloatAnimationData { StartValue = 0.0f, EndValue = 4.0f, Duration = duration, AnimationMode = BosAnimationMode.Single, EaseType = EaseType.EaseInOutQuad, Target = image.gameObject, OnStart = (value, obj) => { imageMaterial.SetFloat(propertyId, value); imageMaterial.SetFloat(ENABLED_PROP, 1.0f); }, OnUpdate = (value, time, obj) => imageMaterial.SetFloat(propertyId, value), OnEnd = (value, obj) => { imageMaterial.SetFloat(propertyId, value); imageMaterial.SetFloat(ENABLED_PROP, 1.0f); } }); }
private IEnumerator MoveInPlaceImpl(MechanicAnimObject mechanicView, TempMechanicInfo info) { yield return(new WaitForSeconds(.2f)); Vector3Animator scaleAnimator = mechanicView.gameObject.GetOrAdd <Vector3Animator>(); Vector2Animator positionAnimator = mechanicView.gameObject.GetOrAdd <Vector2Animator>(); FloatAnimator rotateAnimator = mechanicView.gameObject.GetOrAdd <FloatAnimator>(); RectTransform rectTransform = mechanicView.GetComponent <RectTransform>(); Vector2 startPosition = rectTransform.anchoredPosition; Vector2 endPosition = mechanicView.leftPosition; Vector2AnimationData positionData = new Vector2AnimationData { StartValue = startPosition, EndValue = endPosition, Duration = .3f, EaseType = EaseType.EaseInOutQuad, Target = mechanicView.gameObject, OnStart = rectTransform.UpdatePositionFunctor(), OnUpdate = rectTransform.UpdatePositionTimedFunctor(), OnEnd = rectTransform.UpdatePositionFunctor(() => { Debug.Log($"setup temp mechanic on state => {info.State}"); mechanicView.Setup(info); mechanicViews.Add(mechanicView.TempMechanic.Id, mechanicView); animatedViews.Remove(mechanicView.TempMechanic.Id); }) }; Vector3AnimationData scaleData = new Vector3AnimationData { StartValue = 2f * Vector3.one, EndValue = Vector3.one, Duration = .3f, EaseType = EaseType.EaseInOutQuad, Target = mechanicView.gameObject, OnStart = rectTransform.UpdateScaleFunctor(), OnUpdate = rectTransform.UpdateScaleTimedFunctor(), OnEnd = rectTransform.UpdateScaleFunctor() }; FloatAnimationData rotateData = new FloatAnimationData { StartValue = rectTransform.localRotation.eulerAngles.z, EndValue = 0, Duration = .3f, EaseType = EaseType.EaseInOutQuad, Target = mechanicView.gameObject, OnStart = rectTransform.UpdateZRotation(), OnUpdate = rectTransform.UpdateZRotationTimed(), OnEnd = rectTransform.UpdateZRotation() }; positionAnimator.StartAnimation(positionData); scaleAnimator.StartAnimation(scaleData); rotateAnimator.StartAnimation(rotateData); }
private void CreateAccumulatedText(double val, bool isManual) { if (textPull.HasObject) { float duration = 1; //isManual ? 0.6f : 0.3f; GameObject inst = textPull.UseAtPosition(new Vector2(UnityEngine.Random.Range(0, 330), -353)); //Instantiate(AccumulatedTextPrefab, transform, false); Text txt = inst.GetComponent <Text>(); txt.text = val.ToCurrencyNumber().PrefixedAbbreviation(); RectTransform textTrs = inst.GetComponent <RectTransform>(); float finalDuration = duration + UnityEngine.Random.Range(-.2f, .2f); Vector2Animator vec2Animator = inst.GetComponent <Vector2Animator>(); vec2Animator.StartAnimation(new Vector2AnimationData { StartValue = textTrs.anchoredPosition, EndValue = textTrs.anchoredPosition + Vector2.down * 5 /* + Vector2.up * 60*/, Duration = finalDuration, EaseType = EaseType.EaseInOutQuad, Target = inst, OnStart = textTrs.UpdatePositionFunctor(), OnUpdate = textTrs.UpdatePositionTimedFunctor(), OnEnd = textTrs.UpdatePositionFunctor(() => textPull.Free(inst)) }); FloatAnimator alphaAnimator = inst.GetComponent <FloatAnimator>(); CanvasGroup cg = inst.GetComponent <CanvasGroup>(); alphaAnimator.Stop(); cg.alpha = 1; alphaAnimator.StartAnimation(new FloatAnimationData { Duration = finalDuration * 1.5f, EaseType = EaseType.EaseInOutQuad, StartValue = 1, EndValue = 0, Target = inst, OnStart = cg.UpdateAlphaFunctor(), OnUpdate = cg.UpdateAlphaTimedFunctor(), OnEnd = cg.UpdateAlphaFunctor() }); Vector3Animator v3animator = inst.GetOrAdd <Vector3Animator>(); v3animator.Stop(); v3animator.StartAnimation(textTrs.ConstructScaleAnimationData(Vector3.one * .1f, Vector3.one, finalDuration * 0.5f, BosAnimationMode.Single, EaseType.EaseInOutQuad, () => { v3animator.StartAnimation(textTrs.ConstructScaleAnimationData(Vector3.one, Vector3.one * .1f, finalDuration * 0.5f, BosAnimationMode.Single, EaseType.EaseInOutQuad)); })); //ColorAnimator colorAnimator = inst.GetComponent<ColorAnimator>(); //colorAnimator.StartAnimation(AnimUtils.GetColorAnimData(txt.color, txt.color.ChangeAlpha(0), finalDuration, EaseType.EaseInOutQuad, textTrs)); } }
private void MoveIn() { CanvasGroup canvasGroup = background.GetComponent <CanvasGroup>(); panelColorAnimator.StartAnimation(AnimUtils.GetColorAnimData(panel.color.ChangeAlpha(0), panel.color.ChangeAlpha(.5f), .1f, EaseType.Linear, panel.GetComponent <RectTransform>(), BosAnimationMode.Single, () => { backAlphaAnimator.StartAnimation(new FloatAnimationData { StartValue = 0, EndValue = 1, Duration = 0.15f, AnimationMode = BosAnimationMode.Single, EaseType = EaseType.EaseInOutQuad, Target = background.gameObject, OnStart = canvasGroup.UpdateAlphaFunctor(), OnUpdate = canvasGroup.UpdateAlphaTimedFunctor(), OnEnd = canvasGroup.UpdateAlphaFunctor() }); backScaleAnimator.StartAnimation(background.ConstructScaleAnimationData(new Vector3(1.5f, 1.5f, 1), new Vector3(1, 1, 1), 0.15f, BosAnimationMode.Single, EaseType.EaseInOutQuad)); })); }
public void Setup(string text, float value, int managerId) { descriptionText.text = text; descriptionValueText.text = $"+{(int)(value * 100)}%"; ViewService.Utils.ApplyManagerIcon(managerIcon, Services.GenerationService.GetGetenerator(managerId), true); RectTransform selfTransform = GetComponent <RectTransform>(); Vector2Animator positionAnimator = gameObject.GetOrAdd <Vector2Animator>(); FloatAnimator alphaAnimator = gameObject.GetOrAdd <FloatAnimator>(); const float kDuration = 2.5f; positionAnimator.StartAnimation(new Vector2AnimationData { StartValue = selfTransform.anchoredPosition, EndValue = selfTransform.anchoredPosition + Vector2.up * 250, Duration = kDuration, AnimationMode = BosAnimationMode.Single, EaseType = EaseType.EaseInOutQuad, Target = gameObject, OnStart = selfTransform.UpdatePositionFunctor(), OnUpdate = selfTransform.UpdatePositionTimedFunctor(), OnEnd = selfTransform.UpdatePositionFunctor(), Events = new List <AnimationEvent <Vector2> > { new AnimationEvent <Vector2> { IsValid = (p, t, o) => t >= 0.5f, Mode = AnimationEventMode.Single, OnEvent = (p, t, o) => { alphaAnimator.StartAnimation(new FloatAnimationData { StartValue = 1, EndValue = 0, AnimationMode = BosAnimationMode.Single, Duration = kDuration * .5f, EaseType = EaseType.Linear, Target = gameObject, OnStart = canvasGroup.UpdateAlphaFunctor(), OnUpdate = canvasGroup.UpdateAlphaTimedFunctor(), OnEnd = canvasGroup.UpdateAlphaFunctor(() => { Destroy(gameObject); }) }); } } } }); StartLight(); StartPercentText(); StartArrow(); }
private void SpawnCoinObject(int coin) { GameObject coinObject = Instantiate <GameObject>(coinPrefab); var coinView = coinObject.GetComponent <SplitLinerCoin>(); coinView.CoinText.text = $"+{coin}"; RectTransform coinRectTransform = coinObject.GetComponent <RectTransform>(); coinRectTransform.SetParent(canvasTransform, false); coinRectTransform.anchoredPosition = Services?.ViewService.Utils.WorldPosToCanvasPos(Camera.main, canvas, playerTransform.position) ?? Vector2.zero; FloatAnimator floatAnimator = coinObject.GetComponent <FloatAnimator>(); Vector3Animator vec3Animator = coinObject.GetComponent <Vector3Animator>(); CanvasGroup canvasGroup = coinObject.GetComponent <CanvasGroup>(); FloatAnimationData alphaAnimData = new FloatAnimationData { StartValue = 1, EndValue = 0, Duration = 0.4f, AnimationMode = BosAnimationMode.Single, EaseType = EaseType.EaseInOutQuad, Target = coinObject, OnStart = (v, o) => canvasGroup.alpha = v, OnUpdate = (v, t, o) => canvasGroup.alpha = v, OnEnd = (v, o) => { canvasGroup.alpha = v; Destroy(coinObject); } }; Vector3AnimationData scaleAnimData = new Vector3AnimationData { StartValue = Vector3.one, EndValue = 1.4f * Vector3.one, Duration = 0.3f, AnimationMode = BosAnimationMode.Single, EaseType = EaseType.EaseInOutQuad, Target = coinObject, OnStart = (s, o) => coinRectTransform.localScale = s, OnUpdate = (s, t, o) => coinRectTransform.localScale = s, OnEnd = (s, o) => { coinRectTransform.localScale = s; floatAnimator.StartAnimation(alphaAnimData); } }; vec3Animator.StartAnimation(scaleAnimData); }
private void SpawnPercentText(int count) { GameObject textInstance = Instantiate <GameObject>(percentPrefab); RectTransform textRectTransform = textInstance.GetComponent <RectTransform>(); textRectTransform.SetParent(canvasTransform, false); textRectTransform.anchoredPosition = Services?.ViewService.Utils.WorldPosToCanvasPos(Camera.main, canvas, playerTransform.position) ?? Vector2.zero; TMPro.TextMeshProUGUI txt = textRectTransform.GetComponent <TMPro.TextMeshProUGUI>(); txt.text = $"+{count}%"; FloatAnimator floatAnimator = txt.GetComponent <FloatAnimator>(); Vector3Animator vec3Animator = txt.GetComponent <Vector3Animator>(); FloatAnimationData alphaAnimData = new FloatAnimationData { StartValue = 1, EndValue = 0, Duration = 0.4f, AnimationMode = BosAnimationMode.Single, EaseType = EaseType.EaseInOutQuad, Target = textRectTransform.gameObject, OnStart = (a, o) => { txt.color = new Color(txt.color.r, txt.color.g, txt.color.b, a); }, OnUpdate = (a, t, o) => txt.color = new Color(txt.color.r, txt.color.g, txt.color.b, a), OnEnd = (a, o) => { txt.color = new Color(txt.color.r, txt.color.g, txt.color.b, a); Destroy(textRectTransform.gameObject); } }; Vector3AnimationData scaleAnimData = new Vector3AnimationData { StartValue = Vector3.one, EndValue = 1.4f * Vector3.one, Duration = 0.3f, AnimationMode = BosAnimationMode.Single, EaseType = EaseType.EaseInOutQuad, Target = textRectTransform.gameObject, OnStart = (s, o) => textRectTransform.localScale = s, OnUpdate = (s, t, o) => textRectTransform.localScale = s, OnEnd = (s, o) => { textRectTransform.localScale = s; floatAnimator.StartAnimation(alphaAnimData); } }; vec3Animator.StartAnimation(scaleAnimData); }
private IEnumerator SetupImpl(int elementId) { yield return(new WaitUntil(() => itemList.IsLoaded)); var endValue = GetEndValue(elementId); var scrollData = new FloatAnimationData { StartValue = scrollRect.content.anchoredPosition.y, EndValue = endValue, Duration = 1, AnimationMode = BosAnimationMode.Single, EaseType = EaseType.EaseInOutQuad, Target = scrollRect.gameObject, OnStart = (v, o) => scrollRect.content.anchoredPosition = new Vector2(0, v), OnUpdate = (v, t, o) => scrollRect.content.anchoredPosition = new Vector2(0, v), OnEnd = (v, o) => scrollRect.content.anchoredPosition = new Vector2(0, v), }; animator.StartAnimation(scrollData); }
private IEnumerator SetupImpl(StoreItemSection section) { yield return(new WaitUntil(() => asyncLoader.gameObject.activeSelf && asyncLoader.gameObject.activeInHierarchy)); asyncLoader.ActivateItems(() => { print("activated completed"); var scrollData = new FloatAnimationData { StartValue = scrollRect.verticalNormalizedPosition, EndValue = sectionPoints[section], Duration = GetAnimationInterval(GetDistance(section)), AnimationMode = BosAnimationMode.Single, EaseType = EaseType.EaseInOutQuad, Target = scrollRect.gameObject, OnStart = (v, o) => scrollRect.verticalNormalizedPosition = v, OnUpdate = (v, t, o) => scrollRect.verticalNormalizedPosition = v, OnEnd = (v, o) => scrollRect.verticalNormalizedPosition = v }; animator.StartAnimation(scrollData); }); }
private void AnimateAuditorObject(SecretaryAnimObject mechanicView, Auditor info) { Vector3Animator scaleAnimator = mechanicView.gameObject.GetOrAdd <Vector3Animator>(); Vector2Animator positionAnimator = mechanicView.gameObject.GetOrAdd <Vector2Animator>(); ColorAnimator colorAnimator = mechanicView.gameObject.GetOrAdd <ColorAnimator>(); FloatAnimator rotateAnimator = mechanicView.gameObject.GetOrAdd <FloatAnimator>(); RectTransform rectTransform = mechanicView.GetComponent <RectTransform>(); Image image = mechanicView.GetComponent <Image>(); Vector2 endOffset = Random.insideUnitCircle.normalized * 300; if (endOffset.y < 0) { endOffset.y = -endOffset.y; } Vector2 startPosition = buyButton.GetComponent <RectTransform>().anchoredPosition; Vector2 endPosition = startPosition + endOffset; Vector2AnimationData positionData = new Vector2AnimationData { StartValue = startPosition, EndValue = endPosition, Duration = 0.3f, EaseType = EaseType.EaseInOutQuad, Target = mechanicView.gameObject, OnStart = rectTransform.UpdatePositionFunctor(), OnUpdate = rectTransform.UpdatePositionTimedFunctor(), OnEnd = rectTransform.UpdatePositionFunctor(() => { StartCoroutine(MoveInPlaceImpl(mechanicView, info)); }) }; Vector3AnimationData scaleData = new Vector3AnimationData { StartValue = Vector3.one, EndValue = 2f * Vector3.one, Duration = .3f, EaseType = EaseType.EaseInOutQuad, Target = mechanicView.gameObject, OnStart = rectTransform.UpdateScaleFunctor(), OnUpdate = rectTransform.UpdateScaleTimedFunctor(), OnEnd = rectTransform.UpdateScaleFunctor() }; ColorAnimationData colorData = new ColorAnimationData { StartValue = new Color(1, 1, 1, 0), EndValue = new Color(1, 1, 1, 1), Duration = .1f, EaseType = EaseType.EaseInOutQuad, Target = mechanicView.gameObject, OnStart = image.UpdateColorFunctor(), OnUpdate = image.UpdateColorTimedFunctor(), OnEnd = image.UpdateColorFunctor() }; FloatAnimationData rotateData = new FloatAnimationData { StartValue = 0, EndValue = Random.Range(-40, 40), Duration = .3f, EaseType = EaseType.EaseInOutQuad, Target = mechanicView.gameObject, OnStart = rectTransform.UpdateZRotation(), OnUpdate = rectTransform.UpdateZRotationTimed(), OnEnd = rectTransform.UpdateZRotation() }; positionAnimator.StartAnimation(positionData); scaleAnimator.StartAnimation(scaleData); colorAnimator.StartAnimation(colorData); rotateAnimator.StartAnimation(rotateData); }
private IEnumerator EmitEffectImpl(GameObject prefab, int count, RectTransform startPoint, RectTransform endPoint, string rewardType, int rewardIndex) { float interval = 1; float controlPointLength = 400; for (int i = 0; i < count; i++) { yield return(new WaitForSeconds(0.06f)); GameObject instance = Instantiate <GameObject>(prefab); RectTransform rectTransform = instance.GetComponent <RectTransform>(); rectTransform.SetParent(transform, false); rectTransform.anchoredPosition = startPoint.anchoredPosition; BezierMover mover = instance.GetComponent <BezierMover>(); BezierData bezierData = null; Vector2 diff = endPoint.anchoredPosition - startPoint.anchoredPosition; if (rewardType == "playercash") { bezierData = new BezierData { Interval = interval, Type = BezierType.Quadratic, Target = instance.GetComponent <RectTransformPositionObject>(), Points = new Vector3[] { startPoint.anchoredPosition, diff * 0.5f + diff.normalized.Orthogonal() * UnityEngine.Random.Range(-controlPointLength, 0), endPoint.anchoredPosition }, OnComplete = g => Destroy(g) }; } else if (rewardType == "companycash") { bezierData = new BezierData { Interval = interval, Type = BezierType.Quadratic, Target = instance.GetComponent <RectTransformPositionObject>(), Points = new Vector3[] { startPoint.anchoredPosition, diff * 0.5f + diff.normalized.Orthogonal() * UnityEngine.Random.Range(0, controlPointLength), endPoint.anchoredPosition }, OnComplete = g => Destroy(g) }; } else { bezierData = new BezierData { Interval = interval, Type = BezierType.Quadratic, Target = instance.GetComponent <RectTransformPositionObject>(), Points = new Vector3[] { startPoint.anchoredPosition, diff * 0.5f + diff.normalized.Orthogonal() * UnityEngine.Random.Range(-controlPointLength * 0.5f, controlPointLength * 0.5f), endPoint.anchoredPosition }, OnComplete = g => Destroy(g) }; } mover.Setup(bezierData); ColorAnimator colorAnimator = instance.GetComponent <ColorAnimator>(); colorAnimator.StartAnimation(AnimUtils.GetColorAnimData(new Color(1, 1, 1, 1f), Color.white, 0.3f, EaseType.EaseInOutQuad, rectTransform, BosAnimationMode.Single, () => { colorAnimator.StartAnimation(AnimUtils.GetColorAnimData(Color.white, new Color(1, 1, 1, 1f), 0.4f, EaseType.EaseInOutQuad, rectTransform, BosAnimationMode.Single, () => { })); })); Vector3Animator scaleAnimator = instance.GetComponent <Vector3Animator>(); scaleAnimator.StartAnimation(new Vector3AnimationData { AnimationMode = BosAnimationMode.PingPong, Duration = 0.2f, EaseType = EaseType.EaseInOutQuad, StartValue = new Vector3(1, 1, 1), EndValue = new Vector3(2f, 2f, 1), Target = instance, OnStart = rectTransform.UpdateScaleFunctor(), OnUpdate = rectTransform.UpdateScaleTimedFunctor(), OnEnd = rectTransform.UpdateScaleFunctor() }); FloatAnimator rotationAnimator = instance.GetComponent <FloatAnimator>(); rotationAnimator.StartAnimation(new FloatAnimationData { Duration = interval, AnimationMode = BosAnimationMode.Single, EaseType = EaseType.Linear, StartValue = 0, EndValue = 720, Target = instance, OnStart = rectTransform.UpdateZRotation(), OnUpdate = rectTransform.UpdateZRotationTimed(), OnEnd = rectTransform.UpdateZRotation() }); } yield return(new WaitForSeconds(interval - 0.1f)); CompleteRewardIndex(rewardIndex); }