void SetSwapLR(BezierCreater.BCPoint bp, Vector3 dir) { if (bp.lp == Vector3.zero) { bp.lp = dir; } if (bp.rp == Vector3.zero) { bp.rp = -dir; } if (bp.lp == dir && bp.rp == -dir) { bp.lp = -dir; bp.rp = dir; } else { bp.lp = dir; bp.rp = -dir; } }
void ShowDefault() { BezierCreater bc = target as BezierCreater; bool repaint = false; GUILayout.Label("总长度: " + bc.length); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("标记大小"); float ival = EditorGUILayout.Slider(_capSize, 0.02f, 1f); if (ival != _capSize) { _capSize = ival; repaint = true; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("平滑度"); ival = EditorGUILayout.Slider(_srate, 0.1f, 1f); if (ival != _srate) { _srate = ival; repaint = true; } EditorGUILayout.EndHorizontal(); bool bval = EditorGUILayout.ToggleLeft("位置测试", _showToggleTest, GUILayout.Width(60)); if (bval != _showToggleTest) { _showToggleTest = bval; repaint = true; _cameraRot = Camera.main.transform.rotation.eulerAngles; } if (_showToggleTest) { _cameraRot = EditorGUILayout.Vector3Field("摄像机角度", _cameraRot); _cameraLookAt = EditorGUILayout.ObjectField("观察目标", _cameraLookAt, typeof(Transform), true) as Transform; EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("自动速度"); _showTestAuto = EditorGUILayout.Slider(_showTestAuto, 0, 2); EditorGUILayout.EndHorizontal(); if (_showTestAuto > 0) { SceneView.RepaintAll(); repaint = true; } ival = EditorGUILayout.Slider(_posTest, 0.0f, 1f); if (ival != _posTest) { _posTest = ival; repaint = true; } } bval = EditorGUILayout.ToggleLeft("锁定位置", _isLockPosition); if (bval != _isLockPosition) { _isLockPosition = bval; _lockPosition = bc.transform.position; } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("新路点")) { BezierCreater.BCPoint nbp = new BezierCreater.BCPoint(); bc.bcList.Add(nbp); BCSelectNone(); nbp.selected = true; repaint = true; } if (GUILayout.Button("全选")) { BCSelectNone(); foreach (BezierCreater.BCPoint p in bc.bcList) { p.selected = true; } repaint = true; } if (GUILayout.Button("全不选")) { BCSelectNone(); repaint = true; } EditorGUILayout.EndHorizontal(); int delIdx = -1; int moveUpIdx = -1; int moveDownIdx = -1; for (int i = 0; i < bc.bcList.Count; i++) { Rect rect = EditorGUILayout.BeginHorizontal(); if (bc.bcList[i].selected || bc.bcList[i].selectedlp || bc.bcList[i].selectedrp) { rect.size = new Vector2(rect.size.x, rect.size.y * 2 + 5); EditorGUI.DrawRect(rect, Color.blue); } else { EditorGUI.DrawRect(rect, Color.black); } bool val = EditorGUILayout.ToggleLeft("", bc.bcList[i].selected, GUILayout.Width(15)); if (val != bc.bcList[i].selected) { if (!Event.current.shift) { BCSelectNone(); } bc.bcList[i].selected = val; repaint = true; } Vector3 newpos = EditorGUILayout.Vector3Field("", bc.bcList[i].point); if (newpos != bc.bcList[i].point) { bc.bcList[i].point = newpos; repaint = true; } val = GUILayout.Toggle(bc.bcList[i].locklr, "对称锁定"); if (val != bc.bcList[i].locklr) { bc.bcList[i].locklr = val; bc.bcList[i].rp = -bc.bcList[i].lp; repaint = true; } if (bc.bcList[i].selected || bc.bcList[i].selectedlp || bc.bcList[i].selectedrp) { EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("↑", GUILayout.Width(20))) { moveUpIdx = i; repaint = true; } if (GUILayout.Button("↓", GUILayout.Width(20))) { moveDownIdx = i; repaint = true; } if (GUILayout.Button("无弧度", GUILayout.Width(50))) { bc.bcList[i].lp = Vector3.zero; bc.bcList[i].rp = Vector3.zero; repaint = true; } if (GUILayout.Button("左右", GUILayout.Width(40))) { SetSwapLR(bc.bcList[i], Vector3.left); repaint = true; } if (GUILayout.Button("上下", GUILayout.Width(40))) { SetSwapLR(bc.bcList[i], Vector3.up); repaint = true; } if (GUILayout.Button("前后", GUILayout.Width(40))) { SetSwapLR(bc.bcList[i], Vector3.forward); repaint = true; } if (GUILayout.Button("删除", GUILayout.Width(40))) { if (EditorUtility.DisplayDialog("删除节点", "要删除这个节点吗?", "是", "否")) { BCSelectNone(); delIdx = i; repaint = true; } } if (GUILayout.Button("复制", GUILayout.Width(40))) { BezierCreater.BCPoint nbp = new BezierCreater.BCPoint(); nbp.point = bc.bcList[i].point; bc.bcList.Add(nbp); BCSelectNone(); nbp.selected = true; repaint = true; } } if (i == 0) { bc.bcList[i].lp = Vector3.zero; } if (i == bc.bcList.Count - 1) { bc.bcList[i].rp = Vector3.zero; } EditorGUILayout.EndHorizontal(); } if (moveUpIdx > 0) { BezierCreater.BCPoint bp = bc.bcList[moveUpIdx]; bc.bcList.RemoveAt(moveUpIdx); bc.bcList.Insert(moveUpIdx - 1, bp); } if (moveDownIdx >= 0 && moveDownIdx < bc.bcList.Count - 1) { BezierCreater.BCPoint bp = bc.bcList[moveDownIdx]; bc.bcList.RemoveAt(moveDownIdx); bc.bcList.Insert(moveDownIdx + 1, bp); } if (delIdx >= 0) { bc.bcList.RemoveAt(delIdx); } if (GUILayout.Button("Save")) { repaint = true; } showDefault = EditorGUILayout.Foldout(showDefault, "原始信息"); if (showDefault) { base.DrawDefaultInspector(); } if (repaint) { EditorUtility.SetDirty(target); SceneView.RepaintAll(); ReCalcBezier(); } }