static void DragFromTo(int fromX, int fromY, int toX, int toY) { if (!FieldMatrix.Get(fromX, fromY, out var fromBlock)) { return; } if (FieldMatrix.Get(toX, toY, out var toBlock)) { var bind = BindMatrix.GetBind(fromBlock, toBlock); var newBlockOffset = new Vector2(toX - fromX, toY - fromY); if (bind == null) { BindMatrix.AddBind(fromBlock, toBlock, newBlockOffset, Bind.BlockBindStrength); return; } if (bind.First != fromBlock) { if (!(fromBlock is RootBlock) && BindMatrix.GetOutBindsCount(fromBlock) == 0) { fromBlock.Destroy(); return; } bind.Break(); BindMatrix.AddBind(fromBlock, toBlock, newBlockOffset, Bind.BlockBindStrength); return; } return; } NodeBlock.Create(toX, toY, fromBlock); }
public void OnPointerClick(PointerEventData eventData) { if (_dragging || Input.touchCount > 1 || eventData.button != PointerEventData.InputButton.Left) { return; } if (nextClickOverride != null) { nextClickOverride(); nextClickOverride = null; return; } Utils.GetInputCoords(out var x, out var y); if (FieldMatrix.Get(x, y, out var block)) { block.logic.Click(eventData); } else { PixelDriver.Add(PixelRoad.Circle(Colors.GetPalette(-1)[3], 3f, 3f, 0.05f, 0.5f, x, y).SetWeight(0.05f)); } }
void FinishPlacing() { if (_placing) { return; } var position = cam.transform.position; int x = Mathf.RoundToInt(position.x), y = Mathf.RoundToInt(position.y); if (FieldMatrix.Get(x, y, out _)) { Animator.Interpolate( new Color(0.3f, 0f, 0f, DarkenAlpha), new Color(0f, 0f, 0f, DarkenAlpha), 1f) .Type(InterpolationType.Square) .PassValue(v => background.color = v); return; } _placing = true; Animator.Interpolate(DarkenAlpha, 0f, 1f).Type(InterpolationType.Linear) .PassValue(v => { background.color = new Color(0, 0, 0, v); }) .WhenDone(() => { gameObject.SetActive(false); Roots.CreateRoot(x, y, -1, palette.ColorsId); _placing = false; }); }
public static PixelRoad NodeBackground() { var pr = new PixelRoad(-1f); pr._colorFunc = (x, y) => { if (FieldMatrix.Get(x, y, out var block)) { return(new WeightedColor(Roots.Root[block.rootId].block.view.PrimaryPainter.palette.GetColor(2), pr._weight)); } return(WeightedColor.Clear); }; return(pr); }
public void OnBeginDrag(PointerEventData eventData) { if (eventData.button != PointerEventData.InputButton.Left || Input.touchCount > 1) { return; } _dragging = true; Utils.GetInputCoords(out var x, out var y); if (FieldMatrix.Get(x, y, out _draggedBlock)) { _draggingBlock = true; _draggedBlock.logic.BeginDrag(eventData); BlockEditor.OnBlockDragStart(_draggedBlock); } }
public void Deserialize() { foreach (var rb in RootBlocks) { rb.Deserialize(); } foreach (var bs in NodeBlocks) { bs.Deserialize(); } foreach (var bs in Binds) { FieldMatrix.Get(bs.FirstX, bs.FirstY, out var first); FieldMatrix.Get(bs.SecondX, bs.SecondY, out var second); var offset = new Vector2(bs.SecondX - bs.FirstX, bs.SecondY - bs.FirstY); BindMatrix.AddBind(first, second, offset, bs.Strength); } foreach (var sps in SoundsPlayers) { sps.Deserialize(); } }