示例#1
0
    void UpdateModeOutlineItem(bool didHit, RaycastHit hit, Snap snap)
    {
        Vector3?targetPoint = snap != null? snap.snappingPoint : (didHit ? hit.point : (Vector3?)null);

        if (targetPoint.HasValue)
        {
            Vector2 targetPoint2d = new Vector2(targetPoint.Value.x, targetPoint.Value.z);
            if (lockedSnap != null)
            {
                targetPoint2d = Vector2.Dot(targetPoint2d - activeOutlineItem.Start, lockedDirection) * lockedDirection + activeOutlineItem.Start;
            }
            activeOutlineItem.End = targetPoint2d;
            if (Input.GetButtonUp("Target") && !Input.GetButton("LockDirection"))    //create new outline item -- on click
            {
                activeOutlineItem = new OutlineItem(targetPoint2d, targetPoint2d);
                activeOutline.AddShape(activeOutlineItem);
                activeOutline.OnShapeChanged();
            }
        }
        else
        {
            activeOutlineItem.End = activeOutlineItem.Start;
        }

        if (Input.GetKeyUp(KeyCode.C))    //close
        {
            activeOutline.Last().End = activeOutline.First().Start;
            activeOutlineItem      = null; //changes mode to OutlineMode
            activeOutline.Complete = activeOutline.Enclosed = true;
        }
        else if (Input.GetKeyUp(KeyCode.F))
        {
            activeOutline.DropShape(activeOutline.Last());   //remove last segment (still open segment)
            activeOutlineItem      = null;
            activeOutline.Complete = true;
        }
        else if (Input.GetKeyDown(KeyCode.E))
        {
            if (activeOutline.Extrusion == 0)
            {
                activeOutline.Extrusion = 1;
            }
            else if (activeOutline.BothSideExtrusion == true)
            {
                activeOutline.BothSideExtrusion = false;
                activeOutline.Extrusion         = 0;
            }
            else
            {
                activeOutline.BothSideExtrusion = true;
            }
        }

        activeOutline.OnShapeChanged();

        DrawModeOutlineItem(didHit, hit, snap);
    }