123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640 |
- using DragonBones;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.EventSystems;
- using System;
- using System.Xml;
- using System.Linq;
- using System.Collections;
- using System.Collections.Generic;
- using Slot = DragonBones.Slot;
- using Random = UnityEngine.Random;
- using Transform = UnityEngine.Transform;
- public enum BodyPart
- {
- Eye,
- Top,
- Shoe,
- Head,
- Dress,
- Mouse,
- Headwear,
- }
- public class CloseUnit
- {
- public enum CloseType
- {
- Top,
- Hair,
- Wing,
- Dress,
- Decarator,
- }
- #region Var
- public int Index;
- public int BuyLevel;
- public string CloseName;
- public Text BtnLab;
- public Sprite Sprite;
- public Image Icon;
- public Button BuyBtn;
- public Button DressBtn;
- public BodyPart BodyPart;
- public Transform Transform;
- public CloseType Type;
- public double BuyAmt;
- public double BuyAdvanceAmt;
- public Current BuyCurrent;
- public Current BuyAdvanceCurrent;
- public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
- #endregion
- public CloseUnit(XmlAttributeCollection attribute)
- {
- CloseName = attribute[2].Value;
- Sprite = SpriteParse(attribute[2].Value);
- Type = TypeParse(attribute[3].Value);
- Index = Auxiliary.IntParse(attribute[4].Value, -1);
- BodyPart = BodyPartParse(attribute[5].Value);
- BuyLevel = Auxiliary.IntParse(attribute[6].Value, 0);
- BuyCurrent = Auxiliary.CurrentParse(attribute[7].Value);
- BuyAmt = Auxiliary.DoubleParse(attribute[8].Value, 0);
- BuyAdvanceCurrent = Auxiliary.CurrentParse(attribute[9].Value);
- BuyAdvanceAmt = Auxiliary.DoubleParse(attribute[10].Value, 0);
- CreateItem();
- }
- protected void CreateItem()
- {
- Transform = ManaReso.Get("CloseItem", Folder.UI, false, ManaReso.Get("Canvas"), false);
- if (Type == CloseType.Top)
- {
- Transform.SetParent(ManaReso.Get("Pb_TopGrid"));
- }
- else if (Type == CloseType.Hair)
- {
- Transform.SetParent(ManaReso.Get("Pa_HairGrid"));
- }
- else if (Type == CloseType.Dress)
- {
- Transform.SetParent(ManaReso.Get("Pc_DressGrid"));
- }
- else if (Type == CloseType.Wing)
- {
- Transform.SetParent(ManaReso.Get("Pe_WingGrid"));
- }
- else if (Type == CloseType.Decarator)
- {
- Transform.SetParent(ManaReso.Get("Pd_DecaratorGrid"));
- }
- else
- {
- throw new Exception();
- }
- Transform.SetSiblingIndex(Index);
- Auxiliary.CompileDic(Transform, ChildDic);
- Icon = ChildDic["Icon"].GetComponent<Image>();
- DressBtn = ChildDic["CloseItem"].GetComponent<Button>();
- BuyBtn = ChildDic["BuyBtn"].GetComponent<Button>();
- BtnLab = ChildDic["BuyBtnLab"].GetComponent<Text>();
- Icon.sprite = Sprite;
- Icon.SetNativeSize();
- float newSize = 100 / Icon.sprite.rect.width;
- Icon.Resize(true, new Vector2(newSize, newSize)); //todo 把NewSize写到配置里
- }
- protected Sprite SpriteParse(string str)
- {
- return ManaPlayer.CloseDic[str];
- }
- protected BodyPart BodyPartParse(string str)
- {
- int type = Auxiliary.IntParse(str, -1);
- if (type == 1)
- {
- return BodyPart.Head;
- }
- else if (type == 2)
- {
- return BodyPart.Dress;
- }
- else if (type == 3)
- {
- return BodyPart.Shoe;
- }
- else if (type == 4)
- {
- return BodyPart.Headwear;
- }
- else if (type == 5)
- {
- return BodyPart.Top;
- }
- else
- {
- throw new Exception();
- }
- }
- protected CloseType TypeParse(string str)
- {
- int type = Auxiliary.IntParse(str, -1);
- if (type == 1)
- {
- return CloseType.Hair;
- }
- else if (type == 2)
- {
- return CloseType.Top;
- }
- else if (type == 3)
- {
- return CloseType.Dress;
- }
- else if (type == 4)
- {
- return CloseType.Decarator;
- }
- else if (type == 5)
- {
- return CloseType.Wing;
- }
- else
- {
- throw new Exception();
- }
- }
- }
- public class Player : Regist , IPointerClickHandler
- {
- #region 变量
- public static bool InDressRoom;
- public static float JumpFrequency;
- public bool AnimLock1;
- public bool AnimLock2;
- public float JumpTime;
- public float JumpTimer;
- public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
- #region 换装
- private string Eye;
- private string Top;
- private string Shoe;
- private string Head;
- private string Dress;
- private string Mouse;
- private string HeadWear;
- private string TempClose;
- public DragonBones.Slot EyeSlot;
- public DragonBones.Slot TopSlot;
- public DragonBones.Slot HeadSlot;
- public DragonBones.Slot DressSlot;
- public DragonBones.Slot MouseSlot;
- public DragonBones.Slot LeftShoeSlot;
- public DragonBones.Slot RightShoeSlot;
- public DragonBones.Slot HeadWearSlot;
- public UnityArmatureComponent UAC;
- #endregion
- #endregion
- public override bool RegistImmed()
- {
- if (base.RegistImmed())
- {
- return true;
- }
- enabled = true;
- Auxiliary.CompileDic(transform, ChildDic);
- Vector3 bigShadowScale = new Vector3(1.820952f, 2.418199f, 1.820952f);
- Vector3 smallShadowScale = new Vector3(1.081191f, 1.435807f, 1.081191f);
- StreamScale streamScale = ChildDic["Shadow"].CreateStreamScale
- (
- new List<float>() {0, 0, 0},
- new List<float>() {0.33f, 0.33f, 0.33f, 0.33f},
- new List<VecPair>() {new VecPair(bigShadowScale, smallShadowScale), new VecPair(smallShadowScale, bigShadowScale), new VecPair(bigShadowScale, smallShadowScale), new VecPair(smallShadowScale, bigShadowScale)},
- true,
- true,
- Curve.EaseOutQuad
- );
- streamScale.AddEventOnetime
- (
- EventType.ForwardFinish,
- () =>
- {
- if (!InDressRoom)
- {
- ManaPlayer.Player.ChildDic["Shadow"].SetActive(false);
- }
- }
- );
- return false;
- }
- public void FixedUpdate()
- {
- if (InDressRoom)
- {
- JumpTimer += Time.fixedDeltaTime;
- if (JumpTimer > JumpTime)
- {
- if (!AnimLock1 && !AnimLock2)
- {
- PlayAnim("newAnimation1");
- }
- AnimLock2 = true;
- }
- if (JumpTimer > JumpFrequency)
- {
- AnimLock2 = false;
- JumpTime = Mathf.Lerp(0, JumpFrequency, Random.Range(0f, 1f));
- JumpTimer = 0;
- }
- }
- }
- public void OnStart(string str, EventObject eventObject)
- {
- if (eventObject.animationState.name == "newAnimation1")
- {
- ChildDic["Shadow"].StreamReForScale();
- AnimLock1 = true;
- TempClose = Eye;
- ChangeClose(BodyPart.Eye, "眼睛表情1");
- }
- else if (eventObject.animationState.name == "newAnimation")
- {
- AnimLock1 = false;
- ChangeClose(BodyPart.Eye, TempClose);
- }
- }
- public void PlayAnim(string animName)
- {
- if (AnimLock1)
- {
- 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)
- {
- EnterDressRoom();
- }
- public void Save()
- {
- ExitDressRoom();
- }
- public void Reset()
- {
-
- }
- public void ExitDressRoom()
- {
- ManaCenter.SceneSwitchLock = false;
- TweenRoot tweenRoot = ManaReso.Get("I_BlackMask").TweenBacCG();
- tweenRoot.AddEventOnetime
- (
- EventType.BackwardFinish,
- () =>
- {
- ManaPlayer.Player.ChildDic["Shadow"].SetActive(false);
- ManaPlayer.Player.transform.position = ManaReso.Get("PlayerPosTra").position;
- ManaPlayer.Player.transform.localScale = ManaReso.Get("PlayerPosTra").lossyScale;
- ManaReso.Get("Garden").TweenForSr();
- ManaReso.Get("DressRoom").TweenBacSr();
- ManaReso.Get("C_Main").TweenForCG();
- ManaReso.Get("P_DressRoom").TweenBacCG();
- }
- );
- tweenRoot = ManaReso.Get("P_DressRoom").GetTweenCG();
- tweenRoot.AddEventOnetime
- (
- EventType.BackwardFinish,
- () =>
- {
- SetAllCollider(true);
- InDressRoom = false;
- ManaReso.Get("I_BlackMask").TweenForCG();
- }
- );
- }
- public void EnterDressRoom()
- {
- if (ManaCenter.SceneSwitchLock)
- {
- return;
- }
- InDressRoom = true;
- JumpTime = Mathf.Lerp(0, JumpFrequency, Random.Range(0.5f, 1f));
- ManaCenter.SceneSwitchLock = true;
- ManaReso.Get("C_Main").TweenBacCG();
- SetAllCollider(false);
- TweenRoot tweenRoot = ManaReso.Get("I_BlackMask").TweenBacCG();
- tweenRoot.AddEventOnetime
- (
- EventType.BackwardFinish,
- () =>
- {
- for (int i = 0; i < ManaGarden.PlantList.Count; i++)
- {
- ManaGarden.PlantList[i].Flower.RetrieveElf();
- }
- ManaPlayer.Player.ChildDic["Shadow"].SetActive(true);
- ManaPlayer.Player.transform.position = ManaReso.Get("DressRoomPos").position;
- ManaPlayer.Player.transform.localScale = ManaReso.Get("DressRoomPos").lossyScale;
- ManaReso.Get("Garden").TweenBacSr();
- ManaReso.Get("DressRoom").TweenForSr();
- ManaReso.Get("P_DressRoom").TweenForCG();
- }
- );
- tweenRoot = ManaReso.Get("P_DressRoom").GetTweenCG();
- tweenRoot.AddEventOnetime
- (
- EventType.ForwardFinish,
- () =>
- {
- ManaReso.Get("I_BlackMask").TweenForCG();
- }
- );
- }
- #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");
- UAC.AddEventListener(EventObject.START, OnStart);
- Eye = "眼睛1";
- Top = "上衣1";
- Shoe = "鞋子1";
- Head = "脑壳1";
- Dress = "裙子1";
- Mouse = "嘴巴1";
- HeadWear = "头饰品1";
- EyeSlot = UAC.armature.GetSlot("眼睛");
- TopSlot = UAC.armature.GetSlot("上衣");
- HeadSlot = UAC.armature.GetSlot("脑壳");
- DressSlot = UAC.armature.GetSlot("裙子");
- MouseSlot = UAC.armature.GetSlot("嘴巴");
- LeftShoeSlot = UAC.armature.GetSlot("鞋子左");
- RightShoeSlot = UAC.armature.GetSlot("鞋子右");
- HeadWearSlot = UAC.armature.GetSlot("头饰品");
- ChangeClose(BodyPart.Eye, "眼睛1", false);
- ChangeClose(BodyPart.Top, "上衣1", false);
- ChangeClose(BodyPart.Shoe, "鞋子1", false);
- ChangeClose(BodyPart.Head, "脑壳1", false);
- ChangeClose(BodyPart.Dress, "裙子1", false);
- ChangeClose(BodyPart.Mouse, "嘴巴1", false);
- ChangeClose(BodyPart.Headwear, "头饰品1", false);
- return UAC;
- }
- public UnityArmatureComponent BuildPink()
- {
- Build();
- ChangeClose(BodyPart.Eye, "眼睛3");
- ChangeClose(BodyPart.Top, "上衣3");
- ChangeClose(BodyPart.Shoe, "脑壳3");
- ChangeClose(BodyPart.Head, "裙子3");
- ChangeClose(BodyPart.Dress, "嘴巴3");
- ChangeClose(BodyPart.Mouse, "鞋子3");
- ChangeClose(BodyPart.Headwear, "头饰品3");
- return UAC;
- }
- public UnityArmatureComponent BuildBlond()
- {
- Build();
- ResetDepth();
- return UAC;
- }
- public UnityArmatureComponent BuildBrown()
- {
- Build();
- ChangeClose(BodyPart.Eye, "眼睛2");
- ChangeClose(BodyPart.Top, "上衣2");
- ChangeClose(BodyPart.Shoe, "脑壳2");
- ChangeClose(BodyPart.Head, "裙子2");
- ChangeClose(BodyPart.Dress, "嘴巴2");
- ChangeClose(BodyPart.Mouse, "鞋子2");
- ChangeClose(BodyPart.Headwear, "头饰品2");
- return UAC;
- }
- public void ResetDepth()
- {
- UAC.transform.SetLZ(2);
-
- transform.FindChild("Armature/" + Eye).SetLZ(-0.001f);
- transform.FindChild("Armature/" + Top).SetLZ(-0.003f);
- transform.FindChild("Armature/" + Head).SetLZ(0);
- transform.FindChild("Armature/" + Dress).SetLZ(-0.002f);
- transform.FindChild("Armature/" + Mouse).SetLZ(-0.001f);
- transform.FindChild("Armature/" + HeadWear).SetLZ(-0.001f);
- Transform shoeTra = transform.FindChild("Armature/" + Shoe);
- shoeTra.SetLZ(-0.001f);
- transform.FindChild("Armature").GetChild(shoeTra.GetSiblingIndex() + 1).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(BodyPart bodyPart, string armatureName, bool setDepth = true)
- {
- List<DragonBones.Slot> slotList = new List<DragonBones.Slot>();
- if (bodyPart == BodyPart.Eye)
- {
- Eye = armatureName;
- slotList.Add(EyeSlot);
- }
- else if (bodyPart == BodyPart.Top)
- {
- Top = armatureName;
- slotList.Add(TopSlot);
- }
- else if (bodyPart == BodyPart.Shoe)
- {
- Shoe = armatureName;
- slotList.Add(LeftShoeSlot);
- slotList.Add(RightShoeSlot);
- }
- else if (bodyPart == BodyPart.Head)
- {
- Head = armatureName;
- slotList.Add(HeadSlot);
- }
- else if (bodyPart == BodyPart.Dress)
- {
- Dress = armatureName;
- slotList.Add(DressSlot);
- }
- else if (bodyPart == BodyPart.Mouse)
- {
- Mouse = armatureName;
-
- slotList.Add(MouseSlot);
- }
- else if (bodyPart == BodyPart.Headwear)
- {
- HeadWear = armatureName;
- slotList.Add(HeadWearSlot);
- }
- else
- {
- throw new Exception();
- }
- ChangeClose(slotList, armatureName, setDepth);
- }
- public void ChangeClose(List<DragonBones.Slot> slotList, string armatureName, bool setDepth = true)
- {
- for (int i = 0; i < slotList.Count; i++)
- {
- slotList[i].childArmature = UnityFactory.factory.BuildArmature(armatureName);
- }
- if (setDepth)
- {
- ResetDepth();
- }
- }
- #endregion
- }
|