void CreateSentenceContent() { ClearChildContent(m_SentenceContent.transform); int startIndex = 0; m_SentenceContent.GetComponent <RectTransform>().sizeDelta = new Vector2(StartWidth, StartPosY + (Interval + ItemHeight) * m_Sentences.Count); foreach (CleanSentence cs in m_Sentences) { GameObject obj = Instantiate(ResourceLoadUtils.Load <GameObject>("TeachTool/HitObjectItem")); obj.transform.SetParent(m_SentenceContent.transform); obj.transform.localScale = Vector2.one; obj.GetComponent <RectTransform>().localPosition = new Vector3(ItemXPos, -StartPosY - (ItemHeight + Interval) * startIndex, 0); TeachHitObjectItem item = obj.GetComponent <TeachHitObjectItem>(); item.ContentInit(this, TeachHitObjectItem.Type.ContentSentence, cs.m_Index); item.SetString(cs.ToString()); startIndex++; } }
IEnumerator ShowPictureSub(string path, bool assignPosition, Vector2 position, float scale, bool autoMatch) { Image image; if (_picture == null) { var go = new GameObject(); go.name = "Picture"; image = go.AddComponent <Image>(); _picture = go.transform as RectTransform; _picture.SetParent(SwitchTransform); _picture.localScale = Vector3.one; } else { image = _picture.GetComponent <Image>(); } if (assignPosition) { _picture.gameObject.SetActive(false); yield return(null); Sprite sprite = ResourceLoadUtils.Load <Sprite>(Path.Combine("Framework/Core/Tutorial/Display", path)); image.sprite = sprite; Vector2 spriteSize = new Vector2(sprite.texture.width * scale, sprite.texture.height * scale); if (autoMatch) { var oldSize = spriteSize; spriteSize = UIUtils.CalculateAutoMatchedSize(spriteSize); var anchorX = Mathf.Clamp01((position.x + spriteSize.x * .5f) / spriteSize.x); var adjust = UIUtils.CalculateAutoMatchedDeltaX() - (spriteSize.x - oldSize.x) * .5f; position.x -= (1f - anchorX * 2f) * adjust; } UIUtils.SetScreenPosition(ref _picture, GetCanvas(), position); _picture.sizeDelta = spriteSize; } _picture.gameObject.SetActive(true); EnableParentCanvasRaycaster(_picture); }
public void ShowChatBubble(ChatBubbleArrowPos cPos, string text, Rect rectPanel, Vector4 deltaSize, bool adaptation = true) { if (_chatBubble == null) { var go = Instantiate(ResourceLoadUtils.Load <GameObject>("Framework/Core/Tutorial/ChatBubble/ChatBubble")) as GameObject; _chatBubble = go.transform as RectTransform; _chatBubble.SetParent(SwitchTransform, false); _chatBubble.localScale = Vector3.one; } _chatBubble.gameObject.SetActive(false); RectTransform root = _chatBubble.Find("Bubble") as RectTransform; if (adaptation) { root.anchorMin = new Vector2(rectPanel.xMin, rectPanel.yMin); root.anchorMax = new Vector2(rectPanel.xMax, rectPanel.yMax); } else { root.anchorMin = Vector2.one * 0.5f; root.anchorMax = Vector2.one * 0.5f; root.localPosition = new Vector2(deltaSize.x, deltaSize.y); root.sizeDelta = new Vector2(deltaSize.z, deltaSize.w); } Text contentText = null; contentText = root.Find("Text").GetComponent <Text>(); if (contentText) { contentText.text = text; } for (ChatBubbleArrowPos i = 0; i < ChatBubbleArrowPos.Count; ++i) { root.Find("Background/" + i.ToString()).gameObject.SetActive(i.Equals(cPos)); } _chatBubble.gameObject.SetActive(true); EnableParentCanvasRaycaster(_chatBubble); }
public void HitNodeStatus() { List <HitInfo> temp = EiderToolPage.Instance.SongObject.HitInfos; for (int i = 0; i < temp.Count; i++) { HitInfo ho = temp[i]; if (ho.EndHitTime < m_HitTimeStart || ho.StartHitTime > m_HitTimeEnd) { if (m_HitNodeNow.ContainsKey(i)) { Destroy(m_HitNodeNow[i].gameObject); m_HitNodeNow.Remove(i); } } else { if (m_HitNodeNow.ContainsKey(i) == false && m_SelectStatus == false) { HitNode tempNode = Instantiate(ResourceLoadUtils.Load <HitNode>("UI/Nodes/HitNode")); tempNode.transform.SetParent(transform.Find("ClickNode").transform); tempNode.Init(); UpdateHitNode(tempNode, ho, i); m_HitNodeNow.Add(i, tempNode); } if (m_HitNodeNow.ContainsKey(i)) { if (m_SelectStatus == false) { UpdateHitNode(m_HitNodeNow[i], ho, i); } else { m_HitNodeNow[i].TextNum(i + 1); } } } } transform.Find("Cibiao").SetAsLastSibling(); }
public bool StartTutorial(string name, Action callback = null) { if (_currentScript != null) { LogManager.LogWarning("Warning! There's already a tutorial running."); return(false); } var asset = ResourceLoadUtils.Load <TextAsset>(Path.Combine(TutorialScriptPath, name), true); if (asset != null) { _callback = callback; LogManager.Log("Start Tutorial: " + name); _currentScript = TutorialScript.LoadFromJson(asset.text); _currentScript.Execute(this); return(true); } return(false); }
public void LoadSong(string songName) { if (!_songCache.ContainsKey(songName)) { AudioClip clip = ResourceLoadUtils.Load <AudioClip>("Audio/" + songName.ToLower(), true); if (clip == null) { string extraPath = Application.dataPath + "/TeachAudioBundles/" + songName; AssetBundle bundle = AssetBundle.LoadFromFile(extraPath); clip = bundle.LoadAsset <AudioClip>(songName); } if (clip != null) { _songCache.Add(songName, clip); } else { PromptManager.Instance.MessageBox(PromptManager.Type.FloatingTip, "找不到音乐 " + songName); } } }
public void ShowFocusFrame(RectTransform rectTrans, Canvas canvas) { if (_focusFrame == null) { var go = Instantiate(ResourceLoadUtils.Load <GameObject>("Framework/Core/Tutorial/Focus/FocusFrame")) as GameObject; _focusFrame = go.transform as RectTransform; _focusFrame.gameObject.SetActive(false); _focusFrame.SetParent(SwitchTransform); _focusFrame.localScale = Vector3.one; } _focusFrame.localScale = rectTrans.localScale; var pageCanvasScale = canvas.transform.localScale.x; var tutorialCanvasScale = transform.parent.localScale.x; _focusFrame.position = UIUtils.GetCenterPosInWorldFromRectTf(rectTrans, pageCanvasScale); float pt = pageCanvasScale / tutorialCanvasScale; _focusFrame.sizeDelta = new Vector2(rectTrans.rect.size.x * pt + 45, rectTrans.rect.size.y * pt + 45); _focusFrame.gameObject.SetActive(true); EnableParentCanvasRaycaster(_focusFrame); }
IEnumerator ShowFocusPointerSub(RectTransform focusRectTf, Canvas canvas, float angle, bool _isMove, float _moveRange, bool isPingPong = true) { Vector2 moveDirection = default(Vector2); if (_isMove) { moveDirection = UIUtils.GetNormalizedFromAngle(angle); } if (_focusPointer == null) { var go = Instantiate(ResourceLoadUtils.Load <GameObject>("Framework/Core/Tutorial/Focus/FocusPointer")) as GameObject; _focusPointer = go.transform as RectTransform; _focusPointer.gameObject.SetActive(false); _focusPointer.SetParent(SwitchTransform); _focusPointer.localScale = Vector3.one; } var pageCanvasScale = canvas.transform.localScale.x; Vector2 pivotPos = UIUtils.GetOctagonalPosOfRectByAngleInWorld(focusRectTf, angle, pageCanvasScale); _focusPointer.position = pivotPos; angle = UIUtils.NormalizedAngle(angle); _focusPointer.localScale = new Vector3(1, angle > 90 && angle < 270 ? 1 : -1, 1); _focusPointer.eulerAngles = new Vector3(0, 0, angle); yield return(null); _focusPointer.gameObject.SetActive(true); if (_isMove) { Vector2 targetPosition = (Vector2)_focusPointer.position - moveDirection * _moveRange * pageCanvasScale; GameObjectMove(_focusPointer.gameObject, _focusPointer.position, targetPosition, 1, isPingPong); } EnableParentCanvasRaycaster(_focusPointer); }
void LoadFile() { m_CurrentSongName = m_DropDown.options[m_DropDown.value].text; string path = "Songs/" + m_CurrentSongName + "OSU"; TextAsset osu = ResourceLoadUtils.Load <TextAsset>(path); string[] contents = null; if (osu == null) { string filePath = GetPathString(m_CurrentSongName + "OSU.txt"); if (File.Exists(filePath)) { contents = File.ReadAllLines(filePath); } else { PromptManager.Instance.MessageBox(PromptManager.Type.FloatingTip, m_CurrentSongName + ".txt 文件没有找到!!"); return; } } else { contents = osu.text.Split('\n'); } m_HitObjects.Clear(); ClearAllContent(); bool hitObjStart = false; for (int i = 0; i < contents.Length; i++) { string parseContent = contents[i].Trim(); if (string.IsNullOrEmpty(parseContent) || parseContent.StartsWith("//")) {//空行和注释行 不解析 continue; } if (parseContent.Contains("[HitObjects]")) { hitObjStart = true; continue; } if (hitObjStart) { if (parseContent.Contains("C") || parseContent.Contains("P") || parseContent.Contains("L") || parseContent.Contains("B")) {//2017年10月28日版本先不做这些功能 continue; } else { string[] param = parseContent.Split(','); if (param.Length != 6) { LogManager.LogError("data parse error: the data file is --", path); } else { Vector2 pos = new Vector2(int.Parse(param[0]), int.Parse(param[1])); int startTime = int.Parse(param[2]); HO ho = new HO(); ho.m_Index = m_HitObjects.Count + 1; ho.m_StartTime = startTime; ho.m_Position = pos; m_HitObjects.Add(ho); } } } } InitLeftBoxHOList(); CreateLeftBoxScrollViewContent(); }
public static Transform ImageArtString(string text) { GameObject root = new GameObject(); root.AddComponent <RectTransform>(); float width = 0; float height = 0; float stringLen = text.Length; float nextLen = 0; float beforeLen = 0; float thisBeforeLen = 0; for (int i = 0; i < stringLen; i++) { float y = 0; string wordPath = "ArtAlphabet/"; if (text[i] >= 'a' && text[i] <= 'z') { wordPath += "Small/" + text[i]; beforeLen = nextLen; nextLen = FontConfig.Instance.GetNextStation(text[i].ToString()); thisBeforeLen = FontConfig.Instance.GetBeforeStation(text[i].ToString()); } else if (text[i] == ' ') { wordPath += "Emty"; beforeLen = nextLen; nextLen = 0; thisBeforeLen = 0; } else if (text[i] == '-') { wordPath += "heng"; y = 6; beforeLen = nextLen; nextLen = 0; thisBeforeLen = 0; } else if (text[i] == '\'') { wordPath += "pie"; beforeLen = nextLen; nextLen = 0; thisBeforeLen = 0; } else { wordPath += "Big/" + text[i]; beforeLen = nextLen; nextLen = FontConfig.Instance.GetNextStation(text[i].ToString()); thisBeforeLen = FontConfig.Instance.GetBeforeStation(text[i].ToString()); } if (i == 0) { thisBeforeLen = 0; } GameObject word = new GameObject(); word.name = text[i].ToString(); Sprite spr = GameObject.Instantiate(ResourceLoadUtils.Load <Sprite>(wordPath)); Image image = word.AddComponent <Image>(); image.sprite = spr; image.SetNativeSize(); word.transform.localScale = Vector3.one; word.transform.SetParent(root.transform); RectTransform wordTransform = word.GetComponent <RectTransform>(); wordTransform.localScale = Vector3.one; float wordWidth = wordTransform.sizeDelta.x; float wordHeight = wordTransform.sizeDelta.y; if (height < wordHeight) { height = wordHeight; } float wordX = width + 0.5f * wordWidth - beforeLen - thisBeforeLen; width = width + wordWidth - beforeLen - thisBeforeLen; wordTransform.localPosition = new Vector3(wordX, y, 0); } float removex = width / 2; for (int i = 0; i < stringLen; i++) { RectTransform wordTransform = root.transform.GetChild(i).GetComponent <RectTransform>(); float wordx = wordTransform.localPosition.x - removex; float wordy = wordTransform.localPosition.y; wordTransform.localPosition = new Vector3(wordx, wordy, 0); } RectTransform thisRectTransform = root.transform.GetComponent <RectTransform>(); thisRectTransform.sizeDelta = new Vector2(width, height); thisRectTransform.localPosition = new Vector3(0, 0, 0); return(root.transform); }
public static Transform SpriteRendererArtString(string text) { GameObject root = new GameObject(); float width = 0; float height = 0; float stringLen = text.Length; float beforeLen = 0; float nextLen = 0; float thisBeforeLen = 0f; for (int i = 0; i < stringLen; i++) { float y = 0; string wordPath = "ArtAlphabet/"; if (text[i] >= 'a' && text[i] <= 'z') { wordPath += "Small/" + text[i]; beforeLen = nextLen; nextLen = FontConfig.Instance.GetNextStation(text[i].ToString()) / 75f; thisBeforeLen = FontConfig.Instance.GetBeforeStation(text[i].ToString()) / 75f; } else if (text[i] == ' ') { wordPath += "Emty"; beforeLen = nextLen; nextLen = 0; thisBeforeLen = 0; } else if (text[i] == '-') { wordPath += "heng"; y = 0.08f; beforeLen = nextLen; nextLen = 0; thisBeforeLen = 0; } else if (text[i] == '\'') { wordPath += "pie"; beforeLen = nextLen; nextLen = 0; thisBeforeLen = 0f; } else { wordPath += "Big/" + text[i]; beforeLen = nextLen; nextLen = FontConfig.Instance.GetNextStation(text[i].ToString()) / 75f; thisBeforeLen = FontConfig.Instance.GetBeforeStation(text[i].ToString()) / 75f; } if (i == 0) { thisBeforeLen = 0; } GameObject word = new GameObject(); word.name = (text[i]).ToString(); Sprite spr = GameObject.Instantiate(ResourceLoadUtils.Load <Sprite>(wordPath)); SpriteRenderer sprRenderer = word.AddComponent <SpriteRenderer>(); sprRenderer.sprite = spr; sprRenderer.sortingLayerName = "Font"; //sprRenderer.color = new Color(1, 151 / 255f, 0); word.transform.SetParent(root.transform); word.transform.localScale = Vector3.one; float wordWidth = sprRenderer.bounds.extents.x * 2; float wordHeight = sprRenderer.bounds.extents.y * 2; if (height < wordHeight) { height = wordHeight; } float wordX = width + 0.5f * wordWidth - beforeLen - thisBeforeLen; width = width + wordWidth - beforeLen - thisBeforeLen; word.transform.localPosition = new Vector3(wordX, y, 0); } float removex = width / 2; for (int i = 0; i < stringLen; i++) { Transform wordTransform = root.transform.GetChild(i); float wordx = wordTransform.localPosition.x - removex; float wordy = wordTransform.localPosition.y; wordTransform.localPosition = new Vector3(wordx, wordy, 0); } return(root.transform); }
public void ShowDialog(DialogType type, CharacterPos cPos, CharacterType chType, string text, bool isDisplayContinue, Rect rectPanel, int hatIndex, bool hideTipball = false) { if (_dialog == null) { var go = Instantiate(ResourceLoadUtils.Load <GameObject>("Framework/Core/Tutorial/Dialog/Dialog")) as GameObject; _dialog = go.transform as RectTransform; _dialog.SetParent(SwitchTransform, false); _dialog.localScale = Vector3.one; } _dialog.gameObject.SetActive(false); RectTransform root = _dialog.Find(type.ToString()) as RectTransform; Text contentText = null; for (int i = 0; i < _dialog.childCount; ++i) { var go = _dialog.GetChild(i).gameObject; go.SetActive(type.ToString() == go.name); if (type.ToString() == go.name) { contentText = go.transform.Find("Background/Text").GetComponent <Text>(); } } if (contentText) { contentText.text = text; } Transform rtrans = null; switch (type) { case DialogType.Anywhere: root.anchorMin = new Vector2(rectPanel.xMin, rectPanel.yMin); root.anchorMax = new Vector2(rectPanel.xMax, rectPanel.yMax); for (CharacterPos i = 0; i < CharacterPos.Count; ++i) { var parentTrans = root.Find("Background/" + i.ToString() + "/Tipball"); parentTrans.parent.gameObject.SetActive(i == cPos); if (i == cPos) { rtrans = parentTrans; var anchorPos = (rtrans.parent as RectTransform).anchoredPosition; Rect rootRect = UIUtils.GetRectInCanvas(GetCanvas(), root.Find("Background") as RectTransform); switch (cPos) { case CharacterPos.BottomLeft: (rtrans.parent as RectTransform).anchoredPosition = new Vector2(rootRect.width * -.3f, anchorPos.y); break; case CharacterPos.BottomRight: (rtrans.parent as RectTransform).anchoredPosition = new Vector2(rootRect.width * .3f, anchorPos.y); break; } } } root.Find("Background/ClickContinuePic").gameObject.SetActive(isDisplayContinue); break; case DialogType.Bottom: rtrans = root.Find("Background/Tipball"); root.Find("Background/ClickContinuePic").gameObject.SetActive(isDisplayContinue); break; } for (int i = 0; i < _tipBalls.Length; ++i) { if ((int)chType == i && !hideTipball) { if (_tipBalls[i] == null) { _tipBalls[i] = Instantiate(ResourceLoadUtils.Load <GameObject>("Framework/Core/Tutorial/Dialog/" + chType.ToString()), rtrans, false); } else { _tipBalls[i].transform.SetParent(rtrans, false); _tipBalls[i].SetActive(true); } for (int j = 0; j < _tipBalls[i].transform.childCount; j++) { _tipBalls[i].transform.GetChild(j).gameObject.SetActive(hatIndex == j); } } else { if (_tipBalls[i]) { _tipBalls[i].SetActive(false); } } } _dialog.gameObject.SetActive(true); EnableParentCanvasRaycaster(_dialog); }
public List <HitInfo> InsertHitNode(HitInfo ho, List <HitInfo> temp) { m_ChangeHitNode = true; HitNode tempNode = Instantiate(ResourceLoadUtils.Load <HitNode>("UI/Nodes/HitNode")); tempNode.transform.SetParent(transform.Find("ClickNode").transform); tempNode.Init(); UpdateHitNode(tempNode, ho, 0); int k = 0; if (temp.Count == 0) { ho.StartHitTime = ho.HitTime; ho.EndHitTime = ho.HitTime + 2000; ho.Type = SentenceInfo.SentenceType.ClickNode; temp.Add(ho); k = 0; } else if (ho.HitTime < temp[0].StartHitTime) { ho.StartHitTime = ho.HitTime; if (temp[0].Type == SentenceInfo.SentenceType.SoundNode) { ho.EndHitTime = temp[0].StartHitTime - 1000; } else { ho.EndHitTime = temp[0].StartHitTime - 100; } ho.Type = SentenceInfo.SentenceType.ClickNode; temp.Insert(0, ho); k = 0; } else { int i = 0; for (i = 0; i < temp.Count; i++) { if (ho.HitTime >= temp[i].StartHitTime && ho.HitTime <= temp[i].EndHitTime) { ho.StartHitTime = temp[i].StartHitTime; ho.EndHitTime = temp[i].EndHitTime; ho.Type = temp[i].Type; } if (temp[i].HitTime < ho.HitTime) { continue; } else { temp.Insert(i, ho); k = i; break; } } if (i == temp.Count) { if (temp[i - 1].EndHitTime <= ho.HitTime) { float lastEndTime = temp[i - 1].EndHitTime; ho.StartHitTime = ho.HitTime; ho.Type = SentenceInfo.SentenceType.ClickNode; ho.EndHitTime = ho.HitTime + 2000; for (int j = temp.Count - 1; j >= 0; j--) { if (temp[j].EndHitTime == lastEndTime) { temp[j].EndHitTime = ho.HitTime - 100; } else { break; } } } else { ho.StartHitTime = temp[i - 1].StartHitTime; ho.EndHitTime = temp[i - 1].EndHitTime; ho.Type = temp[i - 1].Type; } temp.Add(ho); k = temp.Count - 1; } } if (m_HitNodeNow.ContainsKey(k) == false) { m_HitNodeNow.Add(k, tempNode); } else { HitNode node = tempNode; for (int i = k; i < temp.Count; i++) { HitNode ttt; if (m_HitNodeNow.ContainsKey(i)) { ttt = m_HitNodeNow[i]; m_HitNodeNow[i] = node; node = ttt; m_HitNodeNow[i].TextNum(i + 1); } else { m_HitNodeNow.Add(i, node); m_HitNodeNow[i].TextNum(i + 1); break; } } } m_ChangeHitNode = false; return(temp); }
GameObject GetNodePrefab(string type) { var path = "UI/Nodes/" + type; return(ResourceLoadUtils.Load <GameObject>(path, true)); }