From 7b081e13ba93c830051bbebaa9c3279c57f863c4 Mon Sep 17 00:00:00 2001 From: dmytro lytovchenko Date: Wed, 26 Jun 2019 03:04:30 +0200 Subject: [PATCH] Lane arrows look better and work --- TLM/TLM/UI/CanvasGUI/WorldSpaceGUI.cs | 10 +- TLM/TLM/UI/SubTools/LaneArrowTool.cs | 278 ++++++++++++++++++-------- 2 files changed, 196 insertions(+), 92 deletions(-) diff --git a/TLM/TLM/UI/CanvasGUI/WorldSpaceGUI.cs b/TLM/TLM/UI/CanvasGUI/WorldSpaceGUI.cs index 0d630f1a9..6d38677b4 100644 --- a/TLM/TLM/UI/CanvasGUI/WorldSpaceGUI.cs +++ b/TLM/TLM/UI/CanvasGUI/WorldSpaceGUI.cs @@ -73,7 +73,7 @@ private void SetupRectTransform(GameObject gameObject, Vector3 pos, Vector2 size var rectTransform = gameObject.GetComponent(); // adjust position from a more natural way to Unity3d Y facing down - pos.y = -(pos.y + size.y); + // pos.y = -(pos.y + size.y); rectTransform.localPosition = pos; rectTransform.localScale = new Vector3(1f, 1f, 1f); @@ -198,14 +198,16 @@ public void HandleInput() { /// public List RaycastMouse() { // Set up the new Pointer Event + var results = new List(); + if (raycaster_ == null) { + return results; + } + var pointerEventData = new PointerEventData(eventSystem_); // Set the Pointer Event Position to that of the mouse position pointerEventData.position = Input.mousePosition; - // Create a list of Raycast Results - var results = new List(); - // Raycast using the Graphics Raycaster and mouse click position raycaster_.Raycast(pointerEventData, results); return results; diff --git a/TLM/TLM/UI/SubTools/LaneArrowTool.cs b/TLM/TLM/UI/SubTools/LaneArrowTool.cs index be62b459e..354dbbf1a 100644 --- a/TLM/TLM/UI/SubTools/LaneArrowTool.cs +++ b/TLM/TLM/UI/SubTools/LaneArrowTool.cs @@ -19,7 +19,12 @@ private enum LaneButtonState { Disabled } - private static WorldSpaceGUI wsGui = null; + private static WorldSpaceGUI wsGui; + + private GameObject btnCurrentControlButton; + private GameObject btnLaneArrowForward; + private GameObject btnLaneArrowLeft; + private GameObject btnLaneArrowRight; public LaneArrowTool(TrafficManagerTool mainTool) : base(mainTool) { } @@ -86,6 +91,7 @@ private void Deselect() { if (wsGui != null) { wsGui.DestroyCanvas(); wsGui = null; + btnLaneArrowLeft = btnLaneArrowRight = btnLaneArrowForward = null; } } @@ -119,11 +125,22 @@ public override void RenderOverlay(RenderManager.CameraInfo cameraInfo) { } } - private const float LANE_GROUP_WIDTH = 11f; - private const float LANE_BUTTON_GAP = 0.7f; - private const float LANE_GROUP_GAP = LANE_BUTTON_GAP * 2f; - private const float LANE_GROUP_HALFSIZE = (LANE_GROUP_WIDTH - LANE_BUTTON_GAP) / 2f; +// private const float LANE_GROUP_WIDTH = 11f; +// private const float LANE_BUTTON_GAP = 0.7f; +// private const float LANE_GROUP_GAP = LANE_BUTTON_GAP * 2f; +// private const float LANE_GROUP_HALFSIZE = (LANE_GROUP_WIDTH - LANE_BUTTON_GAP) / 2f; + + private const float LANE_BUTTON_SIZE = 4f; // control button size, 4x4m + /// + /// Fill canvas with buttons for the clicked segment. + /// The initial state is one lane control button per lane. + /// Clicking that lane button will produce 3 arrow buttons controlling that lane. + /// Clicking another lane button will destroy these 3 and create 3 new arrow buttons. + /// Clicking away, or clicking another segment will hide everything. + /// + /// The most recently clicked segment, will be used to position + /// and rotate the canvas. private void CreateWorldSpaceGUI(NetSegment netSegment) { var nodesBuffer = Singleton.instance.m_nodes.m_buffer; var lanesBuffer = Singleton.instance.m_lanes.m_buffer; @@ -141,7 +158,7 @@ private void CreateWorldSpaceGUI(NetSegment netSegment) { const float UI_FLOAT_HEIGHT = 5f; var adjustFloat = Vector3.up * UI_FLOAT_HEIGHT; - // Adjust UI to the left + // Adjust UI vertically var guiOriginWorldPos = nodesBuffer[SelectedNodeId].m_position + adjustFloat; wsGui = new WorldSpaceGUI(guiOriginWorldPos, rot); @@ -156,9 +173,9 @@ private void CreateWorldSpaceGUI(NetSegment netSegment) { } var isStartNode = geometry.StartNodeId() == SelectedNodeId; - var expectedGuiWidth = (laneList.Count * LANE_GROUP_WIDTH) + - ((laneList.Count - 1) * LANE_GROUP_GAP); - var offset = -expectedGuiWidth / 2f; +// var expectedGuiWidth = (laneList.Count * LANE_GROUP_WIDTH) + +// ((laneList.Count - 1) * LANE_GROUP_GAP); +// var offset = -expectedGuiWidth / 2f; for (var i = 0; i < laneList.Count; i++) { var laneId = laneList[i].laneId; @@ -169,40 +186,52 @@ private void CreateWorldSpaceGUI(NetSegment netSegment) { Flags.removeLaneArrowFlags(laneList[i].laneId); } - // Get position of the editable lane + // Get position of the editable lane var laneEndPosition = lane.m_bezier.Position(isStartNode ? 0f : 1f); - // laneEndPosition.y = 0f; var buttonPositionRot = rotInverse * (laneEndPosition - guiOriginWorldPos); - var buttonPosition = new Vector3(buttonPositionRot.x, buttonPositionRot.z, 0f); - var laneEditButton = wsGui.AddButton(buttonPosition, new Vector2(4f, 4f)); - wsGui.SetButtonSprite(laneEditButton, TextureResources.LaneArrows.GetArrowsSprite(flags)); + // because UI grows up (away from the node), shift it slightly back in by 3 button sizes + // TODO: Get the distance (junction size) from netSegment.Info and step back by that + var buttonPosition = new Vector3(buttonPositionRot.x, + buttonPositionRot.z - LANE_BUTTON_SIZE * 3f, 0f); - /* - // TODO: Here apply LaneButtonState.Disabled if the lane cannot turn there - var forward = (flags & NetLane.Flags.Forward) != 0 ? LaneButtonState.On : LaneButtonState.Off; - var bForward = GuiAddLaneControlForward(offset, forward); - UnityAction clickForward = () => { - OnClickForward(SelectedSegmentId, SelectedNodeId, laneId, isStartNode, bForward); - }; - bForward.GetComponent