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)
{
ManaText.Add(Text, new LanStr("Object", "FlowerItemG_Lab"));
UIPartical.Begin();
}
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("获得{0} 收入+10% ", Name));
}
}
}
public string Name
{
get
{
return Language.GetStr("FlowerName", _Name);
}
set { _Name = value; }
}
public bool _Plant;
public bool _Unlock;
public string _Name;
public int ID;
public bool Special;
public string Description;
public Slot Slot;
public Text Text;
public Sprite Sprite;
public Image Image;
public Button Button;
public UIPartical UIPartical;
#endregion
public FlowerInfo(XmlAttributeCollection attribute)
{
Transform tra = ManaReso.Get("FlowerItemG", Folder.UI, false, ManaReso.Get("G_RegularGrid"), false);
Dictionary dic = new Dictionary();
Auxiliary.CompileDic(tra, dic);
Text = dic["Lab"].GetComponent();
Image = dic["Icon"].GetComponent();
Button = dic["FlowerItemG"].GetComponent();
UIPartical = dic["UIParticle System"].GetComponent();
ID = int.Parse(attribute[0].Value);
Sprite = ManaReso.Load(attribute[3].Value, Folder.Garden);
_Name = "Flower" + ID;
Description = attribute[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;
OperateBk.SetActive(false);
OperateIcon.SetActive(false);
OperateOutline.SetActive(false);
ManaReso.GetHudText("得分+15", Color.white, 25, ChildDic["ScorePosTra"], ManaReso.Get("D_Status"), true);
ManaMiniGame.Score += 15;
}
}
}
private int _Phase;
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 FlowerInfo FlowerInfo
{
get { return _FlowerInfo; }
set
{
_FlowerInfo = value;
FlowerIcon.sprite = FlowerInfo.Sprite;
}
}
public bool _Award;
private FlowerInfo _FlowerInfo;
public int ID;
public Slot Slot;
public Vector3 LocalPos;
public Animator ParticleAC;
public Transform GoldBk;
public Transform GoldIcon;
private Dictionary ChildDic;
#endregion
public void Regist()
{
ChildDic = new Dictionary();
Auxiliary.CompileDic(transform, ChildDic);
GoldBk = ChildDic["GoldBk"];
GoldIcon = ChildDic["GoldIcon"];
ParticleAC = ChildDic["FlashLight"].GetComponent();
FlowerIcon = ChildDic["FlowerIcon"].GetComponent();
OperateBk = ChildDic["OperateBk"].GetComponent();
OperateIcon = ChildDic["OperateIcon"].GetComponent();
OperateOutline = ChildDic["OperateOutline"].GetComponent();
Tween tween = FlowerIcon.CreateTweenSr(new Color(1, 1, 1), new Color(1, 0.5f, 0.5f), 0.2f, false, true, true, Curve.EaseOutQuad);
tween.OnForwardFinish += () =>
{
FlowerIcon.TweenBacSr();
};
tween = OperateIcon.CreateTweenSr(new Color(1, 1, 1), new Color(1, 0.5f, 0.5f), 0.2f, false, true, true, Curve.EaseOutQuad);
tween.OnForwardFinish += () =>
{
OperateIcon.TweenBacSr();
};
tween = OperateBk.CreateTweenSr(new Color(1, 1, 1), new Color(1, 0.5f, 0.5f), 0.2f, false, true, true, Curve.EaseOutQuad);
tween.OnForwardFinish += () =>
{
OperateBk.TweenBacSr();
};
OperateBk.CreateTweenScale(OperateBk.transform.localScale + new Vector3(0.1f, 0.1f, 0.1f), 0.25f, false, true, Curve.EaseOutQuad);
}
#region MiniGame
public void GameOver()
{
ChildDic["MiniGame"].SetActive(false);
OperateBk.TweenBacScale();
}
public void GameBegin()
{
ChildDic["MiniGame"].SetActive(true);
OperateIcon.SetActive(false);
}
public void SetFirstOp()
{
OperateBk.TweenForScale();
OperateIcon.SetAlpha(1);
OperateOutline.SetAlpha(1);
OperateIcon.SetActive(true);
OperateOutline.SetActive(true);
}
public void SetSecondOp()
{
OperateIcon.SetAlpha(1);
OperateOutline.SetAlpha(1);
OperateIcon.SetActive(true);
OperateOutline.SetActive(false);
}
public void SetThirdOp()
{
OperateIcon.SetAlpha(0.5f);
OperateOutline.SetAlpha(0.5f);
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;
OperateIcon.sprite = ManaReso.Load("Rip", Folder.UI);
}
else if (random <= 0.6666666f)
{
OpType = OpType.Water;
OperateIcon.sprite = ManaReso.Load("Water", Folder.UI);
}
else
{
OpType = OpType.Fertilize;
OperateIcon.sprite = ManaReso.Load("Fertilize", Folder.UI);
}
if (sequence == 0)
{
SetFirstOp();
}
else if (sequence == 1)
{
SetSecondOp();
}
else
{
SetThirdOp();
}
}
public bool Operate(OpType opType)
{
if (opType != OpType) //错误的操作
{
OperateBk.TweenForSr();
FlowerIcon.TweenForSr();
OperateIcon.TweenForSr();
OperateIcon.Shake(1, 3, new Vector3(0.2f, 0, 0), Curve.EaseOutQuad);
return false;
}
else //操作正确 植物升级
{
Phase++;
PlayParticle();
OperateBk.TweenBacScale();
return true;
}
}
#endregion
public void PlayAnim(ObjType obj)
{
Animator animator = ManaReso.GetAnim(FlowerIcon.bounds, obj, FlowerIcon.transform.position, transform).GetComponentInChildren();
animator.SetTrigger("Play");
}
public void PlayParticle()
{
ParticleAC.SetTrigger("Play");
}
public void GetAward()
{
PlayParticle();
ManaGarden.Award = true;
int coin = Mathf.CeilToInt(ManaData.CoinPerson*Random.Range(0.05f, 0.08f)*ManaData.SkillPlus);
ManaData.Coin += coin;
ManaData.FlowerCoin += coin;
ManaReso.GetHudText("+" + coin, Color.white, 25, ChildDic["GoldPosTra"], ManaReso.Get("A_HudParent"), true);
GoldBk.SetActive(false);
}
public void ShowAward()
{
GoldBk.CreateTweenSr(new Color(1, 1, 1, 0), new Color(1, 1, 1, 1), 1f, false, true, true, Curve.EaseOutQuad);
GoldIcon.CreateTweenSr(new Color(1, 1, 1, 0), new Color(1, 1, 1, 1), 1f, false, true, true, Curve.EaseOutQuad);
GoldBk.SetY(transform.position.y + 2.5f);
GoldBk.TweenForSr();
GoldIcon.TweenForSr();
GoldBk.Move2D
(
GoldBk.transform.localPosition + new Vector3(0, 0.5f, 0),
1f,
true,
Curve.EaseOutQuad
);
}
public void OnPointerClick(PointerEventData eventData)
{
if (eventData.rawPointerPress.transform == transform)
{
ManaReso.Get("G_Flower").TweenForCG();
ManaGarden.ShowRetrieveCard(FlowerInfo);
}
else if (eventData.rawPointerPress.transform == GoldBk)
{
Award = false;
}
}
}