using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class HideCommand : ICommand { List _hideList; List _hideObjectNumberIDs; List _hideStateList; bool _setVisible; GameObject _sceneRef; string _sceneName = "SCENE"; string _controlPathName = "HIDER/CONTROL"; public HideCommand(string objectName, bool setVisible) { Init(setVisible); InitVisibilityStates(objectName); } public HideCommand(List objectNames, bool setVisible) { Init(setVisible); foreach (string objectName in objectNames) { InitVisibilityStates(objectName); } } public void Execute() { SetVisibility(_setVisible); foreach (int objectNumber in _hideObjectNumberIDs) { string objectName = _G.OBJs[objectNumber][0]; UpdateHideList(_setVisible, objectName); } } public string GetAction() { return _setVisible ? "Reveal" : "Hide"; } public void Undo() { for (int i = 0; i < _hideList.Count; i++) { GameObject go = _hideList[i]; go.SetActive(_hideStateList[i][0]); go.GetComponent().enabled = _hideStateList[i][1]; go.GetComponent().enabled = _hideStateList[i][2]; int objectNumber = _hideObjectNumberIDs[i]; string objectName = _G.OBJs[objectNumber][0]; UpdateHideList(!_setVisible, objectName); } } public void UpdateCommand() { for (int i = 0; i < _hideList.Count; i++) { GameObject go = _hideList[i]; int objectNumber = _hideObjectNumberIDs[i]; if (go == null && _G.OBJs[objectNumber][0] != "null") { string objectName = _G.OBJs[_hideObjectNumberIDs[i]][0]; Debug.Log(objectName); _hideList[i] = _sceneRef.transform.Find(objectName).gameObject; } } } private void Init(bool setVisible) { _hideList = new List(); _hideObjectNumberIDs = new List(); _hideStateList = new List(); _setVisible = setVisible; } private void InitVisibilityStates(string objectName) { _sceneRef = GameObject.Find(_sceneName); GameObject go = _sceneRef.transform.Find(objectName).gameObject; //GameObject.Find(objectName); _hideList.Add(go); _hideObjectNumberIDs.Add(Get.GetObjectIndex(objectName)); _hideStateList.Add(GetVisibilityStates(go)); } private void SetVisibility(bool isVisible) { foreach (GameObject go in _hideList) { go.SetActive(isVisible); go.GetComponent().enabled = isVisible; go.GetComponent().enabled = isVisible; GameObject OgeeSet=Get.o2("OgeeContainer","OgeeSet"+go.name); if(OgeeSet!=null){ OgeeSet.SetActive(isVisible); } } } private bool[] GetVisibilityStates(GameObject go) { bool[] visibilityStates = new bool[] { go.activeSelf, go.GetComponent().enabled, go.GetComponent().enabled }; return visibilityStates; } private void UpdateHideList(bool setVisible, string objectName) { if (setVisible) { SceneModeManager.GetObjectInScene(objectName).GetComponent().material = _G.INV; _G.HIDELIST.Remove(objectName); } else { _G.HIDELIST.Add(objectName); } UpdateHideButtons(setVisible); } static public void UpdateHideButtons(bool setVisible) { // Hide Button GameObject btnHide = Get.o1("btnHIDE"); if (btnHide != null) { if (setVisible) { Get.o1("btnHIDE").GetComponent().color = _G.colorButton; Get.o2("btnHIDE", "Icon").GetComponent().color = _G.colorIcon; } else if (_G.HIDELIST.Contains(SceneModeManager.SelectedName)) { Get.o1("btnHIDE").GetComponent().color = _G.colorIcon; Get.o2("btnHIDE", "Icon").GetComponent().color = _G.colorButton; } } // Unhide button GameObject btnUnhide = Get.o1("btnUNHIDE"); if (btnUnhide != null) { if (_G.HIDELIST.Count == 0) { Get.o1("btnUNHIDE").GetComponent().color = _G.colorButton; Get.o2("btnUNHIDE", "Icon").GetComponent().color = _G.colorIcon; Get.o3("btnUNHIDE", "Icon", "RedCircle").SetActive(false); } else { Get.o1("btnUNHIDE").GetComponent().color = _G.colorIcon; Get.o2("btnUNHIDE", "Icon").GetComponent().color = _G.colorButton; Get.o3("btnUNHIDE", "Icon", "RedCircle").SetActive(true); } } } }