123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574 |
- 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 FlowerInfo
- {
- #region 变量
- public bool Plant
- {
- get { return Plant_; }
- set
- {
- Plant_ = value;
- if (Plant_)
- {
- Text.SetActive(true);
- ManaLan.Add(Text, new LanStr("Object", "FlowerItemG_Lab"));
- UIPartical.Begin();
- }
- else
- {
- Text.SetActive(false);
- }
- }
- }
- public bool Unlock
- {
- get { return Unlock_; }
- set
- {
- Unlock_ = value;
- if (Unlock_)
- {
- Image.material = null;
- if (Special)
- {
- if (ManaGarden.MyFlowerSpec == 0)
- {
- ManaReso.Get("G_Regular").TweenForVec();
- ManaReso.SetActive("G_Special", true);
- }
- ManaGarden.MyFlowerSpec++;
- }
- else
- {
- ManaGarden.MyFlowerRegu++;
- }
- ManaCenter.SkillPlus += 0.1f;
- }
- }
- }
- public string ID
- {
- get
- {
- return "Flower" + ID_;
- }
- }
- public string Name
- {
- get
- {
- return Language.GetStr("FlowerName", ID);
- }
- }
- public string Description
- {
- get { return Language.GetStr("FlowerDesc", ID); }
- }
- public Sprite Icon
- {
- get { return ManaReso.LoadSprite(Icon_, Folder.Scene); }
- }
- public int ID_;
- public bool Plant_;
- public bool Unlock_;
- public string Icon_;
- public bool Special;
- public Slot Slot;
- public Text Text;
- public Image Image;
- public Button Button;
- public UIPartical UIPartical;
- public Transform FlowerItem;
- #endregion
- public FlowerInfo(XmlAttributeCollection attribute)
- {
- FlowerItem = ManaReso.Get("FlowerItem", Folder.UI, false, ManaReso.Get("G_RegularGrid"), false, ObjType.FlowerItem);
- Dictionary<string, Transform> dic = new Dictionary<string, Transform>();
- Auxiliary.CompileDic(FlowerItem, dic);
- Text = dic["Lab"].GetComponent<Text>();
- Image = dic["Icon"].GetComponent<Image>();
- Button = dic["FlowerItem"].GetComponent<Button>();
- UIPartical = dic["UIParticle System"].GetComponent<UIPartical>();
- ID_ = int.Parse(attribute[0].Value);
- Icon_ = attribute[3].Value;
- Image.sprite = Icon;
- Image.Resize(true, 0.2f, 0.2f);
- Button.onClick.AddListener
- (
- () =>
- {
- if (Unlock)
- {
- ManaGarden.PlantFlower(this);
- }
- else
- {
- Toast.Show(1.5f, Name + " " + Language.GetStr("Common", "Unlock"));
- }
- }
- );
- }
- }
- public class Flower : Regist, IPointerClickHandler
- {
- #region 变量
- #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 ManaReso.LoadSprite("Rip", Folder.UI);
- }
- }
- public Sprite WaterSprite
- {
- get
- {
- return ManaReso.LoadSprite("Water", Folder.UI);
- }
- }
- public Sprite FertilizeSprite
- {
- get
- {
- return ManaReso.LoadSprite("Fertilize", Folder.UI);
- }
- }
- public FlowerInfo FlowerInfo
- {
- get { return FlowerInfo_; }
- set
- {
- FlowerInfo_ = value;
- ID = FlowerInfo.ID_;
- FlowerIcon.sprite = FlowerInfo.Icon;
- }
- }
- public bool Award_;
- private FlowerInfo FlowerInfo_;
- public int ID;
- public Slot Slot;
- public Animator ParticleAC;
- public Transform GoldBk;
- public Transform GoldIcon;
- public List<Transform> ElfList = new List<Transform>();
- public Dictionary<string, Transform> ChildDic = new Dictionary<string, Transform>();
- public static string CoinFml;
- #endregion
- public override bool RegistImmed()
- {
- if (base.RegistImmed())
- {
- return true;
- }
- enabled = true;
- Auxiliary.CompileDic(transform, ChildDic);
- GoldBk = ChildDic["GoldBk"];
- GoldIcon = ChildDic["GoldIcon"];
- ParticleAC = ChildDic["FlashLight"].GetComponent<Animator>();
- FlowerIcon = ChildDic["FlowerIcon"].GetComponent<SpriteRenderer>();
- OperateBk = ChildDic["OperateBk"].GetComponent<SpriteRenderer>();
- OperateIcon = ChildDic["OperateIcon"].GetComponent<SpriteRenderer>();
- OperateOutline = ChildDic["OperateOutline1"].GetComponent<SpriteRenderer>();
- GoldBk.CreateTweenSr(0, 1, 1f, false, true, Curve.EaseOutQuad);
- GoldIcon.CreateTweenSr(0, 1, 1f, false, true, Curve.EaseOutQuad);
- 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();
- };
- 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["MiniGame"].SetActive(false);
- OperateBk.TweenBacScale();
- }
- public void GameBegin()
- {
- ChildDic["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();
- }
- }
- public bool Operate(OpType opType)
- {
- if (opType == OpType.Rip)
- {
- ManaReso.Get("D_Rip2").TweenForScale();
- }
- else if (opType == OpType.Water)
- {
- ManaReso.Get("D_Water2").TweenForScale();
- }
- else if (opType == OpType.Fertilize)
- {
- ManaReso.Get("D_Fertilize2").TweenForScale();
- }
- if (opType != OpType)
- {
- OperateBk.TweenForSr();
- FlowerIcon.TweenForSr();
- OperateIcon.Shake(0.5f, 3, new Vector3(0.2f, 0, 0), Curve.EaseOutQuad);
- ManaAudio.PlayClip(Clip.ErrorClip);
- return false;
- }
- else
- {
- ManaReso.GetHudText("+15", Color.white, 90, ChildDic["ScorePosTra"], ManaReso.Get("D_HudParent"), true);
- ManaMiniGame.Score += 15;
- PlayParticle();
- OpType = OpType.Null;
- OperateBk.TweenBacScale();
- OperateBk.SetActive(false);
- OperateIcon.SetActive(false);
- OperateOutline.SetActive(false);
- ManaAudio.PlayClip(Clip.BtnClip);
- return true;
- }
- }
- #endregion
- public void GetElf(ObjType obj, float xMin = -0.75f, float xMax = 0.75f, float yMin = 0, float yMax = 0.75f)
- {
- ElfList.Add(ManaReso.GetElf(this, new Vector4(xMin, xMax, yMin, yMax), obj));
- }
- public void Retrieve()
- {
- ChildDic["Flash"].SetActive(false);
- ChildDic["Particle System"].SetActive(false);
-
- ManaReso.Save(this);
- for (int i = 0; i < ElfList.Count; i++)
- {
- ManaReso.Save(ElfList[i]);
- }
- ElfList = new List<Transform>();
- Award_ = false;
- ResetAward();
- }
- public void PlayParticle()
- {
- ParticleAC.SetTrigger("Play");
- }
- public void GetAward()
- {
- ManaAudio.PlayClip(Clip.CurrentClip);
- PlayParticle();
- int coin;
- if (ManaVisit.InVisit)
- {
- int awardMin = Mathf.CeilToInt((float) Auxiliary.FmlParse(ManaVisit.AwardMinFml, "l", ManaCenter.Level.ToString()));
- int awardMax = Mathf.CeilToInt((float) Auxiliary.FmlParse(ManaVisit.AwardMaxFml, "l", ManaCenter.Level.ToString()));
- coin = Mathf.CeilToInt(Mathf.Lerp(awardMin, awardMax, Random.Range(0f, 1f)));
- ManaCenter.Coin += coin;
- }
- else
- {
- coin = Mathf.CeilToInt((float)Auxiliary.FmlParse(CoinFml, "l", Mathf.Clamp(ManaCenter.Level, 1, Mathf.Infinity).ToString()));
- ManaCenter.Coin += coin;
- ManaCenter.FlowerCoin++;
- }
- ManaReso.GetHudText("<(金币)>+" + coin, Color.white, 90, ChildDic["GoldPosTra"], ManaReso.Get("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.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 (ManaVisit.InVisit)
- {
- return;
- }
- ManaReso.Get("G_Flower").TweenForCG();
- ManaGarden.ShowFlowerCard(FlowerInfo);
- }
- else if (eventData.rawPointerPress.transform == GoldBk)
- {
- Award = false;
- }
- }
- }
|