private void CreatePlayer(float scale, Vector3 position) { _pawn = VOXGameObject.CreateGameObject("Assets/tiles/player.vox", scale); _pawn.name = "player"; _pawn.transform.parent = this.transform; _pawn.transform.position = position; }
private void AddOrInstantiate(Vector3 loc, int id, string def) { if (id == 0) { return; } float d = 0.0f; if (objects.ContainsKey(id)) { //Debug.Log(String.Format("found object {0}, cloning", id)); GameObject obj = Instantiate(objects[id], loc, Quaternion.identity, frame.transform); var bData = obj.GetComponent <BlockData>(); bData.Location = loc; bData.id = id; bData.def = def; obj.SetActive(true); } else { //Debug.Log(String.Format("object {0} not found, loading", id)); GameObject newObj = VOXGameObject.CreateGameObject("Assets/tiles/" + id + ".vox", Game.Global_Scale); var bData = newObj.AddComponent <BlockData>(); bData.Location = loc; bData.id = id; bData.def = def; if (VOXGameObject.model.sizeX == 0 && VOXGameObject.model.sizeY == 0 && VOXGameObject.model.sizeZ == 0) { //Debug.Log(String.Format("object {0} has not been found, creating unknow instead", id)); GameObject.Destroy(newObj); newObj = VOXGameObject.CreateGameObject("Assets/tiles/" + def + ".vox", Game.Global_Scale); newObj.AddComponent <UnknownTile>(); if (VOXGameObject.model.sizeX == 0 && VOXGameObject.model.sizeY == 0 && VOXGameObject.model.sizeZ == 0) { //Debug.Log(String.Format("unknow has not been found", id)); return; } } newObj.transform.parent = cached.transform; newObj.SetActive(false); newObj.name = id.ToString(); objects[id] = newObj; size.x = VOXGameObject.model.sizeX * (VOXGameObject.scale + d); size.y = VOXGameObject.model.sizeZ * (VOXGameObject.scale + d); GameObject obj = Instantiate(newObj, loc, Quaternion.identity, frame.transform); obj.SetActive(true); } }
public void Awake() { _pfb = new GameObject("prefabs"); var files = Directory.GetFiles("Assets/tiles", "*.vox"); foreach (var file in files) { var name = Path.GetFileNameWithoutExtension(file).ToLower(); var newObj = VOXGameObject.CreateGameObject(file, Game.Global_Scale); newObj.SetActive(false); newObj.name = name; newObj.transform.parent = _pfb.transform; VoxelCache.Add(name, newObj); } }