Files
Studio/Assets/Scripts/XED/Building/WallGroup.cs
2025-02-21 11:57:09 +09:00

126 lines
3.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Pool;
using XRLib;
namespace XED
{
public class WallGroup : TwinObject
{
public HashSet<Wall> groupWalls = new();
public HashSet<LinePoint> groupPoints = new();
public Transform walls;
public Transform linepoints;
public Action<TwinObject> onRemove;
public override void AfterAwake()
{
walls = Find<Transform>(nameof(walls));
linepoints = Find<Transform>(nameof(linepoints));
}
public bool CheckIncludeGroupWall(Wall wall)
{
if (groupWalls.Contains(wall))
return true;
return false;
}
public void AddWall(Wall wallLine)
{
if(groupWalls.Add(wallLine))
{
wallLine.transform.SetParent(walls);
var centerPoints = wallLine.GetCenterPoints();
foreach(var centerPoint in centerPoints) {
AddGroupPoints(centerPoint);
}
}
}
public void AddGroupPoints(LinePoint centerPoint)
{
centerPoint.transform.SetParent(linepoints);
groupPoints.Add(centerPoint);
}
public override void SetDisplayable(bool value)
{
foreach (var wallLine in groupWalls)
{
wallLine.SetDisplayable(!value);
}
}
public override void SetInteractible(bool value)
{
foreach(var wallLine in groupWalls)
{
wallLine.SetInteractible(!value);
}
}
public override void Select()
{
foreach(var wallLine in groupWalls)
{
wallLine.Select();
}
}
public override void Deselect()
{
foreach (var wallLine in groupWalls)
{
wallLine.Deselect();
}
}
public void LineResetting()
{
foreach (var walls in groupWalls)
{
walls.MoveLine();
}
}
public bool ContainPointInWallGroup(Wall wall)
{
var linePoints = wall.GetCenterPoints();
foreach(var point in linePoints)
{
if(groupPoints.Contains(point))
{
return true;
}
}
return false;
}
public void Release()
{
groupWalls.Clear();
groupPoints.Clear();
gameObject.SetActive(false);
foreach(var w in groupWalls)
{
onRemove?.Invoke(w);
}
//onRemoveWallGroupEvent?.Invoke(this);
}
public override void MaterialChange(Material mat)
{
foreach(var wallLine in groupWalls)
{
wallLine.MaterialChange(mat);
}
}
}
}