123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707 |
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Serialization;
- using UnityEngine.EventSystems;
- using System;
- using System.Xml;
- using System.Collections;
- using System.Collections.Generic;
- using Random = UnityEngine.Random;
- public enum OpType
- {
- Rip,
- Null,
- Water,
- Fertilize,
- }
- public class FlowerLabel
- {
- public static string GoldBk = "GoldBk";
- public static string GoldIcon = "GoldIcon";
- public static string FlashLight = "FlashLight";
- public static string FlowerIcon = "FlowerIcon";
- public static string OperateBk = "OperateBk";
- public static string OperateIcon = "OperateIcon";
- public static string OperateOutline1 = "OperateOutline1";
- public static string NewFlowerEffect = "NewFlowerEffect";
- public static string FlowerShadow = "FlowerShadow";
- public static string ScorePosTra = "ScorePosTra";
- public static string MiniGame = "MiniGame";
- public static string Flash = "Flash";
- public static string ParticleSystem = "Particle System";
- public static string GoldPosTra = "GoldPosTra";
- public static string GoldBKPosLeft = "GoldBKPosLeft";
- }
- public class FlowerInfo
- {
- #region Config
- public int Amount
- {
- get { return amount; }
- set
- {
- amount = value;
- AmountLab.SetActive(true);
- AmountLab.text = AmountTextPrefix + amount;
- }
- }
- public int amount;
- public int RemainAmount
- {
- get { return Amount - PlantAmt; }
- }
- public int PlantAmt;
- public bool Plant
- {
- get { return PlantAmt > 0; }
- }
- public bool Unlock
- {
- get { return Unlock_; }
- set
- {
- Unlock_ = value;
- if (Unlock_)
- {
- Image.material = null;
- if (Special)
- {
- if (GardenManager.MyFlowerSpec == 0)
- {
- ResourceManager.Get(ObjectLabel.G_Regular).TweenForVec();
- ResourceManager.SetActive(ObjectLabel.G_Special, true);
- }
- GardenManager.MyFlowerSpec++;
- }
- else
- {
- GardenManager.MyFlowerRegu++;
- }
- Amount = 1;
- Manager.SkillPlus += SkillPlus;
- }
- }
- }
- private float SkillPlus = 0.1f;
- public static string IDPrefix = "Flower";
- public static string AmountTextPrefix = "x";
- public string FullID
- {
- get
- {
- return IDPrefix + ID_;
- }
- }
- public string Name
- {
- get
- {
- return Language.GetStr(LabelUtility.CombineLanguageLabel(LanguageLabel.FlowerName, FullID));
- }
- }
- public string Description
- {
- get { return null; }
- }
- public Sprite Icon
- {
- get { return ResourceManager.LoadSprite(Icon_, Folder.Atlas2); }
- }
- public int ID_;
- public bool Unlock_;
- public string Icon_;
- public bool Special;
- public int UnlockAmt;
- public float FlowerCoinBuff;
- public Current UnlockCur;
- public Text Text;
- public Text AmountLab;
- public Image Image;
- public Button Button;
- public UIPartical UIPartical;
- public Transform FlowerItem;
- public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
- #endregion
- public FlowerInfo(XmlAttributeCollection attribute)
- {
- FlowerItem = ResourceManager.Get(ResourceLabel.FlowerItem, Folder.UI, false, ResourceManager.Get(ObjectLabel.G_RegularGrid), false, ObjType.FlowerItem);
- FlowerItem.AddComponent<FlowerItem>();
- Auxiliary.CompileDic(FlowerItem, ChildDic);
- Text = ChildDic[FlowerItemLabel.Lab].GetComponent<Text>();
- Image = ChildDic[FlowerItemLabel.Icon].GetComponent<Image>();
- Button = ChildDic[FlowerItemLabel.FlowerItem].GetComponent<Button>();
- UIPartical = ChildDic[FlowerItemLabel.UIParticleSystem].GetComponent<UIPartical>();
- AmountLab = ChildDic[FlowerItemLabel.AmtLab].GetComponent<Text>();
- ID_ = int.Parse(attribute[0].Value);
- Icon_ = attribute[5].Value;
- UnlockCur = Auxiliary.CurrentParse(attribute[3].Value);
- UnlockAmt = Auxiliary.StringToInt(attribute[4].Value, 0);
- FlowerCoinBuff = Auxiliary.StringToFloat(attribute[7].Value, 1);
- Image.sprite = Icon;
- Image.Resize(true, 0.25f, 0.25f);
- Button.onClick.AddListener
- (
- () =>
- {
- if (Plant)
- {
- AudioManager.PlayClip(AudioLabel.ClickButton);
- GardenManager.ShowRetrieveCard(this);
- }
- else if (Unlock)
- {
- GardenManager.ShowPlantCard(this);
- }
- else
- {
- GardenManager.ShowUnlockCard(this);
- }
- }
- );
- }
- public void Add()
- {
- if (Unlock)
- Amount++;
- else
- Unlock = true;
- }
- }
- public class Flower : Regist, IPointerClickHandler
- {
- #region Config
- #region MiniGame
- public OpType OpType
- {
- get { return OpType_; }
- set
- {
- OpType_ = value;
- if (OpType_ == OpType.Rip)
- {
- OperateIcon.sprite = RipSprite;
- }
- else if (OpType_ == OpType.Water)
- {
- OperateIcon.sprite = WaterSprite;
- }
- else if (OpType_ == OpType.Fertilize)
- {
- OperateIcon.sprite = FertilizeSprite;
- }
- }
- }
- public OpType OpType_;
- public SpriteRenderer FlowerIcon;
- public SpriteRenderer OperateBk;
- public SpriteRenderer OperateIcon;
- public SpriteRenderer OperateOutline;
- #endregion
- public bool Award
- {
- get { return Award_; }
- set
- {
- Award_ = value;
- if (Award_)
- {
- ShowAward();
- }
- else
- {
- GetAward();
- }
- }
- }
- public Sprite RipSprite
- {
- get
- {
- return ResourceManager.LoadSprite(ResourceLabel.Rip, Folder.UI);
- }
- }
- public Sprite WaterSprite
- {
- get
- {
- return ResourceManager.LoadSprite(ResourceLabel.Water, Folder.UI);
- }
- }
- public Sprite FertilizeSprite
- {
- get
- {
- return ResourceManager.LoadSprite(ResourceLabel.Fertilize, Folder.UI);
- }
- }
- public FlowerInfo FlowerInfo
- {
- get { return FlowerInfo_; }
- set
- {
- FlowerInfo_ = value;
- ID = FlowerInfo.ID_;
- FlowerIcon.sprite = FlowerInfo.Icon;
- }
- }
- public SpriteRenderer ShadowSr;
- public bool Award_;
- private FlowerInfo FlowerInfo_;
- public int ID;
- public Slot Slot;
- public Animator FlashLightAC;
- public Transform GoldBk;
- public Transform GoldIcon;
- public MaterialUnit NewFlowerEffectMatUnit;
- protected ParticleSystem NewFlowerEffect;
- public List<Transform> ElfList = new List<Transform>();
- public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
- public static string FlowerCoinFml;
- #endregion
- public override bool InitAtOnce()
- {
- if (base.InitAtOnce())
- {
- return true;
- }
- enabled = true;
- Auxiliary.CompileDic(transform, ChildDic);
- GoldBk = ChildDic[FlowerLabel.GoldBk];
- GoldIcon = ChildDic[FlowerLabel.GoldIcon];
- FlashLightAC = ChildDic[FlowerLabel.FlashLight].GetComponent<Animator>();
- FlowerIcon = ChildDic[FlowerLabel.FlowerIcon].GetComponent<SpriteRenderer>();
- OperateBk = ChildDic[FlowerLabel.OperateBk].GetComponent<SpriteRenderer>();
- OperateIcon = ChildDic[FlowerLabel.OperateIcon].GetComponent<SpriteRenderer>();
- OperateOutline = ChildDic[FlowerLabel.OperateOutline1].GetComponent<SpriteRenderer>();
- NewFlowerEffect = ChildDic[FlowerLabel.NewFlowerEffect].GetComponent<ParticleSystem>();
- ShadowSr = ChildDic[FlowerLabel.FlowerShadow].GetComponent<SpriteRenderer>();
- GoldBk.CreateTweenSr(0, 1, 1f, false, true, Curve.EaseOutQuad);
- GoldIcon.CreateTweenSr(0, 1, 1f, false, true, Curve.EaseOutQuad);
- #region 新花粒子特效
- Renderer renderer = NewFlowerEffect.GetComponent<Renderer>();
- Material material = new Material(renderer.material);
- renderer.material = material;
- NewFlowerEffectMatUnit = new MaterialUnit(material, NewFlowerEffect.transform, new List<string>() { "_Alpha" });
- NewFlowerEffectMatUnit.CreateTweenMatFloat(0, 1, 0.25f, false, true, Curve.EaseOutQuad);
- #endregion
- TweenRoot tween = OperateBk.CreateTweenSr(new Color(1, 1, 1), new Color(1, 0.5f, 0.5f), 0.2f, true, true, Curve.EaseOutQuad, false, true);
- tween.OnForwardFinish += () =>
- {
- OperateBk.TweenBacSr();
- };
- tween = OperateBk.CreateTweenScale(OperateBk.transform.localScale + new Vector3(0.1f, 0.1f, 0.1f), 0.25f, false, true, Curve.EaseOutQuad);
- tween.OnBackwardFinish += () =>
- {
- if (OpType != OpType.Null)
- {
- OperateBk.SetActive(true);
- }
- };
- return false;
- }
- #region MiniGame
- public void GameOver()
- {
- OpType = OpType.Null;
- ChildDic[FlowerLabel.MiniGame].SetActive(false);
- OperateBk.TweenBacScale();
- }
- public void GameBegin()
- {
- ChildDic[FlowerLabel.MiniGame].SetActive(true);
- OperateBk.SetActive(false);
- }
- public void SetFirstOp()
- {
- OperateBk.TweenForScale();
- OperateIcon.SetAlpha(1);
- OperateOutline.SetAlpha(1);
- OperateIcon.SetActive(true);
- OperateOutline.SetActive(true);
- }
- public void SetThirdOp()
- {
- OperateIcon.SetAlpha(0.5f);
- OperateOutline.SetAlpha(0.5f);
- OperateIcon.SetActive(true);
- OperateOutline.SetActive(false);
- }
- public void SetSecondOp()
- {
- OperateIcon.SetAlpha(1);
- OperateOutline.SetAlpha(1);
- OperateIcon.SetActive(true);
- OperateOutline.SetActive(false);
- }
- public void CreateOp(int sequence)
- {
- float random = Random.Range(0f, 1f);
- OperateBk.SetActive(true);
- if (random <= 0.3333333f)
- {
- OpType = OpType.Rip;
- }
- else if (random <= 0.6666666f)
- {
- OpType = OpType.Water;
- }
- else
- {
- OpType = OpType.Fertilize;
- }
- if (sequence == 0)
- {
- SetFirstOp();
- }
- else if (sequence == 1)
- {
- SetSecondOp();
- }
- else
- {
- SetThirdOp();
- }
- }
- public void CreateOp(int sequence, OpType opType)
- {
- OpType = opType;
- OperateBk.SetActive(true);
- if (sequence == 0)
- {
- SetFirstOp();
- }
- else if (sequence == 1)
- {
- SetSecondOp();
- }
- else
- {
- SetThirdOp();
- }
- }
- private int PunchScore = 15;
- public bool Operate(OpType opType)
- {
- if (opType == OpType.Rip)
- {
- ResourceManager.Get(ObjectLabel.D_Rip2).TweenForScale();
- }
- else if (opType == OpType.Water)
- {
- ResourceManager.Get(ObjectLabel.D_Water2).TweenForScale();
- }
- else if (opType == OpType.Fertilize)
- {
- ResourceManager.Get(ObjectLabel.D_Fertilize2).TweenForScale();
- }
- if (opType != OpType)
- {
- TweenRoot tween = FlowerIcon.CreateTweenSr(new Color(1, 1, 1), new Color(1, 0.5f, 0.5f), 0.2f, true, true, Curve.EaseOutQuad, false, true);
- tween.OnForwardFinish += () =>
- {
- FlowerIcon.TweenBacSr();
- };
- OperateBk.TweenForSr();
- FlowerIcon.TweenForSr();
- OperateIcon.Shake(0.5f, 3, new Vector3(0.2f, 0, 0), Curve.EaseOutQuad);
- AudioManager.PlayClip(AudioLabel.Error);
- return false;
- }
- else
- {
- ResourceManager.GetHudText($"+{PunchScore}", Color.white, 90, ChildDic[FlowerLabel.ScorePosTra], ResourceManager.Get(ObjectLabel.D_HudParent), true);
- MiniGameManager.Score += PunchScore;
- PlayFlashLight();
- OpType = OpType.Null;
- OperateBk.TweenBacScale();
- OperateBk.SetActive(false);
- OperateIcon.SetActive(false);
- OperateOutline.SetActive(false);
- AudioManager.PlayClip(AudioLabel.ClickButton);
- return true;
- }
- }
- #endregion
- public void GetElf(ElfType elfType, float xMin = -0.75f, float xMax = 0.75f, float yMin = 0, float yMax = 0.75f)
- {
- ElfList.Add(ResourceManager.GetElf(this, new Vector4(xMin, xMax, yMin, yMax), elfType));
- }
- public void Retrieve()
- {
- ChildDic[FlowerLabel.Flash].SetActive(false);
- ChildDic[FlowerLabel.ParticleSystem].SetActive(false);
-
- FlowerInfo.ChildDic[FlowerItemLabel.UIFlash].SetActive(false);
- FlowerInfo.ChildDic[FlowerItemLabel.UIParticleSystem].SetActive(false);
- ShadowSr.SetAlpha(1);
- StopNewFlowerEffec();
- ResourceManager.Save(this);
- RetrieveElf();
- Award_ = false;
- ResetAward();
- }
- public void RetrieveElf()
- {
- for (int i = 0; i < ElfList.Count; i++)
- {
- ResourceManager.Save(ElfList[i]);
- }
- ElfList = new List<Transform>();
- }
- public void PlayFlashLight()
- {
- FlashLightAC.SetTrigger("Play");
- }
- public void PlayNewFlowerEffec()
- {
- NewFlowerEffectMatUnit.TweenForMatFloat();
- }
- public void StopNewFlowerEffec()
- {
- NewFlowerEffectMatUnit.TweenBacMatFloat();
- }
- public void SetShadow()
- {
- //ShadowSr.transform.SetLX((FlowerIcon.sprite.pivot.x - 0.5f)*FlowerIcon.sprite.rect.width/100);
- //ShadowSr.transform.SetLY((FlowerIcon.sprite.pivot.y - 0.5f)*FlowerIcon.sprite.rect.height/100);
- }
- public void GetAward()
- {
- AudioManager.PlayClip(AudioLabel.GetCurrent);
- PlayFlashLight();
- int coin;
- if (VisitManager.InVisit)
- {
- int awardMin = Mathf.CeilToInt((float)Auxiliary.FmlParse(VisitManager.AwardMinFml, "l", Manager.Level.ToString()));
- int awardMax = Mathf.CeilToInt((float)Auxiliary.FmlParse(VisitManager.AwardMaxFml, "l", Manager.Level.ToString()));
- coin = Mathf.CeilToInt(Mathf.Lerp(awardMin, awardMax, Random.Range(0f, 1f)));
- }
- else
- {
- coin = Mathf.CeilToInt((float)Auxiliary.FmlParse(FlowerCoinFml, "l", Mathf.Clamp(Manager.Level, 1, Mathf.Infinity).ToString()) * FlowerInfo.FlowerCoinBuff);
- Manager.FlowerCoin++;
- }
- Transform flyGold = ResourceManager.Get(ResourceLabel.FlyGold, Folder.Scene, false, null, GoldIcon.position, ObjType.FlyGold);
- TweenRoot tweenRoot = flyGold.GetTweenSr();
- if (tweenRoot == null)
- {
- tweenRoot = flyGold.CreateTweenSr(1, 0, 0.25f, true, false, Curve.EaseOutQuad);
- tweenRoot.AddEventOnetime(EventType.ForwardFinish, () => { ResourceManager.Save(flyGold); });
- }
- else
- {
- tweenRoot.InOrigin = true;
- }
-
- Move2D move2D = new Move2D(flyGold);
- move2D.Restrain2D = Restrain2D.Y;
- Vector3 destination = Camera.main.ScreenToWorldPoint(ResourceManager.Get(ObjectLabel.C_Coin).position);
- move2D.StartMove(destination, 0.5f, false, Curve.EaseOutQuad);
- move2D = new Move2D(flyGold);
- move2D.Restrain2D = Restrain2D.X;
- destination = Camera.main.ScreenToWorldPoint(ResourceManager.Get(ObjectLabel.C_Coin).position);
- move2D.StartMove(destination, 0.5f, false, Curve.Linear);
- DelayCall.Call
- (
- 0.4f,
- () =>
- {
- tweenRoot.StartForward();
- Manager.AddCoin(coin, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.ClickFlower);
- }
- );
- ResourceManager.GetHudText($"{TransferLabel.CoinSprite}+{coin}", Color.white, 90, ChildDic[FlowerLabel.GoldPosTra], ResourceManager.Get(ObjectLabel.A_HudParent), true);
- ResetAward();
- }
- public void ResetAward()
- {
- GoldBk.SetActive(false);
- GoldBk.GetTweenSr().Pause();
- GoldIcon.GetTweenSr().Pause();
- GoldBk.GetTweenSr().InOrigin = true;
- GoldIcon.GetTweenSr().InOrigin = true;
- }
- public void ShowAward()
- {
- GoldBk.SetX(ChildDic[FlowerLabel.GoldBKPosLeft].position.x);
- GoldBk.GetComponent<SpriteRenderer>().flipX = true;
- GoldBk.SetY(transform.position.y + 2.5f);
- GoldBk.TweenReForSr();
- GoldIcon.TweenReForSr();
- GoldBk.MoveOffset2D
- (
- new Vector3(0, 0.5f, 0),
- 1f,
- true,
- Curve.EaseOutQuad
- );
- }
- public void OnPointerClick(PointerEventData eventData)
- {
- if (eventData.rawPointerPress.transform == transform)
- {
- if (VisitManager.InVisit)
- {
- return;
- }
- ResourceManager.Get(ObjectLabel.G_Flower).TweenForCG();
- GardenManager.ShowRetrieveCard(FlowerInfo, Slot);
- }
- else if (eventData.rawPointerPress.transform == GoldBk)
- {
- Award = false;
- }
- }
- public void OnDisable()
- {
- FlashLightAC.transform.GetChild(0).SetActive(false);
- FlashLightAC.transform.GetChild(1).SetActive(false);
- }
- }
|