static void mergeCellsByLocP2(int[] a, int[] b) { SnapGrid aSG = locToSGP2(a); SnapGrid bSG = locToSGP2(b); mergeCells(aSG, bSG); }
void LineAdorner_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (!IsControlModeOn) { if (this.IsMouseCaptured) { CustomLineElement line = this.AdornedElement as CustomLineElement; LineLogicItem lineItem = line.DataContext as LineLogicItem; Point p = SnapGrid.Snap(e.GetPosition(line), gridSize, GridOffsetLeft, GridOffsetTop); if (IsStartPoint) { lineItem.X1 = p.X; lineItem.Y1 = p.Y; } else { lineItem.X2 = p.X; lineItem.Y2 = p.Y; } // update line item modification flag //if (originalLineItem.CheckForModification(lineItem)) // lineItem.IsModified = true; this.InvalidateVisual(); this.ReleaseMouseCapture(); this.Cursor = Cursors.Arrow; } } }
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) { if (this.DataContext is PageItem) { PageItem Page = this.DataContext as PageItem; Point p = SnapGrid.Snap(e.GetPosition(this), GridSize, GridOffsetLeft, GridOffsetTop); if (this.IsMouseCaptured) { if ((currentLineItem.X1 == p.X && currentLineItem.Y1 == p.Y) || (currentLineItem.X1 == currentLineItem.X2 && currentLineItem.Y1 == currentLineItem.Y2)) { Page.Items.Remove(currentLineItem); currentLineItem = null; this.ReleaseMouseCapture(); } else { currentLineItem.X2 = p.X; currentLineItem.Y2 = p.Y; this.ReleaseMouseCapture(); } } } }
//private bool IsControlModeOn = false; Point GetClickLocation(Point p, double offsetLeft, double offsetTop) { return(new Point() { X = SnapGrid.Snap(p.X, GridSizeCreate, offsetLeft), Y = SnapGrid.Snap(p.Y, GridSizeCreate, offsetTop) }); }
void LineAdorner_MouseMove(object sender, MouseEventArgs e) { if (this.IsMouseCaptured) { if (this.AdornedElement.GetType() == typeof(CustomLineElement)) { CustomLineElement line = this.AdornedElement as CustomLineElement; LineLogicItem lineItem = line.DataContext as LineLogicItem; Point p = SnapGrid.Snap(e.GetPosition(line), gridSize, GridOffsetLeft, GridOffsetTop); // edit mode: move line start point OR move line end point if (mode == LineAdornerMode.Edit) { if (IsStartPoint) { lineItem.X1 = p.X; lineItem.Y1 = p.Y; } else { lineItem.X2 = p.X; lineItem.Y2 = p.Y; } } // move mode: move line start point AND move line end point if (mode == LineAdornerMode.Move) { if (IsStartPoint) { double dX = lineItem.X1 - p.X; double dY = lineItem.Y1 - p.Y; Point pEnd = new Point(lineItem.X2 - dX, lineItem.Y2 - dY); lineItem.X1 = p.X; lineItem.Y1 = p.Y; lineItem.X2 = pEnd.X; lineItem.Y2 = pEnd.Y; } else { double dX = lineItem.X2 - p.X; double dY = lineItem.Y2 - p.Y; Point pStart = new Point(lineItem.X1 - dX, lineItem.Y1 - dY); lineItem.X2 = p.X; lineItem.Y2 = p.Y; lineItem.X1 = pStart.X; lineItem.Y1 = pStart.Y; } } this.InvalidateVisual(); } } }
private void Update() { SnapGrid snapGrid = SnapGrid.Instance; if (Vector2.Distance(transform.position, _nextTarget) > 1.5f) { // we have been moved away from where we were UpdatePath(); } }
public static void registerSnapGrid(SnapGrid x, int player) { if (player == 1) { sgs.Add(x); } else { sgsP2.Add(x); } }
protected override void OnMouseMove(MouseEventArgs e) { if (this.DataContext is PageItem) { PageItem Page = this.DataContext as PageItem; Point p = SnapGrid.Snap(e.GetPosition(this), GridSize, GridOffsetLeft, GridOffsetTop); if (this.IsMouseCaptured) { currentLineItem.X2 = p.X; currentLineItem.Y2 = p.Y; } } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); SnapGrid actor = target as SnapGrid; if (actor.snapToGrid) { actor.transform.position = RoundTransform(actor.transform.position, actor.snapValue); } if (actor.sizeToGrid) { actor.transform.localScale = RoundTransform(actor.transform.localScale, actor.sizeValue); } }
//do DFS from s to get list of all reachable SnapGrids. Change material to green color + signal that selected (meaning specific coin can teleport there) public static void selectReachablePipeSegs(SnapGrid s) { List <SnapGrid> explored = new List <SnapGrid>(); Stack <SnapGrid> stack = new Stack <SnapGrid> (); stack.Push(s); while (stack.Count > 0) { SnapGrid n = stack.Pop(); bool nWasExplored = false; foreach (SnapGrid sg in explored) { if ((sg.finalPosition[0] == n.finalPosition[0]) && (sg.finalPosition[1] == n.finalPosition[1])) { nWasExplored = true; } } if (!nWasExplored) { explored.Add(n); if (n.n1 != null) { stack.Push(n.n1); } if (n.n2 != null) { stack.Push(n.n2); } if (n.n3 != null) { stack.Push(n.n3); } if (n.n4 != null) { stack.Push(n.n4); } } } //idea is that now explored is all the reachable SnapGrids--so same connected component foreach (SnapGrid sg in explored) { sg.gameObject.GetComponent <Renderer>().material.color = Color.green; sg.selected = true; } }
public void UpdatePath() { SnapGrid snapGrid = SnapGrid.Instance; Vector2Int startCoord = snapGrid.GetCoordFromCentre(transform.position); Vector2Int endCoord = snapGrid.GetCoordFromCentre(_endTarget); CurrentPath = new LinkedList <Vector2>(); List <Vector2Int> coordList = _pathMgr.FindPath(startCoord, endCoord, _enemyAttack.DPS, _movement.MovementSpeed); if (coordList != null && coordList.Count > 0) { for (int i = 0; i < coordList.Count; ++i) { Vector2 newWaypoint = snapGrid.GetCellCentre(coordList[i]); CurrentPath.AddLast(newWaypoint); } } OnWaypointReached(transform.position); }
public void HandleObjectsInteraction(GameObject clickedGo, Vector3 point) { // build stuff, check if clicked snapgrid SnapGrid clickedGrid = clickedGo.GetComponent <SnapGrid>(); if (clickedGrid) { ClearSelection(); if (!chosenPrefabToBuild) // leave if there is no prefab { return; // #todo: need to add some ui action like choose } // check if can build, and build if (CanBuildIt(chosenPrefabToBuild.GetComponent <PlaceableObject>())) { gameData.resources = gameData.resources - chosenPrefabToBuild.GetComponent <PlaceableObject>().cost; PlaceObjectWithParams(chosenPrefabToBuild, point, Quaternion.identity); } EnterBuildMode(); } // for interaction with anything, like.. Building? ClickableObject clickableGo = clickedGo.GetComponent <ClickableObject>(); if (clickableGo) { PlaceableObject clickedBuilding = clickableGo.GetComponent <PlaceableObject>(); if (clickedBuilding) { selectedGO = clickableGo.gameObject; // set clicked go as selected EnableBuildingSelectionFrameTo(selectedGO); ExitBuildMode(); } clickableGo.OnClick(); } }
//links a to b (not viceversa) static void mergeCellsDir(SnapGrid a, SnapGrid b) { if (a.n1 == null) { a.n1 = b; return; } if (a.n2 == null) { a.n2 = b; return; } if (a.n3 == null) { a.n3 = b; return; } if (a.n4 == null) { a.n4 = b; return; } }
private void Thumb_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) { var item = (sender as FrameworkElement).DataContext as Item; if (item is LineLogicItem) { // ILine line = item as ILine; } else if (item is DataBlockLogicItem) { SnapDataBlockLogicItem(item, e.HorizontalChange, e.VerticalChange, DataBlockSnapMode.Auto); //item.IsModified = true; } else { double left = item.X + e.HorizontalChange; double top = item.Y + e.VerticalChange; item.X = SnapGrid.Snap(left, GridSize, GridOffsetLeft); item.Y = SnapGrid.Snap(top, GridSize, GridOffsetTop); //item.IsModified = true; } }
private void Awake() { grid = FindObjectOfType <SnapGrid>(); rb = transform.GetComponent <Rigidbody>(); }
void LineAdorner_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (Keyboard.Modifiers == ModifierKeys.Control) { IsControlModeOn = true; } CustomLineElement line = this.AdornedElement as CustomLineElement; LineLogicItem lineItem = line.DataContext as LineLogicItem; Point p = SnapGrid.Snap(e.GetPosition(line), GridSize, GridOffsetLeft, GridOffsetTop); double dStart = 0.0; double dEnd = 0.0; if (!this.IsMouseCaptured) { // copy original coordinates originalLineItem = new LineLogicItem() { X1 = lineItem.X1, Y1 = lineItem.Y1, X2 = lineItem.X2, Y2 = lineItem.Y2 }; // calculate start/end point coordinates dStart = Math.Sqrt(Math.Pow(lineItem.X1 - p.X, 2) + Math.Pow(lineItem.Y1 - p.Y, 2)); dEnd = Math.Sqrt(Math.Pow(lineItem.X2 - p.X, 2) + Math.Pow(lineItem.Y2 - p.Y, 2)); } if (IsControlModeOn) { if (this.IsMouseCaptured) { if (IsStartPoint) { lineItem.X1 = p.X; lineItem.Y1 = p.Y; } else { lineItem.X2 = p.X; lineItem.Y2 = p.Y; } this.InvalidateVisual(); this.ReleaseMouseCapture(); IsControlModeOn = false; } else { IsStartPoint = dStart < dEnd ? true : false; this.Cursor = Cursors.Hand; this.InvalidateVisual(); this.CaptureMouse(); } } else { if (!this.IsMouseCaptured) { IsStartPoint = dStart < dEnd ? true : false; this.Cursor = Cursors.Hand; this.InvalidateVisual(); this.CaptureMouse(); } } }
internal override void CalculateNewSprite() { base.CalculateNewSprite(); var(n, nl) = MatchingWall(SnapGrid.GetInDir(Direction.North)); var(ne, nel) = MatchingWall(SnapGrid.GetInDir(Direction.NorthEast)); var(e, el) = MatchingWall(SnapGrid.GetInDir(Direction.East)); var(se, sel) = MatchingWall(SnapGrid.GetInDir(Direction.SouthEast)); var(s, sl) = MatchingWall(SnapGrid.GetInDir(Direction.South)); var(sw, swl) = MatchingWall(SnapGrid.GetInDir(Direction.SouthWest)); var(w, wl) = MatchingWall(SnapGrid.GetInDir(Direction.West)); var(nw, nwl) = MatchingWall(SnapGrid.GetInDir(Direction.NorthWest)); // ReSharper disable InconsistentNaming var cornerNE = CornerFill.None; var cornerSE = CornerFill.None; var cornerSW = CornerFill.None; var cornerNW = CornerFill.None; var lowCornerNE = CornerFill.None; var lowCornerSE = CornerFill.None; var lowCornerSW = CornerFill.None; var lowCornerNW = CornerFill.None; // ReSharper restore InconsistentNaming if (n) { cornerNE |= CornerFill.CounterClockwise; cornerNW |= CornerFill.Clockwise; if (!nl) { lowCornerNE |= CornerFill.CounterClockwise; lowCornerNW |= CornerFill.Clockwise; } } if (ne) { cornerNE |= CornerFill.Diagonal; if (!nel && (nl || el || n && e)) { lowCornerNE |= CornerFill.Diagonal; } } if (e) { cornerNE |= CornerFill.Clockwise; cornerSE |= CornerFill.CounterClockwise; if (!el) { lowCornerNE |= CornerFill.Clockwise; lowCornerSE |= CornerFill.CounterClockwise; } } if (se) { cornerSE |= CornerFill.Diagonal; if (!sel && (sl || el || s && e)) { lowCornerSE |= CornerFill.Diagonal; } } if (s) { cornerSE |= CornerFill.Clockwise; cornerSW |= CornerFill.CounterClockwise; if (!sl) { lowCornerSE |= CornerFill.Clockwise; lowCornerSW |= CornerFill.CounterClockwise; } } if (sw) { cornerSW |= CornerFill.Diagonal; if (!swl && (sl || wl || s && w)) { lowCornerSW |= CornerFill.Diagonal; } } if (w) { cornerSW |= CornerFill.Clockwise; cornerNW |= CornerFill.CounterClockwise; if (!wl) { lowCornerSW |= CornerFill.Clockwise; lowCornerNW |= CornerFill.CounterClockwise; } } if (nw) { cornerNW |= CornerFill.Diagonal; if (!nwl && (nl || wl || n && w)) { lowCornerNW |= CornerFill.Diagonal; } } Sprite.LayerSetState(CornerLayers.NE, $"{StateBase}{(int) cornerNE}"); Sprite.LayerSetState(CornerLayers.SE, $"{StateBase}{(int) cornerSE}"); Sprite.LayerSetState(CornerLayers.SW, $"{StateBase}{(int) cornerSW}"); Sprite.LayerSetState(CornerLayers.NW, $"{StateBase}{(int) cornerNW}"); Sprite.LayerSetState(OverCornerLayers.NE, $"{StateBase}over_{(int) lowCornerNE}"); Sprite.LayerSetState(OverCornerLayers.SE, $"{StateBase}over_{(int) lowCornerSE}"); Sprite.LayerSetState(OverCornerLayers.SW, $"{StateBase}over_{(int) lowCornerSW}"); Sprite.LayerSetState(OverCornerLayers.NW, $"{StateBase}over_{(int) lowCornerNW}"); LastCornerNE = cornerNE; LastCornerSE = cornerSE; LastCornerSW = cornerSW; LastCornerNW = cornerNW; foreach (var entity in SnapGrid.GetLocal()) { if (entity.TryGetComponent(out WindowComponent window)) { window.UpdateSprite(); } } }
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { if (this.DataContext is PageItem) { //if (Keyboard.Modifiers == ModifierKeys.Control) // IsControlModeOn = true; /* * PageItem Page = this.DataContext as PageItem; * Point p = GetClickLocation(e.GetPosition(this), GridOffsetLeft, GridOffsetTop); * Page.Items.Add(new AndGateLogicItem() * { * IsNew = true, * IsModified = false, * IsDeleted = false, * X = p.X, * Y = p.Y, * Z = 1 * }); */ PageItem Page = this.DataContext as PageItem; Page.SelectedItem = null; Point p = SnapGrid.Snap(e.GetPosition(this), GridSize, GridOffsetLeft, GridOffsetTop); if (this.IsMouseCaptured) { //currentLineItem.X2 = p.X; //currentLineItem.Y2 = p.Y; //c.ReleaseMouseCapture(); } else { Point pHit = e.GetPosition(this); CustomLineElement lineHit = null; HitTestResult result = VisualTreeHelper.HitTest(this, pHit); if (result != null) { if (result.VisualHit.GetType() == typeof(CustomLineElement)) { lineHit = result.VisualHit as CustomLineElement; } } if (lineHit == null && selectedLine == null) { currentLineItem = new LineLogicItem() { IsNew = false, IsModified = false, IsDeleted = false, X1 = p.X, Y1 = p.Y, X2 = p.X, Y2 = p.Y, Z = 0 }; Page.Items.Add(currentLineItem); this.CaptureMouse(); } if (lineHit != selectedLine && selectedLine != null) { if (Keyboard.Modifiers != ModifierKeys.Control) { var LineAdornerLayer = AdornerLayer.GetAdornerLayer(selectedLine); if (LineAdornerLayer != null) { LineAdornerLayer.Remove(LineAdornerLayer.GetAdorners(selectedLine)[0]); } selectedLine = null; } } if (lineHit != null && lineHit != selectedLine) { selectedLine = lineHit; var LineAdornerLayer = AdornerLayer.GetAdornerLayer(lineHit); if (LineAdornerLayer != null) { LineAdornerLayer.Add(new LineAdorner(lineHit)); } } //currentLineItem = new LineLogicItem() { X1 = p.X, Y1 = p.Y, X2 = p.X, Y2 = p.Y, Z = 0 }; //Page.Items.Add(currentLineItem); //c.CaptureMouse(); } } }
public EditorUI() { float bbOrigin = BUTTON_PADDING + BUTTON_SIZE * 0.5f; playButton = new Button("play", new Vector2(bbOrigin, bbOrigin), BUTTON_SIZE, false); playbackTimeButton = new Button("time", new Vector2(bbOrigin + BUTTON_SIZE + BUTTON_PADDING, bbOrigin), BUTTON_SIZE, false); notesButton = new Button("click", new Vector2(bbOrigin + BUTTON_SIZE * 2 + BUTTON_PADDING * 2, bbOrigin), BUTTON_SIZE, false); notesButton.mySymbol.rotation = 45f; notesButton.mySymbol.color = Note.QUANTIZATION_COLORS[0]; gridButton = new Button("grid", new Vector2(bbOrigin + BUTTON_SIZE * 3 + BUTTON_PADDING * 3, bbOrigin), BUTTON_SIZE, false); scrollButton = new Button("scroll", new Vector2(bbOrigin + BUTTON_SIZE * 4 + BUTTON_PADDING * 4, bbOrigin), BUTTON_SIZE, false); soundAssistButton = new Button("metronome", new Vector2(bbOrigin + BUTTON_SIZE * 5 + BUTTON_PADDING * 5, bbOrigin), BUTTON_SIZE, false); bpmButton = new Button("Raleway32", "BPM" + Environment.NewLine + VoezEditor.Editor.project.songBPM.ToString(), new Vector2(bbOrigin + BUTTON_SIZE * 6 + BUTTON_PADDING * 6, bbOrigin), BUTTON_SIZE, false); saveButton = new Button("save", new Vector2(bbOrigin + BUTTON_SIZE * 7 + BUTTON_PADDING * 7, bbOrigin), BUTTON_SIZE, false); VoezEditor.Editor.AddObject(playButton); VoezEditor.Editor.AddObject(playbackTimeButton); VoezEditor.Editor.AddObject(notesButton); VoezEditor.Editor.AddObject(gridButton); VoezEditor.Editor.AddObject(scrollButton); VoezEditor.Editor.AddObject(soundAssistButton); VoezEditor.Editor.AddObject(bpmButton); VoezEditor.Editor.AddObject(saveButton); float sliderStart = BUTTON_PADDING * 9 + BUTTON_SIZE * 8 + 44f; float sliderEnd = VoezEditor.windowRes.x - 160f; playbackSlider = new Slider(new Vector2((sliderStart + sliderEnd) * 0.5f, BUTTON_PADDING + BUTTON_SIZE * 0.5f), sliderEnd - sliderStart); VoezEditor.Editor.AddObject(playbackSlider); grid = new SnapGrid(); VoezEditor.Editor.AddObject(grid); trackAdder = new TrackAddPreview(); VoezEditor.Editor.AddObject(trackAdder); playbackTimeLabel = new DropshadowLabel("Raleway32", BeatTimeStamp(0), new Vector2(VoezEditor.windowRes.x - 75f, BUTTON_PADDING + BUTTON_SIZE * 0.5f), new Vector2(2f, -2f)); VoezEditor.Editor.AddObject(playbackTimeLabel); string levelText = ""; if (VoezEditor.editType == "easy") { levelText = "Easy Lv." + Mathf.FloorToInt(VoezEditor.Editor.project.easyLevel).ToString(); } else if (VoezEditor.editType == "hard") { levelText = "Hard Lv." + Mathf.FloorToInt(VoezEditor.Editor.project.hardLevel).ToString(); } else if (VoezEditor.editType == "extra") { levelText = "Special Lv." + Mathf.FloorToInt(VoezEditor.Editor.project.extraLevel).ToString(); } levelLabel = new DropshadowLabel("Raleway32", levelText, new Vector2(VoezEditor.windowRes.x - BUTTON_PADDING * 1.5f - 24f, VoezEditor.windowRes.y - BUTTON_PADDING * 1.5f - 24f), new Vector2(1f, -1f)); levelLabel.normalText.alignment = FLabelAlignment.Right; if (VoezEditor.editType == "easy") { levelLabel.normalText.color = ProjectsUI.EASY_COLOR; } else if (VoezEditor.editType == "hard") { levelLabel.normalText.color = ProjectsUI.HARD_COLOR; } else if (VoezEditor.editType == "extra") { levelLabel.normalText.color = ProjectsUI.SPECIAL_COLOR; } levelLabel.shadowText.alignment = FLabelAlignment.Right; VoezEditor.Editor.AddObject(levelLabel); backButton = new Button("back", new Vector2(bbOrigin * 1.5f, VoezEditor.windowRes.y - bbOrigin * 1.5f), BUTTON_SIZE * 1.5f, true); backButton.mySymbol.scale = 1.5f; VoezEditor.Editor.AddObject(backButton); }
//links a and b to each other static void mergeCells(SnapGrid a, SnapGrid b) { mergeCellsDir(a, b); mergeCellsDir(b, a); }
//links a and b to each other static void mergeCells(SnapGrid a, SnapGrid b) { mergeCellsDir (a, b); mergeCellsDir (b, a); }
public static void registerSnapGrid(SnapGrid x,int player) { if (player == 1) { sgs.Add (x); } else { sgsP2.Add (x); } }
void CastRayToWorld(Vector2 pos) { //Debug.Log ("initially: " + clicks); Ray r = Camera.main.ScreenPointToRay(pos); //Vector3 p = r.origin + r.direction*(10 - (-.17f)); Vector3 p = Vector3.zero; RaycastHit test; LayerMask lm; //our layermask for raycasting to ignore coins not in turn if (turn == 1) //so p1's turn want to mask out p2 coins. so mask out layer p2 { lm = lm2; //so lm2 is only layer p2. Then at end invert this. } else { lm = lm1; } lm = ~lm; bool hitCoin = false; GameObject coinHit; //Debug.Log (lm.value); //Debug.Log (r.direction); if (Physics.Raycast(r.origin, r.direction, out test, Mathf.Infinity, lm)) { //so need to check if hit a coin. else lower p.y else raise p.y (because if it's a coin then we're going to miss it if we incrase the ray's height.. /*namely we know from that default unity cylinder primitive = 2 units high * this means due to .1 scale our coins are .2 units high so .2/2 = .1, the half height of interest. */ p = test.point; GameObject gotHit = test.collider.gameObject; //Vector3 adjust = gotHit.transform.up;//so the normal of the surface that was hit //so need to make adjust to be terrain normal now.. if (!gotHit.name.StartsWith("Terrain")) { if (clicks == 0) { focus coinF = gotHit.GetComponent <focus>(); if (!coinF) { return; } coinF.handleSelection(); return; } //p.y -= .1f;// //Vector3 adjust = gotHit.transform.up; //try something else b/c when coin upside down, we get 0 -1 0 rather than 0 1 0. Vector3 adjust = test.normal; adjust.Normalize(); //Debug.Log ("p prev: " + p); p += -.1f * adjust; //AHA! So that's why. Adjust is being negative b/c coin is flipped over. //Debug.Log(adjust); //Debug.Log ("p adjusted: " + p + " and adjustment used: " + adjust); //Debug.Log("On a coin"); } else //so need the Terrain normal - credit to Eric on unity forumns //p.y += .1f; /* * Terrain t = gotHit.GetComponent<Terrain>(); * Vector3 relPos = p - t.transform.position; * Vector2 nPos = new Vector2(Mathf.InverseLerp(0.0f, t.terrainData.size.x, relPos.x), Mathf.InverseLerp(0.0f, t.terrainData.size.z, relPos.z)); * * Vector3 adjust = t.terrainData.GetInterpolatedNormal(nPos.x,nPos.y); */ //adjust = adjust.normalized; { deselectAllCoins(); GameObject.Find("P1Merger").GetComponent <coinMerger>().clearLines(); GameObject.Find("P2Merger").GetComponent <coinMerger>().clearLines(); //added //now if this coin has reachable pipeline emphasized(coin selected + pressed "S") and clicked on //a reachable segment, then teleport to some height above grid cell center (for now--later animate/lerp/rotate/roll) //and then reset clicks to 0 and return (not sure need to set to 0 as in already would be set to 0???) if (gotHit.GetComponent <SnapGrid>() != null) // && storePipes.teleportationInitiated){ { SnapGrid sg = gotHit.GetComponent <SnapGrid>(); if (sg.selected) { //Debug.Log(sg.finalPosition[0]+.5f); if (sg.owner == 1) { Vector3 teleportLoc = Vector3.zero; teleportLoc.x = sg.finalPosition[0] + .5f; teleportLoc.z = sg.finalPosition[1] + .5f; storePipes.CoinThatCanTeleport.transform.position = teleportLoc; storePipes.clearTeleportation(); storePipes.clearTeleportationP2(); clicks = 0; return; //added } else { Vector3 teleportLoc = Vector3.zero; teleportLoc.x = sg.finalPosition[0] + .5f; teleportLoc.z = sg.finalPosition[1] + .5f; storePipes.CoinThatCanTeleportP2.transform.position = teleportLoc; storePipes.clearTeleportation(); storePipes.clearTeleportationP2(); clicks = 0; return; } } } else { storePipes.clearTeleportation(); storePipes.clearTeleportationP2(); } Vector3 adjust = test.normal; adjust.Normalize(); p += .1f * adjust; //Debug.Log("On the floor"); //Debug.Log(adjust); //Debug.Log(gotHit.transform.up); aha, so transform.up gives the normal. need to use this for adjustment so that will work also on inclined surfaces,not just flat ones w/ normal of 0 1 0 } } if (clicks == 0) { clickPos = p; clicks += 1; //Debug.Log("h " + clicks);//added } else { clicks = 0; Vector3 dir = p - clickPos; //k so here rather than debug dray ray do a line renderer so viewer can see in scene StartCoroutine(drawLine(clickPos, p, 1.0f)); Debug.DrawRay(clickPos, dir, Color.blue, 5.0f); RaycastHit hit; float dist = dir.magnitude; if (Physics.Raycast(clickPos, dir, out hit, dist, lm)) { GameObject target = hit.collider.gameObject; coinAndroidTest info = target.GetComponent <coinAndroidTest>(); //if (info.owner != turn){return;} // so exit if WAIT NO use raycast layber bitmask and here just check for locked/set it if false to true and increment a var to decide if turn over if (!info) { return; } if (info.locked) //so this coin is locked meaning have already launched it { return; } info.toggleLocked(true); info.locked = true; //so we're going to launch this so need to lock it so can't double launch in same turn Rigidbody coin = target.GetComponent <Rigidbody>(); float distToHit = Vector3.Distance(hit.point, clickPos); float ratio = distToHit / dist; //Debug.Log("N/D: " + ratio); Vector3 offset = hit.point - coin.position; float offsetsize = offset.magnitude; //Debug.Log(offsetsize); offset = useless for coins--always = .5. For pencilwars (original) it had meaning... forceFactor = target.GetComponent <coinAndroidTest>().forceFactor; Vector3 forceToAdd = dir.normalized * ratio * forceFactor; // * Mathf.Pow (offsetsize,spower); //Debug.Log(coin.name + forceToAdd); coin.AddForceAtPosition(forceToAdd, hit.point); } } //Debug.Log ("at the end: " + clicks); }
private void CoreObjectsFindOnScene() { grid = FindObjectOfType <SnapGrid>(); }
//do DFS from s to get list of all reachable SnapGrids. Change material to green color + signal that selected (meaning specific coin can teleport there) public static void selectReachablePipeSegs(SnapGrid s) { List<SnapGrid> explored = new List<SnapGrid>(); Stack<SnapGrid> stack = new Stack<SnapGrid> (); stack.Push (s); while (stack.Count > 0) { SnapGrid n = stack.Pop(); bool nWasExplored = false; foreach(SnapGrid sg in explored){ if ((sg.finalPosition[0] == n.finalPosition[0]) && (sg.finalPosition[1] == n.finalPosition[1]) ){ nWasExplored = true; } } if (!nWasExplored){ explored.Add(n); if (n.n1!=null){ stack.Push(n.n1); } if (n.n2!=null){ stack.Push(n.n2); } if (n.n3!=null){ stack.Push(n.n3); } if (n.n4!=null){ stack.Push(n.n4); } } } //idea is that now explored is all the reachable SnapGrids--so same connected component foreach (SnapGrid sg in explored) { sg.gameObject.GetComponent<Renderer>().material.color = Color.green; sg.selected = true; } }
protected override void OnMouseRightButtonDown(MouseButtonEventArgs e) { if (this.DataContext is PageItem) { PageItem Page = this.DataContext as PageItem; Point p = SnapGrid.Snap(e.GetPosition(this), GridSize, GridOffsetLeft, GridOffsetTop); if (this.IsMouseCaptured) { Page.Items.Remove(currentLineItem); currentLineItem = null; this.ReleaseMouseCapture(); } else { // delete line element /* * Point pHit = e.GetPosition(this); * * CustomLineElement lineHit = null; * HitTestResult result = VisualTreeHelper.HitTest(this, pHit); * if (result != null) * { * if (result.VisualHit.GetType() == typeof(CustomLineElement)) * { * lineHit = result.VisualHit as CustomLineElement; * Page.Items.Remove(lineHit.DataContext as LineLogicItem); * } * } */ } /* * Canvas c = sender as Canvas; * Point p = SnapGrid.Snap(e.GetPosition(this), GridSize, GridOffsetLeft, GridOffsetTop); * CustomLineElement lineHit = null; * * HitTestResult result = VisualTreeHelper.HitTest(c, p); * if (result != null) * { * if (result.VisualHit.GetType() == typeof(CustomLineElement)) * { * lineHit = result.VisualHit as CustomLineElement; * } * } * * if (selectedLine != null && lineHit != selectedLine) * { * var LineAdornerLayer = AdornerLayer.GetAdornerLayer(selectedLine); * LineAdornerLayer.Remove(LineAdornerLayer.GetAdorners(selectedLine)[0]); * selectedLine = null; * } * * if (lineHit != null && lineHit != selectedLine) * { * selectedLine = lineHit; * var LineAdornerLayer = AdornerLayer.GetAdornerLayer(lineHit); * LineAdornerLayer.Add(new LineAdorner(lineHit)); * } */ } }
void SnapDataBlockLogicItem(ILocation locacion, double dX, double dY, DataBlockSnapMode mode) { double left = SnapGrid.Snap(locacion.X + dX, UnitConverter.CmToDip(0.1)); //double top = SnapGrid.Snap(locacion.Y + dY, UnitConverter.CmToDip(1.0), UnitConverter.CmToDip(0.1)); double top = UnitConverter.CmToDip(Math.Floor(UnitConverter.DipToCm(locacion.Y + dY)) + 0.1); switch (mode) { case DataBlockSnapMode.Input: { left = UnitConverter.CmToDip(1.3); } break; case DataBlockSnapMode.Output: { left = UnitConverter.CmToDip(31.2); } break; case DataBlockSnapMode.Auto: { if (left < UnitConverter.CmToDip(1.3)) { // X < 1.3cm left = UnitConverter.CmToDip(1.3); } else if (left >= UnitConverter.CmToDip(1.3) && left < UnitConverter.CmToDip(11.2)) { // 1.3cm >= X > 11.2cm left = UnitConverter.CmToDip(1.3); } else if (left >= UnitConverter.CmToDip(11.2) && left < UnitConverter.CmToDip(31.2)) { // 11.2cm >= X > 31.2cm if (left <= UnitConverter.CmToDip(21.2)) { // move to inputs left = UnitConverter.CmToDip(1.3); } else { // move to outputs left = UnitConverter.CmToDip(31.2); } } else { // X >= 31.2cm left = UnitConverter.CmToDip(31.2); } } break; } if (top <= UnitConverter.CmToDip(2.1)) { // Y <= 2.1cm top = UnitConverter.CmToDip(2.1); } else if (top >= UnitConverter.CmToDip(25.1)) { // Y >= 25.1 top = UnitConverter.CmToDip(25.1); } else { // 2.1cm < Y < 25.1cm //top = top + UnitConverter.CmToDip(0.1); } locacion.X = left; locacion.Y = top; }