public Explorer(Model model, int[] explorerData, PlayScene parent) : base(model, parent) { Model mArrow = PlayContentHolder.Instance.ModelArrow; //tao cac nut dieu khien _buttons = new Button3D[5]; //nut len tren _buttons[0] = new Button3D(mArrow); //nut sang phai _buttons[1] = new Button3D(mArrow); _buttons[1].Rotation = new Vector3(0, MathHelper.ToRadians(-90), 0); //nut xuong duoi _buttons[2] = new Button3D(mArrow); _buttons[2].Rotation = new Vector3(0, MathHelper.ToRadians(-180), 0); //nut sang trai _buttons[3] = new Button3D(mArrow); _buttons[3].Rotation = new Vector3(0, MathHelper.ToRadians(-270), 0); //nut giua _buttons[4] = new Button3D(PlayContentHolder.Instance.ModelCenter); //di chuyen vi tri model va cac nut bam Position = explorerData; //khoi tao vi tri tuong doi so voi texture cua nen unitFactor = 25.6f / (float)(parent.MazeSize); unitPosition = new Vector2(); Wait(); }
void Setup3DGUI() { editButton = Setup3DButton("새로 만들기", editButtonEnablePosition, editButtonEnableScale); cancelEditingButton = Setup3DButton("취소", cancelEditingButtonEnablePosition, cancelEditingButtonEnableScale); saveEditingButton = Setup3DButton("저장", saveEditingButtonEnablePosition, saveEditingButtonEnableScale); doneEditingButton = Setup3DButton("완료", doneEditingButtonEnablePosition, doneEditingButtonEnableScale); }
// Use this for initialization void Start() { for (int i = 0; i < transform.childCount; i++) { GameObject obj = transform.GetChild(i).gameObject; Button3D button = obj.GetComponent <Button3D>(); if (button != null) { button.SetMenu(this); elements++; } } }
Button3D Setup3DButton(string label, Vector3 enablePosition, Vector3 enableScale) { Transform buttonTransform = (Transform)Instantiate(button3D, buttonDisablePosition, Quaternion.identity); buttonTransform.parent = buttonContainer; buttonTransform.localScale = buttonDisableScale; buttonTransform.localPosition = buttonDisablePosition; Button3D button = buttonTransform.GetComponent <Button3D>(); button.EnablePosition = enablePosition; button.EnableScale = enableScale; button.DisablePosition = enablePosition; button.DisableScale = buttonDisableScale; button.SwollenScale = buttonSwollenScale; button.Text = label; button.enabled = false; return(button); }
void Update() { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 100f)) { Debug.Log(hit.transform); if (hit.transform.GetComponent <Button3D> ()) { Button3D button = hit.transform.GetComponent <Button3D> (); button.OnClick(); } } } }
void Point() { Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { //treat if hit UI Button3D button = hit.transform.GetComponent <Button3D>(); if (button && button != lookingButton) { lookingButton = button; lookingButton.OnEnter(); } } else { if (lookingButton) { lookingButton.OnExit(); lookingButton = null; } } }
public void OnPickStateChanged(PickState prevState, PickState currentState, Picker picker, GameObject target) { switch (currentState) { case PickState.None: if (target && target.tag.Equals(TAG_PART)) { Part part = target.GetComponent <Part>(); part.Highlighted = Part.HighlightDegree.None; part.DisconnectFromRigidbody(); if (picker != null) { picker.Reset(); } } else if (target && target.tag.Equals(TAG_BUTTON)) { Highlightable button = target.GetComponentInChildren <Highlightable>(); button.Highlighted = Highlightable.HighlightDegree.None; } break; case PickState.Hovering: if (target && target.tag.Equals(TAG_PART)) { Part part = target.GetComponent <Part>(); part.Highlighted = Part.HighlightDegree.Half; part.DisconnectFromRigidbody(); if (prevState == PickState.Picking) { part.Highlighted = Part.HighlightDegree.None; if (picker != null) { picker.Reset(); } } } else if (target && target.tag.Equals(TAG_BUTTON)) { Highlightable button = target.GetComponentInChildren <Highlightable>(); button.Highlighted = Highlightable.HighlightDegree.Half; } if (currentShelf.CurrentPreset().Type == Preset.PresetType.NewPresetPlaceHolder) { audio.PlayOneShot(audioHover); } break; case PickState.Picking: if (target && target.tag.Equals(TAG_PART) && picker != null) { Part part = target.GetComponent <Part>(); part.Highlighted = Part.HighlightDegree.Full; part.ConnectToRigidbody(picker.MiddlePointContainer.rigidbody, Vector3.zero); pickedAnyPart = true; if (currentShelf.CurrentPreset().Type == Preset.PresetType.NewPresetPlaceHolder) { audio.PlayOneShot(audioPickPart); } } else if (target && target.tag.Equals(TAG_BUTTON)) { Highlightable highlightable = target.GetComponentInChildren <Highlightable>(); highlightable.Highlighted = Highlightable.HighlightDegree.Full; Button3D button = target.transform.parent.GetComponent <Button3D>(); if (button == editButton) { StartCoroutine(OnEditButtonPicked()); } else if (button == saveEditingButton) { StartCoroutine(OnSaveButtonPicked()); } else if (button == cancelEditingButton) { StartCoroutine(OnCancelButtonPicked()); } else if (button == doneEditingButton) { OnDoneButtonPicked(); } audio.PlayOneShot(audioPickButton); } break; } }
private void FixedUpdate() { for (int i = 0; i < hands.Length; i++) { Ray ray = new Ray(hands[i].transform.position, hands[i].transform.forward); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hands[i].isClickingTheButton) { continue; } LineRenderer line = (i == 0) ? line1 : line2; DrawLine(line, ray.origin, hit.point, lineWidth, lineColor); //treat if hit a grabbable OVRGrabbable grabbable = hit.transform.GetComponent <OVRGrabbable>(); if (grabbable != null) { if (i == 0) { //Debug.Log("seen"); if (grabbable == hands[i].lookingGrabbable) { continue; } } hands[i].lookingGrabbable = grabbable; hands[i].lookingGrabbable.GetComponent <MeshRenderer>().material.color = Color.red; // Add the grabbable int refCount = 0; hands[i].m_grabCandidates.TryGetValue(grabbable, out refCount); hands[i].m_grabCandidates[grabbable] = refCount + 1; //Debug.Log("obj to pool"); continue; } //treat if hit UI Button3D button = hit.transform.GetComponent <Button3D>(); if (button) { hands[i].lookingButton = button; hands[i].lookingButton.OnEnter(); continue; } StopLook(hands[i], i); } else { StopLook(hands[i], i); LineRenderer line = (i == 0) ? line1 : line2; DrawLine(line, Vector3.zero, Vector3.zero, 0, Vector4.zero); } } }
// Use this for initialization void Start() { button3D = gameObject.GetComponent <Button3D>(); }
IEnumerator InstantiateButtons() { yield return(new WaitForSeconds(0.4f)); int number = 1; for (int i = 0; i < 4; i++) { Vector3 pos = new Vector3(-6.4f, 8.8f - (3.3f * i), 0f); for (int j = 0; j < 5; j++) { GameObject obj = Instantiate(module2MapButton); spawnedMapButtons.Add(obj); obj.transform.SetParent(module2Levels.transform); obj.transform.localPosition = pos; obj.name = "PreLevel" + number.ToString(); RankingManager.Record?bestResult = RankingManager.GetTheBestRecord("PreLevel" + number.ToString()); if (bestResult != null) { obj.transform.GetChild(0).GetComponent <TextMeshPro>().text += $" <size=\"1\"><b>{((RankingManager.Record)bestResult).points.ToString()}</b></size>"; } else { obj.transform.GetChild(0).GetComponent <TextMeshPro>().text += " <size=\"1\"><b>0</b></size>"; } Button3D btn = obj.GetComponent <Button3D>(); string iconPath = $"Maps/{Path.GetFileNameWithoutExtension($"{obj.name}_icon.jpg")}"; MeshRenderer renderer = obj.GetComponent <MeshRenderer>(); Material mat = new Material(Shader.Find("Legacy Shaders/Diffuse")); Texture2D texture = Resources.Load <Texture2D>(iconPath); print(iconPath); if (texture != null) { mat.mainTexture = texture; renderer.material = mat; } btn.OnClick.AddListener((sender) => { MapSerializer serializer = new MapSerializer(MapSerializer.MapsPath + "/" + sender.name); Map deserializedMap = serializer.Deserialize(true); module2Levels.SetActive(false); module2Info.SetActive(true); currentLevelModule2 = sender.name; RankingManager.Record[] records = RankingManager.GetRecords(currentLevelModule2); TextMeshPro text = module2Info.transform.GetChild(2).GetComponent <TextMeshPro>(); text.text = ""; SetMapIcon(MapSerializer.MapsPath + "/" + sender.name + ".xml", module2Info.transform.GetChild(0).gameObject); foreach (RankingManager.Record r in records) { text.text += $"Points: <b>{r.points.ToString()} | </b>Count of moves: <b>{r.moves.ToString()}</b> | Date: <b>{r.date.ToShortDateString()} {r.date.ToShortTimeString()}</b>\n"; } Button3D playBtn = module2Info.transform.GetChild(4).GetComponent <Button3D>(); Button3D playSavedBtn = module2Info.transform.GetChild(5).GetComponent <Button3D>(); playSavedBtn.isClickable = SaveLoadManager.SaveExists(deserializedMap); playSavedBtn.OnClick.RemoveAllListeners(); if (playSavedBtn.isClickable) { playSavedBtn.OnClick.AddListener(s => { Map progressedMap = SaveLoadManager.LoadLevelProgress(deserializedMap, out int movesCount); StartCoroutine(Coroutine()); IEnumerator Coroutine() { camAnim.SetInteger("view", LEVEL); camAnim.SetTrigger("switch"); yield return(new WaitForSeconds(0.5f)); if (spawnModule2ButtonsCor != null) { StopCoroutine(spawnModule2ButtonsCor); spawnModule2ButtonsCor = null; } foreach (GameObject o in spawnedMapButtons) { Destroy(o); } spawnedMapButtons.Clear(); module2.SetActive(false); module2Info.SetActive(false); camAnim.enabled = false; LevelManager.CurrentManager.SetBackgroundColor(progressedMap.biomeType); LevelManager.CurrentManager.LoadLevel(progressedMap, movesCount); } }); } playBtn.OnClick.RemoveAllListeners(); playBtn.OnClick.AddListener(s => { SaveLoadManager.ClearSave(deserializedMap); StartCoroutine(Coroutine()); IEnumerator Coroutine() { camAnim.SetInteger("view", LEVEL); camAnim.SetTrigger("switch"); yield return(new WaitForSeconds(0.5f)); if (spawnModule2ButtonsCor != null) { StopCoroutine(spawnModule2ButtonsCor); spawnModule2ButtonsCor = null; } foreach (GameObject o in spawnedMapButtons) { Destroy(o); } spawnedMapButtons.Clear(); module2.SetActive(false); module2Info.SetActive(false); camAnim.enabled = false; LevelManager.CurrentManager.SetBackgroundColor(deserializedMap.biomeType); LevelManager.CurrentManager.LoadLevel(deserializedMap); } }); }); number++; pos += new Vector3(5.3f, 0f, 0f); yield return(new WaitForSeconds(0.075f)); } } spawnModule2ButtonsCor = null; }
private void LoadModule3() { module3MapButtons.ForEach(item => Destroy(item)); module3MapButtons.Clear(); string[] allAvailableMaps = MapEditor.GetAllMapsPaths(); for (int i = 0; i < allAvailableMaps.Length; i++) { Vector3 pos = new Vector3(4f, 9.7f - (i * 0.6f), 0f); GameObject newBtn = Instantiate(module3MapButton); newBtn.transform.SetParent(module3.transform); newBtn.transform.localPosition = pos; newBtn.transform.rotation = Quaternion.identity; newBtn.transform.GetChild(3).GetComponent <TextMeshPro>().text = Path.GetFileName(allAvailableMaps[i]); newBtn.transform.GetChild(4).GetComponent <TextMeshPro>().text = File.GetLastAccessTime(allAvailableMaps[i]).ToString(); string path = MapEditor.PathToMapsDir + "/" + newBtn.transform.GetChild(1).transform.parent.GetChild(3).GetComponent <TextMeshPro>().text; newBtn.transform.GetChild(1).GetComponent <Button3D>().OnClick.AddListener((sender) => { StartCoroutine(Coroutine()); IEnumerator Coroutine() { camAnim.SetInteger("view", LEVEL); camAnim.SetTrigger("switch"); yield return(new WaitForSeconds(0.5f)); module3.SetActive(false); camAnim.enabled = false; MapSerializer serializer = new MapSerializer(path); Map deserializedMap = serializer.Deserialize(false); mapEditor.InitializeEditor(deserializedMap, path); } }); newBtn.transform.GetChild(0).GetComponent <Button3D>().OnClick.AddListener((sender) => { MapSerializer serializer = new MapSerializer(path); Map deserializedMap = serializer.Deserialize(false); module3.SetActive(false); module2Info.SetActive(true); RankingManager.Record[] records = RankingManager.GetRecords(deserializedMap.name); TextMeshPro text = module2Info.transform.GetChild(2).GetComponent <TextMeshPro>(); text.text = ""; foreach (RankingManager.Record r in records) { text.text += $"Points: <b>{r.points.ToString()} | </b>Count of moves: <b>{r.moves.ToString()}</b> | Date: <b>{r.date.ToShortDateString()} {r.date.ToShortTimeString()}</b>\n"; } SetMapIcon(path, module2Info.transform.GetChild(0).gameObject); Button3D playBtn = module2Info.transform.GetChild(4).GetComponent <Button3D>(); Button3D playSavedBtn = module2Info.transform.GetChild(5).GetComponent <Button3D>(); playSavedBtn.isClickable = SaveLoadManager.SaveExists(deserializedMap); playSavedBtn.OnClick.RemoveAllListeners(); if (playSavedBtn.isClickable) { playSavedBtn.OnClick.AddListener(s => { Map progressedMap = SaveLoadManager.LoadLevelProgress(deserializedMap, out int movesCount); StartCoroutine(Coroutine()); IEnumerator Coroutine() { camAnim.SetInteger("view", LEVEL); camAnim.SetTrigger("switch"); yield return(new WaitForSeconds(0.5f)); module3.SetActive(false); module2Info.SetActive(false); camAnim.enabled = false; LevelManager.CurrentManager.SetBackgroundColor(progressedMap.biomeType); LevelManager.CurrentManager.LoadLevel(progressedMap, movesCount); } }); } playBtn.OnClick.RemoveAllListeners(); playBtn.OnClick.AddListener(s => { SaveLoadManager.ClearSave(deserializedMap); StartCoroutine(Coroutine()); IEnumerator Coroutine() { camAnim.SetInteger("view", LEVEL); camAnim.SetTrigger("switch"); yield return(new WaitForSeconds(0.5f)); module3.SetActive(false); module2Info.SetActive(false); camAnim.enabled = false; LevelManager.CurrentManager.SetBackgroundColor(deserializedMap.biomeType); LevelManager.CurrentManager.LoadLevel(deserializedMap); } }); }); newBtn.transform.GetChild(2).GetComponent <Button3D>().OnClick.AddListener((sender) => { File.Delete(MapEditor.PathToMapsDir + "/" + sender.transform.parent.GetChild(3).GetComponent <TextMeshPro>().text); LoadModule3(); }); module3MapButtons.Add(newBtn); } }