/// <summary> /// 绘制选择对象的控制 /// </summary> /// <param name="i">点对象索引值</param> private void DrawSelectionHandle(TileTarget data, int i) { if (Event.current.button != 0) { return; } MyVector3Int myV3Int = data.TileDataLst[i].MyV3Int; Handles.color = data.Color; var v3Int = myV3Int.ToVector3Int(); var pos = _fromMap.GetPos(v3Int); var pointSize = GetPointSize(myV3Int, data); if (Handles.Button(new Vector3(pos.x, -1f, pos.z), Quaternion.identity, pointSize, pointSize, Handles.SphereHandleCap) && fromMapWindow.DetailReorderableList.index != i) { fromMapWindow.DetailReorderableList.index = i; InternalEditorUtility.RepaintAllViews(); } DrawPointAxisLine(myV3Int, Vector3.right, Color.red, data); DrawPointAxisLine(myV3Int, Vector3.up, Color.green, data); DrawPointAxisLine(myV3Int, Vector3.forward, Color.blue, data); // TODO 报错 //Handles.BeginGUI(); //GUILayout.BeginArea(LabelRect(pos)); //guiStyle.normal.textColor = data.Color; //guiStyle.fontSize = data.IndexFontSize; //GUILayout.Label(new GUIContent(i.ToString(), string.Format("Point {0}\nPosition: {1}", i, myV3Int)), guiStyle); //GUILayout.EndArea(); //Handles.EndGUI(); }
/// <summary> /// 绘制点对象自身的轴 /// </summary> /// <param name="i">索引</param> /// <param name="dir">方向</param> /// <param name="color">颜色</param> private void DrawPointAxisLine(MyVector3Int myV3Int, Vector3 dir, Color color, TileTarget data) { var v3Int = myV3Int.ToVector3Int(); var pos = _fromMap.GetPos(v3Int); Handles.color = color; if (_fromMap.Use_ScreenSize) { Handles.DrawLine(pos, pos + dir * AxisLength * GetPointSize(myV3Int, data)); } else { Handles.DrawLine(pos, pos + dir * AxisLength); } }
/// <summary> /// 根据是否使用屏幕大小,获取点大小 /// </summary> /// <param name="myV3Int">点的位置</param> /// <returns>点的实际大小</returns> private float GetPointSize(MyVector3Int myV3Int, TileTarget data) { float pointSize; var v3Int = myV3Int.ToVector3Int(); var pos = _fromMap.GetPos(v3Int); if (_fromMap.Use_ScreenSize) { pointSize = HandleUtility.GetHandleSize(pos) * data.PointSize; } else { pointSize = data.PointSize; } return(pointSize); }
/// <summary> /// 绘制移动和旋转的控制 /// </summary> /// <param name="i">点对象的索引</param> /// <param name="type">工具类型</param> private void DrawControl(TileTarget data, int i, Tool type) { if (type != Tool.Move && type != Tool.Rotate) { return; } Handles.color = data.Color; EditorGUI.BeginChangeCheck(); var v3Int = data.TileDataLst[i].MyV3Int.ToVector3Int(); Handles.SphereHandleCap(0, _fromMap.GetPos(v3Int), Quaternion.identity, GetPointSize(data.TileDataLst[i].MyV3Int, data), EventType.Repaint); Vector3 newPos = new Vector3(); if (type == Tool.Move) { newPos = Handles.PositionHandle(_fromMap.GetPos(v3Int), Quaternion.identity); } if (EditorGUI.EndChangeCheck()) { if (type == Tool.Move) { MyVector3Int newV3Int = _fromMap.GetMyVector3Int(newPos); if (_fromMap.HasTile(newV3Int)) { return; } Undo.RecordObject(target, "Move Point"); data.TileDataLst[i].MyV3Int = newV3Int; } // 保存 SaveData(); } }