public void removeDumbObject(BaseTileObject tileObject) { locationList.Remove(tileObject.getObjectID()); scaleList.Remove(tileObject.getObjectID()); rotationList.Remove(tileObject.getObjectID()); dumbObjectsList.Remove(tileObject); setDirty(); }
public void setInteractableObject(BaseTileObject tileObject) { if (tileObject.getInteractable()) { interactableObject = tileObject; } else { Debug.LogError("Someone tried to set a non interactable object as the interactable object (" + tileObject.getObjectID() + ") of the tile :" + this); } }
public void addDumbObject(BaseTileObject tileObject) { if (!tileObject.getInteractable()) { dumbObjectsList.Add(tileObject); } else { Debug.LogError("Someone tried to set a interactable object as a dumb object of the tile :" + this); } }
private void updateButtons(VRAR_Tile tile) { //We can only attack neighbours foreach (VRAR_Tile circleTile in GameStateManager.getInstance().getCurrentLevel().selectCircle(GamePlayManagerAR.instance.localPlayer.GetCurrentVec().x, GamePlayManagerAR.instance.localPlayer.GetCurrentVec().y, 1)) { if (circleTile == currentTile) { //if there is an npc show attack button NonPlayer npc = tile.getNPC(); if (npc != null) { attackButtonPrefab.SetActive(true); } //if there is another player also show attack button if (client != null) { List <BasePlayer> players = client.getPlayerList(); foreach (BasePlayer player in players) { if (player.GetCurrentTile() == tile) { attackButtonPrefab.SetActive(true); } } } } } if (tile.GetWalkable()) { walkButtonPrefab.SetActive(true); //if an object is walkable that means there is no object there so we can ignore te rest in this function return; } BaseTileObject baseTileObject = tile.getInteractableObject(); //show hand if interactable if (baseTileObject.getInteractable() || tile.getInterior() != null) { handButtonPrefab.SetActive(true); inspectButtonPrefab.SetActive(true); currentTileText.text = baseTileObject.getName(); } //if its not interactable we want to allow the player to inspec the object, but not if ther is object (id == 0) else { inspectButtonPrefab.SetActive(true); currentTileText.text = baseTileObject.getName(); } }
//Add a tileobject to the gridview and in the world public void AddTileObject(BaseTileObject tileObject) { if (tileObject != null) { //Debug.Log("Adding a tileobject current size = " + indexTracker.Count + " and added id is " + tileObject.getObjectID()); string key = standartKeyName + tileObject.getObjectID(); //Debug.Log("Added a new key: " + key); int id = tileObject.getObjectID(); Debug.Log("Trying to get id: " + id); foreach (KeyValuePair <string, BaseTileObject> a in objectTracker) { Debug.Log("Key: " + a.Key); } if (!objectTracker.ContainsKey(key)) { //print("Did not exists"); objectTracker.Add(key, tileObject); indexTracker.Add(key, id); InstantiateObject(tileObject, id); //InstantiateObject(tileObject.getPrefab().gameObject, id); print("1 :" + selectedTile); print("2 :" + selectedTile.tileGameObject); print("3 :" + tileObjects); selectedTile.AddPosition(id, selectedTile.tileGameObject.position); selectedTile.AddScale(id, new Vector3(1, 1, 1)); selectedTile.AddRotation(id, new Quaternion()); TileRenderer.instance.updateTile(selectedTile); //TODO should be handled better tileObjects.Clear(); foreach (KeyValuePair <string, BaseTileObject> entry in objectTracker) { tileObjects.Add(entry.Value); } selectedTile.UpdateList(tileObjects, GetElevation(), GetWalkable(), terrain); } else { print("Already exists"); } } else { throw new System.Exception("Null tile object"); } }
public BaseTileObject PlaceObject(BaseTileObject obj, Positioning Connected = Positioning.Center) { if (Connected == Positioning.Center) { obj.Place(Location); } else { obj.Place(Location, Connected); } Objects.Add(obj); return(obj); }
/// <summary> /// Add a tileobject to the properties screen /// </summary> public void Add() { try { BaseTileObject tileObject = TileObjectManger.TILE_OBJECTS[selectedIconIndex]; //tileProperties.GetComponent<TileObjectEditor>().AddTileObject(tileObject); UIRayCastScript.GetTileObjectEditor().AddTileObject(tileObject); } catch (IndexOutOfRangeException ex) { Debug.LogWarning(ex.Message); } }
private void addTileObject(VRAR_Tile tile, BaseTileObject tileObject) { //tile.AddPosition(tileObject.getObjectID(), tile.tileGameObject.position+new Vector3(UnityEngine.Random.Range(0.0f, 1f), 0, UnityEngine.Random.Range(0.0f, 1f))); Vector3 position = tile.tileGameObject.position + new Vector3(UnityEngine.Random.Range(0.0f, 1f), 0, UnityEngine.Random.Range(0.0f, 1f)); float scale = UnityEngine.Random.Range(0.5f, 1f); //tile.AddScale(tileObject.getObjectID(), new Vector3(scale, scale, scale)); Vector3 scaleVector = new Vector3(scale, scale, scale); //tile.AddRotation(tileObject.getObjectID(), Quaternion.Euler(new Vector3(UnityEngine.Random.Range(0, 2), UnityEngine.Random.Range(0, 360), 0))); Quaternion rotation = Quaternion.Euler(new Vector3(UnityEngine.Random.Range(0, 2), UnityEngine.Random.Range(0, 360), 0)); tile.addDumbObject(tileObject, position, rotation, scaleVector); //TileRenderer.instance.updateTile(tile); }
public void setInteractableObject(BaseTileObject tileObject) { //Debug.Log("THis created a bugged tile so disabling it for now"); return; if (tileObject.getInteractable()) { interactableObject = tileObject; } else { Debug.LogError("Someone tried to set a non interactable object as the interactable object (" + tileObject.getObjectID() + ") of the tile :" + this); } }
static ObjectBox() { BaseTileObject partialCover; partialCover = new BaseTileObject("CoverPartial", "CoverPartial", new SimpleCords(0, 0, 0), true, true, CoverType.Partial, TraversalType.None); BaseTileObject lowWall; lowWall = new BaseTileObject("WallLow", "WallLow", new SimpleCords(0, 0, 0), true, false, CoverType.Partial, TraversalType.Vault); BaseTileObject highWall; highWall = new BaseTileObject("WallHigh", "WallHigh", new Vector3(0, 0.5f, 0), true, false, CoverType.Full, TraversalType.None); AddToBox(partialCover); AddToBox(lowWall); AddToBox(highWall); }
public void addDumbObject(BaseTileObject tileObject, Vector3 position, Quaternion rotation, Vector3 scale) { AddPosition(tileObject.getObjectID(), position); AddRotation(tileObject.getObjectID(), rotation); AddScale(tileObject.getObjectID(), scale); //Debug.Log("Adding new object with id : " + tileObject.getObjectID()); //if (!tileObject.getInteractable()) { dumbObjectsList.Add(tileObject); } //else { //Debug.LogError("Someone tried to set a interactable object as a dumb object of the tile :" + this); } setDirty(); }
public void InspectButtonPressed() { //Clear buttons and hide tilehighlighter //clearButtons(); //TileRenderer.instance.updateTileHighlighter(this.transform, false); BaseTileObject baseTileObject = null; List <BaseTileObject> objectList = currentTile.getDumbObjectsList(); if (objectList != null && objectList.Count > 0) { baseTileObject = currentTile.getDumbObjectsList()[0]; } //show hand if interactable if (baseTileObject != null) { currentTileText.text = baseTileObject.getInspect(); return; } NonPlayer npc = currentTile.getNPC(); if (npc != null) { currentTileText.text = npc.GetInspect(); return; } if (client != null) { List <BasePlayer> players = client.getPlayerList(); foreach (BasePlayer player in players) { if (player.GetCurrentTile() == currentTile) { currentTileText.text = "This is " + player.GetName(); return; } } } }
/// <summary> /// Instantiate the buttons for display in the content holder /// </summary> /// <param name="tileObject"></param> //private void InstantiateObject(GameObject tileObject, int id) private void InstantiateObject(BaseTileObject baseTileObject, int id) { print("InstantiateObject :" + baseTileObject + " id :" + id); GameObject tileObject = baseTileObject.getPrefab().gameObject; if (tileObject == null) { Debug.LogWarning("Warning given tileObject is null"); } GameObject f = Instantiate(tileObject.transform.Find("IconButton").gameObject); //GameObject mesh = tileObject.GetComponentInChildren<MeshFilter>().gameObject; //print("mesh object :" + mesh.name); //Image image = f.GetComponent<Image>(); //Texture2D texture = AssetPreview.GetMiniThumbnail(TileObjectManger.instance.prefabsThisArrayWillBeReplacedWithAnAutomaticWay[2]); //image.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); f.transform.SetParent(GameObject.Find("Content").gameObject.transform); f.transform.localScale = new Vector3(1, 1, 1); f.transform.rotation = new Quaternion(0, 0, 0, 0); //f.transform.localPosition = new Vector3(f.transform.position.x, f.transform.position.y, 0); f.transform.localPosition = new Vector3(); f.GetComponent <BoxCollider>().size = new Vector3(50, 50); //Give the object the name of the id f.name = standartKeyName + id; //Add an click listener for when the button is clicked //Button b = f.GetComponent<Button>(); // f.transform.GetChild(0).gameObject.GetComponent<Indexer>().index = prefabs.Count - 1; // b.onClick.AddListener(delegate { this.SelectTileObject(f); }); //spawn mesh for preview GameObject mesh = Instantiate(tileObject.GetComponentInChildren <MeshFilter>().gameObject); Renderer meshRenderer = mesh.GetComponent <Renderer>(); Vector3 size = meshRenderer.bounds.size; Vector3 scale = transform.localScale; if (size.x > size.y) { if (size.x > size.z) { scale /= size.x; } else { scale /= size.z; } } else if (size.z > size.y) { if (size.z > size.x) { scale /= size.z; } else { scale /= size.x; } } else { scale /= size.y; } scale.Scale(new Vector3(1, 1, 0.1f)); //mesh.transform.localScale = scale*40; scale.Scale(new Vector3(0.02f, 0.0007f, 1f)); mesh.transform.localScale = scale; mesh.transform.parent = f.transform; //mesh.transform.localPosition = new Vector3(f.transform.position.x, f.transform.position.y-30f, -10); mesh.transform.localPosition = new Vector3(); mesh.transform.localEulerAngles = new Vector3(); }
private BaseTileObject addTileObject(int id) { TILE_OBJECTS[id] = new BaseTileObject(id); return(TILE_OBJECTS[id]); }
public BaseTileObject Clone() { BaseTileObject temp = new BaseTileObject(ObjectName, ModelName, ModelOffset, HasHitBox, isCenter, Solidity, TraversalKind); return(temp); }
public static void AddToBox(BaseTileObject obj) { Box.Add(obj.ObjectName, obj); }
public void removeDumbObject(BaseTileObject tileObject) { dumbObjectsList.Remove(tileObject); }
private BaseTileObject addTileObject(int id) { tileObjects[id] = new BaseTileObject(id); return(tileObjects[id]); }
public void readLVLFile() { TextReader tr; if (Application.isEditor) {//use the project location tr = new StreamReader(Application.dataPath + "/levels/" + "/level_" + levelTile.tileIndex_X + "#" + levelTile.tileIndex_Y + ".sav"); } else {//use the user save location tr = new StreamReader(Application.persistentDataPath + "/levels/" + "/level_" + levelTile.tileIndex_X + "#" + levelTile.tileIndex_Y + ".sav"); } string line; while ((line = tr.ReadLine()) != null) { string[] splitted = line.Split(';'); if (splitted.Length < 4) { } else { VRAR_Tile tile = new VRAR_Tile(int.Parse(splitted[0]), int.Parse(splitted[1]), float.Parse(splitted[2]), splitted[5], bool.Parse(splitted[6])); BaseTileObject interactableObject = TileObjectManger.TILE_OBJECTS[int.Parse(splitted[3])]; if (interactableObject.getInteractable()) { tile.setInteractableObject(interactableObject); } //Debug.Log("Reading lvl file interactable object :" + interactableObject.getName()); if (splitted[4].Length > 0) { string[] dumbObjectIDs = splitted[4].Split('<'); foreach (string dumbString in dumbObjectIDs) { tile.addDumbObject(TileObjectManger.TILE_OBJECTS[int.Parse(dumbString)]); } } vrarTiles.Add(tile); vrarTileDict.Add(new Vector2Int(int.Parse(splitted[0]), int.Parse(splitted[1])), tile); //Debug.Log("added tile :" +tile); } } //if level empty, spawn default lvl tiles if (vrarTiles.Count == 0) { Debug.Log("HOOOOOO"); int radius = Random.Range(1, 8); for (int y = -radius; y <= radius; y++) { for (int x = -radius; x <= radius; x++) { if (x * x + y * y <= radius * radius) { VRAR_Tile tile = new VRAR_Tile(x, y); vrarTiles.Add(tile); vrarTileDict.Add(new Vector2Int(x, y), tile); } } } } }
public void loadLevel() { TextReader tr; if (Application.isEditor) {//use the project location tr = new StreamReader(Application.dataPath + "/levels/" + "/level_" + levelTile.tileIndex_X + "#" + levelTile.tileIndex_Y + ".sav"); } else {//use the user save location tr = new StreamReader(Application.persistentDataPath + "/levels/" + "/level_" + levelTile.tileIndex_X + "#" + levelTile.tileIndex_Y + ".sav"); } string line; while ((line = tr.ReadLine()) != null) { string[] splitted = line.Split(';'); if (splitted.Length < 4) { } else { VRAR_Tile tile = new VRAR_Tile(int.Parse(splitted[0]), int.Parse(splitted[1]), float.Parse(splitted[2]), splitted[5], bool.Parse(splitted[6])); BaseTileObject interactableObject = TileObjectManger.TILE_OBJECTS[int.Parse(splitted[3])]; if (interactableObject.getInteractable()) { tile.setInteractableObject(interactableObject); tile.SetWalkable(false); } if (splitted.Length >= 8 && splitted[7] != "") { tile.setInterior(TileObjectManger.INTERIOR_BASE_OBJECTS[int.Parse(splitted[7])]); tile.SetWalkable(false); } if (splitted.Length >= 9 && splitted[8] != "") { tile.setNPC(new NonPlayer(int.Parse(splitted[8]), new Vector2Int(tile.tileIndex_X, tile.tileIndex_Y))); tile.SetWalkable(false); } //Debug.Log("Reading lvl file interactable object :" + interactableObject.getName()); if (splitted[4].Length > 0) { string[] dumbObjectIDs = splitted[4].Split('<'); tile.SetWalkable(false); foreach (string dumbString in dumbObjectIDs) { // Debug.Log(dumbObjectIDs.Length + " size"); // Debug.Log(dumbString); string[] splitty = dumbString.Split(','); if (splitty.Length > 1) { // Debug.Log("Base tile id = " + dumbString[0]); // Debug.Log("Splitty size = " + splitty.Length); int id = int.Parse(splitty[0]); float positionX = float.Parse(splitty[1]); float positionY = float.Parse(splitty[2]); float positionZ = float.Parse(splitty[3]); Vector3 position = new Vector3(positionX, positionY, positionZ); float scaleX = float.Parse(splitty[4]); Vector3 scale = new Vector3(scaleX, scaleX, scaleX); Quaternion rotation = new Quaternion(float.Parse(splitty[5]), float.Parse(splitty[6]), float.Parse(splitty[7]), float.Parse(splitty[8])); /* Debug.Log("posx = " + positionX); * Debug.Log("posy = " + positionY); * Debug.Log("posz = " + positionZ); * Debug.Log("scalex = " + scaleX); * Debug.Log("scaley = " + scaleY); * Debug.Log("scalez = " + scaleZ); * Debug.Log("Next string is " + dumbObjectIDs[2]); */ tile.AddPosition(id, position); tile.AddRotation(id, rotation); tile.AddScale(id, scale); tile.addDumbObject(TileObjectManger.TILE_OBJECTS[id]); if (id == TileObjectManger.SPAWN_POINT_ID) { //Debug.Log("Set the spawn points to walkable in a suboptimal way"); tile.SetWalkable(true); } } } } if (tile.terrain == "Water") { //Debug.Log("Set water to no walkable in a suboptimal way"); tile.SetWalkable(false); } vrarTiles.Add(tile); vrarTileDict.Add(new Vector2Int(int.Parse(splitted[0]), int.Parse(splitted[1])), tile); //Debug.Log("added tile :" +tile); } } //if level empty, spawn default lvl tiles if (vrarTiles.Count == 0) { Debug.Log("HOOOOOO"); int radius = Random.Range(1, 8); for (int y = -radius; y <= radius; y++) { for (int x = -radius; x <= radius; x++) { if (x * x + y * y <= radius * radius) { VRAR_Tile tile = new VRAR_Tile(x, y); vrarTiles.Add(tile); vrarTileDict.Add(new Vector2Int(x, y), tile); } } } } }
//Add a prefab to the gridview public void AddPrefab(BaseTileObject prefab) { prefabs.Add(prefab); InstantiateObject(prefab.getPrefab().gameObject); }