/// <summary> /// 文字列から CharacterPair を生成して登録します。 /// </summary> /// <param name="key">キー。</param> /// <param name="characterPair"> /// 1 桁目に通常の文字、2 桁目に Shift キー押下時の文字を持つ文字列。 /// Shift キー押下時の文字がない場合には 1 桁だけで指定します。 /// </param> static void RegisterCharacterPair(Keys key, string characterPair) { var character = characterPair[0]; Nullable <char> shiftCharacter = null; if (1 < characterPair.Length) { shiftCharacter = characterPair[1]; } keyCharacterPairMap[key] = new CharacterPair(character, shiftCharacter); }
/// <summary> /// Casts a ray to see if we hit an NPC and, if so, we interact /// </summary> void TryInteract() { // Multi ray RaycastHit2D[] rHit = Physics2D.RaycastAll(transform.position, Vector2.right * Mathf.Sign(transform.localScale.x), reachDistance, -1); if (rHit.Length > 0) { foreach (RaycastHit2D hit in rHit) { if (hit.collider.tag == "NPC") { // Check for a ghost object if (hit.collider.name.StartsWith("Ghost")) { // Get the ghost's original from the character pair list CharacterPair cp = FindObjectOfType<GhostManager>().characters.Find(c => c.Ghost == hit.collider.gameObject); discussionPartner = cp.Original.GetComponent<NPC>(); discussionPartner.TurnTowards(transform, true); } else { discussionPartner = hit.collider.GetComponent<NPC>(); discussionPartner.TurnTowards(transform); } discussionPartner.SetAIBehaviourActive(false); //Lets grab the NPC's DialogueAssign script... VIDE_Assign assigned = discussionPartner.gameObject.GetComponent<VIDE_Assign>(); if (!diagUI.dialogue.isLoaded) { //... and use it to begin the conversation diagUI.Begin(assigned); } else { //If conversation already began, let's just progress through it diagUI.NextNode(); } isControlledNPC = discussionPartner.name.Contains("Controlled"); // Break the loop so that only one conversation is active in case many NPC's got raycasted break; } } } if (discussionPartner) diagUI.npcName.text = discussionPartner.name; }
/// <summary> /// 增加一个渲染人物 /// </summary> public void AddCharacterWidthHeight(GameObject go, SpriteRenderer sp, Image image, int width, int height) { if (go == null) { return; } if (image == null && sp == null) { return; } if (charPairDict != null && charPairDict.Count > 0) { //foreach (var item in charPairs) //{ // if (item.charGo != null && item.charGo == go) // { // return; // } //} if (charPairDict.ContainsKey(go)) { var item = charPairDict[go]; if (item != null) { RenderTextureDescriptor tempRtd2 = new RenderTextureDescriptor(width, height, RenderTextureFormat.ARGB32, 8); item.ResetCharacterPair(go, sp, image, tempRtd2); return; } } } else if (charPairDict == null) { charPairDict = new Dictionary <GameObject, CharacterPair>(); //charPairs = new List<CharacterPair>(); } SetChildLayer(go.transform, noneLayer); RenderTextureDescriptor tempRtd = new RenderTextureDescriptor(width, height, RenderTextureFormat.ARGB32, 8); CharacterPair characterPair = new CharacterPair(go, sp, image, tempRtd); charPairDict[go] = characterPair; //charPairs.Add(new CharacterPair(go, sp, tempRtd)); //if (!enabled) //{ // enabled = true; //} }
/// <summary> /// 文字列から CharacterPair を生成して登録します。 /// </summary> /// <param name="key">キー。</param> /// <param name="characterPair"> /// 1 桁目に通常の文字、2 桁目に Shift キー押下時の文字を持つ文字列。 /// Shift キー押下時の文字がない場合には 1 桁だけで指定します。 /// </param> static void RegisterCharacterPair(Keys key, string characterPair) { var character = characterPair[0]; Nullable<char> shiftCharacter = null; if (1 < characterPair.Length) shiftCharacter = characterPair[1]; keyCharacterPairMap[key] = new CharacterPair(character, shiftCharacter); }
private int DeleteOneCharPair(int index, CharacterPair item) { charPairDict.Remove(item.charGo); item.Release(); return(index + 1); }
bool RenderChar() { if (cam == null || charPairDict == null || charPairDict.Count < 1) { return(false); } List <GameObject> tempList = new List <GameObject>(charPairDict.Keys); int index = 0; while (index < tempList.Count) { GameObject go = tempList[index]; if (go == null) { index++; continue; } CharacterPair item = charPairDict[go]; if (item == null) { index++; continue; } if (item.charGo == null) { index = DeleteOneCharPair(index, item); continue; } if (item.charSp == null && item.charImage == null) { index = DeleteOneCharPair(index, item); continue; } GameObject renderGameObject = null; if (item.charSp != null) { renderGameObject = item.charSp.gameObject; } if (item.charImage != null) { renderGameObject = item.charImage.gameObject; } if (renderGameObject == null) { index = DeleteOneCharPair(index, item); continue; } if (!renderGameObject.activeInHierarchy) { index = DeleteOneCharPair(index, item); continue; } if (item.needReloadTexture) { item.ReloadRenderTexture(); } RenderTexture renderTexture = item.GetCharRT(); if (!item.charGo.activeSelf) { item.charGo.SetActive(true); } SetChildLayer(item.charGo.transform, defaultLayer); cam.targetTexture = renderTexture; cam.Render(); cam.targetTexture = null; SetChildLayer(item.charGo.transform, noneLayer); if (item.charSp != null) { if (!item.charSp.enabled) { item.charSp.enabled = true; } } if (item.charImage != null) { if (!item.charImage.enabled) { item.charImage.enabled = true; } } index++; } cam.targetTexture = null; if (charPairDict.Count < 1) { return(false); } return(true); }