You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
250 lines
6.8 KiB
C#
250 lines
6.8 KiB
C#
|
4 years ago
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine.UI;
|
||
|
|
using UnityEngine;
|
||
|
|
using SiegeSong;
|
||
|
|
|
||
|
|
namespace SiegeSong
|
||
|
|
{
|
||
|
4 years ago
|
public class Motor : MonoBehaviour
|
||
|
4 years ago
|
{
|
||
|
|
public Animator Animator;
|
||
|
|
public EquipmentManager EquipmentManager;
|
||
|
4 years ago
|
public StatisticsManager Actor;
|
||
|
4 years ago
|
|
||
|
|
public float BaseSpeed = 1.0f;
|
||
|
|
public bool Swimming;
|
||
|
|
//public float TopSpeed;
|
||
|
|
//public float Acceleration;
|
||
|
|
|
||
|
|
public float NonAnimatedSpeedMult = 0.1f;
|
||
|
|
public bool Animated = true;
|
||
|
|
public bool Sprinting = false;
|
||
|
|
public bool Moving = false;
|
||
|
|
|
||
|
|
public bool UsingStation;
|
||
|
|
public Station TargetStation;
|
||
|
|
|
||
|
4 years ago
|
public bool DriveForward;
|
||
|
|
public bool DriveBackward;
|
||
|
|
public bool DriveLeft;
|
||
|
|
public bool DriveRight;
|
||
|
|
public bool DriveRotateLeft;
|
||
|
|
public bool DriveRotateRight;
|
||
|
|
|
||
|
4 years ago
|
#region Animation Fields
|
||
|
|
|
||
|
|
private string AnimationStaggerField = "Stagger";
|
||
|
|
private string AnimationVerticalField = "InputVertical";
|
||
|
|
private string AnimationHorizontalField = "InputHorizontal";
|
||
|
|
private string AnimationMagnitudeField = "InputMagnitude";
|
||
|
|
|
||
|
|
private string MountingAnimationIdVariableName = "MountType";
|
||
|
|
private string MountingStartVariableName = "MountingStart";
|
||
|
|
private string MountingEndVariableName = "MountingEnd";
|
||
|
|
private string MountingActiveVariableName = "Mounted";
|
||
|
|
|
||
|
|
#endregion
|
||
|
4 years ago
|
|
||
|
|
|
||
|
4 years ago
|
private float sprintMagnitude = 1.5f;
|
||
|
4 years ago
|
|
||
|
4 years ago
|
private float currentMoveSpeed;
|
||
|
4 years ago
|
|
||
|
|
|
||
|
|
void Start()
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
void Update()
|
||
|
|
{
|
||
|
4 years ago
|
Animator.enabled = Actor.Stats.Alive;
|
||
|
|
Animated = Actor.Stats.Alive;
|
||
|
|
if (Actor.Stats.Alive)
|
||
|
4 years ago
|
{
|
||
|
4 years ago
|
if (Actor.Stats.Staggered)
|
||
|
4 years ago
|
{
|
||
|
|
Animator.SetTrigger(AnimationStaggerField);
|
||
|
4 years ago
|
Actor.Stats.Staggered = false;
|
||
|
4 years ago
|
}
|
||
|
|
if (Sprinting)
|
||
|
|
{
|
||
|
|
Animator.SetFloat(AnimationMagnitudeField, 1.5f);
|
||
|
4 years ago
|
if (Actor.Stats.Stamina <= 0)
|
||
|
4 years ago
|
Sprinting = false;
|
||
|
|
else
|
||
|
4 years ago
|
Actor.ExpendStamina(Actor.Stats.StaminaRecoveryRate + Actor.Stats.SprintCost);
|
||
|
4 years ago
|
}
|
||
|
|
}
|
||
|
4 years ago
|
|
||
|
|
if (DriveForward)
|
||
|
|
Run(BaseSpeed / 2.0f);
|
||
|
|
|
||
|
|
if (DriveBackward)
|
||
|
|
Run(-BaseSpeed);
|
||
|
|
|
||
|
|
if (DriveLeft)
|
||
|
|
Strafe(-BaseSpeed);
|
||
|
|
|
||
|
|
if (DriveRight)
|
||
|
|
Strafe(BaseSpeed);
|
||
|
|
|
||
|
|
if (DriveRotateLeft)
|
||
|
|
Rotate(-BaseSpeed);
|
||
|
|
|
||
|
|
if (DriveRotateRight)
|
||
|
|
Rotate(BaseSpeed);
|
||
|
4 years ago
|
}
|
||
|
|
|
||
|
|
public void Stop()
|
||
|
|
{
|
||
|
|
currentMoveSpeed = 0.0f;
|
||
|
|
Animator.SetFloat(AnimationMagnitudeField, 0);
|
||
|
|
Moving = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Run(float value)
|
||
|
|
{
|
||
|
|
if (!UsingStation)
|
||
|
|
{
|
||
|
|
Moving = true;
|
||
|
|
transform.Translate(Vector3.forward * value * BaseSpeed * Time.deltaTime);
|
||
|
|
if (Animated)
|
||
|
|
{
|
||
|
|
Animator.SetFloat(AnimationVerticalField, value);
|
||
|
|
Animator.SetFloat(AnimationMagnitudeField, BaseSpeed);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void StartSprint()
|
||
|
|
{
|
||
|
4 years ago
|
if (Actor.Stats.Stamina > 0)
|
||
|
4 years ago
|
{
|
||
|
|
Sprinting = true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Strafe(float value, bool rotateInPlace = false)
|
||
|
|
{
|
||
|
|
if (!UsingStation)
|
||
|
|
{
|
||
|
|
Moving = true;
|
||
|
|
if (!rotateInPlace)
|
||
|
|
transform.Translate(-Vector3.left * value * BaseSpeed * Time.deltaTime);
|
||
|
|
if (Animated)
|
||
|
|
{
|
||
|
|
Animator.SetFloat(AnimationHorizontalField, rotateInPlace ? 1 : value);
|
||
|
|
Animator.SetFloat(AnimationMagnitudeField, BaseSpeed);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Jump()
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Crouch()
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Rotate(float value)
|
||
|
|
{
|
||
|
4 years ago
|
RotateToDirection(new Vector3(transform.eulerAngles.x, transform.eulerAngles.y + value, transform.eulerAngles.z));
|
||
|
4 years ago
|
}
|
||
|
|
|
||
|
|
public void RotateToDirection(Vector3 direction, bool onlyHead = true)
|
||
|
|
{
|
||
|
|
if (!UsingStation)
|
||
|
4 years ago
|
{
|
||
|
4 years ago
|
transform.rotation = Quaternion.Euler(new Vector3(transform.eulerAngles.x, direction.y, transform.eulerAngles.z));
|
||
|
4 years ago
|
if (Animated)
|
||
|
|
{
|
||
|
|
Animator.SetFloat(AnimationHorizontalField, direction.x > 0 ? 1 : -1);
|
||
|
|
Animator.SetFloat(AnimationMagnitudeField, BaseSpeed);
|
||
|
|
}
|
||
|
|
}
|
||
|
4 years ago
|
}
|
||
|
|
|
||
|
|
public void StartUsingStation(Station target)
|
||
|
|
{
|
||
|
|
TargetStation = target;
|
||
|
|
|
||
|
|
UsingStation = true;
|
||
|
|
|
||
|
|
transform.position = target.MountingAnchor.position;
|
||
|
|
transform.rotation = target.MountingAnchor.rotation;
|
||
|
|
|
||
|
|
Animator.SetInteger(MountingAnimationIdVariableName, target.MountingAnimationID);
|
||
|
|
Animator.SetTrigger(MountingStartVariableName);
|
||
|
|
Animator.SetBool(MountingActiveVariableName, true);
|
||
|
|
|
||
|
|
if (target.StartMounting != null)
|
||
|
|
target.StartMounting.Invoke();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void StopUsingStation(Station target)
|
||
|
|
{
|
||
|
|
UsingStation = false;
|
||
|
|
|
||
|
|
Animator.SetInteger(MountingAnimationIdVariableName, 0);
|
||
|
|
Animator.SetTrigger(MountingEndVariableName);
|
||
|
|
Animator.SetBool(MountingActiveVariableName, false);
|
||
|
|
|
||
|
|
transform.eulerAngles = new Vector3(0.0f, 0.0f, 0.0f);
|
||
|
|
|
||
|
|
if (TargetStation.EndMounting != null)
|
||
|
|
TargetStation.EndMounting.Invoke();
|
||
|
|
TargetStation = null;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void NextLeftEquip()
|
||
|
|
{
|
||
|
|
EquipmentManager.NextLeftEquip();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void NextLeftTechnique()
|
||
|
|
{
|
||
|
|
EquipmentManager.NextLeftTechnique();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void NextRightEquip()
|
||
|
|
{
|
||
|
|
EquipmentManager.NextRightEquip();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void NextRightTechnique()
|
||
|
|
{
|
||
|
|
EquipmentManager.NextRightTechnique();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void NextAbilityEquip()
|
||
|
|
{
|
||
|
|
EquipmentManager.NextAbilityEquip();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void NextAbilityTechnique()
|
||
|
|
{
|
||
|
|
EquipmentManager.NextAbilityTechnique();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void UseLeft()
|
||
|
|
{
|
||
|
|
EquipmentManager.UseLeft();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void UseAbility()
|
||
|
|
{
|
||
|
|
EquipmentManager.UseAbility();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void UseRight()
|
||
|
|
{
|
||
|
|
EquipmentManager.UseRight();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|