public void SaveThumbnail(hLevel serialData) { m_skybox.gameObject.SetActive(true); hLevel level = m_levelSetter.CreateLevel(serialData); m_levelSetter.AdjustCamera(m_camera, level, m_skybox); m_camera.Render(); RenderTexture.active = m_renderTexture; Texture2D tex = new Texture2D(m_renderTexture.width, m_renderTexture.height, TextureFormat.RGBA32, false); tex.ReadPixels(new Rect(0, 0, m_renderTexture.width, m_renderTexture.height), 0, 0, false); RenderTexture.active = null; byte[] bytes = tex.EncodeToPNG(); string fileName = level.difficulty.ToString() + "_" + level.levelNum.ToString() + ".png"; string path = Path.Combine(m_folderPath, fileName); File.WriteAllBytes(path, bytes); level.gameObject.SetActive(false); m_skybox.gameObject.SetActive(false); /*Thread thread = new Thread(new ThreadStart(() => File.WriteAllBytes(path, bytes))); * thread.Start();*/ }
public hLevel CreateLevel(hLevel data) { hColorManager.current.SetTheme(data.difficulty, true); hLevel level = Instantiate(data, transform); level.gameBall = level.GetComponentInChildren <hGameBall>(); return(level); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); hLevel level = (hLevel)target; if (GUILayout.Button("Serialize")) { level.Save(); } }
public void SetUp(hLevel level) { gameObject.SetActive(true); _selectedLevel = level; _levelStartBtn.level = level; /*Texture2D texture = new Texture2D((int)_thumbnail.rectTransform.rect.width, (int)_thumbnail.rectTransform.rect.height, TextureFormat.RGBA32, false); * texture.LoadImage(System.IO.File.ReadAllBytes(Application.persistentDataPath + "/Thumbnails/" + ((Difficulty)level.difficulty).ToString() + "_" + level.levelNum.ToString() + ".png")); * * _thumbnail.texture = texture;*/ _thumbnail.sprite = level.Thumbnail; StartCoroutine(SetRecords(level)); }
private IEnumerator DisplayRecords(hLevel inLevel) { yield return(null); /*List<hUserRecord> userRecords = new List<hUserRecord>(); * yield return hDatabase.current.GetLevelRecords(inLevel.difficulty, inLevel.levelNum, userRecords); * * for (int i = 0; i < userRecords.Count; ++i) * { * hRecordLine recordLine = Instantiate(m_recordLinePrefab, m_scrollViewContent); * recordLine.rank.text = (i + 1).ToString(); * recordLine.userName.text = userRecords[i].userName; * recordLine.record.text = userRecords[i].record.ToString("F2"); * * Color color = recordLine.background.color; * if (i % 2 == 1) * color.a = .25f; * else * color.a = .75f; * recordLine.background.color = color; * }*/ }
private IEnumerator SetRecords(hLevel level = default) { float record = PlayerPrefs.GetFloat(level.difficulty.ToString() + level.levelNum, 0f); _bestRecord.text = string.Format("{0:0.00}", record); if (level.levelNum == -1) { level = _selectedLevel; } if (level.levelNum == -1) { //Debug.LogError("No level!"); yield break; } yield break; /*List<hUserRecord> userRecords = new List<hUserRecord>(); * var op = hDatabase.current.GetLevelRecords((Difficulty)level.difficulty, level.levelNum, userRecords); * while (op != null && !op.isDone) * yield return null; * * if (userRecords.Count > 0) * { * _bestRecordID.text = userRecords[0].userName; * _bestRecord.text = userRecords[0].record.ToString("F2"); * var userData = userRecords.Find((data) => { if (data.id == hSharedData.userId && data.userName == hSharedData.userName) return true; return false; }); * if (userData.id == default) * _myRecord.text = " - "; * else * _myRecord.text = userData.record.ToString("F2"); * } * else * { * _bestRecordID.text = " - "; * _bestRecord.text = " - "; * _myRecord.text = " - "; * }*/ }
public override void Click() { if (_isClicked) { return; } _isClicked = true; //go next level hLevel nextLevel = new hLevel(); bool isEnd = hSharedData.GetNextLevel(ref nextLevel); if (!isEnd) { hSharedData.nextSceneNum = 1; } else { hSharedData.nextSceneNum = 2; hSharedData.curLevel = nextLevel; } /*var levelList = hSharedData.levelList; * * int index = System.Array.FindIndex(levelList, level => level == hSharedData.curLevel); ; * if (++index == levelList.Length) * hSharedData.nextSceneNum = 0; * else * { * hSharedData.nextSceneNum = 2; * hSharedData.curLevel = hSharedData.levelList[index]; * }*/ SceneManager.LoadSceneAsync(0, LoadSceneMode.Additive); //hAdManager.TryShow(); }
/*public hLevel CreateLevel(hLevel.SerialData serialData) * { * hColorManager.current.SetTheme((Difficulty)serialData.difficulty, true); * * hLevel level = serialData.DeSerialize(transform); * * level.gameObject.layer = LayerMask.NameToLayer("Outside"); * * return level; * }*/ #endregion public void AdjustCamera(Camera camera, hLevel level, Transform skyBox) { //set Camera Collider[] colliderBounds = level.GetComponentsInChildren <Collider>(); Bounds totalBounds = colliderBounds[1].bounds; for (int i = 2; i < colliderBounds.Length; ++i) { totalBounds.Encapsulate(colliderBounds[i].bounds); } var dir = -camera.transform.forward; var newPos = totalBounds.center + dir * 30f; camera.transform.position = newPos; var min = camera.WorldToScreenPoint(totalBounds.min); var max = camera.WorldToScreenPoint(totalBounds.max); min.z = 0; max.z = 0; var rightdownCorner = camera.ScreenToWorldPoint(new Vector3(max.x, min.y, 0)); min = camera.ScreenToWorldPoint(min); max = camera.ScreenToWorldPoint(max); var width = Vector3.Distance(min, rightdownCorner); var height = Vector3.Distance(max, rightdownCorner); camera.orthographicSize = Mathf.Max(totalBounds.size.x, totalBounds.size.y) + 5f;//(width > height ? width : height); /*var screenRatio = Screen.height / (float)Screen.width; * camera.orthographicSize *= screenRatio / 0.5625f;*/ //level boundary var collider = level.GetComponent <BoxCollider>(); if (collider == null) { collider = level.gameObject.AddComponent <BoxCollider>(); collider.isTrigger = true; } collider.size = totalBounds.size + Vector3.one * 1.5f; collider.center = totalBounds.center; if (level.wayPointList != null) { level.wayPointList.Sort((hWayPoint a, hWayPoint b) => { if (a.id > b.id) { return(1); } return(-1); }); } var scale = skyBox.localScale; scale.y = camera.orthographicSize * 2.5f; skyBox.localScale = scale; //Set gradient var bound = level.GetComponent <Collider>().bounds; var minmax = new Vector4( level.transform.position.y + bound.center.y - bound.extents.y, level.transform.position.y + bound.center.y + bound.extents.y, 0, 0); for (int i = 0; i < hDatabase.current.groundMats.Count; ++i) { hDatabase.current.groundMats[i].SetVector("_MinMaxHeight", minmax); } }
public void Open(hLevel inLevel) { gameObject.SetActive(true); StartCoroutine(DisplayRecords(inLevel)); }
/// <summary> /// Eliminieren von Einbettungen /// </summary> /// <param name="doc"></param> private static void headlineMarker(XElement doc) { // Finden aller Headlines var headlines = doc.Elements().Where(e => System.Text.RegularExpressions.Regex.IsMatch(e.Name.LocalName, @"h\d")); int pos = 0; Stack <hLevel> hnummer = new Stack <hLevel>(); string hierarchieWurzel = ""; bool hnummerOn = false; foreach (var h in headlines) { string newAnchorName = AnchorName(pos++); XElement oldAnchor = doc.XPathSelectElement(".//a[@id='" + newAnchorName + "']"); if (oldAnchor != null) { // Alten Anker löschen oldAnchor.Remove(); } string überschrift = h.Value.Trim(); string anfang = ""; if (überschrift.Contains(" ")) { anfang = überschrift.Substring(0, überschrift.IndexOf(' ')); } if (h.Name.LocalName == "h1") { // Prüfen, ob der Text mit einer Hierarchienummer beginnt if (HierachischeNummern.IstHierarchischeNummer(anfang)) { hnummerOn = true; hierarchieWurzel = anfang; hnummer.Clear(); hLevel hl = new hLevel(); hl.Level = HierachischeNummern.Level(hierarchieWurzel); hl.SiblingsCount = HierachischeNummern.ValueAtLevel(hierarchieWurzel, hl.Level - 1); hnummer.Push(hl); } } else if (hnummerOn) { // Alte hierarchische Nummern löschen if (HierachischeNummern.IstHierarchischeNummer(anfang)) { überschrift = überschrift.Substring(anfang.Length); } int LevelÜberschrift = int.Parse(h.Name.LocalName.Substring(1)); // Hierarchiche Nummern bilden // Der Vorgänger ist auf dem gleichen Level if (hnummer.Count() == LevelÜberschrift) { // -> Count auf dem Level inkermentieren hLevel top = hnummer.Pop(); top.SiblingsCount++; hnummer.Push(top); } else if (hnummer.Count < LevelÜberschrift) { // Der Vorgänger ist auf einem höheren Level // Hinzufügen eines neuer Levels for (int i = hnummer.Count; i < LevelÜberschrift; i++) { hLevel hl = new hLevel(); hl.Level = hnummer.Peek().Level + 1; hl.SiblingsCount = 1; hnummer.Push(hl); } } else { // Der Vorgänger ist auf einem tieferen Level int abzubauendeLevels = hnummer.Count - LevelÜberschrift; while (abzubauendeLevels > 0) { hnummer.Pop(); abzubauendeLevels--; } // -> Count auf dem Level inkermentieren hLevel top = hnummer.Pop(); top.SiblingsCount++; hnummer.Push(top); } // Neuen Hierarchienummer bilden StringBuilder bldHn = new StringBuilder(hierarchieWurzel); for (int i = 1; i < hnummer.Count; i++) { hLevel hl = hnummer.ElementAt(hnummer.Count - i - 1); bldHn.Append("."); bldHn.Append(hl.SiblingsCount.ToString()); } überschrift = bldHn.ToString() + " " + überschrift; h.SetValue(überschrift); } AddNewAnchor(h, newAnchorName); } }
private IEnumerator GetAssetBundle() { /*//if current version is lower * var version = PlayerPrefs.GetString("Version", "99"); #if UNITY_EDITOR * PlayerPrefs.DeleteAll(); * version = "99"; #endif * * UnityWebRequest www = UnityWebRequest.Get(hNetworkManager.serverURL + "/levelasset/" + version); * yield return www.SendWebRequest(); * * if (www.isNetworkError || www.isHttpError) * { * Application.Quit(); * } * else * { * string assetBundleDirectory = Application.persistentDataPath + "/AssetBundle"; * string serialDataPath = Application.persistentDataPath + "/SerialData"; * * // 에셋 번들을 저장할 경로의 폴더가 존재하지 않는다면 생성시킨다. * if (!Directory.Exists(assetBundleDirectory)) * Directory.CreateDirectory(assetBundleDirectory); * if (!Directory.Exists(serialDataPath)) * Directory.CreateDirectory(serialDataPath);*/ AssetBundle assetBundle; hLevel[] levelDatas; GameObject[] assets; Material[] mats; /*if (www.downloadHandler.data.Length == 0) * {*/ #if UNITY_EDITOR assetBundle = AssetBundle.LoadFromFile("C:/Users/HURJM/Desktop/work/Unity/ProjectDelta(URP)/AssetBundles/StandaloneWindows/levels.unity3d"); #else assetBundle = AssetBundle.LoadFromFile("levels.unity3d"); #endif if (assetBundle == null) { //Debug.Log("Failed to load AssetBundle!"); yield break; } mats = assetBundle.LoadAllAssets <Material>(); for (int i = 0; i < mats.Length; ++i) { var mat = mats[i]; mat.shader = Shader.Find(mat.shader.name); if (mat.name.Contains("Ground")) { hDatabase.current.groundMats.Add(mat); } } //binary 파일은 textasset으로 저장하고 불러옴 assets = assetBundle.LoadAllAssets <GameObject>(); levelDatas = new hLevel[assets.Length]; for (int i = 0; i < assets.Length; ++i) { levelDatas[i] = assets[i].GetComponent <hLevel>(); } hSharedData.Initialize(levelDatas); _loading.FirstLoading(); yield break; /*} * * var studio = Instantiate(m_thumbnailStudio); * * string lastVersion = ""; * int head = 0; * for (; head < www.downloadHandler.data.Length; ++head) * { * if ((char)www.downloadHandler.data[head] == '?') * { * PlayerPrefs.SetString("Version", lastVersion); ++head; * break; * } * lastVersion += (char)www.downloadHandler.data[head]; * } * * byte[] data = new byte[www.downloadHandler.data.Length - head]; * System.Array.Copy(www.downloadHandler.data, head, data, 0, data.Length); * * // 파일 입출력을 통해 받아온 에셋을 저장하는 과정 * File.WriteAllBytes(Path.Combine(assetBundleDirectory, "levels.unity3d"), data); * * assetBundle = AssetBundle.LoadFromFile(Path.Combine(assetBundleDirectory, "levels.unity3d")); * * if (assetBundle == null) * { * //Debug.Log("Failed to load AssetBundle!"); * yield break; * } * * //binary 파일은 textasset으로 저장하고 불러옴 * mats = assetBundle.LoadAllAssets<Material>(); * for (int i = 0; i < mats.Length; ++i) * { * var mat = mats[i]; * mat.shader = Shader.Find(mat.shader.name); * if (mat.name.Contains("Ground")) * hDatabase.current.groundMats.Add(mat); * } * * assets = assetBundle.LoadAllAssets<GameObject>(); * levelDatas = new hLevel[assets.Length]; * for (int i = 0; i < assets.Length; ++i) * levelDatas[i] = assets[i].GetComponent<hLevel>(); * * var lastThemeColor = hColorManager.current.curColor; * for (int i = 0; i < levelDatas.Length; ++i) * studio.SaveThumbnail(levelDatas[i]); * * hColorManager.current.SetTheme(lastThemeColor, true); * hSharedData.Initialize(levelDatas); * _loading.FirstLoading();*/ #region Binary Asset /*TextAsset[] textAssets; * AssetBundle assetBundle; * hLevel.SerialData[] serialDatas; * MemoryStream memoryStream; * BinaryFormatter formatter; * * if (www.downloadHandler.data.Length == 0) * { * assetBundle = AssetBundle.LoadFromFile(Path.Combine(assetBundleDirectory, "levels.unity3d")); * if (assetBundle == null) * { * //Debug.Log("Failed to load AssetBundle!"); * yield break; * } * else * //Debug.Log("Successed to load AssetBundle!"); * * //binary 파일은 textasset으로 저장하고 불러옴 * textAssets = assetBundle.LoadAllAssets<TextAsset>(); * serialDatas = new hLevel.SerialData[textAssets.Length]; * * memoryStream = new MemoryStream(); * formatter = new BinaryFormatter(); * for (int i = 0; i < textAssets.Length; ++i) * { * memoryStream.Write(textAssets[i].bytes, 0, textAssets[i].bytes.Length); * memoryStream.Position = 0; * serialDatas[i] = (hLevel.SerialData)formatter.Deserialize(memoryStream); * memoryStream.SetLength(0); * } * memoryStream.Close(); * * hSharedData.Initialize(serialDatas); * _loading.FirstLoading(); * yield break; * } * * var studio = Instantiate(m_thumbnailStudio); * * string lastVersion = ""; * int head = 0; * for (; head < www.downloadHandler.data.Length; ++head) * { * if((char)www.downloadHandler.data[head] == '?') * { * PlayerPrefs.SetString("Version", lastVersion); ++head; * break; * } * lastVersion += (char)www.downloadHandler.data[head]; * } * * byte[] data = new byte[www.downloadHandler.data.Length - head]; * System.Array.Copy(www.downloadHandler.data, head, data, 0, data.Length); * * // 파일 입출력을 통해 받아온 에셋을 저장하는 과정 * File.WriteAllBytes(Path.Combine(assetBundleDirectory , "levels.unity3d"), data); * * assetBundle = AssetBundle.LoadFromFile(Path.Combine(assetBundleDirectory, "levels.unity3d")); * * if (assetBundle == null) * { * //Debug.Log("Failed to load AssetBundle!"); * yield break; * } * else * //Debug.Log("Successed to load AssetBundle!"); * * //binary 파일은 textasset으로 저장하고 불러옴 * textAssets = assetBundle.LoadAllAssets<TextAsset>(); * * serialDatas = new hLevel.SerialData[textAssets.Length]; * * memoryStream = new MemoryStream(); * formatter = new BinaryFormatter(); * for (int i = 0; i < textAssets.Length; ++i) * { * memoryStream.Write(textAssets[i].bytes, 0, textAssets[i].bytes.Length); * memoryStream.Position = 0; * serialDatas[i] = (hLevel.SerialData)formatter.Deserialize(memoryStream); * memoryStream.SetLength(0); * } * memoryStream.Close(); * * var lastThemeColor = hColorManager.current.curColor; * for (int i = 0; i < serialDatas.Length; ++i) * studio.SaveThumbnail(serialDatas[i]); * hColorManager.current.SetTheme(lastThemeColor, true); * hSharedData.Initialize(serialDatas); * _loading.FirstLoading();*/ #endregion }