This commit is contained in:
CortexCore
2023-11-06 01:17:23 +08:00
parent bd40165ade
commit 5446067f91
114 changed files with 2023 additions and 414 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Security.Permissions;
using UnityEngine;
using BITKit.Entities;
using BITKit.Events;
@@ -23,7 +24,7 @@ namespace BITKit.Vehicles
public WheelType wheelType;
}
public sealed class Vehicle : MonoBehaviour
public sealed class Vehicle : EntityBehavior
{
[Header(Constant.Header.Settings)] public float maxMotorTorque = 64;
[SerializeField] private float maxSteeringAngle = 45;
@@ -36,6 +37,9 @@ namespace BITKit.Vehicles
[SerializeField]
private new Rigidbody rigidbody;
[SerializeField] private GameObject[] objects;
[SerializeField] private GameObject[] destroyedObjects;
[SerializeField] private Transform driveAnchor;
[Header(Constant.Header.Gameobjects)]
@@ -52,8 +56,30 @@ namespace BITKit.Vehicles
private float horizontal;
private bool isBraking;
private readonly ValidHandle highSpeedHandle = new();
private IEntity _entity;
private void Start()
private IUnityEntity _unityEntity;
[Inject]
private IHealth _health;
public override void OnAwake()
{
base.OnAwake();
_health.OnSetAlive += OnSetAlive;
}
private void OnSetAlive(bool obj)
{
foreach (var x in objects)
{
x.SetActive(obj);
}
foreach (var x in destroyedObjects)
{
x.SetActive(!obj);
}
}
public override void OnStart()
{
highSpeedHandle.AddListener(x =>
{
@@ -69,8 +95,7 @@ namespace BITKit.Vehicles
});
highSpeedHandle.Invoke();
}
private void Update()
public override void OnUpdate(float deltaTime)
{
var torque = maxMotorTorque *(optionalVertical.Allow ? optionalVertical.Value : vertical);
var steel =maxSteeringAngle * (optionalHorizontal.Allow ? optionalHorizontal.Value : horizontal);