private void UpdateCurrentPieceInstance(PaletteItem item, Texture2D preview) { _itemSelected = item; _itemPreview = preview; _pieceSelected = (LevelPiece)item.GetComponent <LevelPiece> (); Repaint(); }
private void PlaceBlockHold(WorldPos _bPos, int _id, LevelPiece _piece, bool _isErase) { // Debug.Log ("[" + _bPos.ToString () + "](" + _id.ToString () + ")-" + (_isErase?"Delete":"Add")); for (int i = 0; i < _piece.holdBlocks.Count; i++) { LevelPiece.Hold bh = _piece.holdBlocks [i]; int x = _bPos.x + bh.offset.x; int y = _bPos.y + bh.offset.y; int z = _bPos.z + bh.offset.z; BlockHold.piecePos bhData = new BlockHold.piecePos(); bhData.blockPos = _bPos; bhData.pieceID = _id; Predicate <BlockHold.piecePos> samePiecePos; samePiecePos = delegate(BlockHold.piecePos obj) { return(obj.blockPos.Compare(bhData.blockPos) && obj.pieceID == bhData.pieceID); }; BlockHold bhBlock = GetBlock(x, y, z) as BlockHold; if (_isErase) { if (bhBlock != null && bhBlock.roots.Exists(samePiecePos)) { bhBlock.roots.RemoveAt(bhBlock.roots.FindIndex(samePiecePos)); } if (bhBlock.roots.Count == 0) { SetBlock(x, y, z, null); } } else { if (bhBlock != null) { if (!bhBlock.roots.Exists(samePiecePos)) { bhBlock.roots.Add(bhData); } } else { SetBlock(x, y, z, new BlockHold()); bhBlock = GetBlock(x, y, z) as BlockHold; if (bhBlock != null) { bhBlock.roots.Add(bhData); } } if (bhBlock != null && bh.isSolid) { bhBlock.SetSolid(true); } } } }
private void OnEnable() { lp = (LevelPiece)target; maxX = lp.maxX; minX = lp.minX; maxY = lp.maxY; minY = lp.minY; maxZ = lp.maxZ; minZ = lp.minZ; }
public void PlacePiece(WorldPos bPos, WorldPos gPos, LevelPiece _piece, Transform _parent) { Vector3 pos = Volume.GetPieceOffset(gPos.x, gPos.z); VGlobal vg = VGlobal.GetSetting(); GameObject pObj = null; float x = bPos.x * vg.w + pos.x; float y = bPos.y * vg.h + pos.y; float z = bPos.z * vg.d + pos.z; if (_piece != null) { pObj = GameObject.Instantiate(_piece.gameObject); pObj.transform.parent = _parent; pObj.transform.localPosition = new Vector3(x, y, z); pObj.transform.localRotation = Quaternion.Euler(0, Volume.GetPieceAngle(gPos.x, gPos.z), 0); } }
public void SetPiece(WorldPos bPos, WorldPos gPos, LevelPiece piece) { if (pieceNames == null) { pieceNames = new string[9]; } GameObject pObj = (piece != null) ? piece.gameObject : null; int id = gPos.z * 3 + gPos.x; if (pObj != null) { pieceNames [id] = pObj.GetComponent <PaletteItem> ().name; } else { pieceNames [id] = null; } }
public void PlacePiece(WorldPos bPos, WorldPos gPos, LevelPiece _piece) { Block block = GetBlock(bPos.x, bPos.y, bPos.z); BlockAir blockAir = null; GameObject pObj; if (block != null && !(block is BlockAir || block is BlockItem)) { return; } if (_piece != null) { if (block == null) { SetBlock(bPos.x, bPos.y, bPos.z, new BlockAir()); block = GetBlock(bPos.x, bPos.y, bPos.z); } if (!nodes.ContainsKey(bPos)) { CreateNode(bPos); } pObj = nodes [bPos].pieces [gPos.z * 3 + gPos.x]; if (pObj != null) { PlaceBlockHold(bPos, gPos.z * 3 + gPos.x, pObj.GetComponent <LevelPiece> (), true); GameObject.DestroyImmediate(pObj); } #if UNITY_EDITOR pObj = PrefabUtility.InstantiatePrefab(_piece.gameObject) as GameObject; #else pObj = GameObject.Instantiate(_piece.gameObject); #endif pObj.transform.parent = nodes [bPos].pieceRoot.transform; Vector3 pos = GetPieceOffset(gPos.x, gPos.z); VGlobal vg = VGlobal.GetSetting(); float x = bPos.x * vg.w + pos.x; float y = bPos.y * vg.h + pos.y; float z = bPos.z * vg.d + pos.z; pObj.transform.localPosition = new Vector3(x, y, z); pObj.transform.localRotation = Quaternion.Euler(0, GetPieceAngle(gPos.x, gPos.z), 0); nodes [bPos].pieces [gPos.z * 3 + gPos.x] = pObj; if (block is BlockAir) { blockAir = block as BlockAir; blockAir.SetPiece(bPos, gPos, pObj.GetComponent <LevelPiece> ()); blockAir.SolidCheck(nodes [bPos].pieces); if (_piece.isHold == true) { PlaceBlockHold(bPos, gPos.z * 3 + gPos.x, pObj.GetComponent <LevelPiece> (), false); } } } else { if (block is BlockAir) { blockAir = block as BlockAir; blockAir.SetPiece(bPos, gPos, null); blockAir.SolidCheck(nodes [bPos].pieces); } if (nodes.ContainsKey(bPos)) { pObj = nodes [bPos].pieces [gPos.z * 3 + gPos.x]; if (pObj != null) { PlaceBlockHold(bPos, gPos.z * 3 + gPos.x, pObj.GetComponent <LevelPiece> (), true); GameObject.DestroyImmediate(pObj); } } if (RemoveNodeIfIsEmpty(bPos)) { SetBlock(bPos.x, bPos.y, bPos.z, null); } } }