123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- 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,
- Water,
- Fertilize,
- }
- public class FlowerInfo
- {
- #region 变量
- public bool Plant
- {
- get { return _Plant; }
- set
- {
- _Plant = value;
- if (_Plant)
- {
- Text.text = "已放置";
- }
- else
- {
- Text.text = "";
- }
- }
- }
- public bool Unlock
- {
- get { return _Unlock; }
- set
- {
- _Unlock = value;
- if (_Unlock)
- {
- Text.text = "";
- Image.material = null;
- Button.interactable = true;
- if (Special)
- {
- if (ManaGarden.MyFlowerSpec == 0)
- {
- ManaReso.Get("G_Regular").TweenForVec();
- ManaReso.SetActive("G_Special", true);
- }
- ManaGarden.MyFlowerSpec++;
- }
- else
- {
- ManaGarden.MyFlowerRegu++;
- }
- ManaData.SkillPlus += 0.1f;
- ManaDebug.Log(string.Format("获得<color=red>{0}</color> 收入<color=red>+10%</color>", Name));
- }
- }
- }
- public bool _Plant;
- public bool _Unlock;
- public int Id;
- public bool Special;
- public string Name;
- public string Description;
- public Slot Slot;
- public Text Text;
- public Sprite Sprite;
- public Image Image;
- public Button Button;
- #endregion
- public FlowerInfo(XmlAttributeCollection attributes)
- {
- Transform tra = ManaReso.Get("FlowerItemG", Folder.PrefabUI, false, ManaReso.Get("G_RegularGrid"), false);
- Dictionary<string, Transform> dic = new Dictionary<string, Transform>();
- Auxiliary.CompileDic(tra, dic);
- Text = dic["Lab"].GetComponent<Text>();
- Image = dic["Icon"].GetComponent<Image>();
- Button = dic["FlowerItemG"].GetComponent<Button>();
- Id = int.Parse(attributes[0].Value);
- Sprite = ManaReso.Load<Sprite>(attributes[3].Value, Folder.Garden);
-
- Name = Language.GetStr("FlowerName", "Flower" + Id);
- Description = attributes[2].Value;
- Image.sprite = Sprite;
- Vector2 newSize = Sprite.rect.size;
- newSize.x *= 0.2f;
- newSize.y *= 0.2f;
- Image.rectTransform.sizeDelta = newSize;
- Button.onClick.AddListener
- (
- () =>
- {
- ManaGarden.PlantFlower(this);
- }
- );
- }
- }
- public class Flower : ObjRoot, IPointerClickHandler
- {
- #region 变量
- #region MiniGame
- public int Phase
- {
- get { return _Phase; }
- set
- {
- _Phase = value;
- if (Phase == 1)
- {
- Phase = 0;
- OperateIcon.SetActive(false);
- ManaReso.GetHudText("得分+15", Color.red, 18, ChildDic["ScoreTra"], ManaReso.Get("D_Status"), true);
- ManaMiniGame.Score += 15;
- }
- }
- }
- private int _Phase;
- private OpType OpType;
- private SpriteRenderer FlowerSr;
- private SpriteRenderer OperateIcon;
- #endregion
- public FlowerInfo FlowerInfo
- {
- get { return _FlowerInfo; }
- set
- {
- _FlowerInfo = value;
- FlowerSr.sprite = FlowerInfo.Sprite;
- }
- }
- private FlowerInfo _FlowerInfo;
- public int Id;
- public Slot Slot;
- public Vector3 LocalPos;
- private Dictionary<string, Transform> ChildDic;
- #endregion
-
- private void Awake()
- {
- ChildDic = new Dictionary<string, Transform>();
-
- Auxiliary.CompileDic(transform, ChildDic);
- FlowerSr = ChildDic["FlowerIcon"].GetComponent<SpriteRenderer>();
- OperateIcon = ChildDic["OperateIcon"].GetComponent<SpriteRenderer>();
- }
- #region MiniGame
-
- public void GameOver()
- {
- ChildDic["MiniGame"].SetActive(false);
- }
- public void GameBegin()
- {
- ChildDic["MiniGame"].SetActive(true);
- OperateIcon.SetActive(false);
- }
- public void SetFirstOp()
- {
- OperateIcon.SetAlpha(1);
- OperateIcon.material.shader = Shader.Find("DashGame/HighLight");
- OperateIcon.SetActive(true);
- }
- public void SetSecondOp()
- {
- OperateIcon.SetAlpha(1);
- OperateIcon.material.shader = Shader.Find("Sprites/Default");
- OperateIcon.SetActive(true);
- }
- public void SetThirdOp()
- {
- OperateIcon.SetAlpha(0.5f);
- OperateIcon.material.shader = Shader.Find("Sprites/Default");
- OperateIcon.SetActive(true);
- }
- public void CreateOp(int sequence)
- {
- float random = Random.Range(0f, 1f);
- if (random <= 0.3333333f)
- {
- OpType = OpType.Rip;
- OperateIcon.sprite = ManaReso.Load<Sprite>("Rip", Folder.SpriteUI);
- }
- else if (random <= 0.6666666f)
- {
- OpType = OpType.Water;
- OperateIcon.sprite = ManaReso.Load<Sprite>("Water", Folder.SpriteUI);
- }
- else
- {
- OpType = OpType.Fertilize;
- OperateIcon.sprite = ManaReso.Load<Sprite>("Fertilize", Folder.SpriteUI);
- }
- if (sequence == 0)
- {
- SetFirstOp();
- }
- else if (sequence == 1)
- {
- SetSecondOp();
- }
- else
- {
- SetThirdOp();
- }
- }
- public bool Operate(OpType opType)
- {
- if (opType != OpType) //错误的操作
- {
- return false;
- }
- else //操作正确 植物升级
- {
- Phase++;
- OperateIcon.SetActive(false);
- return true;
- }
- }
- #endregion
- public void OnPointerClick(PointerEventData eventData)
- {
- ManaReso.Get("G_Flower").TweenForCG();
- ManaGarden.ShowRetrieveCard(FlowerInfo);
- }
- }
|