public void Execute(object data) { Lane targetLane = (Lane)data; RoadPositionRecords.DeleteLanes(new List <Lane> { targetLane }); deleted = targetLane; }
private void Update() { foreach (var g in GameObject.FindGameObjectsWithTag("Road/curveIndicator")) { Destroy(g); } if (radius == 0f) { var l = RoadPositionRecords.QueryClosestCPs3DCurve(input.MousePosition); if (l == null) { return; } Vector3 p = l.ControlPoints.MinBy((Vector3 cp) => (cp - input.MousePosition).magnitude); var indi = GameObject.CreatePrimitive(PrimitiveType.Sphere); indi.transform.position = p; indi.transform.localScale = Vector3.one * 0.3f; indi.tag = "Road/curveIndicator"; } else { var l = stickyMouseSource.StickTo3DCurve(input.MousePosition, out Vector3 out_pos, radius); if (l == null) { return; } foreach (var cp in l.ControlPoints) { var indi = GameObject.CreatePrimitive(PrimitiveType.Sphere); indi.transform.position = cp; indi.transform.localScale = Vector3.one * 0.3f; indi.tag = "Road/curveIndicator"; } } }
public void Undo() { RoadPositionRecords.RestoreLanes(new List <Lane> { deleted }); }
void OnEnable() { if (inputHandler.stickyMouse != null) { UseDefaultStickyMouseForRoad(inputHandler.stickyMouse); } // Init behavior inputHandler.OnClick += delegate(object sender, (Vector3, Curve3DSampler)pos_parent) { if (currentLane == null) { Debug.Log("add new"); Curve currentCurve = null; if (spawnType == typeof(Line)) { currentCurve = Line.GetDefault(); } if (spawnType == typeof(Arc)) { currentCurve = Arc.GetDefault(); } if (spawnType == typeof(Bezier)) { currentCurve = Bezier.GetDefault(); } Function currentFunc = new LinearFunction(); // TODO: Create more currentLane = new Lane(currentCurve, currentFunc); } Vector3 position; Curve3DSampler parentCurve; // which virtual curve does the road under construction belong to? (position, parentCurve) = pos_parent; new PlaceEndingCommand(position).Execute(currentLane); if (currentLane.IsValid) { // Place GetComponent <FollowMouseBehavior>().enabled = false; var placeCmd = new PlaceLaneCommand(); inputHandler.commandSequence.Push(placeCmd); placeCmd.Execute(currentLane); currentLane.SetGameobjVisible(false); currentLane = null; GetComponent <HighLightCtrlPointBehavior>().radius = highlightRadius; UseDefaultStickyMouseForRoad(inputHandler.stickyMouse); } else { // Next ctrl point Pending if (parentCurve != null) { UseSingleVirtualCurveForRoad(parentCurve); } else { UseDefaultStickyMouseForRoad(inputHandler.stickyMouse); } GetComponent <FollowMouseBehavior>().enabled = true; GetComponent <FollowMouseBehavior>().SetTarget(currentLane); GetComponent <HighLightCtrlPointBehavior>().radius = 0f; } }; // Adjust behavior inputHandler.OnDragStart += delegate(object sender, Vector3 position) { Lane targetLane = RoadPositionRecords.QueryClosestCPs3DCurve(position); if (targetLane != null) { GetComponent <FollowMouseBehavior>().enabled = true; currentLane = new Lane(targetLane); GetComponent <FollowMouseBehavior>().SetTarget(currentLane); //replace targetLane with a temporary object (currentLane) var removeCmd = new RemoveLaneCommand(); inputHandler.commandSequence.Push(removeCmd); removeCmd.Execute(targetLane); GetComponent <HighLightCtrlPointBehavior>().radius = 0f; } }; inputHandler.OnDragEnd += delegate(object sender, Vector3 position) { if (currentLane != null) { GetComponent <FollowMouseBehavior>().enabled = false; GetComponent <HighLightCtrlPointBehavior>().radius = highlightRadius; // add actual lane to network var placeCmd = new PlaceLaneCommand(); inputHandler.commandSequence.Push(placeCmd); placeCmd.Execute(currentLane); currentLane.SetGameobjVisible(false); currentLane = null; } }; }
private void Start() { // Init behavior inputHandler.OnClick += delegate(object sender, Vector3 position) { Debug.Log("Onclick"); if (currentLane == null) { Curve currentCurve = null; if (spawnType == typeof(Line)) { currentCurve = Line.GetDefault(); } if (spawnType == typeof(Arc)) { currentCurve = Arc.GetDefault(); } if (spawnType == typeof(Bezier)) { currentCurve = Bezier.GetDefault(); } Function currentFunc = new LinearFunction(); // TODO: Create more currentLane = new Lane(currentCurve, currentFunc); } new PlaceEndingCommand(position).Execute(currentLane); if (currentLane.IsValid) { // Quit Init GetComponent <FollowMouseBehavior>().enabled = false; var placeCmd = new PlaceLaneCommand(); commandSequence.Push(placeCmd); placeCmd.Execute(currentLane); currentLane.SetGameobjVisible(false); currentLane = null; GetComponent <HighLightCtrlPointBehavior>().radius = highlightRadius; } else { // Pending GetComponent <FollowMouseBehavior>().enabled = true; GetComponent <FollowMouseBehavior>().SetTarget(currentLane); GetComponent <HighLightCtrlPointBehavior>().radius = 0f; } }; // Adjust behavior inputHandler.OnDragStart += delegate(object sender, Vector3 position) { Lane targetLane = RoadPositionRecords.QueryClosestCPs3DCurve(position); if (targetLane != null) { GetComponent <FollowMouseBehavior>().enabled = true; currentLane = new Lane(targetLane); GetComponent <FollowMouseBehavior>().SetTarget(currentLane); //replace targetLane with a temporary object (currentLane) var removeCmd = new RemoveLaneCommand(); commandSequence.Push(removeCmd); removeCmd.Execute(targetLane); GetComponent <HighLightCtrlPointBehavior>().radius = 0f; } }; inputHandler.OnDragEnd += delegate(object sender, Vector3 position) { if (currentLane != null) { GetComponent <FollowMouseBehavior>().enabled = false; GetComponent <HighLightCtrlPointBehavior>().radius = highlightRadius; // add actual lane to network var placeCmd = new PlaceLaneCommand(); commandSequence.Push(placeCmd); placeCmd.Execute(currentLane); currentLane.SetGameobjVisible(false); currentLane = null; } }; inputHandler.OnUndoPressed += delegate { var latestCmd = commandSequence.Pop(); latestCmd.Undo(); }; }
public void Execute(object data) { RoadPositionRecords.AddLane((Curve3DSampler)data, out added, out deleted); }
public void Undo() { RoadPositionRecords.DeleteLanes(added); RoadPositionRecords.RestoreLanes(deleted); }