1
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "BITFALL.Entities.Cosmetic.Runtime",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:709caf8d7fb6ef24bbba0ab9962a3ad0",
|
||||
"GUID:2b6752324f5c76d4cad13e2095c77b9e",
|
||||
"GUID:0743625b554095843871fab2dd150305",
|
||||
"GUID:1bb4187526a9431478feccaef064696a",
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:9e24947de15b9834991c9d8411ea37cf",
|
||||
"GUID:84651a3751eca9349aac36a66bba901b"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BITFALL.Cosmetic;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITFALL.Entities.Cosmetic
|
||||
{
|
||||
public sealed class CosmeticTextureBehaviour : EntityBehavior
|
||||
{
|
||||
[SerializeField] private Renderer[] renderers;
|
||||
[SerializeField] private Renderer[] steveRenderers;
|
||||
[SerializeField] private Renderer[] alexRenderers;
|
||||
[Inject(true)] private ICosmeticService _cosmeticService;
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
if (_cosmeticService is not null)
|
||||
_cosmeticService.OnCosmeticsChanged += OnCosmeticsChanged;
|
||||
}
|
||||
|
||||
private void OnCosmeticsChanged()
|
||||
{
|
||||
foreach (var cosmetic in _cosmeticService.Cosmetics)
|
||||
{
|
||||
foreach (var content in cosmetic.Contents.OfType<CosmeticTextureContent>())
|
||||
{
|
||||
foreach (var _renderer in renderers)
|
||||
{
|
||||
if (content.Texture is Texture2D texture2D)
|
||||
{
|
||||
var multiple = texture2D.width / 64;
|
||||
var color = texture2D.GetPixels32()[17 * multiple * texture2D.width + 51* multiple];
|
||||
var isSteve = color.a is 1;
|
||||
Debug.Log(color);
|
||||
steveRenderers.ForEach(x => x.enabled = isSteve);
|
||||
alexRenderers.ForEach(x => x.enabled = !isSteve);
|
||||
}
|
||||
_renderer.material.mainTexture = content.Texture;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security;
|
||||
using BITFALL.Cosmetic;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using BITKit.Steamwork;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
namespace BITFALL.Entities.Cosmetic
|
||||
{
|
||||
[CustomType(typeof(ICosmeticService))]
|
||||
public class EntityCosmeticService : EntityBehavior,ICosmeticService
|
||||
{
|
||||
[SerializeReference, SubclassSelector] private ISteamService steamService;
|
||||
|
||||
public ICosmetic[] Cosmetics { get; private set; }
|
||||
public event Action OnCosmeticsChanged;
|
||||
public override async void OnStart()
|
||||
{
|
||||
base.OnStart();var items =await steamService.GetInventoryItemDefsAsync(destroyCancellationToken);
|
||||
Cosmetics = items.Select(itemDef => Addressables.LoadAssetAsync<ICosmetic>(itemDef.AddressablePath).WaitForCompletion()).ToArray();
|
||||
OnCosmeticsChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user