using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LightDigital.UI;
using UnityEngine.UI;
using DG.Tweening;
using UnityEngine.EventSystems;
using LightDigital.Core;
public class C0001 : QuestionBase
{
enum Dir {
Dir_None,
Dir_Left,
Dir_Right,
Dir_Over
}
public List<GameObject> listBox = new List<GameObject>();
Queue<GameObject> queBox = new Queue<GameObject>();
Button btnMoney;
Image imgPersonStatic;
Image imgPersonLeft;
Image imgPersonRight;
int fPersonLeftStartX = 0;
int fPersonLeftEndX = -750;
int fPersonRightStartX = -750;
int fPersonRightEndX = 0;
float fSpeed = 1;//速度
float fAddSpeed = 5f;//每次增加的速度
Dir eDir = Dir.Dir_None;//当前方向
void Awake()
{
btnMoney = UIHelper.GetButton(gameObject, "btnMoney");
imgPersonStatic = UIHelper.GetImage(gameObject, "imgPersonStatic");
imgPersonLeft = UIHelper.GetImage(gameObject, "imgPersonLeft");
imgPersonRight = UIHelper.GetImage(gameObject, "imgPersonRight");
}
void Start()
{
btnMoney.onClick.AddListener(onBtnCallback);
imgPersonLeft.gameObject.SetActive(false);
imgPersonRight.gameObject.SetActive(false);
}
void Update()
{
if (!imgPersonStatic.gameObject.activeSelf)
{
switch (eDir)
{
case Dir.Dir_Left:
imgPersonLeft.gameObject.SetActive(true);
imgPersonLeft.transform.Translate(Vector3.left * fSpeed * Time.deltaTime);//加速度
if (imgPersonLeft.GetComponent<RectTransform>().anchoredPosition.x < fPersonLeftEndX)
{
eDir = Dir.Dir_Right;
imgPersonLeft.gameObject.SetActive(false);
imgPersonLeft.GetComponent<RectTransform>().anchoredPosition = v2Left;
}
break;
case Dir.Dir_Right:
imgPersonRight.gameObject.SetActive(true);
imgPersonRight.transform.Translate(Vector3.right * fSpeed * Time.deltaTime);//加速度
if (imgPersonRight.GetComponent<RectTransform>().anchoredPosition.x > fPersonRightEndX)
{
eDir = Dir.Dir_Left;
imgPersonRight.GetComponent<RectTransform>().anchoredPosition = v2Right;
imgPersonRight.gameObject.SetActive(false);
}
break;
}
}
}
void onBtnCallback()
{
imgPersonStatic.gameObject.SetActive(false);
fSpeed *= fAddSpeed;
switch (eDir)
{
case Dir.Dir_None:
eDir = Dir.Dir_Left;
break;
case Dir.Dir_Over:
break;
}
}
}