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 = "已放置";
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 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;
public UIPartical UIPartical;
#endregion
public FlowerInfo(XmlAttributeCollection attributes)
{
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(attributes[0].Value);
Sprite = ManaReso.Load(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;
OperateBk.SetActive(false);
OperateIcon.SetActive(false);
OperateOutline.SetActive(false);
ManaReso.GetHudText("得分+15", ManaColor.HudText, 25, ChildDic["ScoreTra"], ManaReso.Get("D_Status"), true);
ManaMiniGame.Score += 15;
}
}
}
private int _Phase;
private OpType OpType;
private SpriteRenderer FlowerIcon;
private SpriteRenderer OperateBk;
private SpriteRenderer OperateIcon;
private 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 Animator;
public Transform GoldBk;
public Transform GoldIcon;
private Dictionary ChildDic;
#endregion
private void Awake()
{
ChildDic = new Dictionary();
Auxiliary.CompileDic(transform, ChildDic);
GoldBk = ChildDic["GoldBk"];
GoldIcon = ChildDic["GoldIcon"];
Animator = 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, 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, 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, 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();
MoveVec move = OperateIcon.CreateMoveVec();
move.StartMove(OperateIcon.transform.position + new Vector3(0.2f, 0), 0.1f, Curve.Linear);
move.OnFinish = () =>
{
move.StartMove(OperateIcon.transform.position + new Vector3(-0.4f, 0), 0.1f, Curve.Linear);
move.OnFinish = () =>
{
move.StartMove(OperateIcon.transform.position + new Vector3(0.2f, 0), 0.1f, Curve.Linear);
move.OnFinish = () =>
{
move.StartMove(OperateIcon.transform.position + new Vector3(0.1f, 0), 0.1f, Curve.Linear);
move.OnFinish = () =>
{
move.StartMove(OperateIcon.transform.position + new Vector3(-0.2f, 0), 0.1f, Curve.Linear);
move.OnFinish = () =>
{
move.StartMove(OperateIcon.transform.position + new Vector3(0.1f, 0), 0.1f, Curve.Linear);
move.OnFinish = () =>
{
};
};
};
};
};
};
return false;
}
else //操作正确 植物升级
{
Phase++;
PlayAnim();
OperateBk.TweenBacScale();
return true;
}
}
#endregion
public void PlayAnim()
{
Animator.SetTrigger("Play");
}
public void GetAward()
{
PlayAnim();
ManaGarden.Award = true;
int coin = Mathf.CeilToInt(ManaData.CoinPerson*Random.Range(0.05f, 0.08f)*ManaData.SkillPlus);
ManaData.Coin += coin;
ManaReso.GetHudText("+" + coin, ManaColor.HudText, 25, ChildDic["GoldTra"], 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, true, true, Curve.EaseOutQuad);
GoldIcon.CreateTweenSr(new Color(1, 1, 1, 0), new Color(1, 1, 1, 1), 1f, true, true, Curve.EaseOutQuad);
GoldBk.SetY(transform.position.y + 2.5f);
GoldBk.TweenForSr();
GoldIcon.TweenForSr();
GoldBk.MoveVec
(
GoldBk.transform.position + new Vector3(0, 0.5f, 0),
1f,
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;
}
}
}