//参数 (物体,开始Alpha,目标alpha, 持续时间,延迟时间,是否仅开启 Alpha 动画, 回调函数) public void StartAlpha(GameObject obj, float fromAlpha, float toAlpha, float timeLength, float delayTime, bool isOpenOnlyType, Action <GameObject> callBackFunc) { if (!isAwake) { Debug.LogError(string.Format("This GameObject({0}) is not activated", this.gameObject.name)); } //obj.transform.SetParent(transform); TweenObjAttribute attribute = isOpenOnlyType ? new TweenObjAttribute(4) : new TweenObjAttribute(moveType, scaleType, rotateType, alphaType, this); attribute.Obj = obj; attribute.FromAlpha = fromAlpha; attribute.ToAlpha = toAlpha; attribute.UpdateTime = 0; attribute.Time = timeLength; attribute.DelayTime = delayTime; attribute.Obj.transform.GetComponent <RectTransform>().anchoredPosition = fromPos; attribute.CallBackFunc = callBackFunc; objAttributeList.Add(attribute); attribute.IsTweening = true; }
private void Update() { //** 自定义物体 动画 if (isTweening && animGameObj) { updateTime += Time.deltaTime; //判断 是否动画完成 if (updateTime - delayTime > time) { StopNormalTween(); } else if (updateTime - delayTime >= 0) { float t = (updateTime - delayTime) / time; UpdateMove(moveType, animGameObj, fromPos, toPos, t); UpdateScale(scaleType, animGameObj, fromScale, toScale, t); UpdateRotate(rotateType, animGameObj, fromRotate, toRotate, t); //UpdateFade(alphaType, animGameObj, fromAlpha, toAlpha, t); } } //** 代码里指定的物体 动画 if (objAttributeList.Count <= 0) { return; } for (int i = 0; i < objAttributeList.Count; i++) { TweenObjAttribute objAttribute = objAttributeList[i]; if (!objAttribute.IsTweening) { continue; } objAttribute.UpdateTime += Time.deltaTime; //判断 是否动画完成 if (objAttribute.UpdateTime - objAttribute.DelayTime > objAttribute.Time) { StopTween(objAttribute); } else if (objAttribute.UpdateTime - objAttribute.DelayTime >= 0) { if (!objAttribute.Obj.activeSelf) { objAttribute.Obj.SetActive(true); } float t = (objAttribute.UpdateTime - objAttribute.DelayTime) / objAttribute.Time; UpdateMove(objAttribute.MoveType, objAttribute.Obj, objAttribute.FromPos, objAttribute.ToPos, t, objAttribute.IsCounterX, objAttribute.IsCounterY, objAttribute.Offset); UpdateScale(objAttribute.ScaleType, objAttribute.Obj, objAttribute.FromScale, objAttribute.ToScale, t); UpdateRotate(objAttribute.RotateType, objAttribute.Obj, objAttribute.FromRotate, objAttribute.ToRotate, t); //UpdateFade(objAttribute.AlphaType, objAttribute.Obj, objAttribute.FromAlpha, objAttribute.ToAlpha, t); } } }
//参数 (物体,开始Pos,目标Pos, 持续时间,延迟时间,是否仅开启移动动画,x曲线是否反轨迹运动,y曲线是否反轨迹运动,回调函) public void StartMove(GameObject obj, Vector3 fromPos, Vector3 toPos, float timeLength, float delayTime, bool isOpenOnlyType, bool isCounterX, bool isCounterY, Action <GameObject> callBackFunc, float offset) { if (!isAwake) { Debug.LogError(string.Format("This GameObject({0}) is not activated", this.gameObject.name)); } //obj.transform.SetParent(transform); TweenObjAttribute attribute = isOpenOnlyType ? new TweenObjAttribute(1) : new TweenObjAttribute(moveType, scaleType, rotateType, alphaType, this); attribute.Obj = obj; //attribute.RectTrans = obj.GetComponent<RectTransform>(); attribute.FromPos = fromPos; attribute.ToPos = toPos; attribute.UpdateTime = 0; attribute.Time = timeLength; attribute.DelayTime = delayTime; //obj.transform.localPosition = fromPos; attribute.IsCounterX = isCounterX; attribute.IsCounterY = isCounterY; attribute.Offset = offset; attribute.CallBackFunc = callBackFunc; objAttributeList.Add(attribute); attribute.IsTweening = true; }
private void StopTween(TweenObjAttribute objManager) { if (objManager.Obj == null) { return; } if (objManager.MoveType != TweenType.None) { objManager.Obj.transform.localPosition = objManager.ToPos; } if (objManager.ScaleType != TweenType.None) { objManager.Obj.transform.localScale = toScale; } if (objManager.RotateType != TweenType.None) { objManager.Obj.transform.localRotation = Quaternion.Euler(toRotate); } //if (objManager.AlphaType != TweenType.None) //{ // AnimatedAlpha g = objManager.Obj.GetComponent<AnimatedAlpha>(); // if (g != null) // { // g.alpha = objManager.ToAlpha; // } //} objManager.IsTweening = false; objManager.UpdateTime = 0; if (objManager.CallBackFunc != null) { objManager.CallBackFunc(objManager.Obj); } objAttributeList.Remove(objManager); }