using UnityEngine;
namespace ServiceSim
{
///
/// 店の設定ファイルの共通部分。
/// 店の形そのものは、種類ごとの実装(GridStoreLayout / BandStoreLayout)が
/// StorePlan(部品をどこに置くかの一覧)として作る。
///
/// 新しい店の形は、StoreLayout の .asset を1つ足すだけで作れる(コードは触らない)。
/// 店に関する数字はすべて .asset に置く。
///
public abstract class StoreLayout : ScriptableObject
{
[Header("細い通路の幅")]
[Tooltip("細い通路の幅の選択肢(m)。止まっている椅子の背と、隣の席の背または壁のあいだで測る")]
public float[] aisleWidthOptions = { 0.8f, 1.0f, 1.2f };
[Tooltip("いま使う細い通路の幅(aisleWidthOptions の番号)")]
public int aisleWidthIndex = 2;
[Header("ロボットの止まる点")]
[Tooltip("卓に料理を置く停止点を、細い通路の中心から卓の側へずらす距離(m)")]
public float deliveryOffsetFromAisleCenter = 0f;
[Tooltip("細い通路に入る前に待つ位置を、通路の入口から手前へ下げる距離(m)")]
public float aisleEntranceSetback = 0.8f;
[Tooltip("入口で待つ位置を、通路の中心から横へずらす距離(m)。待っている台の横を、戻る台が通れるようにする")]
public float aisleEntranceSideOffset = 0.45f;
[Header("床と壁")]
public float wallHeight = 2.4f;
public float wallThickness = 0.15f;
[Tooltip("床の厚み(m)")]
public float floorThickness = 0.2f;
[Header("見分けやすさ(計測には効かない)")]
[Tooltip("通路の床に色の板を敷くか。当たりは持たないので NavMesh には焼かれない")]
public bool showAisleMarks = true;
[Tooltip("通路の色板の厚み(m)")]
public float aisleMarkThickness = 0.02f;
[Header("床の塗り分け(見た目だけ。NavMesh は変えない)")]
[Tooltip("床の塗り分けを出すか。水色=ロボットの体が入れる床、薄い黄色=人だけが入れる床")]
public bool showFloorPaint = true;
[Tooltip("塗り分けを作るときのマスの大きさ(m)。小さいほどきれいだが重い")]
public float floorPaintCellSize = 0.05f;
[Tooltip("塗りの板を置く高さ(m)。通路の色板より上にして、塗りが見えるようにする")]
public float floorPaintHeight = 0.03f;
[Tooltip("場所の名前(レジ・待合・ドリンクバーなど)を床の上に出すか。計測の回では出さない")]
public bool showPlaceNames = true;
[Tooltip("場所の名前の文字の大きさ(m)")]
public float placeNameSize = 0.14f;
[Tooltip("場所の名前を置く高さ(m)。床の塗りより上にする")]
public float placeNameHeight = 0.06f;
[Header("NavMesh のベイク設定(自前ベイカーが使う)")]
[Tooltip("経路を焼くときの通行者の半径(m)。ロボットの半径に合わせる")]
public float navAgentRadius = 0.25f;
public float navAgentHeight = 1.2f;
public float navAgentClimb = 0.2f;
public float navAgentSlope = 10f;
[Tooltip("ベイクの細かさ(m)。0.8 m の通路を正しく出すために細かくする")]
public float navVoxelSize = 0.05f;
[Tooltip("これより小さい島は捨てる(m^2)")]
public float navMinRegionArea = 0.3f;
[Tooltip("ベイクする範囲に足す余白(m)")]
public float navBoundsPadding = 1.0f;
// ---- 共通で使えるもの ----
/// いま使う細い通路の幅(m)
public float AisleWidth
{
get
{
if (aisleWidthOptions == null || aisleWidthOptions.Length == 0) return 1.0f;
int i = Mathf.Clamp(aisleWidthIndex, 0, aisleWidthOptions.Length - 1);
return aisleWidthOptions[i];
}
}
/// 細い通路の幅のうち、いちばん狭いもの(m)
public float MinAisleWidth
{
get
{
float m = float.MaxValue;
if (aisleWidthOptions != null)
for (int i = 0; i < aisleWidthOptions.Length; i++)
if (aisleWidthOptions[i] > 0f) m = Mathf.Min(m, aisleWidthOptions[i]);
return m < float.MaxValue ? m : AisleWidth;
}
}
/// 細い通路の幅のうち、いちばん広いもの(m)
public float MaxAisleWidth
{
get
{
float m = 0f;
if (aisleWidthOptions != null)
for (int i = 0; i < aisleWidthOptions.Length; i++) m = Mathf.Max(m, aisleWidthOptions[i]);
return m > 0f ? m : 1.0f;
}
}
public int AisleWidthCount
{
get { return aisleWidthOptions != null ? aisleWidthOptions.Length : 0; }
}
///
/// 卓の停止点を通路の中心からずらす距離。
/// 通路が狭いときは、NavMesh の上に乗る範囲までに抑える。
///
public float DeliveryOffset()
{
float limit = Mathf.Max(0f, AisleWidth * 0.5f - navAgentRadius - 0.02f);
return Mathf.Min(deliveryOffsetFromAisleCenter, limit);
}
/// この .asset の形を、部品の一覧(StorePlan)にする
protected abstract StorePlan Compose();
/// 店の種類の名前(報告に出す)
public virtual string StoreKindName { get { return GetType().Name; } }
///
/// 入口まわり(ドリンクバー・待合・レジ・入口)が帯に入ったかの報告。
/// Build Store が store_report.txt と Console に出す。入らなかったものはここに出す。
///
public virtual string FrontFitReport() { return ""; }
///
/// ロボットの待機場所(B2)の報告。点の座標・点どうしの距離・
/// 太い通路に残る通り道の幅・スタッフが立つ点との距離を出す。
/// Build Store が store_report.txt と Console に出す。
///
public virtual string RobotStandbyReport() { return ""; }
/// いまの幅で部品の一覧を作る
public StorePlan NewPlan()
{
StorePlan plan = Compose();
if (plan == null) return null;
plan.wallHeight = wallHeight;
plan.wallThickness = wallThickness;
plan.floorThickness = floorThickness;
plan.aisleWidth = AisleWidth;
return plan;
}
}
}