94 lines
2.2 KiB
C#
94 lines
2.2 KiB
C#
using System;
|
|
using Newtonsoft.Json;
|
|
using Octopus.Simulator;
|
|
using UnityEngine;
|
|
|
|
[Serializable]
|
|
public class ResourceInfo
|
|
{
|
|
public string resource_name;
|
|
public int capacity;
|
|
public float speed_factor;
|
|
public int? breakdown_interval;
|
|
public int? repair_time;
|
|
}
|
|
|
|
[Serializable]
|
|
public class ResourceStatus
|
|
{
|
|
public string resource_name;
|
|
public int requesters;
|
|
public int claimers;
|
|
public int available;
|
|
public int capacity;
|
|
public int original_capacity;
|
|
public float utilization;
|
|
public float occupancy;
|
|
public int broken_units;
|
|
public float speed_factor;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class SimulationModelResource : SimulationModel
|
|
{
|
|
ResourceInfo info;
|
|
ResourceStatus currentStatus;
|
|
|
|
private void Message_Initialized(ResourceInfo data)
|
|
{
|
|
this.info = data;
|
|
|
|
this.gameObject.SetActive(false);
|
|
}
|
|
|
|
private void Message_Status_Updted(ResourceStatus data)
|
|
{
|
|
this.currentStatus = data;
|
|
SetBubble($"{data.claimers}/{data.original_capacity}");
|
|
if (currentBubble)
|
|
{
|
|
currentBubble.SetDetail(data, logicType.resource, FindAnyObjectByType<LogicUIManager>().itemMap[nodeID].Label);
|
|
}
|
|
}
|
|
|
|
public override void GetData(string data)
|
|
{
|
|
var message = JsonConvert.DeserializeObject<BaseJson>(data);
|
|
|
|
switch (message._event)
|
|
{
|
|
case "resource_initialized":
|
|
Message_Initialized(message.data.ToObject<ResourceInfo>());
|
|
|
|
return;
|
|
|
|
case "resource_status_update":
|
|
Message_Status_Updted(message.data.ToObject<ResourceStatus>());
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
return;
|
|
}
|
|
}
|
|
|
|
public override void SetBubble(object data)
|
|
{
|
|
string msg = data.ToString();
|
|
|
|
if (currentBubble == null)
|
|
{
|
|
// 생성
|
|
currentBubble = Instantiate(bubbleUIPrefab, FindAnyObjectByType<Canvas_Bubble>().transform);
|
|
currentBubble.target = DataBubbleSocket;
|
|
currentBubble.worldOffset = new Vector3(0, 2.0f, 0); // 필요에 따라 조절
|
|
}
|
|
// 텍스트 갱신
|
|
currentBubble.SetMessage(msg);
|
|
}
|
|
}
|