void Update() { // Cast ray from mouse if playing if (playing) { // TODO: Hardcoded input, check this later maybe if (Input.GetMouseButtonDown(0)) { // Cast a ray from camera through the mouse position onto the scene Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { // Get value from button if it's a button // TODO: Maybe tag the buttons to simplify this process //Debug.Log("Ray hit: " + hit.collider.gameObject.name); CodeButton cb = hit.collider.gameObject.GetComponent <CodeButton>(); int v; if (cb != null) { v = cb.GetValue(); // update UI and value UpdateInputCode(v.ToString()); } } } } }
public void TryToInteract() { RaycastHit hit; if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, speakDistance)) { DialogueTrigger dialogueTrigger = hit.transform.GetComponent <DialogueTrigger>(); if (dialogueTrigger != null) { dialogueTrigger.TriggerDialogue(); } else { CodeButton codeButton = hit.transform.GetComponent <CodeButton>(); codeButton?.ModifyTexture(); } } }
void ReleaseDesignerOutlets() { if (MainToolbar != null) { MainToolbar.Dispose(); MainToolbar = null; } if (PagePopUpButton != null) { PagePopUpButton.Dispose(); PagePopUpButton = null; } if (RefreshButton != null) { RefreshButton.Dispose(); RefreshButton = null; } if (CodeButton != null) { CodeButton.Dispose(); CodeButton = null; } if (Spinner != null) { Spinner.Dispose(); Spinner = null; } if (TitleTextField != null) { TitleTextField.Dispose(); TitleTextField = null; } }
public void TranslateCommandToCode(Command command, string additional) { int lineNumber = buttons.Count + 1; // foreach (Command command in commandsPanel.Comands) //{ if (command != Command.None) { GameObject newButton = GameObject.Instantiate(button, contentPanel, false); //command != Command.EndLoop && command != Command.Loop if (command != Command.Variable) { UpdateEntries(true); } Buttons.Add(newButton); CodeButton codeButton = newButton.GetComponent <CodeButton>(); codeButton.LineNumber.text = lineNumber.ToString(); if (GameManager.instance.TutoredGameplayMode || command == Command.EndLoop) { codeButton.DeleteButton.gameObject.SetActive(false); } codeButton.DeleteButton.onClick.AddListener(() => { if (gameCanvas.IsPlaying) { GameManager.instance.ResetGame(); } for (int i = buttons.Count - 1; i >= 0; i--) { if (gameCanvas.IsPlaying) { GameManager.instance.ResetGame(); } if (buttons[i].gameObject.GetComponent <CodeButton>().LineNumber.text == codeButton.LineNumber.text) { if (command == Command.Loop) { RemoveUnfinishedLoopPanel(); while (true) { try { Command commandAux = commands.Commands[i]; RemoveButton(i); if (commandAux == Command.EndLoop) { break; } } catch (ArgumentOutOfRangeException e) { Debug.Log(e); break; } } break; } else if (command == Command.EndLoop) { while (true) { Command commandAux = commands.Commands[i]; RemoveButton(i); if (commandAux == Command.Loop) { break; } else { i--; } } } else { buttons.RemoveAt(i); RemoveCommand(i); Destroy(codeButton.gameObject); UpdateEntries(false); break; } } } for (int i = buttons.Count - 1; i >= 0; i--) { CodeButton codeButtonTemp = buttons[i].gameObject.GetComponent <CodeButton>(); codeButtonTemp.LineNumber.text = (i + 1).ToString(); } }); codeButton.CommandName.text = TranslateCommandToString(command, additional); if (command != Command.If && command != Command.Else && command != Command.EndIf) { if (GameManager.instance.ConditionalMode == 1 || GameManager.instance.ConditionalMode == 2) { codeButton.MainPanel.GetComponent <RectTransform>().offsetMin = new Vector2(10, 0); } } if (command == Command.If) { codeButton.CommandName.GetComponent <Text>().fontSize = 12; GameManager.instance.ConditionalMode = 1; commands.ConditionalButton.GetComponentInChildren <Text>().text = "SenĂ£o"; } else if (command == Command.Else) { GameManager.instance.ConditionalMode = 2; commands.ConditionalButton.GetComponentInChildren <Text>().text = "Fimse"; } else if (command == Command.EndIf) { GameManager.instance.ConditionalMode = 0; commands.ConditionalButton.GetComponentInChildren <Text>().text = "Se"; } if (GameManager.instance.LoopMode) { codeButton.AddSpaceLeft(); } } //} }
protected static void CreateCodeButton() { GameObject go = CreateGameObject("CodeButton", true); CodeButton button = go.AddComponent <CodeButton>(); }