Первый коммит

This commit is contained in:
2024-04-20 11:16:35 +03:00
parent 284e0891d9
commit 2452b24ee5
5427 changed files with 4562744 additions and 0 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2d8812b7400d174419776a0c5239af75
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,227 @@
using UnityEngine;
using System.Collections;
using UnityEngine.InputSystem;
namespace RootMotion
{
public class CameraController : MonoBehaviour
{
[System.Serializable]
public enum UpdateMode
{
Update,
FixedUpdate,
LateUpdate,
FixedLateUpdate
}
public Transform target; // The target Transform to follow
//public Transform rotationSpace; // If assigned, will use this Transform's rotation as the rotation space instead of the world space. Useful with spherical planets.
public UpdateMode updateMode = UpdateMode.LateUpdate; // When to update the camera?
public bool lockCursor = true; // If true, the mouse will be locked to screen center and hidden
[Header("Position")]
public bool smoothFollow; // If > 0, camera will smoothly interpolate towards the target
public Vector3 offset = new Vector3(0, 1.5f, 0.5f); // The offset from target relative to camera rotation
public float followSpeed = 10f; // Smooth follow speed
[Header("Rotation")]
public float rotationSensitivity = 3.5f; // The sensitivity of rotation
public float yMinLimit = -20; // Min vertical angle
public float yMaxLimit = 80; // Max vertical angle
public bool rotateAlways = true; // Always rotate to mouse?
[Header("Distance")]
public float distance = 10.0f; // The current distance to target
public float minDistance = 4; // The minimum distance to target
public float maxDistance = 10; // The maximum distance to target
public float zoomSpeed = 10f; // The speed of interpolating the distance
public float zoomSensitivity = 1f; // The sensitivity of mouse zoom
[Header("Blocking")]
public LayerMask blockingLayers;
public float blockingRadius = 1f;
public float blockingSmoothTime = 0.1f;
public float blockingOriginOffset;
[Range(0f, 1f)] public float blockedOffset = 0.5f;
public float x { get; private set; } // The current x rotation of the camera
public float y { get; private set; } // The current y rotation of the camera
public float distanceTarget { get; private set; } // Get/set distance
private Vector3 targetDistance, position;
private Quaternion rotation = Quaternion.identity;
private Vector3 smoothPosition;
private Camera cam;
private bool fixedFrame;
private float fixedDeltaTime;
private Quaternion r = Quaternion.identity;
private Vector3 lastUp;
private float blockedDistance = 10f, blockedDistanceV;
//Rotation
public void SetAngles(Quaternion rotation)
{
Vector3 euler = rotation.eulerAngles;
this.x = euler.y;
this.y = euler.x;
}
public void SetAngles(float yaw, float pitch)
{
this.x = yaw;
this.y = pitch;
}
// Initiate, set the params to the current transformation of the camera relative to the target
protected virtual void Awake()
{
Vector3 angles = transform.eulerAngles;
x = angles.y;
y = angles.x;
distanceTarget = distance;
smoothPosition = transform.position;
cam = GetComponent<Camera>();
//_rotate = new Controller();
//_rotate.Player.CameraRotation.performed += context => UpdateInput();
//lastUp = rotationSpace != null ? rotationSpace.up : Vector3.up;
}
//private void OnEnable()
//{
// _rotate.Enable();
//}
//private void OnDisable()
//{
// _rotate.Disable();
//}
protected virtual void Update()
{
if (updateMode == UpdateMode.Update) UpdateTransform();
}
protected virtual void FixedUpdate()
{
fixedFrame = true;
fixedDeltaTime += Time.deltaTime;
if (updateMode == UpdateMode.FixedUpdate) UpdateTransform();
}
protected virtual void LateUpdate()
{
UpdateInput();
if (updateMode == UpdateMode.LateUpdate) UpdateTransform();
if (updateMode == UpdateMode.FixedLateUpdate && fixedFrame)
{
UpdateTransform(fixedDeltaTime);
fixedDeltaTime = 0f;
fixedFrame = false;
}
}
// Read the user input
public void UpdateInput()
{
if (!cam.enabled) return;
// Cursors
Cursor.lockState = lockCursor ? CursorLockMode.Locked : CursorLockMode.None;
Cursor.visible = lockCursor ? false : true;
// Should we rotate the camera?
bool rotate = rotateAlways;
// delta rotation
if (rotate)
{
// var _pass = _rotate.Player.CameraRotation.ReadValue<Vector2>();
//x += _pass.normalized.x;
//y = ClampAngle(y +_pass.normalized.y * rotationSensitivity, yMinLimit, yMaxLimit);
}
// Distance
distanceTarget = Mathf.Clamp(distanceTarget + zoomAdd, minDistance, maxDistance);
}
// Update the camera transform
public void UpdateTransform()
{
UpdateTransform(Time.deltaTime);
}
public void UpdateTransform(float deltaTime)
{
if (!cam.enabled) return;
// Rotation
//rotation = Quaternion.AngleAxis(x, Vector3.up) * Quaternion.AngleAxis(y, Vector3.right);
if (target != null)
{
// Distance
distance += (distanceTarget - distance) * zoomSpeed * deltaTime;
// Smooth follow
if (!smoothFollow) smoothPosition = target.position;
else smoothPosition = Vector3.Lerp(smoothPosition, target.position, deltaTime * followSpeed);
// Position
Vector3 t = smoothPosition + rotation * offset;
Vector3 f = rotation * -Vector3.forward;
if (blockingLayers != -1)
{
RaycastHit hit;
if (Physics.SphereCast(t - f * blockingOriginOffset, blockingRadius, f, out hit, blockingOriginOffset + distanceTarget - blockingRadius, blockingLayers))
{
blockedDistance = Mathf.SmoothDamp(blockedDistance, hit.distance + blockingRadius * (1f - blockedOffset) - blockingOriginOffset, ref blockedDistanceV, blockingSmoothTime);
}
else blockedDistance = distanceTarget;
distance = Mathf.Min(distance, blockedDistance);
}
position = t + f * distance;
// Translating the camera
transform.position = position;
}
transform.rotation = rotation;
}
// Zoom input
private float zoomAdd
{
get
{
float scrollAxis = Input.GetAxis("Mouse ScrollWheel");
if (scrollAxis > 0) return -zoomSensitivity;
if (scrollAxis < 0) return zoomSensitivity;
return 0;
}
}
// Clamping Euler angles
private float ClampAngle(float angle, float min, float max)
{
if (angle < -360) angle += 360;
if (angle > 360) angle -= 360;
return Mathf.Clamp(angle, min, max);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e341eaad837507147a3173befe82f713
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
Assets/Scripts/Car.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0c6c85fbd6a14ed409e35051fddd61b9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,19 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CarController : MonoBehaviour
{
#region Wheels
//
public Transform FrontLeftWheelTransform;
public Transform FrontRightWheelTransform;
public Transform RearLeftWheelTransform;
public Transform RearRightWheelTransform;
public Transform[] ExtraRearWheelTransform;
#endregion
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b1a1526faad80734d845657393bb0289
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Core : MonoBehaviour
{
#region Create WheelColliders
public void CreateWheelColliders(CarController carController)
{
List <Transform> allWheelModels = new List <Transform> ();
allWheelModels.Add (carController.FrontLeftWheelTransform);
}
#endregion
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4e1829d0d5b4c4144bf629b553d45a72
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,55 @@
using UnityEngine;
using System.Collections;
[ExecuteInEditMode()]
public class EasySuspension : MonoBehaviour {
[Range(0, 20)]
public float naturalFrequency = 10;
[Range(0, 3)]
public float dampingRatio = 0.8f;
[Range(-1, 1)]
public float forceShift = 0.03f;
public bool setSuspensionDistance = true;
void Update () {
// work out the stiffness and damper parameters based on the better spring model
foreach (WheelCollider wc in GetComponentsInChildren<WheelCollider>()) {
JointSpring spring = wc.suspensionSpring;
spring.spring = Mathf.Pow(Mathf.Sqrt(wc.sprungMass) * naturalFrequency, 2);
spring.damper = 2 * dampingRatio * Mathf.Sqrt(spring.spring * wc.sprungMass);
wc.suspensionSpring = spring;
Vector3 wheelRelativeBody = transform.InverseTransformPoint(wc.transform.position);
float distance = GetComponent<Rigidbody>().centerOfMass.y - wheelRelativeBody.y + wc.radius;
wc.forceAppPointDistance = distance - forceShift;
// the following line makes sure the spring force at maximum droop is exactly zero
if (spring.targetPosition > 0 && setSuspensionDistance)
wc.suspensionDistance = wc.sprungMass * Physics.gravity.magnitude / (spring.targetPosition * spring.spring);
}
}
// uncomment OnGUI to observe how parameters change
/*
public void OnGUI()
{
foreach (WheelCollider wc in GetComponentsInChildren<WheelCollider>()) {
GUILayout.Label (string.Format("{0} sprung: {1}, k: {2}, d: {3}", wc.name, wc.sprungMass, wc.suspensionSpring.spring, wc.suspensionSpring.damper));
}
var rb = GetComponent<Rigidbody> ();
GUILayout.Label ("Inertia: " + rb.inertiaTensor);
GUILayout.Label ("Mass: " + rb.mass);
GUILayout.Label ("Center: " + rb.centerOfMass);
}
*/
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3089a8970aaa5f24194f910c4b8428ec
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,23 @@
using UnityEngine;
class Finish : MonoBehaviour
{
[SerializeField] private GameObject Effects;
private void Start()
{
Effects.SetActive(false);
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player 1" || other.gameObject.tag == "Player 2")
{
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
Effects.SetActive(true);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 740b084a5b2918d479603cbf4fb1ac29
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,63 @@
using UnityEngine;
using System.Collections;
public class RearWheelDrive : MonoBehaviour {
private WheelCollider[] wheels;
public float maxAngle = 30;
public float maxTorque = 300;
public GameObject wheelShape;
// here we find all the WheelColliders down in the hierarchy
public void Start()
{
wheels = GetComponentsInChildren<WheelCollider>();
for (int i = 0; i < wheels.Length; ++i)
{
var wheel = wheels [i];
// create wheel shapes only when needed
if (wheelShape != null)
{
var ws = GameObject.Instantiate (wheelShape);
ws.transform.parent = wheel.transform;
}
}
}
// this is a really simple approach to updating wheels
// here we simulate a rear wheel drive car and assume that the car is perfectly symmetric at local zero
// this helps us to figure our which wheels are front ones and which are rear
public void Update()
{
float angle = maxAngle * Input.GetAxis("Horizontal");
float torque = maxTorque * Input.GetAxis("Vertical");
foreach (WheelCollider wheel in wheels)
{
// a simple car where front wheels steer while rear ones drive
if (wheel.transform.localPosition.z > 0)
wheel.steerAngle = angle;
if (wheel.transform.localPosition.z < 0)
wheel.motorTorque = torque;
// update visual wheels if any
if (wheelShape)
{
Quaternion q;
Vector3 p;
wheel.GetWorldPose (out p, out q);
// assume that the only child of the wheelcollider is the wheel shape
Transform shapeTransform = wheel.transform.GetChild (0);
shapeTransform.position = p;
shapeTransform.rotation = q;
shapeTransform.localScale = new Vector3(1, 1, 1);
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a315b19833d58ff49abead1689c81f47
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ae500b40028402740ad5d722bd47dabe
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ControlEffects : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2ecd6b9579651bb48b9d55df7fc27da2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,6 @@
static public class GameSetting
{
static public int SelectedMap = 1;
static public bool OnePlayer = true;
static public bool isNight = false;
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 35593ea8fc133ea4eb12258491be3327
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,10 @@
using UnityEngine;
using UnityEngine.SceneManagement;
public class ScriptBackToMenu : MonoBehaviour
{
public void BackToMenu()
{
SceneManager.LoadScene(0);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 002ea68226b389f489fcfc1c64cb80da
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,58 @@
using TMPro;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using System.Linq;
using UnityEngine.InputSystem.Utilities;
public class ScriptNumGamepad : MonoBehaviour
{
[SerializeField] private TextMeshProUGUI[] PlayerGamepad;
[SerializeField] private TextMeshProUGUI[] PlayerGamepadConnect;
private void Start()
{
ChangeGamepadInfo();
}
private void Update()
{
InputSystem.onDeviceChange +=
(device, change) =>
{
if ((device.name.Equals("Keyboard") || device.name.Equals("Mouse")) != true)
{
switch (change)
{
case InputDeviceChange.Added:
Debug.Log("Added");
ChangeGamepadInfo();
break;
case InputDeviceChange.Removed:
Debug.Log("Removed");
ChangeGamepadInfo();
break;
}
}
};
}
private void ChangeGamepadInfo()
{
var allGamepads = Gamepad.all;
for (int i = 0; i < PlayerGamepad.Length; i++)
{
try
{
PlayerGamepad[i].text = allGamepads[i].name;
PlayerGamepadConnect[i].text = "Connected";
}
catch
{
PlayerGamepad[i].text = "Disconnected";
PlayerGamepadConnect[i].text = "Disconnected";
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 981455c989641cb4e8163b4bd36021b7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,10 @@
using UnityEngine;
using UnityEngine.SceneManagement;
public class ScriptStartGame : MonoBehaviour
{
public void StartGame()
{
SceneManager.LoadScene(GameSetting.SelectedMap);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f33ddee681d6edc4b8256e368b7b7786
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 37e32468ad9546c468cf6e4a58bb8c00
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,38 @@
using TMPro;
using UnityEngine;
public class ScriptMenuChangeNumberPlayers : MonoBehaviour
{
private TextMeshProUGUI text;
private void Awake()
{
text = gameObject.GetComponentInChildren<TextMeshProUGUI>();
}
private void Start()
{
if (GameSetting.OnePlayer)
{
text.text = "One Player";
}
else
{
text.text = "Two Player";
}
}
public void ChageNumberPlayersScript()
{
if (GameSetting.OnePlayer)
{
GameSetting.OnePlayer = false;
text.text = "Two Player";
}
else
{
GameSetting.OnePlayer = true;
text.text = "One Player";
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b6f64385e1cc12c41af39593bc7f68bb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,38 @@
using TMPro;
using UnityEngine;
public class ScriptMenuChangeTime : MonoBehaviour
{
private TextMeshProUGUI text;
private void Awake()
{
text = gameObject.GetComponentInChildren<TextMeshProUGUI>();
}
private void Start()
{
if (GameSetting.isNight)
{
text.text = "Night";
}
else
{
text.text = "Day";
}
}
public void ChageNumberChangeTime()
{
if (GameSetting.isNight)
{
GameSetting.isNight = true;
text.text = "Night";
}
else
{
GameSetting.isNight = false;
text.text = "Day";
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7e76c0215d817f7499896759a4f6c314
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,9 @@
using UnityEngine;
public class ScriptMenuExitGame : MonoBehaviour
{
public void Exit()
{
Application.Quit();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e5e27c6445fe31c44809d2e2ae894700
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,53 @@
using UnityEngine;
using UnityEngine.UI;
public class ScriptSelectMap : MonoBehaviour
{
[SerializeField] private Sprite [] images;
private Image currentImage;
private int maxNum;
private void Awake()
{
maxNum = images.Length;
currentImage = gameObject.GetComponent<Image>();
}
private void Start()
{
// todo
// придумать как убрать -1
ChangeMap();
}
private void ChangeMap()
{
currentImage.sprite = images[GameSetting.SelectedMap - 1];
}
public void ChangePlus()
{
if (GameSetting.SelectedMap == maxNum)
{
GameSetting.SelectedMap = 1;
}
else
{
GameSetting.SelectedMap++;
}
ChangeMap();
}
public void ChangeMinus()
{
if (GameSetting.SelectedMap == 1)
{
GameSetting.SelectedMap = maxNum;
}
else
{
GameSetting.SelectedMap--;
}
ChangeMap();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d2a1ac716f6f76544b3ea66128b6e25b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 782c640615299f84c91add17712cb5d3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,61 @@
using UnityEngine;
using UnityEditor;
using System.Collections;
class BoxyCarWizard : EditorWindow {
private int axlesCount = 2;
private float mass = 1000;
private float axleStep = 2;
private float axleWidth = 2;
private float axleShift = -0.5f;
[MenuItem ("Vehicles/Boxy car wizard")]
public static void ShowWindow () {
EditorWindow.GetWindow(typeof(BoxyCarWizard));
}
void OnGUI () {
axlesCount = EditorGUILayout.IntSlider ("Axles: ", axlesCount, 2, 10);
mass = EditorGUILayout.FloatField ("Mass: ", mass);
axleStep = EditorGUILayout.FloatField ("Axle step: ", axleStep);
axleWidth = EditorGUILayout.FloatField ("Axle width: ", axleWidth);
axleShift = EditorGUILayout.FloatField ("Axle shift: ", axleShift);
if (GUILayout.Button("Generate")) {
CreateCar ();
}
}
void CreateCar()
{
var root = new GameObject ("carRoot");
var rootBody = root.AddComponent<Rigidbody> ();
rootBody.mass = mass;
var body = GameObject.CreatePrimitive (PrimitiveType.Cube);
body.transform.parent = root.transform;
float length = (axlesCount - 1) * axleStep;
float firstOffset = length / 2;
body.transform.localScale = new Vector3(axleWidth, 1, length);
for (int i = 0; i < axlesCount; ++i)
{
var leftWheel = new GameObject (string.Format("a{0}l", i));
var rightWheel = new GameObject (string.Format("a{0}r", i));
leftWheel.AddComponent<WheelCollider> ();
rightWheel.AddComponent<WheelCollider> ();
leftWheel.transform.parent = root.transform;
rightWheel.transform.parent = root.transform;
leftWheel.transform.localPosition = new Vector3 (-axleWidth / 2, axleShift, firstOffset - axleStep * i);
rightWheel.transform.localPosition = new Vector3 (axleWidth / 2, axleShift, firstOffset - axleStep * i);
}
root.AddComponent<EasySuspension>();
root.AddComponent<RearWheelDrive>();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d11ca71fba2b56547b7adb0a99b82031
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: