This commit is contained in:
CortexCore
2023-11-02 20:58:55 +08:00
parent f0f348c246
commit ee3ecec6cb
168 changed files with 58830 additions and 379 deletions

View File

@@ -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
}

View File

@@ -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;
}
}
}
}
}
}

View File

@@ -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();
}
}
}

View File

@@ -15,6 +15,7 @@ using BITKit.Entities.Melee;
using BITKit.Entities.VFX;
using Cinemachine;
using Cysharp.Threading.Tasks;
using Unity.Mathematics;
namespace BITKit.Entities
{
@@ -171,7 +172,7 @@ namespace BITKit.Entities
[SerializeField] private Optional<int> overrideIndex;
[SerializeField] private AnimationCurve zoomCurve;
[SerializeField] private Optional<GameObject> optionalScope;
public event Action<IBasicItem> OnEquip;
public event Action<IBasicItem> OnUnEquip;
@@ -180,7 +181,6 @@ namespace BITKit.Entities
private readonly EntryGroup<IEquipBase> equips = new();
protected IEquipBase entryComplete;
private PlayerConfig playerConfig;
private IBasicItem _currentItem;
@@ -244,7 +244,24 @@ namespace BITKit.Entities
if (virtualCamera is not null)
{
virtualCamera.m_Lens.FieldOfView =zoomCurve.Evaluate(Zoom.Allow?Zoom.Value:0);
virtualCamera.m_Lens.FieldOfView =
Mathf.Lerp(
virtualCamera.m_Lens.FieldOfView,
Zoom.Allow ?
Mathf.Rad2Deg * CalcZoomFOV(Mathf.Deg2Rad * 60f, Zoom.Value) : PlayerConfig.Singleton.Fov,
16*deltaTime
);
float CalcZoomFOV(float baseFOV, float zoom)
{
return 2.0f * Mathf.Atan(Mathf.Tan(baseFOV / 2.0f) / zoom);
}
}
if (optionalScope.Allow)
{
optionalScope.Value.SetActive(AllowScope);
}
if (overrideIndex.Allow && (_health?.IsAlive ?? true))