public Door(QuestData.Door questDoor, Game gameObject) : base(gameObject) { qDoor = questDoor; Texture2D newTex = Resources.Load("sprites/door") as Texture2D; // Check load worked if (newTex == null) { Debug.Log("Error: Cannot load door image"); Application.Quit(); } // Create object unityObject = new GameObject("Object" + qDoor.name); unityObject.tag = "board"; unityObject.transform.parent = game.tokenCanvas.transform; // Create the image image = unityObject.AddComponent <UnityEngine.UI.Image>(); Sprite tileSprite = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 1); // Set door colour image.sprite = tileSprite; image.rectTransform.sizeDelta = new Vector2(0.4f, 1.6f); // Rotate as required unityObject.transform.RotateAround(Vector3.zero, Vector3.forward, qDoor.rotation); // Move to square (105 units per square) unityObject.transform.Translate(new Vector3(-(float)0.5, (float)0.5, 0), Space.World); unityObject.transform.Translate(new Vector3(qDoor.location.x, qDoor.location.y, 0), Space.World); SetColor(qDoor.colourName); game.tokenBoard.Add(this); }
// Initialise from a door public TokenControl(QuestData.Door d) { UnityEngine.UI.Button button = d.gameObject.AddComponent <UnityEngine.UI.Button>(); button.interactable = true; button.onClick.AddListener(delegate { startEvent(); }); e = d; }
override public float AddSubEventComponents(float offset) { doorComponent = component as QuestData.Door; UIElement ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(0, offset, 6, 1); ui.SetText(new StringKey("val", "X_COLON", new StringKey("val", "ROTATION"))); ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(6, offset, 3, 1); ui.SetText(doorComponent.rotation.ToString() + "˚"); ui.SetButton(delegate { Rotate(); }); new UIElementBorder(ui); offset += 2; ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(0.5f, offset, 8, 1); ui.SetText(COLOR); ui.SetButton(delegate { Colour(); }); new UIElementBorder(ui); offset += 2; game.quest.ChangeAlpha(doorComponent.sectionName, 1f); return(offset); }
public EditorComponentDoor(string nameIn) : base() { Game game = Game.Get(); doorComponent = game.quest.qd.components[nameIn] as QuestData.Door; component = doorComponent; name = component.name; Update(); }
public void NewDoor() { Game game = Game.Get(); int index = 0; while (game.quest.qd.components.ContainsKey("Door" + index)) { index++; } QuestData.Door door = new QuestData.Door("Door" + index); game.quest.qd.components.Add("Door" + index, door); CameraController cc = GameObject.FindObjectOfType <CameraController>(); door.location.x = game.gameType.SelectionRound() * Mathf.Round(cc.gameObject.transform.position.x / game.gameType.SelectionRound()); door.location.y = game.gameType.SelectionRound() * Mathf.Round(cc.gameObject.transform.position.y / game.gameType.SelectionRound()); game.quest.Add("Door" + index); SelectComponent("Door" + index); }
public void SelectAddVisibility(bool add, int index, string component) { string target = component; int i; if (component.Equals("{NEW:Door}")) { i = 0; while (game.quest.qd.components.ContainsKey("Door" + i)) { i++; } target = "Door" + i; QuestData.Door door = new QuestData.Door(target); Game.Get().quest.qd.components.Add(target, door); CameraController cc = GameObject.FindObjectOfType <CameraController>(); door.location.x = game.gameType.TileRound() * Mathf.Round(cc.gameObject.transform.position.x / game.gameType.TileRound()); door.location.y = game.gameType.TileRound() * Mathf.Round(cc.gameObject.transform.position.y / game.gameType.TileRound()); game.quest.Add(target); } if (component.Equals("{NEW:Tile}")) { i = 0; while (game.quest.qd.components.ContainsKey("Tile" + i)) { i++; } target = "Tile" + i; QuestData.Tile tile = new QuestData.Tile(target); Game.Get().quest.qd.components.Add(target, tile); CameraController cc = GameObject.FindObjectOfType <CameraController>(); tile.location.x = game.gameType.TileRound() * Mathf.Round(cc.gameObject.transform.position.x / game.gameType.TileRound()); tile.location.y = game.gameType.TileRound() * Mathf.Round(cc.gameObject.transform.position.y / game.gameType.TileRound()); game.quest.Add(target); } if (component.Equals("{NEW:Token}")) { i = 0; while (game.quest.qd.components.ContainsKey("Token" + i)) { i++; } target = "Token" + i; QuestData.Token token = new QuestData.Token(target); Game.Get().quest.qd.components.Add(target, token); CameraController cc = GameObject.FindObjectOfType <CameraController>(); token.location.x = game.gameType.TileRound() * Mathf.Round(cc.gameObject.transform.position.x / game.gameType.TileRound()); token.location.y = game.gameType.TileRound() * Mathf.Round(cc.gameObject.transform.position.y / game.gameType.TileRound()); game.quest.Add(target); } if (component.Equals("{NEW:UI}")) { i = 0; while (game.quest.qd.components.ContainsKey("UI" + i)) { i++; } target = "UI" + i; Game.Get().quest.qd.components.Add(target, new QuestData.UI(target)); } if (component.Equals("{NEW:QItem}")) { i = 0; while (game.quest.qd.components.ContainsKey("QItem" + i)) { i++; } target = "QItem" + i; Game.Get().quest.qd.components.Add(target, new QuestData.QItem(target)); } if (index != -1) { if (add) { eventComponent.addComponents[index] = target; } else { eventComponent.removeComponents[index] = target; } Update(); return; } string[] oldC = null; if (add) { oldC = eventComponent.addComponents; } else { oldC = eventComponent.removeComponents; } string[] newC = new string[oldC.Length + 1]; for (i = 0; i < oldC.Length; i++) { newC[i] = oldC[i]; } newC[i] = target; if (add) { eventComponent.addComponents = newC; } else { eventComponent.removeComponents = newC; } Update(); }
// Add a door public void add(QuestData.Door d) { tc.Add(new TokenControl(d)); }