private static string GetMatrixPosition(int id, int x, int y) { PuzzleObject obj; int top = SearchTopSide(id, x); int bottom = SearchBottomSide(id, x, y); int left = SearchLeftSide(id, x); int right = SearchRightSide(id, x); if (top == 3) { obj = new PuzzleObject(id - x); string b_side = obj.GetTypeSide(); //Debug.Log("top " + b_side); top = (b_side[1] == '1') ? 2: 1; } if (left == 3) { obj = new PuzzleObject(id - 1); string r_side = obj.GetTypeSide(); //Debug.Log("left " + r_side); left = (r_side[3] == '1') ? 2: 1; } return(top + "" + bottom + "" + left + "" + right); }
private void ObjectRemoved(PuzzleObject puzzleObject) { if (_worldObjects.ContainsKey(puzzleObject.Position)) { DestroyImmediate(_worldObjects[puzzleObject.Position]); } }
public void OnEndDrag(PointerEventData eventData) { if (enabled) { GameObject.Find("Click down").gameObject.GetComponent <AudioSource>().Play(); //obj.CheckScene(); //PuzzlesService.CheckAllPiece(); if (PuzzlesService.CheckBackPlace(obj.GetID())) { enabled = !enabled; //Debug.Log(enabled); PuzzlesService.Disabled(obj.GetID()); } else { obj.CheckScene(); PuzzlesService.CheckAllPiece(); } obj = null; rt = null; dragged = null; } }
private void updateCurState() { // Clear old state curState.Clear(); // Find all objects in our square range Collider[] colliders = Physics.OverlapBox(transform.position, new Vector3(size * 0.5f, 10, size * 0.5f), Quaternion.identity, notTerrain); foreach (Collider collider in colliders) { GameObject go = collider.gameObject; Vector2 gridPos = realToGrid(go.transform.position); // Init list if needed if (!curState.ContainsKey(gridPos) || curState[gridPos] == null) { curState[gridPos] = new List <PuzzleObject>(); } // Make sure it's a valid object, Make sure we don't add the same object twice PuzzleObject po = go.GetComponent <PuzzleObject>(); if (po != null) { curState[gridPos].Add(po); } } }
void CheckObject(PuzzleObject obj, string name, int layer, float scale, int width, string sprite, int tcolour, string text) { Assert.AreEqual(name, obj.Name); Assert.AreEqual(layer, obj.Layer); Assert.AreEqual(scale, obj.Scale); Assert.AreEqual(width, obj.Width); Assert.AreEqual(sprite, obj.Sprite.Join()); Assert.AreEqual(tcolour, obj.TextColour); Assert.AreEqual(text, obj.Text); }
public static void SetSave(PuzzleObject obj) { SaveModel sm = new SaveModel(); sm.obj_id = obj._component.id; sm.enabled = obj._component.rt.gameObject.GetComponent <PuzzleDragAndDrop>().enabled == true ? 1 : 0; sm.posx = obj._component.rt.anchoredPosition3D.x + ""; sm.posy = obj._component.rt.anchoredPosition3D.y + ""; sm.parent = obj.GetParent(); sm.Save(); }
public void ToolMouseDown(object sender, MouseEventArgs e) { this.xInitial = e.X; this.yInitial = e.Y; if (e.Button == MouseButtons.Left && canvas != null) { canvas.DeselectAllObjects(); canvas.SelectObjectAt(e.X, e.Y); selected_object = canvas.SelectObjectAt(e.X, e.Y); } }
private void drawGlows() { for (int i = 0; i < resolution; i++) { for (int j = 0; j < resolution; j++) { Vector2 curGrid = new Vector2(i, j); Vector3 cur = gridToReal(curGrid); if (!curState.ContainsKey(curGrid)) { continue; } if (!targetState.ContainsKey(curGrid)) { continue; } List <PuzzleObject> inCell = curState[curGrid]; PuzzleObject targetItem = targetState[curGrid]; if (inCell != null && inCell.Count == 1 && inCell.Contains(targetItem)) { if (!glowGrid.ContainsKey(curGrid)) { glowGrid[curGrid] = false; } if (!glowGrid[curGrid]) { glowGrid[curGrid] = true; GameObject glowInstance = Instantiate(glow, cur + new Vector3(size / resolution * 0.5f, 0, size / resolution * 0.5f), Quaternion.identity) as GameObject; glowInstance.name = "Glow " + curGrid; } } else if (inCell != null && (inCell.Count != 1 || !inCell.Contains(targetItem))) { if (!glowGrid.ContainsKey(curGrid)) { glowGrid[curGrid] = false; } if (glowGrid[curGrid]) { glowGrid[curGrid] = false; GameObject glowInstance = GameObject.Find("Glow " + curGrid); Destroy(glowInstance); } } } } }
// Generate mural texture based on a target state public void generateTexture(Dictionary <Vector2, PuzzleObject> state) { muralTex = new Texture2D(imageRes * numSquares, imageRes * numSquares, TextureFormat.ARGB32, false); Color[] newPixels = new Color[imageRes * numSquares * imageRes * numSquares]; for (int i = 0; i < newPixels.Length; i++) { newPixels[i] = muralColor; } foreach (KeyValuePair <Vector2, PuzzleObject> pair in state) { Vector2 coord = pair.Key; PuzzleObject obj = pair.Value; Texture2D image = obj.image; // The coordinates for texturing are mirrored, so we need to flip the cord values coord.x = (numSquares - 1) - coord.x; coord.y = (numSquares - 1) - coord.y; // Calculate where to start adding these pixels to new int offx = (int)coord.x * imageRes; int offy = (int)coord.y * imageRes * imageRes * numSquares; Color[] pixels = image.GetPixels(); // Add image pixels to newPixels for (int i = 0; i < imageRes; i++) { for (int j = 0; j < imageRes; j++) { Color newColor = new Color(); Color imgColor = pixels[j + i * imageRes]; Color bgColor = newPixels[j + i * numSquares * imageRes + offx + offy]; newColor.a = 1 - (1 - newColor.a) * (1 - bgColor.a); // alpha newColor.r = imgColor.r * imgColor.a / newColor.a + bgColor.r * bgColor.a * (1 - imgColor.a) / newColor.a; // Red newColor.g = imgColor.g * imgColor.a / newColor.a + bgColor.g * bgColor.a * (1 - imgColor.a) / newColor.a; // Green newColor.b = imgColor.b * imgColor.a / newColor.a + bgColor.b * bgColor.a * (1 - imgColor.a) / newColor.a; // Blue newPixels[j + i * numSquares * imageRes + offx + offy] = newColor; } } } muralTex.SetPixels(newPixels); muralTex.Apply(); gameObject.GetComponent <Renderer>().materials[1].mainTexture = muralTex; }
private void Push(PuzzleObject puzzleObject) { puzzleObject.Select(); _selectedPuzzleObjects.Push(puzzleObject); var c = puzzleObject.Letter; _answer += c; var go = Instantiate(AnswerObject, Vector3.zero, Quaternion.identity); go.GetComponent <PuzzleObject>().SetCharacter(c); go.transform.parent = AnswerParentTransform; go.transform.localPosition = Vector2.right * 0.8f * _selectedPuzzleObjects.Count; go.transform.localScale = Vector3.one; AnswerParentTransform.position += Vector3.left * 0.4f; }
public static void GetSave(PuzzleObject obj) { SaveModel sm = new SaveModel(); sm.id = obj._component.id; sm.Loading(); Debug.Log(sm.obj_id); if (sm.obj_id > 0) { obj._component.rt.gameObject.GetComponent <PuzzleDragAndDrop>().enabled = sm.enabled == 1 ? true : false; if (sm.parent > 0) { obj.SetParentLocal(new PuzzleObject(sm.parent)); } obj.SetTransform(new Vector3(float.Parse(sm.posx), float.Parse(sm.posy), 0.0f)); } }
public void OnBeginDrag(PointerEventData eventData) { if (enabled) { GameObject.Find("Click up").gameObject.GetComponent <AudioSource>().Play(); dragged = gameObject; rt = dragged.GetComponent <RectTransform>(); offset = rt.sizeDelta.x / 2; obj = new PuzzleObject(dragged.GetComponent <PuzzleComponent>().id); int pid = obj.GetParent(); if (pid > 0) { obj = new PuzzleObject(pid); rt = obj._component.rt; } enabled = GameObject.Find("puzzle" + obj.GetID()).GetComponent <PuzzleDragAndDrop>().enabled; } }
public static void GeneratorPuzzles(int x, int y, string image) { puzzleArray = new PuzzleObject[y * x]; backArray = new PuzzleObject[y * x]; //horizontal for (int i = 0; i < y; i++) { //vertical for (int j = 0; j < x; j++) { //formula getting id of puzzle int id = j + (x * i) + 1; PuzzleObject puzzle = new PuzzleObject("puzzle_UI", new Vector3(GeneratePX(), GeneratePZ(), 0), id, Scale(x)); //save object puzzleArray[id - 1] = puzzle; //Debug.Log("start id = " + id + " / x=" + x + " / y=" + y); puzzle.SetMaterial(image, GetMatrixPosition(id, x, y)); //float off = 1.0f / (float)y * 0.32f; float off_x = 1.0f / (float)x * 0.32f; float off_y = 1.0f / (float)y * 0.32f; puzzle.SetMaterialOffset(new Vector2((1.0f / (float)x * (float)j) - off_x, (1.0f / (float)y * ((float)y - 1 - (float)i)) - off_y)); float scale_x = 1.0f / (float)x * 0.609f; puzzle.SetMaterialScale(new Vector2((1.0f / (float)x) + scale_x, (1.0f / (float)y) / 0.609f)); PuzzleObject puzzle_back = new PuzzleObject("puzzle_UI_back", back_position(id, x, y), id, Scale(x), "back"); backArray[id - 1] = puzzle_back; puzzle_back.SetMaterial("back", puzzle.GetTypeSide()); //puzzle_back.SetMaterialOffset(new Vector2((1.0f / (float)x * (float)j) - off_x, (1.0f / (float)y * ((float)y - 1 -(float)i)) - off_y)); //puzzle_back.SetMaterialScale(new Vector2((1.0f / (float)x) + scale_x, (1.0f / (float)y) / 0.609f)); puzzle_back.AttachToBack(); puzzle_back.SetTransform(back_position(id, x, y)); } } }
public void ClearActivePuzzle() { activePuzzle = null; }
public void SetActivePuzzle(PuzzleObject puzzle) { activePuzzle = puzzle; }
public override bool Remove(PuzzleObject obj) { throw new NotImplementedException(); }
private void AddRemovedObject(PuzzleObject puzzleObject) { _removedObjects.Add(puzzleObject); }
public void RemoveCalled(PuzzleObject changedObject) { Calls.Add(new CallInfo(CallInfo.CallType.Remove, changedObject.Type, changedObject.Position)); }
public override void Deselect(PuzzleObject obj) { obj.ChangeState(StaticState.GetInstance()); }
public override bool Add(PuzzleObject obj) { return(false); }
public override void Select(PuzzleObject obj) { obj.ChangeState(EditState.GetInstance()); }
public override void Draw(PuzzleObject obj) { obj.RenderOnStaticView(); }
public override void Draw(PuzzleObject obj) { obj.RenderOnPreview(); }
public RemoveObjectCommand(PuzzleLayout layout, TilePos position) { _position = position; _layout = layout; _previousPuzzleObject = _layout.GetObjectAt(_position); }
public SetSingletonObjectCommand(PuzzleLayout layout, string type, TilePos position) : base(layout, type, position) { _previousPuzzleObject = layout.GetSingleton(type); }
public override bool Remove(PuzzleObject obj) { return(false); }
public override void Draw(PuzzleObject obj) { obj.RenderOnEditingView(); }