GQ_Communicate/GQ_TongXin/Assets/Adam/Scripts/UPosManger.cs

82 lines
2.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//============================================================
//支持中文文件使用UTF-8编码
//@author #AUTHOR#
//@create #CREATEDATE#
//@company #COMPANY#
//
//@description:
//============================================================
public class UPosManger : MonoBehaviour
{
public UPosItem[] uPosItems;
public List<UPosItem> currentUPosIsOccupied = new List<UPosItem>();
// Use this for initialization
private void Start()
{
uPosItems = GetComponentsInChildren<UPosItem>();
}
/// <summary>
/// 监视所有U位
/// </summary>
public void SwitchUItem()
{
for (int i = 0; i < uPosItems.Length; i++)
{
uPosItems[i].isOccupied = false;
}
}
/// <summary>
/// 计算是否符合放置条件
/// </summary>
public int CountUPos(int count, int currentUPosIndex)
{
int startIndex = currentUPosIndex - count;
if (startIndex < 0) startIndex = 0;
for (int i = currentUPosIndex - 1; i >= startIndex; i--)
{
if (uPosItems[i].isOccupied)
{
startIndex = i + 1;
break;
//currentUPosIsOccupied.Add(uPosItems[i]);
//uPosItems[i].isOccupied = true;
}
}
if (startIndex + count > uPosItems.Length) return -1;
for (int i = startIndex; i < startIndex + count; i++)
{
if (uPosItems[i].isOccupied)
return -1;
}
return startIndex;
//return startIndex + count - 1;
}
public void SetCurrentUPosIsOccupied(int startIndex, int count, bool isEnabel)
{
//Debug.Log("startIndex-------------" + startIndex);
//Debug.Log("count-------------" + count);
for (int i = startIndex; i < startIndex+count; i++)
{
uPosItems[i].isOccupied = isEnabel;
if (isEnabel)
{
uPosItems[i].SetInstructColor(Color.red);
}
else
{
uPosItems[i].SetInstructColor(Color.green);
}
}
}
}