void Update() { var hover = ASUI.MouseOver(UICurve.I.transform as RectTransform) || ASUI.MouseOver(UICamera.I.rectView as RectTransform); if (hover && Input.GetKeyDown(KeyCode.C)) { CopyFrame(); } else if (hover && Input.GetKeyDown(KeyCode.V)) { PasteFrame(); } if (f.toggleIK.isOn || f.toggleIKSingle.isOn) { IKSolve(joints.ToArray()); } else if (f.toggleLockOneSide.isOn || f.toggleLockMirror.isOn) { end = avatar[joints[0]].transform; IKSolve(lockPos1, joints.ToArray()); if (f.toggleLockMirror.isOn) { end = avatar[joints2[0]].transform; IKSolve(lockPos2, joints2.ToArray()); } } else if (f.toggleWeaponIK.isOn) { ExBoneIK(); } }
private void MouseDrag(MB button) { use = true; if (!ASUI.MouseOver(area)) { return; } var deltaV = ASUI.mousePositionRef - oldPos; //deltaV = deltaV.Divide(areaSize); //deltaV = Vector2.Scale(deltaV, new Vector2(rulerLength, 0)); switch (button) { case MB.Left: //lx = ASUI.mousePositionRef.x - area.anchoredPosition.x; //lx = lx / area.rect.width; //lx = Mathf.Clamp01(lx); //frameIdx = (int)startPos.x + Mathf.RoundToInt(lx * rulerLength); break; case MB.Right: break; case MB.Middle: startPos -= deltaV; break; default: throw null; } oldPos = ASUI.mousePositionRef; }
public static void DrawLineOrtho(Vector2 p1, Vector2 p2, Color color, bool clip = true) { //p1 += ASUI.AbsPos(ASUI.owner); //p2 += ASUI.AbsPos(ASUI.owner); //p1 += MathTool.ReverseY(ASUI.owner.anchoredPosition); //p2 += MathTool.ReverseY(ASUI.owner.anchoredPosition); //clip if (clip) { var rect = ASUI.Rect(ASUI.owner); if (LineClip.ClipCohSuth(rect[0], rect[1], ref p1, ref p2) == LineClip.Result.discard) { return; } } //normalize & flip y p1.x /= ASUI.scaler.referenceResolution.x; p1.y = ASUI.scaler.referenceResolution.y - p1.y; p1.y /= ASUI.scaler.referenceResolution.y; p2.x /= ASUI.scaler.referenceResolution.x; p2.y = ASUI.scaler.referenceResolution.y - p2.y; p2.y /= ASUI.scaler.referenceResolution.y; GL.Begin(GL.LINES); GL.Color(color); GL.Vertex(p1); GL.Vertex(p2); GL.End(); }
// 控制粗细的线条实际是画四边形,不一定与坐标轴垂直。 public static void DrawLineWidth(Vector2 p1, Vector2 p2, float width, Color color, bool clip = true) { //p1 += MathTool.ReverseY(ASUI.owner.anchoredPosition); //p2 += MathTool.ReverseY(ASUI.owner.anchoredPosition); //clip if (clip) { var rect = ASUI.Rect(ASUI.owner); if (LineClip.ClipCohSuth(rect[0], rect[1], ref p1, ref p2) == LineClip.Result.discard) { return; } } var v = p2 - p1; var v2 = p1 - p2; width *= 0.5f; var p1a = p1 + new Vector2(-v.y, v.x).normalized *width; var p1b = p1 + new Vector2(v.y, -v.x).normalized *width; var p2a = p2 + new Vector2(-v2.y, v2.x).normalized *width; var p2b = p2 + new Vector2(v2.y, -v2.x).normalized *width; //四边形可能切成更多边形,暂时没做画多边形功能因此暂不裁剪宽度,只裁剪长度 DrawQuads(p1a, p1b, p2a, p2b, color); }
static void SortY(ref Vector2 p1, ref Vector2 p2) { if (p1.y > p2.y) { ASUI.swapPts(ref p1, ref p2); } }
static void SortX(ref Vector2 p1, ref Vector2 p2) { if (p1.x > p2.x) { ASUI.swapPts(ref p1, ref p2); } }
void GetInput() { // var shift = Events.Shift; // var ctrl = Events.Ctrl; // var alt = Events.Alt; var use = false; // over = ASUI.MouseOver(area, ruler); // var simMidDown = Events.MouseDown(MB.Left) && alt; // if ((Events.MouseDown(MB.Middle) || simMidDown) && over) { oldPos = ASUI.mousePositionRef; MouseDown(MB.Middle); middle = true; } // if (Events.MouseDown(MB.Left) && over && !simMidDown) { oldPos = ASUI.mousePositionRef; MouseDown(MB.Left); left = true; } // var simMid = Events.Mouse(MB.Left) && alt; // if (!Events.Mouse(MB.Middle) && !simMid) middle = false; // if (!Events.Mouse(MB.Left) || simMid) left = false; // if (middle) MouseDrag(MB.Middle); // if (left) MouseDrag(MB.Left); float delta = Events.AxisMouseWheel; if (delta != 0 && ASUI.MouseOver(rt, ruler)) { use = true; SIZE.x -= delta * rulerScalerSensitivity; SIZE.x = Mathf.Clamp(SIZE.x, 10, Mathf.Infinity); } frameIdx = frameIdx_KeyHandler.GetInput(frameIdx); if (Events.KeyDown(KeyCode.I)) { if (Events.Alt) { RemoveKey(); } else { InsertKey(); } } if (ASUI.MouseOver(rt) && Events.Mouse1to3) { use = true; } if (use) { Events.Use(); } }
public static Result ClipCohSuth(Vector2 min, Vector2 max, ref Vector2 p1, ref Vector2 p2) { byte code1, code2; bool plotLine = false; Result result = Result.none; float m = 0; int iter = 0; while (result == Result.none && iter < 4)//顶多处理四次 否则出错 { code1 = encode(p1, min, max); code2 = encode(p2, min, max); if (accept(code1, code2)) { result = plotLine ? Result.processed : Result.origin;//是否经过处理(相交) } else { if (reject(code1, code2)) { result = Result.discard;//丢弃 } else { if (inside(code1))//将窗口外的点标为p1 { ASUI.swapPts(ref p1, ref p2); ASUI.swapCodes(ref code1, ref code2); } if (p2.x != p1.x)//使用斜率m来算出线和裁剪边的相交点 { m = (p2.y - p1.y) / (p2.x - p1.x); } if ((code1 & leftBit) != 0) { plotLine = true; p1.y += (min.x - p1.x) * m; p1.x = min.x; } else if ((code1 & rightBit) != 0) { plotLine = true; p1.y += (max.x - p1.x) * m; p1.x = max.x; } else if ((code1 & bottomBit) != 0) { plotLine = true; if (p2.x != p1.x)//只需要为不垂直的线更新p1.x { p1.x += (min.y - p1.y) / m; } p1.y = min.y; } else if ((code1 & topBit) != 0) { plotLine = true; if (p2.x != p1.x) { p1.x += (max.y - p1.y) / m; } p1.y = max.y; } } } iter++; } return(result); }