海淀天下城电子沙盘单机版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

109 lines
3.0 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public enum MovingDefenseMode { none, hide, CannotClick }
public class UIMoveManager : MonoBehaviour
{
public RectTransform MovePanel;
public Button MoveOut;
public Button MoveIn;
public MoveDir MoveOutDirction;
public MoveDir MoveInDirction;
public float MoveTime;
public float Offset;
public MovingDefenseMode DefenseMode;
private UIMove UIMoving;
private float timmer;
bool click = false;
bool MoveOver;
void Start()
{
MoveOut.onClick.AddListener(MoveOut_Click);
MoveIn.onClick.AddListener(MoveIn_Click);
SetMoving();
}
public void SetMoving()
{
if (!MovePanel.GetComponent<UIMove>())
{
UIMoving = MovePanel.gameObject.AddComponent<UIMove>();
UIMoving.SetPos();
}
else
{
UIMoving = MovePanel.gameObject.GetComponent<UIMove>();
}
}
public void MoveIn_Click()
{
UIMoving.AnchorMove(MovePanel, MoveTime, MoveInDirction, Offset);
switch (DefenseMode)
{
case MovingDefenseMode.hide:
MoveIn.gameObject.SetActive(false);
MoveOut.gameObject.SetActive(true);
break;
case MovingDefenseMode.CannotClick:
click = true;
MoveIn.GetComponent<Button>().interactable = false;
StartCoroutine(WaitForMoveIn(MoveTime));
break;
default: break;
}
}
IEnumerator WaitForMoveIn(float time)
{
yield return new WaitForSeconds(time);
if (MoveOver)
{
MoveIn.GetComponent<Button>().interactable = true;
MoveIn.gameObject.SetActive(false);
MoveOut.gameObject.SetActive(true);
}
}
public void MoveOut_Click()
{
UIMoving.AnchorMove(MovePanel, MoveTime, MoveOutDirction, Offset);
switch (DefenseMode)
{
case MovingDefenseMode.hide:
MoveIn.gameObject.SetActive(true);
MoveOut.gameObject.SetActive(false);
break;
case MovingDefenseMode.CannotClick:
click = true;
MoveOut.GetComponent<Button>().interactable = false;
StartCoroutine(WaitForMoveOut(MoveTime));
break;
default: break;
}
}
IEnumerator WaitForMoveOut(float time)
{
yield return new WaitForSeconds(time);
if (MoveOver)
{
MoveOut.GetComponent<Button>().interactable = true;
MoveIn.gameObject.SetActive(true);
MoveOut.gameObject.SetActive(false);
}
}
void Update()
{
if (click)
{
timmer += Time.deltaTime;
if (timmer >= MoveTime)
{
MoveOver = true;
timmer = 0;
click = false;
}
}
}
}