private void MoveTo(Vector3 currentPos, Vector3 previousPos) { ScriptableBlock currentBlockData = boardData[(int)previousPos.x, (int)previousPos.y, (int)previousPos.z]; boardData[(int)currentPos.x, (int)currentPos.y, (int)currentPos.z] = currentBlockData; // Remove old position from board boardData[(int)previousPos.x, (int)previousPos.y, (int)previousPos.z] = null; }
/// <summary> /// Convert boardDataJson to usable ScriptableBlock format and spawn blocks with their position /// </summary> /// <param name="boardDataJson"></param> public void LoadBoardDataAndSpawn(ArrayList boardDataJson) { foreach (BlockData bd in boardDataJson) { Vector3 position = bd.ConvertPositionData(); ScriptableBlock block = ScriptableObject.CreateInstance <ScriptableBlock>(); bd.JsonParseData(block); boardData[(int)position.x, (int)position.y, (int)position.z] = block; BlockManager.Instance.InitBlock(block, position); } }
public void GenerateBlocks() { Vector2 newPosition = _startPosition; for (var i = 0; i < _verticalSize; i++) { newPosition.x = _startPosition.x; for (var h = 0; h < _horizontalSize; h++) { ScriptableBlock newBlock = SellectBlockType(_blockTypes); GameObject obj = _pooling.GetObjectOnStartPool("Block"); obj.GetComponent <BlockBase>().LoadBlockData(newBlock); obj.transform.position = newPosition; obj.SetActive(true); newPosition.x += _positionGap; } newPosition.y += _positionGap; } }
/// <summary> /// Add new ScriptableBlock metaData at index that matches block's position /// </summary> /// <param name="metaData">ScriptableBlock to be stored</param> /// <param name="block">A GameObject created by BlockManager</param> public void TryAddBlock(ScriptableBlock metaData, GameObject block) { Vector3 position = block.transform.position; int yPos = Mathf.RoundToInt(position.y); try { if (IsValid(position)) { boardData[(int)position.x, yPos, (int)position.z] = metaData; Debug.Log($"BoardManager::TryAddBlock::add block at [{(int)position.x}, {yPos}, {(int)position.z}]"); } else { Debug.LogWarning($"BoardManager::TryAddBlock::Cannot add block at [{(int)position.x}, {yPos}, {(int)position.z}]\n. Location might be overlapping."); Destroy(block); } } catch (IndexOutOfRangeException) { Debug.LogWarning($"BoardManager::TryAddBlock::Cannot add block at [{(int)position.x}, {yPos}, {(int)position.z}]\n. Location is out of range."); Destroy(block); } }
public GameObject InitBlock(ScriptableBlock block, Vector3 position) { return(Instantiate(block.prefab, position, Quaternion.identity)); }
/// <summary> /// Find a ScriptableBlock by its name /// </summary> public ScriptableBlock GetBlockBy(string name) { ScriptableBlock block = blocks.Find(x => x.name == name); return(block); }
void SelectItem() { ScriptableBlock chosenBlock = GetBlock(); BlockManager.Instance.currentBlock = chosenBlock; }
/// <summary> /// Convert JSON to scriptable block /// </summary> /// <param name="block">A ScriptableObject where JSON data is overridden to</param> public void JsonParseData(ScriptableBlock block) { JsonUtility.FromJsonOverwrite(metaData, block); }
/// <summary> /// Convert ScritableBlock to JSON /// </summary> /// <param name="scriptableBlock">a scriptable block in BoardManager.Instance.boardData</param> public string JsonifyData(ScriptableBlock scriptableBlock) { return(JsonUtility.ToJson(scriptableBlock)); }
public BlockData(ScriptableBlock metaData, Vector3 position) { this.metaData = JsonifyData(metaData); this.position = SetPositionDataFrom(position); }