73 lines
2.1 KiB
C#
73 lines
2.1 KiB
C#
using UnityEngine;
|
|
using AibisDream.FixSystem;
|
|
using System.Collections.Generic;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class EmotionModule : MonoBehaviour, ISocket
|
|
{
|
|
public Transform[] socketPositions; // 插槽位置,在Inspector中手动设置
|
|
private bool[] socketOccupied; // 插槽占用状态
|
|
private ExpressionManager expressionManager;
|
|
|
|
private void Awake()
|
|
{
|
|
// 初始化插槽占用状态数组
|
|
socketOccupied = new bool[socketPositions.Length];
|
|
expressionManager = GetComponentInParent<ExpressionManager>();
|
|
}
|
|
|
|
public void PlugIn()
|
|
{
|
|
// 找到最近的空插槽
|
|
int socketIndex = FindNearestEmptySocket();
|
|
if (socketIndex != -1)
|
|
{
|
|
socketOccupied[socketIndex] = true;
|
|
expressionManager?.OnPlugInserted(null, this, socketIndex);
|
|
}
|
|
}
|
|
|
|
public void PlugOut()
|
|
{
|
|
// 找到最近的有插头的插槽
|
|
int socketIndex = FindNearestOccupiedSocket();
|
|
if (socketIndex != -1)
|
|
{
|
|
socketOccupied[socketIndex] = false;
|
|
expressionManager?.OnPlugRemoved(null, this, socketIndex);
|
|
}
|
|
}
|
|
|
|
public Vector3 GetSocketPos()
|
|
{
|
|
int socketIndex = FindNearestEmptySocket();
|
|
return socketIndex != -1 ? socketPositions[socketIndex].position : transform.position;
|
|
}
|
|
|
|
public bool IsAvailable()
|
|
{
|
|
return FindNearestEmptySocket() != -1;
|
|
}
|
|
|
|
private int FindNearestEmptySocket()
|
|
{
|
|
for (int i = 0; i < socketOccupied.Length; i++)
|
|
{
|
|
if (!socketOccupied[i])
|
|
return i;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
private int FindNearestOccupiedSocket()
|
|
{
|
|
for (int i = 0; i < socketOccupied.Length; i++)
|
|
{
|
|
if (socketOccupied[i])
|
|
return i;
|
|
}
|
|
return -1;
|
|
}
|
|
}
|
|
} |