45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITKit;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
namespace Net.Project.B.Interaction
|
|
{
|
|
public class UnityInteractionEvent : MonoBehaviour
|
|
{
|
|
[SerializeField] private UnityEvent onInteraction;
|
|
private int _instanceId;
|
|
private void Start()
|
|
{
|
|
var service = BITApp.ServiceProvider.GetRequiredService<IWorldInteractionService>();
|
|
|
|
service.OnInteraction += OnInteraction;
|
|
|
|
destroyCancellationToken.Register(Dispose);
|
|
|
|
_instanceId = gameObject.GetInstanceID();
|
|
|
|
return;
|
|
void Dispose()
|
|
{
|
|
service.OnInteraction -= OnInteraction;
|
|
}
|
|
}
|
|
|
|
private void OnInteraction(object arg1, IWorldInteractable arg2, WorldInteractionProcess arg3, object arg4)
|
|
{
|
|
if(_instanceId!= arg2.WorldObject.As<GameObject>().GetInstanceID())return;
|
|
switch (arg3)
|
|
{
|
|
case WorldInteractionProcess.Performed:
|
|
onInteraction.Invoke();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|