private void runAnimation(SceneAnimatorObject animation, SceneAnimatorData sad) { // Debug.Log("animate! " +xtarget+"x"+ytarget); _animating = true; CurrentAnimation = animation; if (animation.inScene != null && sad.InObject != null && animation.inScene.gameobject) { // RKLog.Log(animation.inScene.ToString()); // RKLog.Log("SceneAnimator runanimation inscene: " + animation.inScene, "sceneanimator"); SceneLoader.Instance.Show(animation.inScene.State); animation.inScene.gameobject.absolutePosition(new Vector2(sad.InObject.Xfrom, sad.InObject.Yfrom)); beforeTransitionIn(animation.inScene.State); xyid.x = animation.inScene.gameobject.GetComponent <RectTransform>().anchoredPosition.x; xyid.y = animation.inScene.gameobject.GetComponent <RectTransform>().anchoredPosition.y; DOTween.Kill(animation.inScene.gameobject.GetComponent <RectTransform>()); animation.inScene.gameobject.GetComponent <RectTransform>().DOAnchorPos(new Vector2(sad.InObject.Xto, sad.InObject.Yto), animation.speed).OnComplete(completeAnimation).SetEase(animation.ease).OnUpdate(UpdateTween); // RKLog.Log("SceneAnimator runanimation inscene: x" + sad.InObject.Xfrom +" x2: "+ sad.InObject.Xto, "sceneanimator"); //return; if (sad.InObject.ForceToTop) { animation.inScene.gameobject.transform.SetAsLastSibling(); } if (sad.InObject.ScaleFrom != sad.InObject.ScaleTo) { animation.inScene.gameobject.transform.localScale = new Vector2(sad.InObject.ScaleFrom, sad.InObject.ScaleFrom); animation.inScene.gameobject.transform.DOScale(sad.InObject.ScaleTo, animation.speed).SetEase(Ease.OutExpo); } CanvasGroup cg = animation.inScene.gameobject.GetComponent <CanvasGroup>(); if (sad.InObject.AlphaFrom != sad.InObject.AlphaTo) { if (cg) { cg.alpha = sad.InObject.AlphaFrom; cg.DOFade(sad.InObject.AlphaTo, animation.speed); } } else { if (cg) { cg.alpha = 1; } } } else { completeAnimation(); } if (animation.outScene != null && animation.outScene.gameobject != null) { float x = sad.OutObject.Xto; float y = sad.OutObject.Yto; // RKLog.Log("SceneAnimator runanimation outscene: " + animation.outScene, "sceneanimator"); if (sad.OutObject.ForceToTop) { animation.outScene.gameobject.transform.SetAsLastSibling(); } if (animation.inScene == null) { DOTween.Kill(animation.outScene.gameobject.GetComponent <RectTransform>()); animation.outScene.gameobject.GetComponent <RectTransform>().DOAnchorPos(new Vector2(x, y), animation.speed).SetEase(animation.ease).OnComplete(completeAnimation); } else { DOTween.Kill(animation.outScene.gameobject.GetComponent <RectTransform>()); animation.outScene.gameobject.GetComponent <RectTransform>().DOAnchorPos(new Vector2(x, y), animation.speed).SetEase(animation.ease); } if (sad.OutObject.ScaleFrom != sad.OutObject.ScaleTo) { animation.outScene.gameobject.transform.localScale = new Vector2(sad.OutObject.ScaleFrom, sad.OutObject.ScaleFrom); animation.outScene.gameobject.transform.DOScale(sad.OutObject.ScaleTo, animation.speed); } CanvasGroup cg = animation.outScene.gameobject.GetComponent <CanvasGroup>(); if (sad.OutObject.AlphaFrom != sad.OutObject.AlphaTo) { if (cg) { cg.alpha = sad.OutObject.AlphaFrom; cg.DOFade(sad.OutObject.AlphaTo, animation.speed); } } else { if (cg) { cg.alpha = 1; } } } else { completeAnimation(); } }
private void animate() { _height = HelperFunctions.GetHeight((int)width); // Debug.LogError("animate "+ width); // Debug.LogError("animate " + Config.width + " - "+ width); SceneAnimatorObject animation = new SceneAnimatorObject(null, null, SceneAnimator.Animations.LEFT, 0); bool animationFound = false; if (animations.Count > 0) { animation = animations[0]; animationFound = true; //Debug.Log("animate found!"); } else { //Debug.Log("animate not found!"); } if (animationFound) { //Debug.Log("animationfound "+animation.dir); SceneAnimatorData sad = new SceneAnimatorData(); switch (animation.animation) { case Animations.LEFT: sad.InObject.Xto = 0; sad.InObject.Yto = 0; sad.InObject.Xfrom = width; sad.InObject.Yfrom = 0; sad.OutObject.Xto = 0 - width; sad.OutObject.Yto = 0; runAnimation(animation, sad); break; case Animations.RIGHT: sad.InObject.Xto = 0; sad.InObject.Yto = 0; sad.InObject.Xfrom = 0 - width; sad.InObject.Yfrom = 0; sad.OutObject.Xto = width; sad.OutObject.Yto = 0; runAnimation(animation, sad); break; case Animations.UP: sad.InObject.Xto = 0; sad.InObject.Yto = 0; sad.InObject.Xfrom = 0; sad.InObject.Yfrom = 0 - _height; sad.OutObject.Xto = 0; sad.OutObject.Yto = _height; runAnimation(animation, sad); break; case Animations.DOWN: sad.InObject.Xto = 0; sad.InObject.Yto = 0; sad.InObject.Xfrom = 0; sad.InObject.Yfrom = _height; sad.OutObject.Xto = 0; sad.OutObject.Yto = 0 - _height; runAnimation(animation, sad); break; case Animations.SCALEFROMTOP: sad.InObject.AlphaFrom = 0; sad.InObject.AlphaTo = 1; sad.InObject.ScaleFrom = 2; sad.InObject.ScaleTo = 1; sad.InObject.ForceToTop = true; runAnimation(animation, sad); break; case Animations.FADEOUT: sad.OutObject.AlphaFrom = 1; sad.OutObject.AlphaTo = 0; sad.OutObject.ForceToTop = true; runAnimation(animation, sad); break; case Animations.FADEIN: sad.InObject.AlphaFrom = 0; sad.OutObject.AlphaTo = 1; sad.InObject.ForceToTop = true; runAnimation(animation, sad); break; } } }