55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
using System;
|
|
using DamageSystem;
|
|
using UnityEngine;
|
|
using VRSDK;
|
|
|
|
namespace VRBeats
|
|
{
|
|
public class DamageSaber : VR_MeleeWeapon
|
|
{
|
|
[SerializeField] private ColorSide colorSide;
|
|
|
|
private VR_Controller controller;
|
|
|
|
private void Start()
|
|
{
|
|
ResolveController();
|
|
}
|
|
|
|
protected override DamageInfo CreateDamageInfo(Vector3 hitPoint)
|
|
{
|
|
ResolveController();
|
|
|
|
var damageInfo = base.CreateDamageInfo(hitPoint);
|
|
BeatDamageInfo beatDamageInfo = new BeatDamageInfo(damageInfo);
|
|
|
|
Vector3 controllerVelocity = controller != null ? controller.Velocity : Vector3.zero;
|
|
|
|
beatDamageInfo.hitForce = Mathf.Min((controllerVelocity * hitForce).magnitude, maxHitForce);
|
|
beatDamageInfo.hitObject = gameObject;
|
|
beatDamageInfo.colorSide = colorSide;
|
|
beatDamageInfo.velocity = controllerVelocity.magnitude;
|
|
|
|
return beatDamageInfo;
|
|
}
|
|
|
|
private void ResolveController()
|
|
{
|
|
VR_Grabbable grabbable = GetComponent<VR_Grabbable>();
|
|
if (grabbable != null && grabbable.GrabController != null)
|
|
{
|
|
controller = grabbable.GrabController;
|
|
colorSide = controller.ControllerType == VR_ControllerType.Right ? ColorSide.Right : ColorSide.Left;
|
|
return;
|
|
}
|
|
|
|
if (VR_Manager.instance == null || VR_Manager.instance.Player == null)
|
|
return;
|
|
|
|
controller = colorSide == ColorSide.Left
|
|
? VR_Manager.instance.Player.LeftController
|
|
: VR_Manager.instance.Player.RightController;
|
|
}
|
|
}
|
|
}
|