108 lines
3.4 KiB
C#
108 lines
3.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using static Ruins_Buildings;
|
|
|
|
public class Ruins_Node : MonoBehaviour
|
|
{
|
|
//public Ruins_Node father;
|
|
public List<Ruins_Node> son = new List<Ruins_Node>();
|
|
|
|
public Ruins_Buildings ruins_Buildings;
|
|
|
|
private Transform Coverings;
|
|
private Transform Item;
|
|
|
|
public float progress;
|
|
public NodeState state = NodeState.Lock;
|
|
//public List<BlobController> TuanZiInNode = new List<BlobController>();
|
|
|
|
private Vector3 InitialScale;
|
|
|
|
public enum NodeState
|
|
{
|
|
Lock, WaitingForDig, BeingDigged
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
ruins_Buildings = transform.parent.parent.GetComponent<Ruins_Buildings>();
|
|
ruins_Buildings.Node_List.Add(this);
|
|
|
|
Coverings = transform.Find("Coverings");
|
|
Item = transform.Find("Item");
|
|
|
|
InitialScale = Coverings.localScale;
|
|
if(state == NodeState.WaitingForDig)
|
|
{
|
|
Coverings.GetComponent<SpriteRenderer>().color = Color.yellow;
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
Coverings.localScale = InitialScale * (100 - progress) / 100;
|
|
}
|
|
public void DigRuins()
|
|
{
|
|
progress += ruins_Buildings.TuanZiList.Count*10;
|
|
|
|
if (progress >= 100)
|
|
{
|
|
progress = 100;
|
|
CancelInvoke("DigRuins");
|
|
//修改建筑状态
|
|
ruins_Buildings.state = State.isResting;
|
|
//转移团子
|
|
foreach (BlobController blob in ruins_Buildings.TuanZiList)
|
|
{
|
|
blob.transform.position = new Vector3(ruins_Buildings.transform.position.x, ruins_Buildings.transform.position.y, blob.transform.position.z);
|
|
blob.transform.eulerAngles = new Vector3(0, 0, 0);
|
|
}
|
|
//修改节点信息
|
|
state = NodeState.BeingDigged;
|
|
//解锁子节点
|
|
foreach (Ruins_Node n in son)
|
|
{
|
|
n.state = NodeState.WaitingForDig;
|
|
n.Coverings.GetComponent<SpriteRenderer>().color = Color.yellow;
|
|
}
|
|
}
|
|
}
|
|
private void OnMouseDown()
|
|
{
|
|
if (ruins_Buildings.state == State.isResting && state == NodeState.WaitingForDig && ruins_Buildings.TuanZiList.Count>0)
|
|
{
|
|
//修改建筑状态
|
|
ruins_Buildings.state = State.isDigging;
|
|
ruins_Buildings.current_Node = this;
|
|
//转移团子
|
|
foreach (BlobController blob in ruins_Buildings.TuanZiList)
|
|
{
|
|
blob.transform.position = new Vector3(transform.position.x, transform.position.y,blob.transform.position.z);
|
|
blob.transform.eulerAngles = new Vector3(0, 0, 0);
|
|
}
|
|
//每秒挖掘一次
|
|
InvokeRepeating("DigRuins", 0, 1);
|
|
}
|
|
}
|
|
|
|
private void OnMouseEnter()
|
|
{
|
|
if (ruins_Buildings.state == State.isResting && state == NodeState.WaitingForDig && ruins_Buildings.TuanZiList.Count > 0)
|
|
{
|
|
//Debug.Log(123);
|
|
Coverings.GetComponent<SpriteRenderer>().color = Color.blue;
|
|
}
|
|
}
|
|
private void OnMouseExit()
|
|
{
|
|
if (Coverings.GetComponent<SpriteRenderer>().color == Color.blue)
|
|
{
|
|
Coverings.GetComponent<SpriteRenderer>().color = Color.yellow;
|
|
}
|
|
}
|
|
}
|