123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497 |
- 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<string> EyeList = new List<string>();
- private List<string> TopList = new List<string>();
- private List<string> ShoeList = new List<string>();
- private List<string> HeadList = new List<string>();
- private List<string> DressList = new List<string>();
- private List<string> MouseList = new List<string>();
- private List<string> HeadWearList = new List<string>();
- public UnityArmatureComponent UAC;
- public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
- #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<BoxCollider2D>();
- 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<TextAsset>("stand_ske", Folder.Config));
- UnityFactory.factory.LoadDragonBonesData(ManaReso.Load<TextAsset>("Closet_ske", Folder.Config));
- UnityFactory.factory.LoadTextureAtlasData(ManaReso.Load<TextAsset>("stand_tex", Folder.Config), "stand_texture");
- UnityFactory.factory.LoadTextureAtlasData(ManaReso.Load<TextAsset>("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<UnityArmatureComponent>();
- TopUac = transform.FindChild("Armature/上衣3").GetComponent<UnityArmatureComponent>();
- HeadUac = transform.FindChild("Armature/脑壳3").GetComponent<UnityArmatureComponent>();
- DressUac = transform.FindChild("Armature/裙子3").GetComponent<UnityArmatureComponent>();
- MouseUac = transform.FindChild("Armature/嘴巴3").GetComponent<UnityArmatureComponent>();
- LeftShoeUac = transform.FindChild("Armature/鞋子3").GetComponent<UnityArmatureComponent>();
- HeadWearUac = transform.FindChild("Armature/头饰品3").GetComponent<UnityArmatureComponent>();
- RightShoeUac = transform.FindChild("Armature").GetChild(LeftShoeUac.transform.GetSiblingIndex() + 1).GetComponent<UnityArmatureComponent>();
- 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<UnityArmatureComponent>();
- TopUac = transform.FindChild("Armature/上衣1").GetComponent<UnityArmatureComponent>();
- HeadUac = transform.FindChild("Armature/脑壳1").GetComponent<UnityArmatureComponent>();
- DressUac = transform.FindChild("Armature/裙子1").GetComponent<UnityArmatureComponent>();
- MouseUac = transform.FindChild("Armature/嘴巴1").GetComponent<UnityArmatureComponent>();
- LeftShoeUac = transform.FindChild("Armature/鞋子1").GetComponent<UnityArmatureComponent>();
- HeadWearUac = transform.FindChild("Armature/头饰品1").GetComponent<UnityArmatureComponent>();
- RightShoeUac = transform.FindChild("Armature").GetChild(LeftShoeUac.transform.GetSiblingIndex() + 1).GetComponent<UnityArmatureComponent>();
- 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<UnityArmatureComponent>();
- TopUac = transform.FindChild("Armature/上衣2").GetComponent<UnityArmatureComponent>();
- HeadUac = transform.FindChild("Armature/脑壳2").GetComponent<UnityArmatureComponent>();
- DressUac = transform.FindChild("Armature/裙子2").GetComponent<UnityArmatureComponent>();
- MouseUac = transform.FindChild("Armature/嘴巴2").GetComponent<UnityArmatureComponent>();
- LeftShoeUac = transform.FindChild("Armature/鞋子2").GetComponent<UnityArmatureComponent>();
- HeadWearUac = transform.FindChild("Armature/头饰品2").GetComponent<UnityArmatureComponent>();
- RightShoeUac = transform.FindChild("Armature").GetChild(LeftShoeUac.transform.GetSiblingIndex() + 1).GetComponent<UnityArmatureComponent>();
- 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<UnityArmatureComponent>();
- }
- else if (eventObject.animationState.name == "newAnimation")
- {
- AnimLock = false;
- UAC.armature.GetSlot("眼睛").childArmature = UnityFactory.factory.BuildArmature(Eye);
- EyeUac = transform.FindChild("Armature/" + Eye).GetComponent<UnityArmatureComponent>();
- }
- 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
- }
|