Merge branch 'master' of ooftooft.net:Racesm
# Conflicts: # Assets/ML-Agents/Timers/Car Customization_timers.json # Assets/ML-Agents/Timers/Racetrack mini_timers.jsonT
This commit is contained in:
146
Assets/Scripts/CameraControl.cs
Normal file
146
Assets/Scripts/CameraControl.cs
Normal file
@@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
//script from FREAKINGREX, but minor changes to integrate it proberly
|
||||
//https://assetstore.unity.com/packages/templates/systems/arcade-car-controller-lite-version-145489
|
||||
|
||||
public class CameraControl :MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] KeyCode SetCameraKey = KeyCode.C; //Set next camore on PC hotkey.
|
||||
[SerializeField] UnityEngine.UI.Button NextCameraButton;
|
||||
[SerializeField] List<CameraPreset> CamerasPreset = new List<CameraPreset>(); //Camera presets
|
||||
|
||||
int ActivePresetIndex = 0;
|
||||
CameraPreset ActivePreset;
|
||||
public GameObject Loader;
|
||||
public GameObject TargetCar;
|
||||
GameController GameController { get { return GameController.Instance; } }
|
||||
|
||||
float SqrMinDistance;
|
||||
|
||||
Vector3 TargetPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
if (TargetCar == null)
|
||||
{
|
||||
return transform.position;
|
||||
}
|
||||
Rigidbody carRB = TargetCar.GetComponent<Rigidbody>();
|
||||
Vector3 result = carRB.velocity * ActivePreset.VelocityMultiplier*0.05f;
|
||||
result += TargetCar.transform.position;
|
||||
result.y = 0;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public void getCar(GameObject car)
|
||||
{
|
||||
TargetCar = car;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void Awake() {
|
||||
CamerasPreset.ForEach (c => c.CameraHolder.SetActive(false));
|
||||
UpdateActiveCamera ();
|
||||
|
||||
//TargetCar = Loader.GetComponent<CarLoader>().targetcar;
|
||||
|
||||
if (NextCameraButton)
|
||||
{
|
||||
NextCameraButton.onClick.AddListener (SetNextCamera);
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate ()
|
||||
{
|
||||
if (ActivePreset.EnableRotation && (TargetPoint - transform.position).sqrMagnitude >= SqrMinDistance)
|
||||
{
|
||||
Quaternion rotation = Quaternion.LookRotation (TargetPoint - transform.position, Vector3.up);
|
||||
ActivePreset.CameraHolder.transform.rotation = Quaternion.Lerp (ActivePreset.CameraHolder.transform.rotation, rotation, Time.deltaTime * ActivePreset.SetRotationSpeed);
|
||||
}
|
||||
|
||||
transform.position = Vector3.LerpUnclamped (transform.position, TargetPoint, Time.deltaTime * ActivePreset.SetPositionSpeed);
|
||||
|
||||
if (Input.GetKeyDown (SetCameraKey))
|
||||
{
|
||||
SetNextCamera ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private IEnumerator Start ()
|
||||
{
|
||||
// TargetCar = Loader.GetComponent<CarLoader>().targetcar;
|
||||
|
||||
while (GameController == null)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
transform.position = TargetPoint;
|
||||
}
|
||||
|
||||
public void SetNextCamera ()
|
||||
{
|
||||
ActivePresetIndex = LoopClamp (ActivePresetIndex + 1, 0, CamerasPreset.Count);
|
||||
UpdateActiveCamera ();
|
||||
}
|
||||
|
||||
public static int LoopClamp (int value, int minValue, int maxValue)
|
||||
{
|
||||
while (value < minValue || value >= maxValue)
|
||||
{
|
||||
if (value < minValue)
|
||||
{
|
||||
value += maxValue - minValue;
|
||||
}
|
||||
else if (value >= maxValue)
|
||||
{
|
||||
value -= maxValue - minValue;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public void UpdateActiveCamera ()
|
||||
{
|
||||
if (ActivePreset != null)
|
||||
{
|
||||
ActivePreset.CameraHolder.SetActive(false);
|
||||
}
|
||||
|
||||
ActivePreset = CamerasPreset[ActivePresetIndex];
|
||||
ActivePreset.CameraHolder.SetActive(true);
|
||||
|
||||
SqrMinDistance = ActivePreset.MinDistanceForRotation * 2;
|
||||
|
||||
if (ActivePreset.EnableRotation && (TargetPoint - transform.position).sqrMagnitude >= SqrMinDistance)
|
||||
{
|
||||
Quaternion rotation = Quaternion.LookRotation (TargetPoint - transform.position, Vector3.up);
|
||||
ActivePreset.CameraHolder.transform.rotation = rotation;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[System.Serializable]
|
||||
|
||||
class CameraPreset
|
||||
{
|
||||
public GameObject CameraHolder;
|
||||
public float SetPositionSpeed = 1; //Change position speed.
|
||||
public float VelocityMultiplier; //Velocity of car multiplier.
|
||||
|
||||
public bool EnableRotation;
|
||||
public float MinDistanceForRotation = 0.1f; //Min distance for potation, To avoid uncontrolled rotation.
|
||||
public float SetRotationSpeed = 1; //Change rotation speed.
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/CameraControl.cs.meta
Normal file
11
Assets/Scripts/CameraControl.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa5b7c6348736da45b5cb01d41f7b6fe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -10,7 +10,9 @@ public class CarLoader : MonoBehaviour
|
||||
string carType;
|
||||
string carColor;
|
||||
public Material[] Colors;
|
||||
public CinemachineVirtualCamera vcam;
|
||||
public GameObject cam;
|
||||
|
||||
public GameObject targetcar;
|
||||
void Start()
|
||||
{
|
||||
carType = GameObject.Find("Car Data").GetComponent<CarData>().carType;
|
||||
@@ -30,8 +32,8 @@ public class CarLoader : MonoBehaviour
|
||||
car.GetComponent<carcontrolv2>().enabled = true;
|
||||
car.GetComponent<AgentControllerV6>().enabled = false;
|
||||
|
||||
vcam.Follow = car.transform;
|
||||
vcam.LookAt = car.transform;
|
||||
cam.GetComponent<CameraControl>().getCar(car);
|
||||
//LookAt = car.transform;
|
||||
|
||||
if (color == "Default")
|
||||
{
|
||||
|
||||
97
Assets/Scripts/GameController.cs
Normal file
97
Assets/Scripts/GameController.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Base class game controller.
|
||||
/// </summary>
|
||||
public class GameController :MonoBehaviour
|
||||
{
|
||||
[SerializeField] KeyCode NextCarKey = KeyCode.N;
|
||||
[SerializeField] UnityEngine.UI.Button NextCarButton;
|
||||
public static GameController Instance;
|
||||
public GameObject PlayerCar;
|
||||
public static bool RaceIsStarted { get { return true; } }
|
||||
public static bool RaceIsEnded { get { return false; } }
|
||||
|
||||
carcontrolv2 m_PlayerCar;
|
||||
List<carcontrolv2> Cars = new List<carcontrolv2>();
|
||||
int CurrentCarIndex = 0;
|
||||
|
||||
protected virtual void Awake ()
|
||||
{
|
||||
|
||||
Instance = this;
|
||||
|
||||
//Find all cars in current game.
|
||||
Cars.AddRange (GameObject.FindObjectsOfType<carcontrolv2> ());
|
||||
Cars = Cars.OrderBy (c => c.name).ToList();
|
||||
|
||||
foreach (var car in Cars)
|
||||
{
|
||||
var userControl = car.GetComponent<carcontrolv2>();
|
||||
var audioListener = car.GetComponent<AudioListener>();
|
||||
|
||||
if (userControl == null)
|
||||
{
|
||||
userControl = car.gameObject.AddComponent<carcontrolv2> ();
|
||||
}
|
||||
|
||||
if (audioListener == null)
|
||||
{
|
||||
audioListener = car.gameObject.AddComponent<AudioListener> ();
|
||||
}
|
||||
|
||||
userControl.enabled = false;
|
||||
audioListener.enabled = false;
|
||||
}
|
||||
|
||||
m_PlayerCar = Cars[0];
|
||||
m_PlayerCar.GetComponent<carcontrolv2> ().enabled = true;
|
||||
m_PlayerCar.GetComponent<AudioListener> ().enabled = true;
|
||||
|
||||
if (NextCarButton)
|
||||
{
|
||||
NextCarButton.onClick.AddListener (NextCar);
|
||||
}
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (Input.GetKeyDown (NextCarKey))
|
||||
{
|
||||
NextCar ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void NextCar ()
|
||||
{
|
||||
m_PlayerCar.GetComponent<carcontrolv2> ().enabled = false;
|
||||
m_PlayerCar.GetComponent<AudioListener> ().enabled = false;
|
||||
|
||||
CurrentCarIndex = LoopClamp (CurrentCarIndex + 1, 0, Cars.Count);
|
||||
|
||||
m_PlayerCar = Cars[CurrentCarIndex];
|
||||
m_PlayerCar.GetComponent<carcontrolv2> ().enabled = true;
|
||||
m_PlayerCar.GetComponent<AudioListener> ().enabled = true;
|
||||
}
|
||||
|
||||
public static int LoopClamp (int value, int minValue, int maxValue)
|
||||
{
|
||||
while (value < minValue || value >= maxValue)
|
||||
{
|
||||
if (value < minValue)
|
||||
{
|
||||
value += maxValue - minValue;
|
||||
}
|
||||
else if (value >= maxValue)
|
||||
{
|
||||
value -= maxValue - minValue;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GameController.cs.meta
Normal file
11
Assets/Scripts/GameController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b00fe924fac7ccc488443310caf9e5b9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -111,11 +111,11 @@ public class carcontrolv2 : MonoBehaviour
|
||||
}
|
||||
|
||||
//idk camera mobning rammer hårdt
|
||||
float THINP = hInput/10;
|
||||
if (THINP != hInput)
|
||||
{
|
||||
THINP+=hInput/10;
|
||||
}
|
||||
// float THINP = hInput/10;
|
||||
// if (THINP != hInput)
|
||||
// {
|
||||
// THINP+=hInput/10;
|
||||
// }
|
||||
|
||||
|
||||
//lookat.transform.localPosition = new Vector3 (THINP*1.5f,1,4);
|
||||
|
||||
93
Assets/Scripts/gameController1.cs
Normal file
93
Assets/Scripts/gameController1.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class gameController1 : MonoBehaviour
|
||||
{
|
||||
[SerializeField] KeyCode NextCarKey = KeyCode.N;
|
||||
[SerializeField] UnityEngine.UI.Button NextCarButton;
|
||||
public static gameController1 Instance;
|
||||
public GameObject PlayerCar;
|
||||
public static bool RaceIsStarted { get { return true; } }
|
||||
public static bool RaceIsEnded { get { return false; } }
|
||||
|
||||
carcontrolv2 m_PlayerCar;
|
||||
List<carcontrolv2> Cars = new List<carcontrolv2>();
|
||||
int CurrentCarIndex = 0;
|
||||
|
||||
protected virtual void Awake ()
|
||||
{
|
||||
|
||||
Instance = this;
|
||||
|
||||
//Find all cars in current game.
|
||||
Cars.AddRange (GameObject.FindObjectsOfType<carcontrolv2> ());
|
||||
Cars = Cars.OrderBy(c => c.name).ToList();
|
||||
|
||||
foreach (var car in Cars)
|
||||
{
|
||||
var userControl = car.GetComponent<carcontrolv2>();
|
||||
var audioListener = car.GetComponent<AudioListener>();
|
||||
|
||||
if (userControl == null)
|
||||
{
|
||||
userControl = car.gameObject.AddComponent<carcontrolv2> ();
|
||||
}
|
||||
|
||||
if (audioListener == null)
|
||||
{
|
||||
audioListener = car.gameObject.AddComponent<AudioListener> ();
|
||||
}
|
||||
|
||||
userControl.enabled = false;
|
||||
audioListener.enabled = false;
|
||||
}
|
||||
|
||||
m_PlayerCar = Cars[0];
|
||||
m_PlayerCar.GetComponent<carcontrolv2> ().enabled = true;
|
||||
m_PlayerCar.GetComponent<AudioListener> ().enabled = true;
|
||||
|
||||
if (NextCarButton)
|
||||
{
|
||||
NextCarButton.onClick.AddListener (NextCar);
|
||||
}
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (Input.GetKeyDown (NextCarKey))
|
||||
{
|
||||
NextCar ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void NextCar ()
|
||||
{
|
||||
m_PlayerCar.GetComponent<carcontrolv2> ().enabled = false;
|
||||
m_PlayerCar.GetComponent<AudioListener> ().enabled = false;
|
||||
|
||||
CurrentCarIndex = LoopClamp (CurrentCarIndex + 1, 0, Cars.Count);
|
||||
|
||||
m_PlayerCar = Cars[CurrentCarIndex];
|
||||
m_PlayerCar.GetComponent<carcontrolv2> ().enabled = true;
|
||||
m_PlayerCar.GetComponent<AudioListener> ().enabled = true;
|
||||
}
|
||||
|
||||
public static int LoopClamp (int value, int minValue, int maxValue)
|
||||
{
|
||||
while (value < minValue || value >= maxValue)
|
||||
{
|
||||
if (value < minValue)
|
||||
{
|
||||
value += maxValue - minValue;
|
||||
}
|
||||
else if (value >= maxValue)
|
||||
{
|
||||
value -= maxValue - minValue;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/gameController1.cs.meta
Normal file
11
Assets/Scripts/gameController1.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00a8679451d95a34bb31f80049ae6415
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user