using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GamingIsLove.Makinom.Components;
using GamingIsLove.Makinom;
using System.Linq;
using Cysharp.Threading.Tasks;
public class HUDCustomOrderListComponent : BaseHUDListContentComponent<TextContent>
{
//ReactiveCollection<OrderStruct> observableOrders;
//System.IDisposable updateSubscribe;
/*
============================================================================
Content functions
============================================================================
*/
public override void UpdateContent()
{
if (this.contentProvider == null)
{
if (this.gameObject.activeSelf)
{
this.gameObject.SetActive(false);
}
}
else
{
if (!this.gameObject.activeSelf)
{
this.gameObject.SetActive(true);
}
var orderStructListNoCast = Maki.Game.SelectedData.Get("OrderStruct");
if (orderStructListNoCast != null)
{
var orderStructList = orderStructListNoCast.Cast<OrderStruct>().ToArray();
for (int i = 0; i < orderStructList.Count(); i++)
{
// すでにCustomerがOrder済でない場合のみCreate
bool yetSpawned = !spawnedPrefabs.Any(x =>
{
var orderStruct = (OrderStruct)x.Value.User;
return !orderStructList.Any(y => y.orderedCombatant.GetName() == orderStruct.orderedCombatant.GetName());
});
if (yetSpawned)
{
var createdPrefab = CreatePrefab(i, settings.prefab, orderStructList[i]);
}
}
var deletedPrefab = spawnedPrefabs.Where(x =>
{
var orderStruct = (OrderStruct)x.Value.User;
return !orderStructList.ToArray().Any(y =>
{
return y.orderedCombatant.GetName() == orderStruct.orderedCombatant.GetName();
});
});
foreach (var item in deletedPrefab.ToArray())
{
spawnedPrefabs.Remove(item);
Destroy(item.Value.gameObject);
}
}
if (spawnedPrefabs.Count() > 0 && orderStructListNoCast == null)
{
foreach (var prefabHUDContentsProvider in spawnedPrefabs)
{
Destroy(prefabHUDContentsProvider.Value.gameObject,0.1f);
}
spawnedPrefabs.Clear();
}
}
}
/*
============================================================================
Register functions
============================================================================
*/
async public override void Register()
{
await UniTask.DelayFrame(3);
if (!this.isRegistered)
{
Maki.Game.SelectedData.DataChanged += this.MarkUpdateContent;
this.MarkUpdateContent();
base.Register();
}
}
public override void Unregister()
{
if (this.isRegistered)
{
Maki.Game.SelectedData.DataChanged -= this.MarkUpdateContent;
base.Unregister();
}
}
}
It looks like you're new here. If you want to get involved, click one of these buttons!
Also, there's now a HUD Selected Data List component available to use selected data as HUD content.
As for your code - it's hard for me to tell what's wrong, since I don't know your OrderStruct data and how it's created.
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!