private SpriteState GetSpriteInfo(int depth, Transform child) { // 精灵信息 SpriteState ss = new SpriteState(); MaskableGraphic ui = child.GetComponent <MaskableGraphic>(); ss.spriteAlpha = ui.color.a; ss.SetPosition(child.localPosition); ss.SetScale(child.localScale); ss.SetRatation(child.localRotation); if (child.GetComponent <VideoSprite>() != null) { ss.SetType(SpriteState.SpriteType.Movie); ss.SetSource(child.GetComponent <VideoPlayer>().clip.name); } else if (child.GetComponent <Live2dModel>() != null) { ss.SetType(SpriteState.SpriteType.Live2d); ss.SetSource(child.GetComponent <Live2dModel>().modelName); } else { ss.SetType(SpriteState.SpriteType.Normal); Image img = child.GetComponent <Image>(); ss.SetSource(img.sprite == null ? "" : img.sprite.name); } return(ss); }
public void LoadImageInfo() { Dictionary <int, SpriteState> spdic = dm.gameData.fgSprites; //遍历当前的背景图删除 foreach (Transform child in bgPanel.transform) { Destroy(child.gameObject); } foreach (Transform child in fgPanel.transform) { Destroy(child.gameObject); } //遍历存储字典 替换内容 foreach (KeyValuePair <int, SpriteState> child in spdic) { int depth = child.Key; SpriteState ss = child.Value; GameObject go = GetSpriteByDepth(depth); // 如果有则删除 否则直接新建 if (go != null) { DestroyImmediate(go); } string prefab = ""; if (ss.type == SpriteState.SpriteType.Live2d) { prefab = ss.GetSource(); go = GetLive2dObject(depth); go.GetComponent <Live2dModel>().depth = depth; go.GetComponent <Live2dModel>().LoadModel(ss.spriteName, l2dPanel); //go.GetComponent<Live2dModel>().LoadModelWithCamera(ss.spriteName); // TODO: 表情动作 } else if (ss.type == SpriteState.SpriteType.Movie) { prefab = "Prefab/Video_Sprite"; go = Resources.Load(prefab) as GameObject; go = Instantiate(go); go.transform.SetParent(depth < 0 ? bgPanel.transform : fgPanel.transform, false); go.transform.name = "sprite" + depth; // 是动态 RawImage go.GetComponent <VideoSprite>().LoadClip(ss.spriteName); // TODO: 记录时间? } else { prefab = "Prefab/Sprite"; go = Resources.Load(prefab) as GameObject; go = Instantiate(go); go.transform.SetParent(depth < 0 ? bgPanel.transform : fgPanel.transform, false); go.transform.name = "sprite" + depth; Image ui = go.GetComponent <Image>(); //ui.sprite = depth < 0 ? LoadBackground(ss.spriteName): LoadImage(ss.spriteName); ui.sprite = LoadImage(ss.spriteName); ui.SetNativeSize(); } //设置位置等 go.transform.localPosition = ss.GetPosition(); go.transform.localScale = ss.GetScale(); go.transform.localRotation = ss.GetRatation(); go.GetComponent <MaskableGraphic>().color = new Color(1, 1, 1, ss.spriteAlpha); go.GetComponent <MaskableGraphic>().material = null; } // 恢复对话框 //duiManager.ClearText(); //duiManager.ShowWindow(); }