// ================================== PUBLIC FUNCS ================================== #region Public Funcs public void Save() { SetDefaultPath(); HUDJsonObj HUDJsonObj = new HUDJsonObj(); for (int i = 0; i < m_lHUDDesignInfo.Count; i++) { HUDDesignInfo HUDDesignInfo = m_lHUDDesignInfo[i]; HUDInfo HUDInfo = new HUDInfo(); HUDInfo.m_HUDType = HUDDesignInfo.m_HUDType; HUDInfo.m_PrefPath = UtilityClass.GetPathOfObj(HUDDesignInfo.m_Pref); HUDInfo.m_lElementLoc = new List <ObjLocation>(HUDDesignInfo.m_lElementLoc); HUDJsonObj.m_lHUDInfo.Add(HUDInfo); } Debug.Log("saving ___ total HUD info = " + HUDJsonObj.m_lHUDInfo.Count); string json = JsonUtility.ToJson(HUDJsonObj); Debug.Log(json); if (json.Length > 0) { File.WriteAllText(FILE_DB_RAW_PATH, json); } }
// ================================== UNITY FUNCS ================================== #region Unity funcs private void Update() { Vector2 screenSize = CameraController.GetScreenSize(); for (int i = 0; i < transform.childCount; i++) { GameObject hudObj = transform.GetChild(i).gameObject; if (!hudObj.active) { continue; } for (int j = 0; j < m_lHUDDesignInfo.Count; j++) { HUDDesignInfo hudInfo = m_lHUDDesignInfo[j]; if (hudObj == hudInfo.m_Pref) { // update scene info for (int k = 0; k < hudObj.transform.childCount; k++) { GameObject sceneElementObj = hudObj.transform.GetChild(k).gameObject; if (!sceneElementObj.active) { continue; } ObjLocation objLocation = hudInfo.m_lElementLoc.Find(x => x.m_ObjName == sceneElementObj.name); // update location rect of element if (objLocation != null) { // scale for all width & height if (objLocation.m_ScaleSameByY != 0) { Image img = sceneElementObj.GetComponent <Image>(); float elementScale = (screenSize.y * objLocation.m_ScaleSameByY) / img.sprite.rect.height; RectTransform rt = sceneElementObj.GetComponent <RectTransform>(); //rt.sizeDelta = new Vector2(img.sprite.rect.width, img.sprite.rect.height) * elementScale; rt.sizeDelta = new Vector2(img.sprite.rect.width, img.sprite.rect.height); rt.localScale = Vector3.one * elementScale; } objLocation.m_Rect = GetRectOfObjOnCanvas(screenSize, sceneElementObj); } // add new rect of element else { objLocation = new ObjLocation(); objLocation.m_ObjName = sceneElementObj.name; objLocation.m_Rect = GetRectOfObjOnCanvas(screenSize, sceneElementObj); hudInfo.m_lElementLoc.Add(objLocation); } } break; } } } }
public void ClearListElement() { for (int i = 0; i < transform.childCount; i++) { GameObject hudObj = transform.GetChild(i).gameObject; if (!hudObj.active) { continue; } for (int j = 0; j < m_lHUDDesignInfo.Count; j++) { HUDDesignInfo hudInfo = m_lHUDDesignInfo[j]; if (hudObj == hudInfo.m_Pref) { hudInfo.m_lElementLoc.Clear(); } } } }