private void ParseStandingCgExecute(ConversationFileDataStanding data) { SpriteRenderer renderer; Sprite sprite; switch (data.order) { case "Set": GameObject obj = new GameObject("CG", new System.Type[] { typeof(SpriteRenderer), typeof(Animator) }); obj.transform.SetParent(GameManager.Instance.World.transform); obj.transform.localPosition = new Vector2(data.xPos, -360); obj.transform.localScale = new Vector3(1.1f, 1.1f, 1f); RuntimeAnimatorController controller = Resources.Load <RuntimeAnimatorController>("Animations/StandingCG/" + data.spriteName); if (controller == null) { renderer = obj.GetComponent <SpriteRenderer>(); sprite = Resources.Load <Sprite>("Sprites/Conversations/StandingCG/" + data.spriteName); renderer.sprite = sprite; } else { obj.GetComponent <Animator>().runtimeAnimatorController = controller; } renderer = obj.GetComponent <SpriteRenderer>(); renderer.sortingLayerName = "Room"; standingCGs.Add(data.name, renderer); break; case "Change": if (standingCGs.TryGetValue(data.name, out renderer)) { Animator animator = renderer.GetComponent <Animator>(); if (animator != null) { animator.enabled = false; } preLoadedSprites.TryGetValue(data.spriteName, out sprite); renderer.sprite = sprite; } else { Debug.LogError("Could NOT FIND CG Code " + data.name); } break; case "Animation": if (standingCGs.TryGetValue(data.name, out renderer)) { Animator animator = renderer.GetComponent <Animator>(); animator.enabled = true; animator.Play("BasicStandingCGBase"); } else { Debug.LogError("Could NOT FIND CG Code " + data.name); } break; case "Delete": if (standingCGs.TryGetValue(data.name, out renderer)) { standingCGs.Remove(data.name); Destroy(renderer.gameObject); } else { Debug.LogError("Could NOT FIND CG Code " + data.name); } break; } }
private void ParseStandingCG(string fileData, ref int curIndex) { while (fileData[curIndex] != '<') { curIndex += 1; } while (fileData[curIndex] == '<') { curIndex += 1; } string code = ReadUntilTagEnd(fileData, curIndex, out curIndex); ConversationFileDataStanding data = new ConversationFileDataStanding(); data.firstCode = "Standing"; string val; Sprite sprite = null; switch (code) { case "Set": while (fileData[curIndex] != '<') { curIndex += 1; } while (fileData[curIndex] == '<') { curIndex += 1; } val = ReadUntilTagEnd(fileData, curIndex, out curIndex); data.name = val; while (fileData[curIndex] != '<') { curIndex += 1; } while (fileData[curIndex] == '<') { curIndex += 1; } val = ReadUntilTagEnd(fileData, curIndex, out curIndex); data.xPos = int.Parse(val); while (fileData[curIndex] != '<') { curIndex += 1; } while (fileData[curIndex] == '<') { curIndex += 1; } val = ReadUntilTagEnd(fileData, curIndex, out curIndex); data.spriteName = val; data.order = "Set"; convDatas.Add(data); break; case "Change": while (fileData[curIndex] != '<') { curIndex += 1; } while (fileData[curIndex] == '<') { curIndex += 1; } val = ReadUntilTagEnd(fileData, curIndex, out curIndex); data.name = val; while (fileData[curIndex] != '<') { curIndex += 1; } while (fileData[curIndex] == '<') { curIndex += 1; } val = ReadUntilTagEnd(fileData, curIndex, out curIndex); data.spriteName = val; if (!preLoadedSprites.ContainsKey(data.spriteName)) { sprite = Resources.Load <Sprite>("Sprites/Conversations/StandingCG/" + data.spriteName); preLoadedSprites.Add(data.spriteName, sprite); } data.order = "Change"; convDatas.Add(data); break; case "Animation": while (fileData[curIndex] != '<') { curIndex += 1; } while (fileData[curIndex] == '<') { curIndex += 1; } val = ReadUntilTagEnd(fileData, curIndex, out curIndex); data.name = val; data.order = "Animation"; convDatas.Add(data); break; case "Delete": while (fileData[curIndex] != '<') { curIndex += 1; } while (fileData[curIndex] == '<') { curIndex += 1; } val = ReadUntilTagEnd(fileData, curIndex, out curIndex); data.name = val; data.order = "Delete"; convDatas.Add(data); break; } }