123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995 |
- 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 System.Text.RegularExpressions;
- using textUtility;
- using Animation = DragonBones.Animation;
- using Slot = DragonBones.Slot;
- using Random = UnityEngine.Random;
- using Transform = UnityEngine.Transform;
- public class PlayerLabel
- {
- public static string MessageBox = "MessageBox";
- public static string NickName = "NickName";
- public static string Pivot = "Pivot";
- public static string Shadow = "Shadow";
- public static string ExpressionMeshFilter = "ExpressionMeshFilter";
- public static string ShadowParent = "ShadowParent";
- public static string Player = "Player";
- public static string RightPos = "RightPos";
- public static string LeftPos = "LeftPos";
- public static string EnterGameTra = "EnterGameTra";
- }
- public enum BodyPart
- {
- Leg = 0,
- LeftHand = 1,
- RightHand = 2,
- LeftLongSleeve = 3,
- LeftShortSleeve = 4,
- RightLongSleeve = 5,
- RightShortSleeve = 6,
- Neck = 7,
- Eye = 8,
- Top = 9,
- Shoe = 10,
- Head = 11,
- Wing = 12,
- Dress = 13,
- Mouse = 14,
- Headwear = 15,
- }
- public class ExchangeInfo
- {
- public float ExchangeRate;
- public double Value;
- public Current Current;
- public static void GetExchangeValue(ExchangeInfo info, StaticsManager.ConsumeModule consumeModule)
- {
- if (info.Current == Current.Coin)
- {
- Manager.AddCoin(info.Value, StaticsManager.ItemID.获得金币, consumeModule);
- }
- else if (info.Current == Current.Diamond)
- {
- Manager.AddDiamond(info.Value, StaticsManager.ItemID.获得钻石, consumeModule);
- }
- }
- public static ExchangeInfo GetExchangeInfo(Current current, double amt, float rate)
- {
- ExchangeInfo info = new ExchangeInfo();
- info.ExchangeRate = rate;
- info.Value = amt * rate;
- info.Current = current;
- return info;
- }
- }
- public class CloseItemLabel
- {
- public static string Icon1 = "Icon1";
- public static string Icon2 = "Icon2";
- public static string Icon3 = "Icon3";
- public static string CloseItem = "CloseItem";
- public static string BuyBtn = "BuyBtn";
- public static string BuyBtnLab = "BuyBtnLab";
- }
- public class CloseItem
- {
- public enum CloseType
- {
- Top,
- Hair,
- Wing,
- Dress,
- Decarator,
- Shoe,
- }
- #region Config
- public string Name
- {
- get { return Language.GetStr(LanguageLabel.CombineLanguageLabel(LanguageLabel.DressRoom, FullID)); }
- }
- public static string IDPrefix = "Armature";
- public string FullID
- {
- get { return IDPrefix + ID; }
- }
- public int ID;
- public int Index;
- public int BuyLevel;
- public int PixelSize;
- public bool IsBought;
- public string ArmatureName;
- public string[] ExtraArmatureNames;
- public BodyPart[] ExtraBodyParts;
- public float SpriteAlpha;
- public float IconOffset;
- public TextPlus BuyBtnLab;
- public Sprite[] Sprites;
- public Image Icon1;
- public Image Icon2;
- public Image Icon3;
- public Button BuyBtn;
- public Button DressBtn;
- public Vector2 IconOffset0;
- public Vector2 IconOffset1;
- public Vector2 IconOffset2;
- public BodyPart BodyPart;
- public Transform Transform;
- public CloseType Type;
- public bool Unavailable; //True-不显示
- public string desc;
- public double BuyCost;
- public double BuyAdvanceCost;
- public Current BuyCurrent;
- public Current BuyAdvanceCurrent;
- public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
- #endregion
- public CloseItem(XmlAttributeCollection attribute)
- {
- Unavailable = Auxiliary.StringToBool(attribute[19].Value, false);
- ID = Auxiliary.StringToInt(attribute[0].Value, -1);
- BodyPart = BodyPartParse(attribute[4].Value);
- ArmatureName = attribute[16].Value;
- //Debug.Log(ArmatureName);
- PlayerManager.CloseIDDictionary.Add(ArmatureName, ID);
- //Debug.Log(ID);
- PlayerManager.CloseItemDictionary.Add(ID, this);
- if (Unavailable)
- {
- return;
- }
- Type = TypeParse(attribute[2].Value);
- Index = Auxiliary.StringToInt(attribute[3].Value, -1);
- BuyLevel = Auxiliary.StringToInt(attribute[5].Value, 0);
- BuyCurrent = Auxiliary.CurrentParse(attribute[6].Value);
- BuyCost = Auxiliary.StringToDouble(attribute[7].Value, 0);
- BuyAdvanceCurrent = Auxiliary.CurrentParse(attribute[8].Value);
- BuyAdvanceCost = Auxiliary.StringToDouble(attribute[9].Value, 0);
- PixelSize = Auxiliary.StringToInt(attribute[10].Value, 100);
- IconOffset = Auxiliary.StringToFloat(attribute[11].Value, 0);
- IconOffset1 = Auxiliary.StringToVector(',', attribute[12].Value, new Vector3());
- IconOffset2 = Auxiliary.StringToVector(',', attribute[13].Value, new Vector3());
- Sprites = SpriteParse(attribute[14].Value);
- SpriteAlpha = Auxiliary.StringToFloat(attribute[15].Value, 1);
- ExtraBodyParts = BodyPartParses(attribute[17].Value);
- ExtraArmatureNames = Auxiliary.StringToStrings(',', attribute[18].Value, new List<string>()).ToArray();
- IconOffset0 = Auxiliary.StringToVector(',', attribute[20].Value, new Vector3());
- desc = attribute[21].Value;
- CreateItem();
- }
- protected void CreateItem()
- {
- Transform = ResourceManager.Get(ResourceLabel.CloseItem, Folder.UI, false, ResourceManager.Get(CanvasLabel.Canvas), false);
- if (Type == CloseType.Top)
- {
- Transform.SetParent(ResourceManager.Get(CanvasLabel.Pb_TopGrid));
- }
- else if (Type == CloseType.Hair)
- {
- Transform.SetParent(ResourceManager.Get(CanvasLabel.Pa_HairGrid));
- }
- else if (Type == CloseType.Dress)
- {
- Transform.SetParent(ResourceManager.Get(CanvasLabel.Pc_DressGrid));
- }
- else if (Type == CloseType.Wing)
- {
- Transform.SetParent(ResourceManager.Get(CanvasLabel.Pe_WingGrid));
- }
- else if (Type == CloseType.Decarator)
- {
- Transform.SetParent(ResourceManager.Get(CanvasLabel.Pd_DecaratorGrid));
- }
- else if (Type == CloseType.Shoe)
- {
- Transform.SetParent(ResourceManager.Get(CanvasLabel.Pf_ShoeGrid));
- }
- else
- {
- throw new Exception();
- }
- Transform.SetSiblingIndex(Index);
- Auxiliary.CompileDic(Transform, ChildDic);
- Icon1 = ChildDic[CloseItemLabel.Icon1].GetComponent<Image>();
- Icon2 = ChildDic[CloseItemLabel.Icon2].GetComponent<Image>();
- Icon3 = ChildDic[CloseItemLabel.Icon3].GetComponent<Image>();
- DressBtn = ChildDic[CloseItemLabel.CloseItem].GetComponent<Button>();
- BuyBtn = ChildDic[CloseItemLabel.BuyBtn].GetComponent<Button>();
- BuyBtnLab = ChildDic[CloseItemLabel.BuyBtnLab].GetComponent<TextPlus>();
- SetupStandardItem(Icon1, Icon2, Icon3, BuyBtn, BuyBtnLab);
- //BuyBtnLab.GetComponent<TextPlus>().SetY = true;
- //float newSize = PixelSize / Sprites[0].rect.width;
- //SetupUI(newSize, new Vector2(), Icon1, Icon2, Icon3);
- //if (BuyCurrent != Current.Free)
- //{
- // BuyBtnLab.text = Auxiliary.ImageParse(BuyCurrent) + Auxiliary.ShrinkNumberStr(BuyCost);
- //}
- //if (BuyLevel > Manager.GardenLevel)
- //{
- // BuyBtn.interactable = false;
- // BuyBtn.image.material = Lib.GrayMat;
- //}
- BuyBtn.onClick.AddListener
- (
- () =>
- {
- AudioManager.PlayClip(AudioLabel.ClickButton);
- OpenBuyPanel(null, NavigateToChargeFromDressroom);
- //ResourceManager.Get(CanvasLabel.Pa_Info).TweenForCG();
- //float newSize = PixelSize / Sprites[0].rect.width;
- //SetupUI(newSize, new Vector2(0, 22), ResourceManager.Get<Image>(CanvasLabel.Pa_Icon1), ResourceManager.Get<Image>(CanvasLabel.Pa_Icon3), ResourceManager.Get<Image>(CanvasLabel.Pa_Icon2));
- //ResourceManager.SetText(CanvasLabel.Pa_Lab, Name);
- //ResourceManager.SetText(CanvasLabel.Pa_BtnLab, Language.GetStr(LanguageLabel.UI__Pa_BtnLab) + Auxiliary.ImageParse(BuyCurrent) + BuyCost);
- //ResourceManager.SetButtonEvent
- //(
- // CanvasLabel.Pa_Btn,
- // () => OnBuy
- //);
- }
- );
- DressBtn.onClick.AddListener
- (
- () =>
- {
- AudioManager.PlayClip(AudioLabel.ClickButton);
- if (BuyLevel > Manager.GardenLevel)
- {
- Bubble.Show(null, Language.GetStr(LanguageLabel.UI__P_Unlock));
- return;
- }
- ChangeDress(PlayerManager.Player);
- }
- );
- }
- protected Sprite[] SpriteParse(string str)
- {
- string[] spriteNames = str.Split(',');
- Sprite[] sprites = new Sprite[spriteNames.Length];
- for (int i = 0; i < spriteNames.Length; i++)
- {
- if (!PlayerManager.CloseSpriteDictionary.ContainsKey(spriteNames[i]))
- {
- Debug.Log(spriteNames[i]);
- }
- sprites[i] = PlayerManager.CloseSpriteDictionary[spriteNames[i]];
- }
- return sprites;
- }
- protected BodyPart BodyPartParse(string str)
- {
- int type = Auxiliary.StringToInt(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 if (type == 6)
- {
- return BodyPart.Wing;
- }
- else if (type == 7)
- {
- return BodyPart.LeftLongSleeve;
- }
- else if (type == 8)
- {
- return BodyPart.RightLongSleeve;
- }
- else if (type == 9)
- {
- return BodyPart.LeftShortSleeve;
- }
- else if (type == 10)
- {
- return BodyPart.RightShortSleeve;
- }
- else if (type == 11)
- {
- return BodyPart.Eye;
- }
- else if (type == 12)
- {
- return BodyPart.Mouse;
- }
- else
- {
- throw new Exception();
- }
- }
- protected BodyPart[] BodyPartParses(string str)
- {
- List<string> typeIDs = Auxiliary.StringToStrings(',', str, new List<string>());
- BodyPart[] bodyParts = new BodyPart[typeIDs.Count];
- for (int i = 0; i < typeIDs.Count; i++)
- {
- bodyParts[i] = BodyPartParse(typeIDs[i]);
- }
- return bodyParts;
- }
- protected CloseType TypeParse(string str)
- {
- int type = Auxiliary.StringToInt(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 if (type == 6)
- {
- return CloseType.Shoe;
- }
- else
- {
- throw new Exception();
- }
- }
- public void SetupUI(float newSize, Vector2 offset, Image icon1, Image icon2, Image icon3)
- {
- icon1.SetActive(false);
- icon3.SetActive(false);
- icon2.SetActive(true);
- icon2.sprite = Sprites[0];
- icon2.Resize(true, new Vector2(newSize, newSize));
- icon2.SetAlpha(SpriteAlpha);
- icon2.transform.localPosition = IconOffset0 * newSize + offset + new Vector2(0, IconOffset);
- if (Sprites.Length >= 2)
- {
- icon1.SetActive(true);
- icon1.sprite = Sprites[1];
- icon1.Resize(true, new Vector2(newSize, newSize));
- icon1.SetAlpha(SpriteAlpha);
- icon1.transform.localPosition = IconOffset1 * newSize + offset + new Vector2(0, IconOffset);
- }
- if (Sprites.Length >= 3)
- {
- icon3.SetActive(true);
- icon3.sprite = Sprites[2];
- icon3.Resize(true, new Vector2(newSize, newSize));
- icon3.SetAlpha(SpriteAlpha);
- icon3.transform.localPosition = IconOffset2 * newSize + offset + new Vector2(0, IconOffset);
- }
- }
- public void SetupStandardItem(Image icon1, Image icon2, Image icon3, Button buyButton, TextPlus buyButtonText)
- {
- buyButtonText.GetComponent<TextPlus>().SetY = true;
- float newSize = PixelSize / Sprites[0].rect.width;
- SetupUI(newSize, new Vector2(), icon1, icon2, icon3);
- if (BuyCurrent != Current.Free)
- {
- buyButtonText.text = Auxiliary.ImageParse(BuyCurrent) + Auxiliary.ShrinkBigNumberStr(BuyCost);
- buyButton.interactable = true;
- }
- if (BuyLevel > Manager.GardenLevel)
- {
- buyButton.interactable = false;
- buyButton.image.material = Lib.GrayMat;
- }
- }
- public void OpenBuyPanel(Action buySucceedCallback, Action navigateAction)
- {
- ResourceManager.Get(CanvasLabel.Pa_Info).TweenForCG();
- float newSize = PixelSize / Sprites[0].rect.width;
- SetupUI(newSize, new Vector2(0, 22), ResourceManager.Get<Image>(CanvasLabel.Pa_Icon1), ResourceManager.Get<Image>(CanvasLabel.Pa_Icon3), ResourceManager.Get<Image>(CanvasLabel.Pa_Icon2));
- RichText descTxt = ResourceManager.Get<RichText>(CanvasLabel.Pa_Desc);
- if (string.IsNullOrEmpty(desc))
- {
- descTxt.SetActive(false);
- }
- else
- {
- descTxt.SetActive(true);
- string descContent = Language.GetStr("DressRoom", desc);
- Match match = Regex.Match(descContent, "ID\\[\\d+\\]");
- targetSerialNumber = match.Value;
- descContent = descContent.Replace(targetSerialNumber, "");
- targetSerialNumber = Regex.Match(match.Value, "\\d+").Value;
- descTxt.SuperlinkCallbackDictionary = new Dictionary<int, Action<int>>();
- descTxt.SuperlinkCallbackDictionary.Add(0, OnSuperlinkClick);
- descTxt.text = descContent;
- descTxt.SetContent(descContent);
- }
- ResourceManager.SetText(CanvasLabel.Pa_Lab, Name);
- ResourceManager.SetText(CanvasLabel.Pa_BtnLab, Language.GetStr(LanguageLabel.UI__Pa_BtnLab) + Auxiliary.ImageParse(BuyCurrent) + BuyCost);
- ResourceManager.SetButtonEvent
- (
- CanvasLabel.Pa_Btn,
- () => OnBuy(buySucceedCallback, navigateAction)
- );
- }
- private string targetSerialNumber;
- private void OnSuperlinkClick(int id)
- {
- if (Manager.Coin < VisitManager.VisitCost)
- {
- Bubble.Show(Language.GetStr(LanguageLabel.Common__ShortCoin), null, null, Lib.GoldSprite);
- }
- else
- {
- Bubble.Show
- (
- null,
- Language.GetStr(LanguageLabel.UI__Pa_VisitWarning),
- null,
- null,
- () =>
- {
- ResourceManager.Get<Button>(CanvasLabel.Pa_Close).onClick.Invoke();
- PlayerManager.Player.ResetDressDatas();
- TweenRoot tweenRoot = PlayerManager.Player.ExitDressRoom();
- tweenRoot.AddEventOnetime(EventType.ForwardFinish, () =>
- {
- VisitManager.Visit(ConfigSource.SerialNumber, targetSerialNumber);
- });
- }
- );
- }
- }
- public void Unlock()
- {
- if (Unavailable)
- {
- return;
- }
- IsBought = true;
- BuyBtn.interactable = false;
- BuyBtn.image.material = Lib.GrayMat;
- BuyBtnLab.text = Language.GetStr(LanguageLabel.UI__P_BtnLab2);
- Manager.CloseAmt++;
- }
- public void OnBuy(Action buySucceedCallback, Action navigateAction)
- {
- bool navigate = navigateAction != null;
- Manager.Pay
- (
- "",
- BuyCost,
- BuyCurrent,
- () =>
- {
- OnBuySucceed();
- ResourceManager.Get(CanvasLabel.Pa_Info).TweenBacCG();
- ChangeDress(PlayerManager.Player);
- SaveDressData();
- buySucceedCallback.SafeInvoke();
- ConfigManager.SaveConfigDocument();
- ConfigManager.SaveConfigDocumentToDisk();
- },
- StaticsManager.ItemID.解锁服装,
- StaticsManager.ConsumeModule.Shop,
- navigate,
- false,
- () =>
- {
- PlayerManager.Player.ResetDressDatas();
- navigateAction.SafeInvoke();
- }
- );
- }
- public void OnBuySucceed()
- {
- Unlock();
- AudioManager.PlayClip(AudioLabel.GetCurrent);
- PlayerManager.BoughtCloseIDs.UniqueAdd(ID);
- }
- public void NavigateToChargeFromDressroom()
- {
- TweenRoot tweenRoot = ResourceManager.Get(CanvasLabel.Pa_Info).TweenBacCG();
- tweenRoot.AddEventOnetime
- (
- EventType.BackwardFinish,
- () =>
- {
- PlayerManager.Player.LeaveDressroom();
- }
- );
- ResourceManager.Get(CanvasLabel.B_SignIn0).GetTweenCG().AddEventOnetime
- (
- EventType.ForwardFinish,
- () =>
- {
- ResourceManager.Get(CanvasLabel.F_Manage0).TweenForVec();
- }
- );
- }
- public void ChangeDress(Player player, bool resetDepth = true)
- {
- player.ChangeClose(BodyPart, ArmatureName, resetDepth);
- if (Unavailable)
- {
- return;
- }
- if (ExtraBodyParts.Length > 0)
- {
- player.ChangeClose(BodyPart.LeftLongSleeve, "Empty", resetDepth);
- player.ChangeClose(BodyPart.LeftShortSleeve, "Empty", resetDepth);
- player.ChangeClose(BodyPart.RightLongSleeve, "Empty", resetDepth);
- player.ChangeClose(BodyPart.RightShortSleeve, "Empty", resetDepth);
- }
- for (int i = 0; i < ExtraArmatureNames.Length; i++)
- {
- player.ChangeClose(ExtraBodyParts[i], ExtraArmatureNames[i], resetDepth);
- }
- }
- public void SaveDressData() //仅在购买完成时调用
- {
- SaveDressData(BodyPart);
- if (BodyPart == BodyPart.Top)
- {
- PlayerManager.DressDatas[8] = "Empty";
- PlayerManager.DressDatas[9] = "Empty";
- PlayerManager.DressDatas[10] = "Empty";
- PlayerManager.DressDatas[11] = "Empty";
- foreach (var bodyPart in ExtraBodyParts)
- {
- SaveDressData(bodyPart);
- }
- }
- }
- public void SaveDressData(BodyPart bodyPart) //仅在购买完成时调用
- {
- if (bodyPart == BodyPart.LeftLongSleeve)
- {
- PlayerManager.DressDatas[8] = PlayerManager.Player.LeftLongSleeve;
- }
- else if (bodyPart == BodyPart.LeftShortSleeve)
- {
- PlayerManager.DressDatas[9] = PlayerManager.Player.LeftShortSleeve;
- }
- else if (bodyPart == BodyPart.RightLongSleeve)
- {
- PlayerManager.DressDatas[10] = PlayerManager.Player.RightLongSleeve;
- }
- else if (bodyPart == BodyPart.RightShortSleeve)
- {
- PlayerManager.DressDatas[11] = PlayerManager.Player.RightShortSleeve;
- }
- else if (bodyPart == BodyPart.Top)
- {
- PlayerManager.DressDatas[4] = PlayerManager.Player.Top;
- }
- else if (bodyPart == BodyPart.Shoe)
- {
- PlayerManager.DressDatas[2] = PlayerManager.Player.Shoe;
- }
- else if (bodyPart == BodyPart.Head)
- {
- PlayerManager.DressDatas[0] = PlayerManager.Player.Head;
- }
- else if (bodyPart == BodyPart.Wing)
- {
- PlayerManager.DressDatas[7] = PlayerManager.Player.Wing;
- }
- else if (bodyPart == BodyPart.Dress)
- {
- PlayerManager.DressDatas[1] = PlayerManager.Player.Dress;
- }
- else if (bodyPart == BodyPart.Headwear)
- {
- PlayerManager.DressDatas[3] = PlayerManager.Player.HeadWear;
- }
- else
- {
- throw new Exception();
- }
- }
- public void OnLevelChange()
- {
- if (Unavailable)
- {
- return;
- }
- if (IsBought)
- {
- return;
- }
-
- if (BuyLevel <= Manager.GardenLevel)
- {
- BuyBtn.interactable = true;
- BuyBtn.image.material = null;
- }
- }
- public ExchangeInfo GetExchangeValue(float rate, StaticsManager.ConsumeModule consumeModule)
- {
- ExchangeInfo info = ExchangeInfo.GetExchangeInfo(BuyCurrent, BuyCost, rate);
- ExchangeInfo.GetExchangeValue(info, consumeModule);
- return info;
- }
- public static List<KV<Current, KV<int, double>>> GetTotalBuyCost(bool excludeBought, List<int> closeIDs)
- {
- int coinAmount = 0;
- int diamondAmount = 0;
- double totalCoin = 0;
- double totalDiamond = 0;
- foreach (var closeID in closeIDs)
- {
- if (PlayerManager.CloseItemDictionary[closeID].Sprites == null) continue;
- if (PlayerManager.CloseItemDictionary[closeID].ArmatureName == "Empty") continue;
- CloseItem closeItem = PlayerManager.CloseItemDictionary[closeID];
- if (closeItem.IsBought && excludeBought) continue;
- if (closeItem.BuyCurrent == Current.Coin)
- {
- totalCoin += closeItem.BuyCost;
- coinAmount++;
- }
- if (closeItem.BuyCurrent == Current.Diamond)
- {
- totalDiamond += closeItem.BuyCost;
- diamondAmount++;
- }
- }
- List<KV<Current, KV<int, double>>> results = new List<KV<Current, KV<int, double>>>();
- results.Add(new KV<Current, KV<int, double>>(Current.Coin, new KV<int, double>(coinAmount, totalCoin)));
- results.Add(new KV<Current, KV<int, double>>(Current.Diamond, new KV<int, double>(diamondAmount, totalDiamond)));
- return results;
- }
- }
- public enum PlayerDirection
- {
- Left = 0,
- Right = 1,
- }
- public class Player : Regist , IPointerClickHandler
- {
- #region Config
- public static string IdleAnimationName = "newAnimation";
- public static string JumpAnimationName = "newAnimation1";
- public static string WalkAnimationName = "newAnimation2";
- public static string RunAnimationName = "newAnimation3";
- public static bool InDressRoom;
- public static float InDressRoomJumpFrequency;
- public float JumpTime;
- public float JumpTimer;
- public PlayerDirection PlayerDirection
- {
- get { return playerDirection; }
- set
- {
- playerDirection = value;
- Flip(playerDirection);
- }
- }
- public PlayerDirection playerDirection = PlayerDirection.Left;
- public Vector3 PosInGarden;
- public bool IsDisplayInUGUI;
- public float UGUIScale;
- public bool PlayAnimFlag1;
- public bool PlayAnimFlag2;
- public string CurrentAnimationName;
- public Material Material;
- public MeshFilter ExpressionMeshFilter;
- public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
- private string ExpressionName;
- private Coroutine ResetExpressionCoroutine;
- public static Dictionary<string, Vector3> LeftExpressionPositionDictionary = new Dictionary<string, Vector3>
- {
- {"郁闷", new Vector3(0, -0.22f, -0.00001f)},
- {"汗颜", new Vector3(0.35f, 0.91f, -0.00001f)},
- {"惊讶", new Vector3(0.09f, -0.07f, -0.00001f)},
- {"开心", new Vector3(0.1f, -0.22f, -0.00001f)},
- {"哭", new Vector3(0.07f, -0.64f, -0.00001f)},
- {"期待", new Vector3(0.04f, -0.20f, -0.00001f)},
- {"色咪咪", new Vector3(0.03f, -0.09f, -0.00001f)},
- {"委屈", new Vector3(0f, -0.27f, -0.00001f)},
- };
- public static Dictionary<string, Vector3> RightExpressionPositionDictionary = new Dictionary<string, Vector3>
- {
- {"郁闷", new Vector3(0, -0.22f, -0.00001f)},
- {"汗颜", new Vector3(-0.22f, 0.91f, -0.00001f)},
- {"惊讶", new Vector3(-0.09f, -0.07f, -0.00001f)},
- {"开心", new Vector3(-0.1f, -0.22f, -0.00001f)},
- {"哭", new Vector3(-0.07f, -0.64f, -0.00001f)},
- {"期待", new Vector3(-0.04f, -0.20f, -0.00001f)},
- {"色咪咪", new Vector3(-0.03f, -0.09f, -0.00001f)},
- {"委屈", new Vector3(0f, -0.27f, -0.00001f)},
- };
- #region 换装
- public Transform Shadow;
- private Transform Pivot
- {
- get
- {
- if (pivot == null)
- {
- pivot = UAC.transform.FindChild(PlayerLabel.Pivot);
- }
- return pivot;
- }
- }
- private Transform pivot;
- public string Eye;
- public string Top;
- public string Shoe;
- public string Head;
- public string Wing;
- public string Dress;
- public string Mouse;
- public string HeadWear;
- public string LeftLongSleeve;
- public string LeftShortSleeve;
- public string RightLongSleeve;
- public string RightShortSleeve;
- private string TempClose;
- public DragonBones.Slot NeckSlot;
- public DragonBones.Slot LeftHandSlot;
- public DragonBones.Slot RightHandSlot;
- public DragonBones.Slot LeftLegSlot;
- public DragonBones.Slot RightLegSlot;
- public DragonBones.Slot LeftShortSleeveSlot;
- public DragonBones.Slot RightShortSleeveSlot;
- public DragonBones.Slot EyeSlot;
- public DragonBones.Slot TopSlot;
- public DragonBones.Slot HeadSlot;
- public DragonBones.Slot DressSlot;
- public DragonBones.Slot WingSlot;
- public DragonBones.Slot MouseSlot;
- public DragonBones.Slot LeftShoeSlot;
- public DragonBones.Slot RightShoeSlot;
- public DragonBones.Slot HeadWearSlot;
- public string leftShoeDisplayName = "鞋子1";
- public string rightShoeDisplayName = "鞋子1";
- public UnityArmatureComponent UAC;
- //public UnityArmatureComponent LeftShortSleeveUAC;
- //public UnityArmatureComponent RightShortSleeveUAC;
- public UnityArmatureComponent LeftLongSleeveUAC;
- public UnityArmatureComponent RightLongSleeveUAC;
- #endregion
- #endregion
- public override bool InitAtOnce()
- {
- if (base.InitAtOnce())
- {
- 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);
- Shadow = ChildDic[PlayerLabel.Shadow];
- 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
- );
- MeshFilter meshFilter = Shadow.GetComponent<MeshFilter>();
- meshFilter.mesh = SpriteUtility.CreateMesh(ResourceManager.LoadSprite(ResourceLabel.FlowerShadow, Folder.Scene));
- meshFilter.mesh.SetUVs(1, Enumerable.Repeat(new Vector2(0, 1), meshFilter.mesh.vertices.Length).ToList());
- return false;
- }
- public void Update()
- {
- if (InDressRoom)
- {
- JumpTimer += Time.deltaTime;
- if (JumpTimer > JumpTime)
- {
- if (!PlayAnimFlag1 && !PlayAnimFlag2)
- {
- PlayAnim(JumpAnimationName);
- }
- PlayAnimFlag2 = true;
- }
- if (JumpTimer > InDressRoomJumpFrequency)
- {
- PlayAnimFlag2 = false;
- JumpTime = Mathf.Lerp(0, InDressRoomJumpFrequency, Random.Range(0f, 1f));
- JumpTimer = 0;
- }
- }
- //if (GardenSmartFoxManager.GardenSmartFox.PlazaRoomManager.InPlazaRoom)
- //{
- // MoveThread();
- //}
- }
- public void OnAnimStart(string str, EventObject eventObject)
- {
- if (eventObject.animationState.name == JumpAnimationName)
- {
- Shadow.StreamReForScale();
- PlayAnimFlag1 = true;
- TempClose = Eye;
- ChangeClose(BodyPart.Eye, "眼睛表情1");
- }
- else if (eventObject.animationState.name == IdleAnimationName)
- {
- PlayAnimFlag1 = false;
- if (TempClose != null)
- {
- ChangeClose(BodyPart.Eye, TempClose);
- }
- }
- if (IsDisplayInUGUI)
- {
- DisplayInUI(UGUIScale, false);
- }
- }
- public void PlayAnim(string animName)
- {
- if (PlayAnimFlag1)
- {
- return;
- }
- if (UAC.anim.lastAnimationName == animName)
- {
- return;
- }
- if (SFSManager.GardenSmartFox.PlazaRoomController.JoinedPlazaRoom)
- {
- CurrentAnimationName = animName;
- }
- UAC.anim.FadeIn(animName, GetFadeInTime(UAC.anim.lastAnimationName, animName));
- }
- public float GetFadeInTime(string lastAnimation, string targetAnimation)
- {
- if (lastAnimation == JumpAnimationName && targetAnimation == IdleAnimationName)
- return -1f;
- else
- return 0.1f;
- //throw new Exception();
- }
- 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)
- {
- AudioManager.PlayClip(AudioLabel.GetCurrent);
- PlayAnim(JumpAnimationName);
- }
- public void ResetExpression()
- {
- ExpressionMeshFilter.SetActive(false);
- EyeSlot.UnityTransform.GetChild(0).SetActive(true);
- MouseSlot.UnityTransform.GetChild(0).SetActive(true);
- }
- public void ChangeExpression(string expressionName, float duration)
- {
- ExpressionName = expressionName;
- ExpressionMeshFilter.sharedMesh = SpriteUtility.CreateMesh(ResourceManager.LoadSprite(expressionName, Folder.Scene));
- ExpressionMeshFilter.mesh.SetUVs(1, Enumerable.Repeat(new Vector2(0, 1), ExpressionMeshFilter.mesh.vertices.Length).ToList());
- ExpressionMeshFilter.transform.parent = EyeSlot.UnityTransform;
- ExpressionMeshFilter.SetActive(true);
- EyeSlot.UnityTransform.GetChild(0).SetActive(false);
- MouseSlot.UnityTransform.GetChild(0).SetActive(false);
- FlipExpression(expressionName, PlayerDirection);
- if (ResetExpressionCoroutine != null)
- Auxiliary.Instance.StopCoroutine(ResetExpressionCoroutine);
- ResetExpressionCoroutine = Auxiliary.Instance.DelayCall
- (
- () =>
- {
- ResetExpression();
- },
- duration
- );
- }
- public void Flip(PlayerDirection direction)
- {
- FlipExpression(ExpressionName, direction);
- if (direction == PlayerDirection.Left)
- {
- UAC.armature.flipX = false;
- playerDirection = PlayerDirection.Left;
- }
- else if (direction == PlayerDirection.Right)
- {
- UAC.armature.flipX = true;
- playerDirection = PlayerDirection.Right;
- }
- else
- {
- throw new Exception();
- }
- DelayCall.Call(1, () => Shadow.SetX(Pivot.position.x));
- }
- public void FlipExpression(string expressionName, PlayerDirection direction)
- {
- if (string.IsNullOrEmpty(ExpressionName))
- {
- return;
- }
- if (direction == PlayerDirection.Left)
- {
- ExpressionMeshFilter.transform.eulerAngles = new Vector3();
- ExpressionMeshFilter.transform.localPosition = LeftExpressionPositionDictionary[ExpressionName];
- }
- else if (direction == PlayerDirection.Right)
- {
- UAC.armature.flipX = true;
- ExpressionMeshFilter.transform.eulerAngles = new Vector3(0, 180, 0);
- ExpressionMeshFilter.transform.localPosition = RightExpressionPositionDictionary[ExpressionName];
- playerDirection = PlayerDirection.Right;
- }
- else
- {
- throw new Exception();
- }
- }
- public void SaveDressDatas(bool showNavigate)
- {
- AudioManager.PlayClip(AudioLabel.ClickButton);
- List<CloseItem> closeUnitList = new List<CloseItem>();
- closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Head]]);
- closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Dress]]);
- closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Shoe]]);
- closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[HeadWear]]);
- closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Top]]);
- if (Wing != "Empty")
- {
- closeUnitList.Add(PlayerManager.CloseItemDictionary[PlayerManager.CloseIDDictionary[Wing]]);
- }
- for (int i = 0; i < closeUnitList.Count; i++)
- {
- if (!closeUnitList[i].IsBought)
- {
- if (showNavigate)
- {
- BuyDressNavigate(closeUnitList);
- }
- return;
- }
- }
- PlayerManager.DressDatas[0] = Head;
- PlayerManager.DressDatas[1] = Dress;
- PlayerManager.DressDatas[2] = Shoe;
- PlayerManager.DressDatas[3] = HeadWear;
- PlayerManager.DressDatas[4] = Top;
- PlayerManager.DressDatas[7] = Wing;
- PlayerManager.DressDatas[8] = LeftLongSleeve;
- PlayerManager.DressDatas[9] = LeftShortSleeve;
- PlayerManager.DressDatas[10] = RightLongSleeve;
- PlayerManager.DressDatas[11] = RightShortSleeve;
- Toast.Show(1.5f, Language.GetStr(LanguageLabel.UI__P_SaveSucceed));
- }
- public void ResetDressDatas()
- {
- AudioManager.PlayClip(AudioLabel.ClickButton);
- List<string> dressData = new List<string>(PlayerManager.DressDatas);
- dressData[5] = Eye;
- PlayerManager.BuildPlayer(dressData);
- }
- public List<int> GetCurrentChangableDressIDs()
- {
- List<int> ids = new List<int>();
- ids.Add(PlayerManager.CloseIDDictionary[Head]);
- ids.Add(PlayerManager.CloseIDDictionary[Dress]);
- ids.Add(PlayerManager.CloseIDDictionary[Shoe]);
- ids.Add(PlayerManager.CloseIDDictionary[HeadWear]);
- ids.Add(PlayerManager.CloseIDDictionary[Top]);
- ids.Add(PlayAnimFlag1 ? PlayerManager.CloseIDDictionary[TempClose] : PlayerManager.CloseIDDictionary[Eye]);
- ids.Add(PlayerManager.CloseIDDictionary[Mouse]);
- ids.Add(PlayerManager.CloseIDDictionary[Wing]);
- return ids;
- }
- public static List<string> DressIDToDressName(List<int> ids)
- {
- List<string> names = new List<string>();
- foreach (var id in ids)
- {
- names.Add(PlayerManager.CloseItemDictionary[id].ArmatureName);
- }
- return names;
- }
- public List<string> GetCurrentDressNames()
- {
- List<string> names = new List<string>();
- return names;
- }
- public List<string> GetCurrentChangableDressNames()
- {
- List<string> names = new List<string>();
- names.Add(Head);
- names.Add(Dress);
- names.Add(Shoe);
- names.Add(HeadWear);
- names.Add(Top);
- names.Add(Wing);
- if (PlayAnimFlag1) names.Add(TempClose);
- else names.Add(Eye);
- names.Add(Mouse);
- names.Add(Wing);
- return names;
- }
- public void BuyDressNavigate(List<CloseItem> closeUnitList)
- {
- for (int i = 0; i < closeUnitList.Count; i++)
- {
- if (closeUnitList[i].IsBought)
- {
- closeUnitList.RemoveAt(i--);
- }
- else
- {
- closeUnitList[i].BuyBtn.onClick.Invoke();
- closeUnitList.RemoveAt(i--);
- ResourceManager.Get(CanvasLabel.Pa_Info).GetTweenCG().AddEventOnetime
- (
- EventType.BackwardFinish,
- () =>
- {
- if (closeUnitList.Count == 0)
- {
- SaveDressDatas(false);
- }
- else
- {
- BuyDressNavigate(closeUnitList);
- }
- }
- );
- return;
- }
- }
- }
- public void LeaveDressroom()
- {
- bool allSave = true;
- bool allBought = true;
- List<string> currentDerssData = new List<string>() { Head, Dress, Shoe, HeadWear, Top, Wing };
- if (currentDerssData[0] != PlayerManager.DressDatas[0]) allSave = false;
- if (currentDerssData[1] != PlayerManager.DressDatas[1]) allSave = false;
- if (currentDerssData[2] != PlayerManager.DressDatas[2]) allSave = false;
- if (currentDerssData[3] != PlayerManager.DressDatas[3]) allSave = false;
- if (currentDerssData[4] != PlayerManager.DressDatas[4]) allSave = false;
- if (currentDerssData[5] != PlayerManager.DressDatas[7]) allSave = false;
- for (int i = 0; i < currentDerssData.Count; i++)
- {
- if (!PlayerManager.CloseIDDictionary.ContainsKey(currentDerssData[i]))
- {
- continue;
- }
- int id = PlayerManager.CloseIDDictionary[currentDerssData[i]];
- allBought = allBought && PlayerManager.CloseItemDictionary[id].IsBought;
- //Debug.Log(ManaPlayer.CloseUnitDic[id].Name + " " + ManaPlayer.CloseUnitDic[id].Bought);
- //allSave = allSave && currentDerssData[i] == PlayerManager.DressDatas[i];
- //Debug.Log(currentDerssData[i] + " " + PlayerManager.DressDatas[i]);
- }
- //Debug.Log(allBought);
- //Debug.Log(allSave);
- if (allBought)
- {
- if (allSave)
- {
- ExitDressRoom();
- }
- else
- {
- ResetDressDatas();
- ExitDressRoom();
- }
- }
- else
- {
- Bubble.Show
- (
- null, Language.GetStr(LanguageLabel.UI__P_Return), null, null,
- () =>
- {
- ResetDressDatas();
- ResourceManager.Get(CanvasLabel.K_Bubble).GetTweenGra().AddEventOnetime(EventType.BackwardFinish, () => { ExitDressRoom(); });
- }
- );
- }
- }
- public TweenRoot ExitDressRoom()
- {
- Manager.SceneSwitchFlag = false;
- TweenRoot tweenRoot = ResourceManager.Get(CanvasLabel.I_BlackMask).TweenBacCG();
- tweenRoot.AddEventOnetime
- (
- EventType.BackwardFinish,
- () =>
- {
- transform.SetParent(ResourceManager.Get(GardenLabel.GardenPivot));
- transform.position = PosInGarden;
- //transform.position = ResourceManager.Get(GardenLabel.GardenPlayerPos).position;
- transform.localScale = ResourceManager.Get(GardenLabel.GardenPlayerPos).lossyScale;
- ResourceManager.Get(ResourceLabel.Garden).TweenForSr();
- ResourceManager.Get(DressroomLabel.DressRoom).TweenBacSr();
- ResourceManager.Get(CanvasLabel.C_Main).TweenForCG();
- ResourceManager.Get(CanvasLabel.P_DressRoom).TweenBacCG();
- }
- );
- tweenRoot = ResourceManager.Get(CanvasLabel.P_DressRoom).GetTweenCG();
- tweenRoot.AddEventOnetime
- (
- EventType.BackwardFinish,
- () =>
- {
- SetAllCollider(true);
- InDressRoom = false;
- JumpTimer = 0;
- PlayAnim(IdleAnimationName);
- DeactiveShadow();
- ResourceManager.Get(CanvasLabel.B_SignIn0).TweenForCG();
- ResourceManager.Get(CanvasLabel.I_BlackMask).TweenForCG();
- }
- );
- return ResourceManager.Get(CanvasLabel.I_BlackMask).TweenBacCG();
- }
- public void EnterDressRoom()
- {
- if (Manager.SceneSwitchFlag)
- {
- return;
- }
- ResourceManager.Get(CanvasLabel.B_SignIn0).TweenBacCG();
- InDressRoom = true;
- JumpTime = Mathf.Lerp(0, 10, Random.Range(0.5f, 1f));
- Manager.SceneSwitchFlag = true;
- ResourceManager.Get(CanvasLabel.C_Main).TweenBacCG();
- SetAllCollider(false);
- TweenRoot tweenRoot = ResourceManager.Get(CanvasLabel.I_BlackMask).TweenBacCG();
- tweenRoot.AddEventOnetime
- (
- EventType.BackwardFinish,
- () =>
- {
- GardenManager.RetrieveAllElf();
- IAPManager.RetrieveADChest();
- ActiveShadow();
- transform.SetParent(ResourceManager.Get(DressroomLabel.DressRoom));
- PosInGarden = transform.position;
- transform.position = ResourceManager.Get(DressroomLabel.DressRoomPos).position;
- transform.localScale = ResourceManager.Get(DressroomLabel.DressRoomPos).lossyScale;
- ResourceManager.Get(ResourceLabel.Garden).TweenBacSr();
- ResourceManager.Get(DressroomLabel.DressRoom).TweenForSr();
- ResourceManager.Get(CanvasLabel.P_DressRoom).TweenForCG();
- }
- );
- tweenRoot = ResourceManager.Get(CanvasLabel.P_DressRoom).GetTweenCG();
- tweenRoot.AddEventOnetime
- (
- EventType.ForwardFinish,
- () =>
- {
- ResourceManager.Get(CanvasLabel.I_BlackMask).TweenForCG();
- }
- );
- }
- public void ActiveShadow()
- {
- ChildDic[PlayerLabel.ShadowParent].SetActive(true);
- ChildDic[PlayerLabel.ShadowParent].SetLZ(3);
- }
- public void DeactiveShadow()
- {
- Shadow.GetStreamScale().Pause();
- Shadow.GetStreamScale().InOrigin = true;
- ChildDic[PlayerLabel.ShadowParent].SetActive(false);
- }
- private List<TweenRenderer> fadeAnims = new List<TweenRenderer>();
- public void PlayFadeOutAnim()
- {
- fadeAnims = new List<TweenRenderer>();
- if (fadeAnims.Count == 0)
- {
- Renderer[] renderers = PlayerManager.Player.UAC.transform.GetComponentsInChildren<Renderer>(true);
- foreach (var renderer in renderers)
- {
- if (renderer.sharedMaterial == null)
- {
- continue;
- }
- TweenRenderer fadeAnim = AnimManager.CreateTweenRenderer(renderer, 0, 1, 0.25f, true, true, Curve.EaseOutQuad);
- fadeAnim.UseSharedMaterial = true;
- fadeAnims.Add(fadeAnim);
- }
- }
- foreach (var fadeAnim in fadeAnims)
- {
- fadeAnim.StartBackward();
- }
- }
- public void PlayFadeInAnim()
- {
- foreach (var fadeAnim in fadeAnims)
- {
- if (fadeAnim.Target == null)
- {
- continue;
- }
- fadeAnim.StartForward();
- }
- }
- private List<UnityUGUIDisplay> uguiDisplays;
- public void DisplayInUI(float scale, bool adjustScale)
- {
- uguiDisplays = new List<UnityUGUIDisplay>();
- if (adjustScale)
- {
- scale *= ResourceManager.Get<Canvas>(CanvasLabel.Canvas).scaleFactor;
- }
- UGUIScale = scale;
- MeshFilter[] meshFilters = UAC.GetComponentsInChildren<MeshFilter>(true);
- MeshRenderer[] meshRenderers = UAC.GetComponentsInChildren<MeshRenderer>(true);
- for (int i = 0; i < meshRenderers.Length; i++)
- {
- MeshFilter meshFilter = meshFilters[i];
- MeshRenderer meshRenderer = meshRenderers[i];
- UnityUGUIDisplay unityUGUIDisplay = meshRenderer.GetComponent<UnityUGUIDisplay>();
- if (unityUGUIDisplay == null) unityUGUIDisplay = meshRenderer.AddComponent<UnityUGUIDisplay>();
- unityUGUIDisplay.Enable(UAC.transform, meshRenderer.transform, meshFilter, meshRenderer);
- unityUGUIDisplay.raycastTarget = false;
- uguiDisplays.Add(unityUGUIDisplay);
- meshRenderer.enabled = false;
- UAC.transform.localScale = new Vector3(scale, scale, 1);
- SetAllCollider(false);
- DeactiveShadow();
- }
- IsDisplayInUGUI = true;
- ResetDepth();
- }
- public void DisplayInScene()
- {
- MeshRenderer[] meshRenderers = UAC.GetComponentsInChildren<MeshRenderer>(true);
- foreach (var meshRenderer in meshRenderers)
- {
- UnityUGUIDisplay unityUGUIDisplay = meshRenderer.GetComponent<UnityUGUIDisplay>();
- if (unityUGUIDisplay == null) continue;
- unityUGUIDisplay.Disable();
- meshRenderer.enabled = true;
- UAC.transform.localScale = Vector3.one;
- SetAllCollider(true);
- ActiveShadow();
- }
- IsDisplayInUGUI = false;
- ResetDepth();
- }
- #region 换装
- public void CorrectPivot()
- {
- List<Transform> children = new List<Transform>();
- while (transform.childCount > 0)
- {
- children.Add(transform.GetChild(0));
- children.Back(0).parent = null;
- }
- Vector3 offset = Pivot.position - transform.position;
- children[0].position += offset;
- children[1].position += offset;
- transform.position += offset;
- foreach (var collider in GetComponents<BoxCollider2D>())
- {
- collider.offset -= new Vector2(offset.x, offset.y);
- }
- for (int i = 0; i < children.Count; i++)
- {
- children[i].parent = transform;
- }
- }
- public UnityArmatureComponent Build()
- {
- if (!PlayerManager.Inited)
- {
- UnityFactory.factory.LoadDragonBonesData(ResourceManager.Load<TextAsset>(ResourceLabel.StandSke, Folder.Config));
- Initializer.DebugText.text = "error : mp0-2";
- UnityFactory.factory.LoadTextureAtlasData(ResourceManager.Load<TextAsset>(ResourceLabel.StandTex0, Folder.Config), ResourceLabel.StandTexture0);
- Initializer.DebugText.text = "error : mp0-3";
- UnityFactory.factory.LoadTextureAtlasData(ResourceManager.Load<TextAsset>(ResourceLabel.StandTex1, Folder.Config), ResourceLabel.StandTexture1);
- PlayerManager.Inited = 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(IdleAnimationName);
- UAC.AddEventListener(EventObject.START, OnAnimStart);
- Eye = "眼睛1";
- Top = "上衣1";
- Shoe = "鞋子1";
- Head = "脑壳1";
- Wing = "Empty";
- Dress = "裙子1";
- Mouse = "嘴巴1";
- HeadWear = "头饰品1";
- NeckSlot = UAC.armature.GetSlot("脖子");
- LeftHandSlot = UAC.armature.GetSlot("左手");
- RightHandSlot = UAC.armature.GetSlot("右手");
- LeftLegSlot = UAC.armature.GetSlot("左腿");
- RightLegSlot = UAC.armature.GetSlot("右腿");
- LeftLongSleeveUAC = UAC.transform.FindChild("长袖9左 (长袖9左)").GetComponent<UnityArmatureComponent>();
- RightLongSleeveUAC = UAC.transform.FindChild("长袖9右 (长袖9右)").GetComponent<UnityArmatureComponent>();
- LeftShortSleeveSlot = UAC.armature.GetSlot("上衣1袖子左");
- RightShortSleeveSlot = UAC.armature.GetSlot("上衣1袖子右");
- EyeSlot = UAC.armature.GetSlot("眼睛");
- TopSlot = UAC.armature.GetSlot("上衣");
- HeadSlot = UAC.armature.GetSlot("脑壳");
- WingSlot = 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);
- ChangeClose(BodyPart.LeftLongSleeve, "Empty", false);
- ChangeClose(BodyPart.RightLongSleeve, "Empty", false);
- ChangeClose(BodyPart.LeftShortSleeve, "短袖2左", false);
- ChangeClose(BodyPart.RightShortSleeve, "短袖2右", false);
- CorrectPivot();
- Material = UAC.GetComponentInChildren<MeshRenderer>().sharedMaterial;
- Shadow.GetComponent<MeshRenderer>().sharedMaterial = Material;
- ExpressionMeshFilter = ChildDic[PlayerLabel.ExpressionMeshFilter].GetComponent<MeshFilter>();
- ExpressionMeshFilter.GetComponent<MeshRenderer>().sharedMaterial = Material;
- return UAC;
- }
- public UnityArmatureComponent BuildPink()
- {
- Build();
- ChangeClose(BodyPart.Eye, "眼睛3", false);
- ChangeClose(BodyPart.Top, "上衣3", false);
- ChangeClose(BodyPart.Shoe, "鞋子3", false);
- ChangeClose(BodyPart.Head, "脑壳3", false);
- ChangeClose(BodyPart.Wing, "Empty", false);
- ChangeClose(BodyPart.Dress, "裙子3", false);
- ChangeClose(BodyPart.Mouse, "嘴巴3", false);
- ChangeClose(BodyPart.Headwear, "头饰品3", false);
- ResetDepth();
- return UAC;
- }
- public UnityArmatureComponent BuildBlond()
- {
- Build();
- ChangeClose(BodyPart.Wing, "Empty", false);
- ResetDepth();
- return UAC;
- }
- public UnityArmatureComponent BuildBrown()
- {
- Build();
- ChangeClose(BodyPart.Eye, "眼睛2", false);
- ChangeClose(BodyPart.Top, "上衣2", false);
- ChangeClose(BodyPart.Shoe, "鞋子2", false);
- ChangeClose(BodyPart.Head, "脑壳2", false);
- ChangeClose(BodyPart.Wing, "Empty", false);
- ChangeClose(BodyPart.Dress, "裙子2", false);
- ChangeClose(BodyPart.Mouse, "嘴巴2", false);
- ChangeClose(BodyPart.Headwear, "头饰品2", false);
- ResetDepth();
- return UAC;
- }
- public void ResetDepth()
- {
- UAC.transform.SetLZ(0.7f);
- SetSlotLocalZ(WingSlot, 0.00003f);
- SetSlotLocalZ(EyeSlot, -0.00001f);
- SetSlotLocalZ(TopSlot, -0.00003f);
- SetSlotLocalZ(MouseSlot, -0.00001f);
- SetSlotLocalZ(HeadWearSlot, -0.00001f);
- SetSlotLocalZ(LeftShoeSlot, -0.00001f);
- SetSlotLocalZ(RightShoeSlot, -0.00001f);
- SetSlotLocalZ(LeftLegSlot, 0);
- SetSlotLocalZ(RightLegSlot, 0);
- SetSlotLocalZ(NeckSlot, 0.00001f);
- SetSlotLocalZ(LeftHandSlot, -0.00001f);
- SetSlotLocalZ(RightHandSlot, -0.00001f);
- SetSlotLocalZ(LeftShortSleeveSlot, -0.000015f);
- SetSlotLocalZ(RightShortSleeveSlot, -0.000015f);
- SetSlotLocalZ(HeadSlot, 0);
- if (HeadSlot.UnityTransform != null && HeadSlot.UnityTransform.childCount > 1)
- {
- HeadSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
- HeadSlot.UnityTransform.GetChild(1).SetLZ(0f);
- }
- SetSlotLocalZ(DressSlot, -0.00002f);
- if (DressSlot.UnityTransform != null && DressSlot.UnityTransform.childCount > 1)
- {
- DressSlot.UnityTransform.GetChild(0).SetLZ(0.00002f);
- DressSlot.UnityTransform.GetChild(1).SetLZ(0f);
- }
- LeftLongSleeveUAC.transform.SetLZ(-0.000015f);
- RightLongSleeveUAC.transform.SetLZ(-0.000015f);
- if (IsDisplayInUGUI)
- {
- uguiDisplays.MySort((display1, display0) =>
- display1.transform.position.z < display0.transform.position.z);
- //Debug.Log("resetDepth");
- foreach (var display in uguiDisplays)
- {
- if (display.dbGraphic == null)
- {
- continue;
- }
- display.dbGraphic.transform.SetParent(transform.parent);
- }
- foreach (var display in uguiDisplays)
- {
- //Debug.Log(display.dbGraphic.copyTrans.name);
- if (display.dbGraphic == null)
- {
- continue;
- }
- display.dbGraphic.transform.SetParent(UAC.transform);
- display.dbGraphic.transform.SetAsLastSibling();
- //Debug.Log(display.dbGraphic.copyTrans.name, display.dbGraphic.copyTrans);
- }
- //SetSlotAsFirstChild(TopSlot);
- //SetSlotAsFirstChild(DressSlot);
- //SetSlotAsFirstChild(LeftShortSleeveSlot);
- //SetSlotAsFirstChild(RightShortSleeveSlot);
- //LeftLongSleeveUAC.transform.SetAsFirstSibling();
- //RightLongSleeveUAC.transform.SetAsFirstSibling();
- //SetSlotAsFirstChild(EyeSlot);
- //SetSlotAsFirstChild(MouseSlot);
- //SetSlotAsFirstChild(LeftShoeSlot);
- //SetSlotAsFirstChild(RightShoeSlot);
- //SetSlotAsFirstChild(HeadWearSlot);
- //SetSlotAsFirstChild(LeftHandSlot);
- //SetSlotAsFirstChild(RightHandSlot);
- //SetSlotAsFirstChild(HeadSlot);
- //SetSlotAsFirstChild(LeftLegSlot);
- //SetSlotAsFirstChild(RightLegSlot);
- //SetSlotAsFirstChild(NeckSlot);
- //SetSlotAsFirstChild(WingSlot);
- }
- }
- private void SetSlotLocalZ(DragonBones.Slot slot, float z)
- {
- if (slot.UnityTransform == null)
- {
- UAC.transform.FindChild(slot.name).SetLZ(z);
- }
- else
- {
- slot.UnityTransform.SetLZ(z);
- }
- }
- private void SetSlotAsFirstChild(DragonBones.Slot slot)
- {
- if (slot.UnityTransform == null)
- {
- UAC.transform.FindChild(slot.name).SetAsFirstSibling();
- }
- else
- {
- slot.UnityTransform.SetAsFirstSibling();
- }
- }
- public void ChangeClose(BodyPart bodyPart, string armatureName, bool setDepth = true)
- {
- // Debug.Log (bodyPart + " " + armatureName);
- 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);
- Shoe = armatureName;
- int id = PlayerManager.CloseIDDictionary[armatureName];
- CloseItem closeItem = PlayerManager.CloseItemDictionary[id];
- Texture2D leftTexture = PlayerManager.GetCloseTexture(closeItem.Sprites[0].name);
- Texture2D rightTexture;
- leftShoeDisplayName = closeItem.Sprites[0].name;
- if (closeItem.Sprites.Length == 1)
- {
- rightTexture = leftTexture;
- }
- else
- {
- rightTexture = PlayerManager.GetCloseTexture(closeItem.Sprites[1].name);
- }
- UnityFactory.factory.ReplaceSlotDisplay("stand_ske", "Armature", "鞋子左", "鞋子15-2_1", LeftShoeSlot,
- leftTexture, new Material(Shader.Find("Sprites/Default")));
- UnityFactory.factory.ReplaceSlotDisplay("stand_ske", "Armature", "鞋子右", "鞋子15-1_2", RightShoeSlot,
- rightTexture, new Material(Shader.Find("Sprites/Default")));
- leftShoeDisplayName = closeItem.Sprites[0].name;
- if (closeItem.Sprites.Length == 1)
- {
- rightShoeDisplayName = closeItem.Sprites[0].name;
- }
- else
- {
- rightShoeDisplayName = closeItem.Sprites[1].name;
- }
- }
- else if (bodyPart == BodyPart.Head)
- {
- Head = armatureName;
- slotList.Add(HeadSlot);
- }
- else if (bodyPart == BodyPart.Wing)
- {
- if (Wing == armatureName)
- {
- return;
- }
- else
- {
- Wing = armatureName;
- slotList.Add(WingSlot);
- }
- }
- 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 if (bodyPart == BodyPart.Leg)
- {
- slotList.Add(LeftLegSlot);
- slotList.Add(RightLegSlot);
- }
- else if (bodyPart == BodyPart.LeftHand)
- {
- slotList.Add(LeftHandSlot);
- }
- else if (bodyPart == BodyPart.RightHand)
- {
- slotList.Add(RightHandSlot);
- }
- else if (bodyPart == BodyPart.Neck)
- {
- slotList.Add(NeckSlot);
- }
- else if (bodyPart == BodyPart.LeftLongSleeve)
- {
- LeftLongSleeve = armatureName;
- ChangeClose(LeftLongSleeveUAC, armatureName);
- return;
- }
- else if (bodyPart == BodyPart.LeftShortSleeve)
- {
- LeftShortSleeve = armatureName;
-
- slotList.Add(LeftShortSleeveSlot);
- }
- else if (bodyPart == BodyPart.RightLongSleeve)
- {
- RightLongSleeve = armatureName;
- ChangeClose(RightLongSleeveUAC, armatureName);
- return;
- }
- else if (bodyPart == BodyPart.RightShortSleeve)
- {
- RightShortSleeve = armatureName;
- slotList.Add(RightShortSleeveSlot);
- }
- else
- {
- throw new Exception();
- }
- ChangeClose(slotList, armatureName, setDepth);
- if (bodyPart == BodyPart.Wing)
- {
- TweenRoot tweenRoot = transform.FindChild("Armature/" + Wing).GetChild(0).CreateTweenScale(new Vector3(1, 1, 1), new Vector3(0.6f, 1, 1), 0.75f, true, true, Curve.Linear);
- tweenRoot.PingPong = true;
- tweenRoot.StartForward();
- }
- }
- 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, null, null, null, true);
- slotList[i].UnityTransform = slotList[i].childArmature.UnityTransform.parent;
- }
- if (setDepth)
- {
- DelayCall.Call
- (
- 1,
- () =>
- {
- ResetDepth();
- if (IsDisplayInUGUI) DisplayInUI(UGUIScale, false);
- }
- );
- }
- }
- public void ChangeClose(UnityArmatureComponent uac, string armatureName, bool setDepth = true)
- {
- if (armatureName == "Empty")
- {
- uac.SetActive(false);
- }
- else
- {
- uac.SetActive(true);
- }
- if (setDepth)
- {
- DelayCall.Call
- (
- 1,
- () =>
- {
- ResetDepth();
- if (IsDisplayInUGUI) DisplayInUI(UGUIScale, false);
- }
- );
- }
- }
- #endregion
- }
|