/// <summary> /// 椭圆运动 /// VecA与VecB垂直 /// a和b相等,2D就是一个圆,3D就是一个球 /// </summary> /// <param name="centerPos">中心点</param> /// <param name="vecA">向量A,如果是2D,可以当做x或者y轴,与向量B垂直</param> /// <param name="VecB">向量B,如果是2D,可以当做x或者y轴,与向量A垂直</param> /// <param name="a">向量A长度</param> /// <param name="b">向量B长度</param> /// <param name="t"></param> /// <returns>ActionInterval</returns> public static ActionInterval CCEllipse(this Transform obj, float duration, Vector3 centerPos, Vector3 vecA, Vector3 vecB, float a, float b, float startp = 0, float endp = 1, bool relativeWorld = false) { #if UNITY_EDITOR if (vecA == Vector3.zero) { CCLog.LogError("vecA is zero"); } if (vecB == Vector3.zero) { CCLog.LogError("vecB is zero"); } if ((vecA.x * vecB.x + vecA.y * vecB.y + vecA.z * vecB.z) != 0) { CCLog.LogError("vecA X vecA != 0"); } #endif vecA.Normalize(); vecB.Normalize(); Vector3 p1 = relativeWorld ? obj.position : obj.localPosition; var action = CCActionFloat.Create(duration, startp, endp); action.SetUpdate((t, result) => { var pos = CCActionMath.Ellipse(centerPos, vecA, vecB, a, b, result); if (relativeWorld) { obj.position = pos; } else { obj.localPosition = pos; } }); return(action); }
/// <summary> /// 打印机效果 /// </summary> /// <param name="text"></param> /// <param name="duration"></param> /// <param name="s"></param> /// <returns>ActionInterval</returns> public static ActionInterval CCTextPrint(this Text text, float duration, string s) { var action = CCActionFloat.Create(duration, 0, s.Length); action.SetUpdate((t, result) => { text.text = s.Substring(0, (int)result); }); return(action); }
/// <summary> /// 渐变 /// </summary> /// <param name="graphic"></param> /// <param name="duration"></param> /// <param name="to"></param> /// <returns></returns> public static ActionInterval CCFadeTo(this CanvasGroup canvasGroup, float duration, float to = 1) { to = Mathf.Clamp01(to); var action = CCActionFloat.Create(duration, canvasGroup.alpha, to); action.SetInitFunc(() => { return(canvasGroup.alpha); }); action.SetUpdate((t, result) => { canvasGroup.alpha = result; }); return(action); }
/// <summary> /// 跳数字 /// </summary> /// <param name="text"></param> /// <param name="duration"></param> /// <param name="format"></param> /// <param name="from"></param> /// <param name="to"></param> /// <returns></returns> public static ActionInterval CCNumberTo(this Text text, float duration, string format, float from, float to, string endformat = "") { var action = CCActionFloat.Create(duration, from, to); action.SetUpdate((t, result) => { if (t == 1 && !string.IsNullOrEmpty(endformat)) { text.text = string.Format(endformat, result); } else { text.text = string.Format(format, result); } }); return(action); }
/// <summary> /// image fillAmount /// </summary> /// <param name="img">图片</param> /// <param name="duration">时间</param> /// <param name="startp">起始fillAmount值</param> /// <param name="to">结束fillAmount值</param> /// <returns>IFiniteTimeAction</returns> public static ActionInterval CCFillAmout(this Image img, float duration, float to = 1) { #if UNITY_EDITOR if (img.type != Image.Type.Filled) { CCLog.LogError("image type is not Filled"); } #endif to = Mathf.Clamp01(to); var action = CCActionFloat.Create(duration, img.fillAmount, to); action.SetInitFunc(() => { return(img.fillAmount); }); action.SetUpdate((t, result) => { img.fillAmount = result; }); return(action); }
/// <summary> /// 样条曲线 /// </summary> /// <param name="obj"></param> /// <param name="duration">时间</param> /// <param name="c1">第一个控制点</param> /// <param name="c2">第二个控制点</param> /// <param name="p2">目标</param> /// <param name="relativeWorld">是否是世界坐标</param> /// <returns></returns> public static ActionInterval CCCatmullRoomTo(this Transform obj, float duration, Vector3 c1, Vector3 c2, Vector3 p2, bool relativeWorld = false) { Vector3 p1 = relativeWorld ? obj.position : obj.localPosition; var action = CCActionFloat.Create(duration, 0, 1); action.SetUpdate((t, result) => { var pos = CCActionMath.CatmullRoom(p1, c1, c2, p2, result); if (relativeWorld) { obj.position = pos; } else { obj.localPosition = pos; } }); return(action); }
/// <summary> /// 震动 /// </summary> /// <param name="obj"></param> /// <param name="duration">时间</param> /// <param name="magnitude">震动系数</param> /// <param name="relativeWorld">是否是直接坐标</param> /// <returns>ActionInterval</returns> public static ActionInterval CCShake(this Transform obj, float duration, Vector3 magnitude, bool relativeWorld = false) { Vector3 curpos = relativeWorld ? obj.position : obj.localPosition; var action = CCActionFloat.Create(duration, 0, 1); action.SetInitFunc(() => { return(0); }); action.SetUpdate((t, result) => { var pos = CCActionMath.Shake(magnitude, curpos, result); if (relativeWorld) { obj.position = pos; } else { obj.localPosition = pos; } }); return(action); }