using DragonBones; using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.EventSystems; using Slot = DragonBones.Slot; using Transform = UnityEngine.Transform; public class Player : Regist , IPointerClickHandler { #region 变量 public bool AnimLock; private string Eye; private string Top; private string Shoe; private string Head; private string Dress; private string Mouse; private string RightShoe; private string HeadWear; public UnityArmatureComponent EyeUac; public UnityArmatureComponent TopUac; public UnityArmatureComponent HeadUac; public UnityArmatureComponent DressUac; public UnityArmatureComponent MouseUac; public UnityArmatureComponent LeftShoeUac; public UnityArmatureComponent RightShoeUac; public UnityArmatureComponent HeadWearUac; private List EyeList = new List(); private List TopList = new List(); private List ShoeList = new List(); private List HeadList = new List(); private List DressList = new List(); private List MouseList = new List(); private List HeadWearList = new List(); public UnityArmatureComponent UAC; public Dictionary ChildDic = new Dictionary(); #endregion public override bool RegistImmed() { if (base.RegistImmed()) { return true; } enabled = true; Auxiliary.CompileDic(transform, ChildDic); return false; } public void PlayAnim(string animName) { if (AnimLock) { return; } UAC.anim.Play(animName); } public void SetAllCollider(bool enable) { BoxCollider2D[] colliders = GetComponentsInChildren(); for (int i = 0; i < colliders.Length; i++) { colliders[i].enabled = enable; } } public void OnPointerClick(PointerEventData eventData) { PlayAnim("newAnimation1"); } #region 换装 public UnityArmatureComponent Build() { if (!ManaPlayer.Complete) { UnityFactory.factory.LoadDragonBonesData(ManaReso.Load("stand_ske", Folder.Config)); UnityFactory.factory.LoadDragonBonesData(ManaReso.Load("Closet_ske", Folder.Config)); UnityFactory.factory.LoadTextureAtlasData(ManaReso.Load("stand_tex", Folder.Config), "stand_texture"); UnityFactory.factory.LoadTextureAtlasData(ManaReso.Load("Closet_tex", Folder.Config), "Closet_texture"); ManaPlayer.Complete = true; } UAC = UnityFactory.factory.BuildArmatureComponent("Armature"); UAC.transform.parent = transform; UAC.transform.localScale = new Vector3(1, 1, 1); UAC.transform.localPosition = new Vector3(); UAC.anim.Play("newAnimation"); EyeList.Add("眼睛1"); TopList.Add("上衣1"); ShoeList.Add("鞋子1"); HeadList.Add("脑壳1"); DressList.Add("裙子1"); MouseList.Add("嘴巴1"); HeadWearList.Add("头饰品1"); EyeList.Add("眼睛2"); TopList.Add("上衣2"); ShoeList.Add("鞋子2"); HeadList.Add("脑壳2"); DressList.Add("裙子2"); MouseList.Add("嘴巴2"); HeadWearList.Add("头饰品2"); EyeList.Add("眼睛3"); TopList.Add("上衣3"); ShoeList.Add("鞋子3"); HeadList.Add("脑壳3"); DressList.Add("裙子3"); MouseList.Add("嘴巴3"); HeadWearList.Add("头饰品3"); Eye = EyeList[0]; Top = TopList[0]; Shoe = ShoeList[0]; Head = HeadList[0]; Dress = DressList[0]; Mouse = MouseList[0]; HeadWear = HeadWearList[0]; return UAC; } public UnityArmatureComponent BuildPink() { Build(); Eye = "眼睛3"; Top = "上衣3"; Shoe = "鞋子3"; Head = "脑壳3"; Dress = "裙子3"; Mouse = "嘴巴3"; HeadWear = "头饰品3"; UAC.armature.GetSlot("眼睛").childArmature = UnityFactory.factory.BuildArmature(Eye); UAC.armature.GetSlot("上衣").childArmature = UnityFactory.factory.BuildArmature(Top); UAC.armature.GetSlot("脑壳").childArmature = UnityFactory.factory.BuildArmature(Head); UAC.armature.GetSlot("裙子").childArmature = UnityFactory.factory.BuildArmature(Dress); UAC.armature.GetSlot("嘴巴").childArmature = UnityFactory.factory.BuildArmature(Mouse); UAC.armature.GetSlot("鞋子左").childArmature = UnityFactory.factory.BuildArmature(Shoe); UAC.armature.GetSlot("鞋子右").childArmature = UnityFactory.factory.BuildArmature(Shoe); UAC.armature.GetSlot("头饰品").childArmature = UnityFactory.factory.BuildArmature(HeadWear); EyeUac = transform.FindChild("Armature/眼睛3").GetComponent(); TopUac = transform.FindChild("Armature/上衣3").GetComponent(); HeadUac = transform.FindChild("Armature/脑壳3").GetComponent(); DressUac = transform.FindChild("Armature/裙子3").GetComponent(); MouseUac = transform.FindChild("Armature/嘴巴3").GetComponent(); LeftShoeUac = transform.FindChild("Armature/鞋子3").GetComponent(); HeadWearUac = transform.FindChild("Armature/头饰品3").GetComponent(); RightShoeUac = transform.FindChild("Armature").GetChild(LeftShoeUac.transform.GetSiblingIndex() + 1).GetComponent(); ResetDepth(); UAC.AddEventListener(EventObject.START, OnStart); return UAC; } public UnityArmatureComponent BuildBlond() { Build(); Eye = "眼睛1"; Top = "上衣1"; Shoe = "鞋子1"; Head = "脑壳1"; Dress = "裙子1"; Mouse = "嘴巴1"; HeadWear = "头饰品1"; UAC.armature.GetSlot("眼睛").childArmature = UnityFactory.factory.BuildArmature(Eye); UAC.armature.GetSlot("上衣").childArmature = UnityFactory.factory.BuildArmature(Top); UAC.armature.GetSlot("脑壳").childArmature = UnityFactory.factory.BuildArmature(Head); UAC.armature.GetSlot("裙子").childArmature = UnityFactory.factory.BuildArmature(Dress); UAC.armature.GetSlot("嘴巴").childArmature = UnityFactory.factory.BuildArmature(Mouse); UAC.armature.GetSlot("鞋子左").childArmature = UnityFactory.factory.BuildArmature(Shoe); UAC.armature.GetSlot("鞋子右").childArmature = UnityFactory.factory.BuildArmature(Shoe); UAC.armature.GetSlot("头饰品").childArmature = UnityFactory.factory.BuildArmature(HeadWear); EyeUac = transform.FindChild("Armature/眼睛1").GetComponent(); TopUac = transform.FindChild("Armature/上衣1").GetComponent(); HeadUac = transform.FindChild("Armature/脑壳1").GetComponent(); DressUac = transform.FindChild("Armature/裙子1").GetComponent(); MouseUac = transform.FindChild("Armature/嘴巴1").GetComponent(); LeftShoeUac = transform.FindChild("Armature/鞋子1").GetComponent(); HeadWearUac = transform.FindChild("Armature/头饰品1").GetComponent(); RightShoeUac = transform.FindChild("Armature").GetChild(LeftShoeUac.transform.GetSiblingIndex() + 1).GetComponent(); ResetDepth(); UAC.AddEventListener(EventObject.START, OnStart); return UAC; } public UnityArmatureComponent BuildBrown() { Build(); Eye = "眼睛2"; Top = "上衣2"; Shoe = "鞋子2"; Head = "脑壳2"; Dress = "裙子2"; Mouse = "嘴巴2"; HeadWear = "头饰品2"; UAC.armature.GetSlot("眼睛").childArmature = UnityFactory.factory.BuildArmature(Eye); UAC.armature.GetSlot("上衣").childArmature = UnityFactory.factory.BuildArmature(Top); UAC.armature.GetSlot("脑壳").childArmature = UnityFactory.factory.BuildArmature(Head); UAC.armature.GetSlot("裙子").childArmature = UnityFactory.factory.BuildArmature(Dress); UAC.armature.GetSlot("嘴巴").childArmature = UnityFactory.factory.BuildArmature(Mouse); UAC.armature.GetSlot("鞋子左").childArmature = UnityFactory.factory.BuildArmature(Shoe); UAC.armature.GetSlot("鞋子右").childArmature = UnityFactory.factory.BuildArmature(Shoe); UAC.armature.GetSlot("头饰品").childArmature = UnityFactory.factory.BuildArmature(HeadWear); EyeUac = transform.FindChild("Armature/眼睛2").GetComponent(); TopUac = transform.FindChild("Armature/上衣2").GetComponent(); HeadUac = transform.FindChild("Armature/脑壳2").GetComponent(); DressUac = transform.FindChild("Armature/裙子2").GetComponent(); MouseUac = transform.FindChild("Armature/嘴巴2").GetComponent(); LeftShoeUac = transform.FindChild("Armature/鞋子2").GetComponent(); HeadWearUac = transform.FindChild("Armature/头饰品2").GetComponent(); RightShoeUac = transform.FindChild("Armature").GetChild(LeftShoeUac.transform.GetSiblingIndex() + 1).GetComponent(); ResetDepth(); UAC.AddEventListener(EventObject.START, OnStart); return UAC; } public void OnStart(string str, EventObject eventObject) { if (eventObject.animationState.name == "newAnimation1") { AnimLock = true; UAC.armature.GetSlot("眼睛").childArmature = UnityFactory.factory.BuildArmature("眼睛表情1"); EyeUac = transform.FindChild("Armature/眼睛表情1").GetComponent(); } else if (eventObject.animationState.name == "newAnimation") { AnimLock = false; UAC.armature.GetSlot("眼睛").childArmature = UnityFactory.factory.BuildArmature(Eye); EyeUac = transform.FindChild("Armature/" + Eye).GetComponent(); } ResetDepth(); } public void PrevEye() { int index = EyeList.IndexOf(Eye); Eye = EyeList.Prev(index); ChangeClose(EyeUac, Eye); ResetDepth(); } public void PrevTop() { int index = TopList.IndexOf(Top); Top = TopList.Prev(index); ChangeClose(TopUac, Top); ResetDepth(); } public void PrevShoe() { int index = ShoeList.IndexOf(Shoe); Shoe = ShoeList.Prev(index); ChangeClose(LeftShoeUac, Shoe); ChangeClose(RightShoeUac, Shoe); ResetDepth(); } public void PrevHead() { int index = HeadList.IndexOf(Head); Head = HeadList.Prev(index); ChangeClose(HeadUac, Head); ResetDepth(); } public void PrevDress() { int index = DressList.IndexOf(Dress); Dress = DressList.Prev(index); ChangeClose(DressUac, Dress); ResetDepth(); } public void PrevMouse() { int index = MouseList.IndexOf(Mouse); Mouse = MouseList.Prev(index); ChangeClose(MouseUac, Mouse); ResetDepth(); } public void PrevHeadWear() { int index = HeadWearList.IndexOf(HeadWear); HeadWear = HeadWearList.Prev(index); ChangeClose(HeadWearUac, HeadWear); ResetDepth(); } public void NextEye() { int index = EyeList.IndexOf(Eye); Eye = EyeList.Next(index); ChangeClose(EyeUac, Eye); ResetDepth(); } public void NextTop() { int index = TopList.IndexOf(Top); Top = TopList.Next(index); ChangeClose(TopUac, Top); ResetDepth(); } public void NextShoe() { int index = ShoeList.IndexOf(Shoe); Shoe = ShoeList.Next(index); ChangeClose(LeftShoeUac, Shoe); ChangeClose(RightShoeUac, Shoe); ResetDepth(); } public void NextHead() { int index = HeadList.IndexOf(Head); Head = HeadList.Next(index); ChangeClose(HeadUac, Head); ResetDepth(); } public void NextDress() { int index = DressList.IndexOf(Dress); Dress = DressList.Next(index); ChangeClose(DressUac, Dress); ResetDepth(); } public void NextMouse() { int index = MouseList.IndexOf(Mouse); Mouse = MouseList.Next(index); ChangeClose(MouseUac, Mouse); ResetDepth(); } public void NextHeadWear() { int index = HeadWearList.IndexOf(HeadWear); HeadWear = HeadWearList.Next(index); ChangeClose(HeadWearUac, HeadWear); ResetDepth(); } public void ResetDepth() { UAC.transform.SetLZ(2); HeadUac.transform.SetLZ(0); EyeUac.transform.SetLZ(-0.001f); TopUac.transform.SetLZ(-0.003f); DressUac.transform.SetLZ(-0.002f); MouseUac.transform.SetLZ(-0.001f); LeftShoeUac.transform.SetLZ(-0.001f); RightShoeUac.transform.SetLZ(-0.001f); HeadWearUac.transform.SetLZ(-0.001f); transform.FindChild("Armature/左腿").SetLZ(0); transform.FindChild("Armature/右腿").SetLZ(0); transform.FindChild("Armature/脖子").SetLZ(0); transform.FindChild("Armature/左手").SetLZ(-0.001f); transform.FindChild("Armature/右手").SetLZ(-0.001f); } public void ChangeClose(UnityArmatureComponent uac, string armatureName) { //DragonBones.Slot slot = null; //if (uac.armature != null) //{ // slot = uac.armature.parent; // uac.Dispose(false); //} //GameObject go = uac.gameObject; //uac = UnityFactory.factory.BuildArmatureComponent(armatureName, "Closet_ske", null, null, go); //if (uac == null) //{ // uac = UnityFactory.factory.BuildArmatureComponent(armatureName, "stand_ske", null, null, go); //} //uac.name = armatureName; //if (slot != null) //{ // slot.childArmature = uac.armature; //} //uac.sortingLayerName = uac.sortingLayerName; //uac.sortingOrder = uac.sortingOrder; } #endregion }