void OnMouseUp() { beingDragged = false; // stop dragging SlidingPuzzleExample.mainGrid.AlignTransform(transform); // snap into position precisely transform.position = ClampPosition(transform.position); // clamp the position to be safe (because of possible rounding errors above) lastSnap = transform.position; //this is out last save position SlidingPuzzleExample.RegisterObstacle(transform, false); // mark the space as occupied again }
void OnMouseDown() { beingDragged = true; // Start dragging. touchOffset = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position; //offset between the cursor and the block centre lastSnap = transform.position; // this is obviously where we snapped the last time bounds = SlidingPuzzleExample.CalculateSlidingBounds(transform.position, transform.lossyScale); // create default bounds SlidingPuzzleExample.RegisterObstacle(transform, true); // marks this space as free in the matrix (or else we won't be able to return back here) }
///<summary>This is where the dragging logic takes places.</summary> void Drag() { // the destination is where the cursor points (minus the offset) clamped by the bounds Vector3 destination = ClampPosition(Camera.main.ScreenToWorldPoint(Input.mousePosition) - touchOffset); destination.z = transform.position.z; // now use that information to get the new bounds bounds = SlidingPuzzleExample.CalculateSlidingBounds(lastSnap, transform.lossyScale); // simulate a snap to the grid so we can get potentially new bounds in the next step lastSnap = ClampPosition(SlidingPuzzleExample.mainGrid.AlignVector3(destination, transform.lossyScale)); // move to the destination! transform.position = destination; }
void Update() { if (Input.GetKeyDown(KeyCode.C)) { DirectoryInfo info = new DirectoryInfo(System.Environment.CurrentDirectory); FileStream nFile = new FileStream(info.Parent.Parent.FullName + @"\word\config\excelfile\map" + "/" + "data_map_" + SceneManager.GetActiveScene().name + ".erl", FileMode.Create); Encoding encoder = Encoding.UTF8; byte[] bytes = encoder.GetBytes(SlidingPuzzleExample.MatrixToString()); nFile.Write(bytes, 0, bytes.Length); nFile.Close(); Debug.Log(info.Parent.Parent.FullName + @"\word\config\excelfile\server" + "/" + SceneManager.GetActiveScene().name + ".erl"); DirectoryInfo luainfo = new DirectoryInfo(System.Environment.CurrentDirectory); FileStream luaFile = new FileStream(info.Parent.Parent.FullName + @"\client\art\Assets\MapConfigFile" + "/" + "Map" + SceneManager.GetActiveScene().name + ".lua", FileMode.Create); byte[] luabytes = encoder.GetBytes(SlidingPuzzleExample.BuildLua()); luaFile.Write(luabytes, 0, luabytes.Length); luaFile.Close(); } }
// visualizes the matrix in text form to let you see what's going on void OnGUI() { GUI.TextArea(new Rect(10, 10, 400, 100), guiMessage); GUI.TextArea(new Rect(10, Screen.height - 10 - 150, 250, 150), SlidingPuzzleExample.MatrixToString()); }
void Start() { beingDragged = false; // When the game starts no blocks are being dragged. SlidingPuzzleExample.RegisterObstacle(transform, false); // Register this block in the matrix as occupied space. }
private Vector3[] bounds; // we can only move the block within these bounds (the grid itself is the largest possible bound) void Start() { beingDragged = false; SlidingPuzzleExample.RegisterObstacle(transform, false); //register this block in the matrix as occupied space }
// visualizes the matrix in text form to let you see what's going on void OnGUI() { GUI.TextArea(new Rect(10, 10, 250, 150), SlidingPuzzleExample.MatrixToString()); }