initial commit
This commit is contained in:
8
Assets/Scripts/Lesson_1.meta
Normal file
8
Assets/Scripts/Lesson_1.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 935a3af4c5fcb7c4b888179a16d74670
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
107
Assets/Scripts/Lesson_1/AmyRunScript.cs
Normal file
107
Assets/Scripts/Lesson_1/AmyRunScript.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(CharacterController))]
|
||||
public class AmyRunScript : MonoBehaviour
|
||||
{
|
||||
[Header("Amy Properties")]
|
||||
public float runSpeed = 10f;
|
||||
public float runSpeedOnRadiusOffset = 100f;
|
||||
public float angle = 0f;
|
||||
public float startAngle = 0f;
|
||||
public TMP_Text speedText;
|
||||
|
||||
private CharacterController characterController;
|
||||
private Animator animator;
|
||||
private bool isRunning = false;
|
||||
|
||||
|
||||
[Header("Runline")]
|
||||
public RunlinePlacer runline;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
characterController = GetComponent<CharacterController>();
|
||||
animator = GetComponent<Animator>();
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
SetAmyRandomSpeed();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!gameObject.activeSelf) return;
|
||||
if(isRunning) MoveAmyOnTrack();
|
||||
animator.SetBool("isRunning", isRunning);
|
||||
}
|
||||
|
||||
private void MoveAmyOnTrack()
|
||||
{
|
||||
angle += (runSpeed / runSpeedOnRadiusOffset) * Time.deltaTime;
|
||||
|
||||
float x = Mathf.Cos(angle) * runline.radiusX;
|
||||
float z = Mathf.Sin(angle) * runline.radiusZ;
|
||||
|
||||
Vector3 targetPos = new Vector3(x, runline.center.y, z);
|
||||
|
||||
Vector3 direction = targetPos - transform.position;
|
||||
characterController.Move(direction);
|
||||
|
||||
if (direction != Vector3.zero)
|
||||
{
|
||||
transform.rotation = Quaternion.LookRotation(direction);
|
||||
}
|
||||
}
|
||||
|
||||
public void StartRun()
|
||||
{
|
||||
isRunning = true;
|
||||
}
|
||||
|
||||
public void StopRun()
|
||||
{
|
||||
isRunning = false;
|
||||
}
|
||||
|
||||
public void SetAngle(float newAngle)
|
||||
{
|
||||
angle = newAngle;
|
||||
MoveAmyOnTrack();
|
||||
StopRun();
|
||||
}
|
||||
|
||||
public void PlaceOnStartAngle()
|
||||
{
|
||||
angle = startAngle;
|
||||
transform.rotation = new Quaternion(0f, transform.rotation.y, transform.rotation.z, 0f);
|
||||
SetSpeedText();
|
||||
MoveAmyOnTrack();
|
||||
StopRun();
|
||||
}
|
||||
|
||||
[ContextMenu("Set Amy random speed")]
|
||||
public void SetAmyRandomSpeed()
|
||||
{
|
||||
runSpeed = Random.Range(8, 15);
|
||||
}
|
||||
|
||||
|
||||
private void OnTriggerEnter(Collider collider)
|
||||
{
|
||||
if (collider.gameObject.tag == "Endline" && Lesson1Controller.Instance.activeExperiment == 2) ExperimentChooser.Instance.experiment3Button.interactable = true;
|
||||
}
|
||||
|
||||
private void SetSpeedText()
|
||||
{
|
||||
if (Lesson1Controller.Instance.activeExperiment != 2)
|
||||
{
|
||||
speedText.text = "SPEED: " + runSpeed.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
speedText.text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
Assets/Scripts/Lesson_1/AmyRunScript.cs.meta
Normal file
11
Assets/Scripts/Lesson_1/AmyRunScript.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7e7a0b02bdc64641a22e1a69e1c073c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Assets/Scripts/Lesson_1/ApplyDissolveShaderToTerrain.cs
Normal file
35
Assets/Scripts/Lesson_1/ApplyDissolveShaderToTerrain.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent (typeof(Terrain))]
|
||||
public class ApplyDissolveShaderToTerrain : MonoBehaviour
|
||||
{
|
||||
public Terrain terrain;
|
||||
public float dissolveAmount = 0f;
|
||||
public Shader shader;
|
||||
|
||||
private Material originalMaterial;
|
||||
private Material overrideMaterial;
|
||||
|
||||
void Start()
|
||||
{
|
||||
terrain = GetComponent<Terrain>();
|
||||
overrideMaterial = new Material(shader);
|
||||
originalMaterial = terrain.materialTemplate;
|
||||
SetOriginalMaterial();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
terrain.materialTemplate.SetFloat("_dissolveAmount", dissolveAmount);
|
||||
}
|
||||
|
||||
public void SetOriginalMaterial()
|
||||
{
|
||||
terrain.materialTemplate = originalMaterial;
|
||||
}
|
||||
|
||||
public void SetOverrideMaterial()
|
||||
{
|
||||
terrain.materialTemplate = overrideMaterial;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lesson_1/ApplyDissolveShaderToTerrain.cs.meta
Normal file
11
Assets/Scripts/Lesson_1/ApplyDissolveShaderToTerrain.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 421c37adf7a9c7d48abfd35f612c44a5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
79
Assets/Scripts/Lesson_1/DrawDistanceLine.cs
Normal file
79
Assets/Scripts/Lesson_1/DrawDistanceLine.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(LineRenderer))]
|
||||
public class DrawDistanceLine : MonoBehaviour
|
||||
{
|
||||
private float radiusX;
|
||||
private float radiusZ;
|
||||
|
||||
private float startAngle;
|
||||
private float endAngle;
|
||||
|
||||
[Header("ßê³ñòü äóãè")]
|
||||
public int segments = 50;
|
||||
|
||||
[Header("Öåíòð äóãè")]
|
||||
private Vector3 center;
|
||||
|
||||
[Header("²íôîðìàö³ÿ (ò³ëüêè äëÿ ÷èòàííÿ)")]
|
||||
[SerializeField] private float arcLength = 0f;
|
||||
|
||||
private LineRenderer lineRenderer;
|
||||
|
||||
void Start()
|
||||
{
|
||||
radiusX = GetComponent<RunlinePlacer>().radiusX;
|
||||
radiusZ = GetComponent<RunlinePlacer>().radiusZ;
|
||||
center = GetComponent<RunlinePlacer>().center;
|
||||
|
||||
lineRenderer = GetComponent<LineRenderer>();
|
||||
|
||||
lineRenderer.startColor = new Color(1f, 1f, 1f);
|
||||
lineRenderer.endColor = new Color(1f, 1f, 1f);
|
||||
lineRenderer.startWidth = 1f;
|
||||
lineRenderer.endWidth = 1f;
|
||||
lineRenderer.useWorldSpace = true;
|
||||
lineRenderer.material = new Material(Shader.Find("Sprites/Default"));
|
||||
}
|
||||
|
||||
public void DrawDistanceArc()
|
||||
{
|
||||
|
||||
startAngle = GetComponent<RunlinePlacer>().GetStartLineAngle();
|
||||
endAngle = GetComponent<RunlinePlacer>().GetEndLineAngle();
|
||||
|
||||
if (startAngle > endAngle) endAngle += 2 * Mathf.PI;
|
||||
|
||||
lineRenderer.positionCount = segments + 1;
|
||||
float angleStep = (endAngle - startAngle) / segments;
|
||||
|
||||
Vector3 prevPos = Vector3.zero;
|
||||
arcLength = 0f;
|
||||
|
||||
for (int i = 0; i <= segments; i++)
|
||||
{
|
||||
float angle = startAngle + i * angleStep;
|
||||
float x = Mathf.Cos(angle) * radiusX;
|
||||
float z = Mathf.Sin(angle) * radiusZ;
|
||||
lineRenderer.SetPosition(i, new Vector3(x, 0f, z));
|
||||
Vector3 pos = new Vector3(x, 0f, z) + center;
|
||||
|
||||
if (i > 0)
|
||||
arcLength += Vector3.Distance(pos, prevPos);
|
||||
|
||||
prevPos = pos;
|
||||
}
|
||||
|
||||
GameObject startLine = GetComponent<RunlinePlacer>().GetStartLineGameObject();
|
||||
startLine.GetComponent<LineData>().SetDistanceText((int)arcLength);
|
||||
ClearArc();
|
||||
}
|
||||
public void ClearArc()
|
||||
{
|
||||
if (lineRenderer != null)
|
||||
{
|
||||
lineRenderer.positionCount = 0;
|
||||
arcLength = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lesson_1/DrawDistanceLine.cs.meta
Normal file
11
Assets/Scripts/Lesson_1/DrawDistanceLine.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f63d66c47f906544a6eee6ccb3a8a79
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
106
Assets/Scripts/Lesson_1/ExperimentChooser.cs
Normal file
106
Assets/Scripts/Lesson_1/ExperimentChooser.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ExperimentChooser : MonoBehaviour
|
||||
{
|
||||
public static ExperimentChooser Instance { get; private set; }
|
||||
|
||||
public Button experiment1Button;
|
||||
public Button experiment2Button;
|
||||
public Button experiment3Button;
|
||||
|
||||
[Header("All Experiments Objects")]
|
||||
public RunlinePlacer runlinePlacer;
|
||||
public TransitionSphere transitionSphere;
|
||||
public Transform spawnPoint;
|
||||
public Transform player;
|
||||
public GameObject runTrack;
|
||||
public GameObject amy;
|
||||
|
||||
[Header("First Experiment")]
|
||||
public Stopwatch stopwatch;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
else if (Instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
experiment1Button.interactable = true;
|
||||
experiment2Button.interactable = false;
|
||||
experiment3Button.interactable = false;
|
||||
|
||||
experiment1Button.onClick.AddListener(StartExperiment1);
|
||||
experiment2Button.onClick.AddListener(StartExperiment2);
|
||||
experiment3Button.onClick.AddListener(StartExperiment3);
|
||||
}
|
||||
|
||||
private void StartExperiment1()
|
||||
{
|
||||
player.position = spawnPoint.position + Vector3.up * 2f;
|
||||
transitionSphere.PlayAnimation();
|
||||
runTrack.SetActive(true);
|
||||
amy.SetActive(true);
|
||||
runlinePlacer.gameObject.SetActive(true);
|
||||
player.gameObject.GetComponent<PlayerMovement>().SetPlayerEarthSpeed();
|
||||
Lesson1Controller.Instance.SetForestSkybox();
|
||||
|
||||
experiment1Button.interactable = false;
|
||||
if (Lesson1Controller.Instance.activeExperiment == 2) experiment2Button.interactable = true;
|
||||
if (Lesson1Controller.Instance.activeExperiment == 3)
|
||||
{
|
||||
experiment2Button.interactable = true;
|
||||
experiment3Button.interactable = true;
|
||||
}
|
||||
Lesson1Controller.Instance.activeExperiment = 1;
|
||||
stopwatch.isCounting = false;
|
||||
stopwatch.arrow.transform.localRotation = stopwatch.arrowStartRotation;
|
||||
runlinePlacer.RuntimePlace();
|
||||
}
|
||||
|
||||
private void StartExperiment2()
|
||||
{
|
||||
player.position = spawnPoint.position + Vector3.up * 2f;
|
||||
transitionSphere.PlayAnimation();
|
||||
runTrack.SetActive(true);
|
||||
runlinePlacer.gameObject.SetActive(true);
|
||||
amy.SetActive(true);
|
||||
player.gameObject.GetComponent<PlayerMovement>().SetPlayerEarthSpeed();
|
||||
Lesson1Controller.Instance.SetForestSkybox();
|
||||
|
||||
experiment1Button.interactable = true;
|
||||
experiment2Button.interactable = false;
|
||||
if (Lesson1Controller.Instance.activeExperiment == 3) experiment3Button.interactable = true;
|
||||
|
||||
Lesson1Controller.Instance.activeExperiment = 2;
|
||||
stopwatch.isCounting = false;
|
||||
stopwatch.arrow.transform.localRotation = stopwatch.arrowStartRotation;
|
||||
runlinePlacer.RuntimePlace();
|
||||
}
|
||||
|
||||
private void StartExperiment3()
|
||||
{
|
||||
player.position = spawnPoint.position + Vector3.up * 2f;
|
||||
transitionSphere.PlayAnimation();
|
||||
runTrack.SetActive(false);
|
||||
amy.SetActive(false);
|
||||
runlinePlacer.RuntimePlace();
|
||||
runlinePlacer.gameObject.SetActive(false);
|
||||
player.gameObject.GetComponent<PlayerMovement>().SetPlayerLunarSpeed();
|
||||
Lesson1Controller.Instance.SetLunarSkybox();
|
||||
|
||||
experiment1Button.interactable = true;
|
||||
experiment2Button.interactable = true;
|
||||
experiment3Button.interactable = false;
|
||||
|
||||
Lesson1Controller.Instance.activeExperiment = 3;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lesson_1/ExperimentChooser.cs.meta
Normal file
11
Assets/Scripts/Lesson_1/ExperimentChooser.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35ab8365be20aad40aaf611552542795
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
65
Assets/Scripts/Lesson_1/GPUGrassInstancing.cs
Normal file
65
Assets/Scripts/Lesson_1/GPUGrassInstancing.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
public class GPUGrassRenderer : MonoBehaviour
|
||||
{
|
||||
public Mesh grassMesh; // îäíà ìîäåëü òðàâèíêè (îäèí submesh)
|
||||
public Material grassMaterial; // shader ìຠï³äòðèìóâàòè GPU instancing
|
||||
public ComputeShader computeShader;
|
||||
|
||||
public int countX = 256;
|
||||
public int countZ = 256;
|
||||
public float sizeX = 50f;
|
||||
public float sizeZ = 50f;
|
||||
public float height = 0f;
|
||||
|
||||
GraphicsBuffer matricesBuffer;
|
||||
GraphicsBuffer argsBuffer;
|
||||
int totalCount;
|
||||
|
||||
void Start()
|
||||
{
|
||||
totalCount = countX * countZ;
|
||||
|
||||
// 1) create structured buffer for matrices (float4x4 = 16 floats = 64 bytes)
|
||||
matricesBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured, totalCount, 16 * sizeof(float));
|
||||
// 2) args buffer (5 uints): indexCountPerInstance, instanceCount, startIndexLocation, baseVertexLocation, startInstanceLocation
|
||||
uint[] args = new uint[5] { (uint)grassMesh.GetIndexCount(0), (uint)totalCount, (uint)grassMesh.GetIndexStart(0), (uint)grassMesh.GetBaseVertex(0), 0u };
|
||||
argsBuffer = new GraphicsBuffer(GraphicsBuffer.Target.IndirectArguments, 1, sizeof(uint) * args.Length);
|
||||
argsBuffer.SetData(args);
|
||||
|
||||
// dispatch compute to fill matrices
|
||||
int kernel = computeShader.FindKernel("CSMain");
|
||||
computeShader.SetInt("_CountX", countX);
|
||||
computeShader.SetInt("_CountZ", countZ);
|
||||
computeShader.SetFloat("_SizeX", sizeX);
|
||||
computeShader.SetFloat("_SizeZ", sizeZ);
|
||||
computeShader.SetFloat("_Height", height);
|
||||
computeShader.SetBuffer(kernel, "matrices", matricesBuffer);
|
||||
|
||||
int threadGroups = Mathf.CeilToInt(totalCount / 64.0f);
|
||||
computeShader.Dispatch(kernel, threadGroups, 1, 1);
|
||||
|
||||
// bind buffer to material for per-instance matrix access (if shader reads it)
|
||||
grassMaterial.SetBuffer("matrices", matricesBuffer);
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
matricesBuffer?.Dispose();
|
||||
argsBuffer?.Dispose();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// set render params: use simple bounds so Unity can cull
|
||||
var bounds = new Bounds(transform.position, new Vector3(sizeX, 10f, sizeZ));
|
||||
RenderParams rparams = new RenderParams(grassMaterial);
|
||||
// the shader must use UNITY_INDIRECT_DRAW_ARGS / UnityIndirect.cginc if it needs instance id access
|
||||
|
||||
// call indirect draw
|
||||
rparams.worldBounds = new Bounds(transform.position, new Vector3(sizeX, 10f, sizeZ));
|
||||
Graphics.RenderMeshIndirect(rparams, grassMesh, argsBuffer);
|
||||
// parameters: rparams, mesh, argsBuffer, commandCount=1, startCommand=0, worldBounds
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lesson_1/GPUGrassInstancing.cs.meta
Normal file
11
Assets/Scripts/Lesson_1/GPUGrassInstancing.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43221c50bf4e7fc4d90d52e26a82046a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
41
Assets/Scripts/Lesson_1/Lesson1Controller.cs
Normal file
41
Assets/Scripts/Lesson_1/Lesson1Controller.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Lesson1Controller : MonoBehaviour
|
||||
{
|
||||
public static Lesson1Controller Instance { get; private set; }
|
||||
public float activeExperiment = 0;
|
||||
public Material forestSkybox;
|
||||
public Material lunarSkybox;
|
||||
|
||||
public GameObject forestEnvironment;
|
||||
public GameObject lunarEnvironment;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
else if (Instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetForestSkybox()
|
||||
{
|
||||
RenderSettings.skybox = forestSkybox;
|
||||
forestEnvironment.SetActive(true);
|
||||
lunarEnvironment.SetActive(false);
|
||||
|
||||
//DynamicGI.UpdateEnvironment();
|
||||
}
|
||||
|
||||
public void SetLunarSkybox()
|
||||
{
|
||||
RenderSettings.skybox = lunarSkybox;
|
||||
forestEnvironment.SetActive(false);
|
||||
lunarEnvironment.SetActive(true);
|
||||
//DynamicGI.UpdateEnvironment();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lesson_1/Lesson1Controller.cs.meta
Normal file
11
Assets/Scripts/Lesson_1/Lesson1Controller.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17d55a2c5052d424ea054a778ad967b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
31
Assets/Scripts/Lesson_1/LineData.cs
Normal file
31
Assets/Scripts/Lesson_1/LineData.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
public class LineData : MonoBehaviour
|
||||
{
|
||||
public float angle;
|
||||
public TMP_Text distanceText;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (distanceText) distanceText.text = "";
|
||||
}
|
||||
|
||||
public void FindCurrentAngle(float radiusX, float radiusZ)
|
||||
{
|
||||
Vector3 parentPos = transform.parent.position;
|
||||
Vector3 pos = transform.position;
|
||||
angle = Mathf.Atan2(pos.z / radiusZ, pos.x / radiusX);
|
||||
angle = Mathf.Repeat(angle, 2f * Mathf.PI);
|
||||
}
|
||||
|
||||
public void SetDistanceText(float distance)
|
||||
{
|
||||
if(Lesson1Controller.Instance.activeExperiment >= 2)
|
||||
{
|
||||
distanceText.text = "DISTANCE: " + distance.ToString();
|
||||
} else
|
||||
{
|
||||
distanceText.text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lesson_1/LineData.cs.meta
Normal file
11
Assets/Scripts/Lesson_1/LineData.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 324116e4d975df644a2752e17861315e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
34
Assets/Scripts/Lesson_1/PlayerSpeedChecker.cs
Normal file
34
Assets/Scripts/Lesson_1/PlayerSpeedChecker.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
public class PlayerSpeedChecker : MonoBehaviour
|
||||
{
|
||||
public float rayDistance = 10f;
|
||||
public float raycastHeightOffset = 3f;
|
||||
public TMP_Text speedText;
|
||||
|
||||
void Update()
|
||||
{
|
||||
Vector3 rayOrigin = transform.position + Vector3.up * raycastHeightOffset;
|
||||
Vector3 rayDirection = transform.forward;
|
||||
|
||||
// ³çóàë³çàö³ÿ Ray
|
||||
Debug.DrawRay(rayOrigin, rayDirection * rayDistance, Color.red);
|
||||
|
||||
// Raycast
|
||||
if (Physics.Raycast(rayOrigin, rayDirection, out RaycastHit hit, rayDistance))
|
||||
{
|
||||
GameObject go = hit.collider.gameObject;
|
||||
PlayerMovement pm = go.GetComponent<PlayerMovement>();
|
||||
if (pm != null)
|
||||
{
|
||||
if (Lesson1Controller.Instance.activeExperiment == 1) speedText.text = "Speed: " + pm.playerSpeed.ToString("F0");
|
||||
else speedText.text = "???";
|
||||
}
|
||||
|
||||
} else
|
||||
{
|
||||
speedText.text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lesson_1/PlayerSpeedChecker.cs.meta
Normal file
11
Assets/Scripts/Lesson_1/PlayerSpeedChecker.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1a5a99deec0f654289e24b7f30b913b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
97
Assets/Scripts/Lesson_1/RunlinePlacer.cs
Normal file
97
Assets/Scripts/Lesson_1/RunlinePlacer.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class RunlinePlacer : MonoBehaviour
|
||||
{
|
||||
[Header("Runway Properties")]
|
||||
public float radiusX = 105f;
|
||||
public float radiusZ = 55f;
|
||||
public Vector3 center;
|
||||
public List<Transform> linePositions = new List<Transform>();
|
||||
public GameObject startLinePrefab;
|
||||
public GameObject endLinePrefab;
|
||||
public AmyRunScript amy;
|
||||
|
||||
private float largeTurnOffset = 50f;
|
||||
private GameObject activeStartLine;
|
||||
private GameObject activeEndLine;
|
||||
|
||||
private DrawDistanceLine drawDistanceLine;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
center = transform.position;
|
||||
drawDistanceLine = GetComponent<DrawDistanceLine>();
|
||||
}
|
||||
|
||||
[ContextMenu("Respawn lines")]
|
||||
public void RuntimePlace()
|
||||
{
|
||||
drawDistanceLine.ClearArc();
|
||||
foreach (Transform t in linePositions)
|
||||
{
|
||||
foreach (Transform child in t)
|
||||
{
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
int firstPositionIndex = Random.Range(0, 4);
|
||||
int secondPositionIndex;
|
||||
do
|
||||
{
|
||||
secondPositionIndex = Random.Range(0, 4);
|
||||
} while (secondPositionIndex == firstPositionIndex);
|
||||
|
||||
PlaceLine(firstPositionIndex, startLinePrefab, true);
|
||||
PlaceLine(secondPositionIndex, endLinePrefab);
|
||||
|
||||
amy.PlaceOnStartAngle();
|
||||
// Experiment 2
|
||||
if (Lesson1Controller.Instance.activeExperiment == 2) drawDistanceLine.DrawDistanceArc();
|
||||
}
|
||||
|
||||
private void PlaceLine(int positionIndex, GameObject prefabIfSmall, bool isStart = false)
|
||||
{
|
||||
GameObject instantiatedLine = Instantiate(prefabIfSmall);
|
||||
instantiatedLine.transform.SetParent(linePositions[positionIndex]);
|
||||
instantiatedLine.transform.localPosition = Vector3.zero;
|
||||
instantiatedLine.transform.localRotation = Quaternion.identity;
|
||||
if (positionIndex > 1)
|
||||
{
|
||||
Vector3 pos = instantiatedLine.transform.localPosition;
|
||||
pos.x = Random.Range(-largeTurnOffset, largeTurnOffset);
|
||||
instantiatedLine.transform.localPosition = pos;
|
||||
}
|
||||
|
||||
LineData ilinedata = instantiatedLine.GetComponent<LineData>();
|
||||
|
||||
ilinedata.FindCurrentAngle(radiusX, radiusZ);
|
||||
|
||||
if (isStart)
|
||||
{
|
||||
amy.SetAngle(ilinedata.angle);
|
||||
amy.startAngle = ilinedata.angle;
|
||||
activeStartLine = instantiatedLine;
|
||||
} else
|
||||
{
|
||||
activeEndLine = instantiatedLine;
|
||||
}
|
||||
}
|
||||
|
||||
public float GetStartLineAngle()
|
||||
{
|
||||
LineData ilinedata = activeStartLine.GetComponent<LineData>();
|
||||
return ilinedata.angle;
|
||||
}
|
||||
|
||||
public float GetEndLineAngle()
|
||||
{
|
||||
LineData ilinedata = activeEndLine.GetComponent<LineData>();
|
||||
return ilinedata.angle;
|
||||
}
|
||||
public GameObject GetStartLineGameObject()
|
||||
{
|
||||
return activeStartLine;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lesson_1/RunlinePlacer.cs.meta
Normal file
11
Assets/Scripts/Lesson_1/RunlinePlacer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e95668e7c776a184782e93d5c67d3975
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
80
Assets/Scripts/Lesson_1/SatelliteOrbit.cs
Normal file
80
Assets/Scripts/Lesson_1/SatelliteOrbit.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class SatelliteOrbit : MonoBehaviour
|
||||
{
|
||||
[Tooltip("Точка, навколо якої обертається супутник")]
|
||||
public Transform center;
|
||||
|
||||
|
||||
[Tooltip("Радіус орбіти")]
|
||||
public float radius = 5f;
|
||||
|
||||
|
||||
[Tooltip("Швидкість зміни кута в градусах за секунду")]
|
||||
public float angularSpeed = 50f;
|
||||
|
||||
|
||||
[Tooltip("Чи дивитись супутнику на центр під час руху")]
|
||||
public bool lookAtCenter = false;
|
||||
|
||||
|
||||
private float angleTheta; // горизонтальний кут (навколо Y)
|
||||
private float anglePhi; // вертикальний кут (від 0 до 180)
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
radius = Random.Range(300, 600);
|
||||
angularSpeed = Random.Range(5, 25);
|
||||
lookAtCenter = true;
|
||||
if (center == null)
|
||||
{
|
||||
GameObject go = new GameObject("OrbitCenter");
|
||||
go.transform.position = Vector3.zero;
|
||||
center = go.transform;
|
||||
}
|
||||
|
||||
|
||||
// Випадкові початкові кути для різних напрямків руху
|
||||
angleTheta = Random.Range(0f, 360f);
|
||||
anglePhi = Random.Range(0f, 180f);
|
||||
|
||||
|
||||
UpdatePosition();
|
||||
}
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Змінюємо кути для створення сферичної орбіти
|
||||
angleTheta += angularSpeed * Time.deltaTime; // обертання навколо Y
|
||||
anglePhi += angularSpeed * 0.5f * Time.deltaTime; // нахил вгору/вниз
|
||||
|
||||
|
||||
if (angleTheta > 360f) angleTheta -= 360f;
|
||||
if (anglePhi > 360f) anglePhi -= 360f;
|
||||
|
||||
|
||||
UpdatePosition();
|
||||
|
||||
|
||||
if (lookAtCenter)
|
||||
transform.LookAt(center.position);
|
||||
}
|
||||
|
||||
|
||||
private void UpdatePosition()
|
||||
{
|
||||
float thetaRad = angleTheta * Mathf.Deg2Rad;
|
||||
float phiRad = anglePhi * Mathf.Deg2Rad;
|
||||
|
||||
|
||||
// Сферичні координати → декартові
|
||||
float x = radius * Mathf.Sin(phiRad) * Mathf.Cos(thetaRad);
|
||||
float y = radius * Mathf.Cos(phiRad);
|
||||
float z = radius * Mathf.Sin(phiRad) * Mathf.Sin(thetaRad);
|
||||
|
||||
|
||||
transform.position = center.position + new Vector3(x, y, z);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lesson_1/SatelliteOrbit.cs.meta
Normal file
11
Assets/Scripts/Lesson_1/SatelliteOrbit.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 714c5c3bdbbca9149b5fa9760930afd9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
43
Assets/Scripts/Lesson_1/Stopwatch.cs
Normal file
43
Assets/Scripts/Lesson_1/Stopwatch.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Stopwatch : MonoBehaviour
|
||||
{
|
||||
public GameObject arrow;
|
||||
public AmyRunScript amy;
|
||||
|
||||
public Quaternion arrowStartRotation;
|
||||
private float rotationSpeed = 360f / 60f;
|
||||
public bool isCounting = false;
|
||||
|
||||
private float timeCounted = 0f;
|
||||
|
||||
void Start()
|
||||
{
|
||||
arrowStartRotation = arrow.transform.localRotation;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Lesson1Controller.Instance.activeExperiment == 0) return;
|
||||
if (isCounting)
|
||||
{
|
||||
arrow.transform.Rotate(0f, rotationSpeed * Time.deltaTime, 0f);
|
||||
timeCounted += Time.deltaTime;
|
||||
}
|
||||
if (timeCounted >= 60f && Lesson1Controller.Instance.activeExperiment == 1) ExperimentChooser.Instance.experiment2Button.interactable = true;
|
||||
|
||||
if (Input.GetMouseButtonDown(0)) isCounting = !isCounting;
|
||||
if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
arrow.transform.localRotation = arrowStartRotation;
|
||||
isCounting = false;
|
||||
if (Lesson1Controller.Instance.activeExperiment < 3) amy.PlaceOnStartAngle();
|
||||
}
|
||||
|
||||
if (Lesson1Controller.Instance.activeExperiment < 3)
|
||||
{
|
||||
if(isCounting) amy.StartRun();
|
||||
else amy.StopRun();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lesson_1/Stopwatch.cs.meta
Normal file
11
Assets/Scripts/Lesson_1/Stopwatch.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf3c432b87a2fd8488641321aaecb33c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
69
Assets/Scripts/Lesson_1/TransitionSphere.cs
Normal file
69
Assets/Scripts/Lesson_1/TransitionSphere.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class TransitionSphere : MonoBehaviour
|
||||
{
|
||||
public float duration = 1f; // òðèâàë³ñòü àí³ìàö³¿ â ñåêóíäàõ
|
||||
private Material sphereMat;
|
||||
private Color initialColor;
|
||||
private Coroutine currentAnimation;
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Îòðèìóºìî ìàòåð³àë
|
||||
Renderer rend = GetComponent<Renderer>();
|
||||
sphereMat = rend.material;
|
||||
|
||||
// Ïåðåêîíàéñÿ, ùî øåéäåð ï³äòðèìóº ïðîçîð³ñòü (äëÿ URP Lit)
|
||||
sphereMat.SetFloat("_Surface", 1); // Transparent
|
||||
sphereMat.SetFloat("_Blend", 0); // Alpha Blend
|
||||
|
||||
initialColor = sphereMat.color;
|
||||
}
|
||||
|
||||
// Âèêëèê ö³º¿ ôóíêö³¿ çàïóñêຠàí³ìàö³þ
|
||||
public void PlayAnimation()
|
||||
{
|
||||
// ßêùî àí³ìàö³ÿ âæå éäå, çóïèíÿºìî ¿¿
|
||||
if (currentAnimation != null)
|
||||
StopCoroutine(currentAnimation);
|
||||
|
||||
// Ïî÷àòêîâ³ çíà÷åííÿ
|
||||
transform.localScale = Vector3.zero;
|
||||
Color c = initialColor;
|
||||
c.a = 1f;
|
||||
sphereMat.color = c;
|
||||
|
||||
currentAnimation = StartCoroutine(AnimateSphere());
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator AnimateSphere()
|
||||
{
|
||||
float elapsed = 0f;
|
||||
Vector3 startScale = Vector3.zero;
|
||||
Vector3 endScale = Vector3.one * 100f;
|
||||
|
||||
while (elapsed < duration)
|
||||
{
|
||||
elapsed += Time.deltaTime;
|
||||
float t = Mathf.Clamp01(elapsed / duration);
|
||||
|
||||
// Ìàñøòàá
|
||||
transform.localScale = Vector3.Lerp(startScale, endScale, t);
|
||||
|
||||
// Ïðîçîð³ñòü
|
||||
Color c = sphereMat.color;
|
||||
c.a = Mathf.Lerp(1f, 0f, t);
|
||||
sphereMat.color = c;
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// Ô³íàëüíèé ñòàí
|
||||
transform.localScale = endScale;
|
||||
Color finalColor = sphereMat.color;
|
||||
finalColor.a = 0f;
|
||||
sphereMat.color = finalColor;
|
||||
|
||||
currentAnimation = null;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lesson_1/TransitionSphere.cs.meta
Normal file
11
Assets/Scripts/Lesson_1/TransitionSphere.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1995a23ba3627804093ef252dc4e9137
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Lesson_2.meta
Normal file
8
Assets/Scripts/Lesson_2.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c83c7dbfcb1ac3a45a0c964152d0bc48
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Assets/Scripts/Lesson_2/CubeSpawner.cs
Normal file
35
Assets/Scripts/Lesson_2/CubeSpawner.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class CubeSpawner : MonoBehaviour
|
||||
{
|
||||
public WaterLevelController waterLevelController;
|
||||
public GameObject[] cubesPrefabs;
|
||||
|
||||
public int minScale = 1;
|
||||
public int maxScale = 5;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
for (int i = 0; i < cubesPrefabs.Length; i++)
|
||||
{
|
||||
cubesPrefabs[i].transform.localScale = new Vector3(Random.Range(minScale, maxScale), Random.Range(minScale, maxScale), Random.Range(minScale, maxScale));
|
||||
}
|
||||
}
|
||||
|
||||
public void SpawnNewCube(int cubeId)
|
||||
{
|
||||
waterLevelController.currentCubeMass = 0f;
|
||||
waterLevelController.currentCubeVolume = 0f;
|
||||
|
||||
cubeId = cubeId - 1;
|
||||
while (transform.childCount > 0)
|
||||
{
|
||||
DestroyImmediate(transform.GetChild(0).gameObject);
|
||||
}
|
||||
|
||||
GameObject newCube = Instantiate(cubesPrefabs[cubeId]);
|
||||
newCube.transform.SetParent(transform);
|
||||
newCube.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lesson_2/CubeSpawner.cs.meta
Normal file
11
Assets/Scripts/Lesson_2/CubeSpawner.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68b806cec1697c14892810547aec992a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
75
Assets/Scripts/Lesson_2/DensityCube.cs
Normal file
75
Assets/Scripts/Lesson_2/DensityCube.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class DensityCube : MonoBehaviour
|
||||
{
|
||||
public float mass;
|
||||
public float density;
|
||||
public float cubeVolume;
|
||||
public Material[] cubeColorMaterials;
|
||||
|
||||
public enum CubeMaterial
|
||||
{
|
||||
beton,
|
||||
iron,
|
||||
aluminum,
|
||||
copper,
|
||||
silver,
|
||||
gold
|
||||
}
|
||||
|
||||
public CubeMaterial cubeMaterial;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SetCubeDensity();
|
||||
SetCubeMass();
|
||||
}
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
SetCubeDensity();
|
||||
SetCubeMass();
|
||||
}
|
||||
|
||||
private void SetCubeDensity()
|
||||
{
|
||||
switch (cubeMaterial)
|
||||
{
|
||||
case CubeMaterial.beton:
|
||||
density = 2.4f;
|
||||
GetComponent<Renderer>().material = cubeColorMaterials[0];
|
||||
break;
|
||||
case CubeMaterial.iron:
|
||||
density = 7.85f;
|
||||
GetComponent<Renderer>().material = cubeColorMaterials[1];
|
||||
break;
|
||||
case CubeMaterial.aluminum:
|
||||
density = 2.7f;
|
||||
GetComponent<Renderer>().material = cubeColorMaterials[2];
|
||||
break;
|
||||
case CubeMaterial.copper:
|
||||
density = 8.96f;
|
||||
GetComponent<Renderer>().material = cubeColorMaterials[3];
|
||||
break;
|
||||
case CubeMaterial.silver:
|
||||
density = 10.5f;
|
||||
GetComponent<Renderer>().material = cubeColorMaterials[4];
|
||||
break;
|
||||
case CubeMaterial.gold:
|
||||
density = 19.3f;
|
||||
GetComponent<Renderer>().material = cubeColorMaterials[5];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetCubeMass()
|
||||
{
|
||||
float cubeWidth = transform.localScale.x;
|
||||
float cubeHeight = transform.localScale.y;
|
||||
float cubeLength = transform.localScale.z;
|
||||
|
||||
cubeVolume = cubeWidth * cubeHeight * cubeLength;
|
||||
|
||||
mass = cubeVolume * density;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lesson_2/DensityCube.cs.meta
Normal file
11
Assets/Scripts/Lesson_2/DensityCube.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72dd16f3c11f4e54f877cf7a4087e81b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
40
Assets/Scripts/Lesson_2/LookInteract.cs
Normal file
40
Assets/Scripts/Lesson_2/LookInteract.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class LookInteract : MonoBehaviour
|
||||
{
|
||||
public float interactRange = 20f;
|
||||
public Texture2D normalCursor;
|
||||
public Texture2D interactCursor;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (MenuController.Instance.isPaused) return;
|
||||
|
||||
Ray ray = new Ray(Camera.main.transform.position,
|
||||
Camera.main.transform.forward);
|
||||
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, interactRange))
|
||||
{
|
||||
if (hit.collider.CompareTag("Button"))
|
||||
{
|
||||
Cursor.SetCursor(interactCursor, Vector2.zero, CursorMode.Auto);
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
hit.collider.SendMessage("OnLookInteract",
|
||||
SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Cursor.SetCursor(normalCursor, new Vector2(16, 16), CursorMode.Auto);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Cursor.SetCursor(normalCursor, new Vector2(16, 16), CursorMode.Auto);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lesson_2/LookInteract.cs.meta
Normal file
11
Assets/Scripts/Lesson_2/LookInteract.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01fd7d793d9255d4aab21e3b299408ab
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
68
Assets/Scripts/Lesson_2/PickupThrow.cs
Normal file
68
Assets/Scripts/Lesson_2/PickupThrow.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class PickupThrow : MonoBehaviour
|
||||
{
|
||||
public Transform holdPoint;
|
||||
public float pickupRange = 3f;
|
||||
public float throwForce = 10f;
|
||||
|
||||
private Rigidbody heldRb;
|
||||
private Transform originalParent;
|
||||
|
||||
void Update()
|
||||
{
|
||||
// ËÊÌ — âçÿòè / â³äïóñòèòè
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
if (heldRb == null)
|
||||
TryPickup();
|
||||
else
|
||||
Drop(false);
|
||||
}
|
||||
|
||||
// ÏÊÌ — êèíóòè
|
||||
if (Input.GetMouseButtonDown(1) && heldRb != null)
|
||||
Drop(true);
|
||||
}
|
||||
|
||||
void TryPickup()
|
||||
{
|
||||
if (Physics.Raycast(Camera.main.transform.position,
|
||||
Camera.main.transform.forward, out RaycastHit hit, pickupRange))
|
||||
{
|
||||
if (!hit.collider.CompareTag("Pickable")) return;
|
||||
|
||||
heldRb = hit.collider.attachedRigidbody;
|
||||
if (heldRb == null) return;
|
||||
|
||||
originalParent = heldRb.transform.parent;
|
||||
|
||||
// Âèìèêàºìî ô³çèêó
|
||||
heldRb.isKinematic = true;
|
||||
heldRb.useGravity = false;
|
||||
|
||||
// Ïðèêð³ïëþºìî äî ðóêè
|
||||
heldRb.transform.SetParent(holdPoint);
|
||||
heldRb.transform.localPosition = Vector3.zero;
|
||||
heldRb.transform.localRotation = Quaternion.identity;
|
||||
}
|
||||
}
|
||||
|
||||
void Drop(bool throwIt)
|
||||
{
|
||||
// ³äêð³ïëþºìî
|
||||
heldRb.transform.SetParent(originalParent);
|
||||
|
||||
// Âìèêàºìî ô³çèêó
|
||||
heldRb.isKinematic = false;
|
||||
heldRb.useGravity = true;
|
||||
|
||||
if (throwIt)
|
||||
{
|
||||
heldRb.AddForce(Camera.main.transform.forward * throwForce,
|
||||
ForceMode.VelocityChange);
|
||||
}
|
||||
|
||||
heldRb = null;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lesson_2/PickupThrow.cs.meta
Normal file
11
Assets/Scripts/Lesson_2/PickupThrow.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e809941a6cc3be4cbc1ea0e83783b02
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
Assets/Scripts/Lesson_2/ScrollLeverOnHover.cs
Normal file
21
Assets/Scripts/Lesson_2/ScrollLeverOnHover.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class ScrollLeverOnHover : MonoBehaviour
|
||||
{
|
||||
void Update()
|
||||
{
|
||||
float scroll = Input.mouseScrollDelta.y;
|
||||
if (scroll == 0) return;
|
||||
|
||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
if (Physics.Raycast(ray, out RaycastHit hit))
|
||||
{
|
||||
if (hit.collider.gameObject.tag == "LeverParent")
|
||||
{
|
||||
StrikerLeverController slc = hit.collider.gameObject.GetComponent<StrikerLeverController>();
|
||||
if (slc != null) slc.currentAngle += scroll;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Lesson_2/ScrollLeverOnHover.cs.meta
Normal file
11
Assets/Scripts/Lesson_2/ScrollLeverOnHover.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9f1a2816fde2d04782faf4e5a64e2f2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
44
Assets/Scripts/Lesson_2/SpawnCubeButton.cs
Normal file
44
Assets/Scripts/Lesson_2/SpawnCubeButton.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class SpawnCubeButton : MonoBehaviour
|
||||
{
|
||||
public int cubeId = 0;
|
||||
public CubeSpawner cubeSpawner;
|
||||
private Vector3 _originalScale;
|
||||
|
||||
void Start()
|
||||
{
|
||||
_originalScale = transform.localScale;
|
||||
}
|
||||
|
||||
void OnLookInteract()
|
||||
{
|
||||
cubeSpawner.SpawnNewCube(cubeId);
|
||||
StartCoroutine(PressAnimation());
|
||||
}
|
||||
|
||||
private IEnumerator PressAnimation()
|
||||
{
|
||||
float duration = 0.3f;
|
||||
float elapsed = 0f;
|
||||
Vector3 pressedScale = new Vector3(_originalScale.x, _originalScale.y * 0.3f, _originalScale.z);
|
||||
|
||||
while (elapsed < duration)
|
||||
{
|
||||
elapsed += Time.deltaTime;
|
||||
transform.localScale = Vector3.Lerp(_originalScale, pressedScale, elapsed / duration);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
elapsed = 0f;
|
||||
while (elapsed < duration)
|
||||
{
|
||||
elapsed += Time.deltaTime;
|
||||
transform.localScale = Vector3.Lerp(pressedScale, _originalScale, elapsed / duration);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
transform.localScale = _originalScale;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lesson_2/SpawnCubeButton.cs.meta
Normal file
11
Assets/Scripts/Lesson_2/SpawnCubeButton.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2246ba0c8bb0ddb4286c18dafe5f9eda
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
27
Assets/Scripts/Lesson_2/WaterLevelController.cs
Normal file
27
Assets/Scripts/Lesson_2/WaterLevelController.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
public class WaterLevelController : MonoBehaviour
|
||||
{
|
||||
public TextMeshPro waterLevelText;
|
||||
public TextMeshPro cubeMassText;
|
||||
|
||||
private float waterLevel = 100f;
|
||||
public float currentCubeVolume = 0f;
|
||||
public float currentCubeMass = 0f;
|
||||
|
||||
void Update()
|
||||
{
|
||||
waterLevelText.text = "WATER VOLUME " + (waterLevel + currentCubeVolume).ToString().Replace(",", ".") + "L";
|
||||
cubeMassText.text = "OBJECT MASS " + currentCubeMass.ToString().Replace(",", ".") + "KG";
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.gameObject.tag != "DensityCube") return;
|
||||
|
||||
DensityCube dc = other.GetComponent<DensityCube>();
|
||||
currentCubeVolume = dc.cubeVolume;
|
||||
currentCubeMass = dc.mass;
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Lesson_2/WaterLevelController.cs.meta
Normal file
11
Assets/Scripts/Lesson_2/WaterLevelController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7bbbbf5b74451c942a48522409cf86b1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Lesson_3.meta
Normal file
8
Assets/Scripts/Lesson_3.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 20c3e8b4516393947a0b4a520afd54ef
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
85
Assets/Scripts/Lesson_3/HighStrikerController.cs
Normal file
85
Assets/Scripts/Lesson_3/HighStrikerController.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class HighStrikerController : MonoBehaviour
|
||||
{
|
||||
public PlanetData[] planets;
|
||||
public ToyRocketController rocket;
|
||||
|
||||
public StrikerLeverController newtonLever;
|
||||
public StrikerLeverController lengthLever;
|
||||
|
||||
public int currentPlanet = 0;
|
||||
|
||||
public float maxDistanceY = 0f;
|
||||
|
||||
public Transform startRocketPosition;
|
||||
public Transform endRocketPosition;
|
||||
|
||||
void Start()
|
||||
{
|
||||
SetupStriker();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void SetupStriker()
|
||||
{
|
||||
// Rocket initial setup
|
||||
rocket.SetRocketMass(Random.Range(10f, 100f));
|
||||
|
||||
// Planets initial setup
|
||||
maxDistanceY = Random.Range(20000f, 40000f);
|
||||
foreach (PlanetData planet in planets)
|
||||
{
|
||||
float planetY = planet.planetFlightPoint.transform.localPosition.y;
|
||||
float planetDist = Remap(planetY, startRocketPosition.localPosition.y, endRocketPosition.localPosition.y, 0f, maxDistanceY);
|
||||
|
||||
planet.SetupPlanet(planetDist);
|
||||
}
|
||||
|
||||
SetupLevers();
|
||||
}
|
||||
|
||||
private void SetupLevers()
|
||||
{
|
||||
PlanetData planet = planets[currentPlanet];
|
||||
if (Random.Range(0, 100) < 50f) // If Newton Lever
|
||||
{
|
||||
lengthLever.isBlocked = true;
|
||||
newtonLever.isBlocked = false;
|
||||
|
||||
lengthLever.springValue = (2 * (rocket.rocketMass / 1000f) * 9.81f * planet.planetDistanceM) / Random.Range(lengthLever.maxSpringValue * 0.25f, lengthLever.maxSpringValue * 0.9f);
|
||||
} else // If Length Lever
|
||||
{
|
||||
lengthLever.isBlocked = false;
|
||||
newtonLever.isBlocked = true;
|
||||
|
||||
newtonLever.springValue = (2 * (rocket.rocketMass / 1000f) * 9.81f * planet.planetDistanceM) / Random.Range(lengthLever.maxSpringValue * 0.25f, lengthLever.maxSpringValue * 0.9f);
|
||||
}
|
||||
}
|
||||
|
||||
public void FlyRocket()
|
||||
{
|
||||
float k = newtonLever.springValue;
|
||||
float x = lengthLever.springValue / 100f;
|
||||
float m = rocket.rocketMass / 1000f;
|
||||
|
||||
float height = (k * x * x) / (2f * m * 9.81f);
|
||||
|
||||
Vector3 flyTo = rocket.transform.localPosition;
|
||||
Debug.Log(height);
|
||||
flyTo.y = Remap(height, 0f, maxDistanceY / 100f, startRocketPosition.transform.localPosition.y, endRocketPosition.transform.localPosition.y);
|
||||
|
||||
rocket.transform.localPosition = flyTo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private float Remap(float v, float inMin, float inMax, float outMin, float outMax)
|
||||
{
|
||||
return (v - inMin) / (inMax - inMin) * (outMax - outMin) + outMin;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lesson_3/HighStrikerController.cs.meta
Normal file
11
Assets/Scripts/Lesson_3/HighStrikerController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 181ae73eae3ab804b8e7ac20f4e3fa03
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15
Assets/Scripts/Lesson_3/PlanetData.cs
Normal file
15
Assets/Scripts/Lesson_3/PlanetData.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
public class PlanetData : MonoBehaviour
|
||||
{
|
||||
public Transform planetFlightPoint;
|
||||
public TextMeshPro planetDistanceText;
|
||||
public float planetDistanceM;
|
||||
|
||||
public void SetupPlanet(float distance)
|
||||
{
|
||||
planetDistanceM = distance;
|
||||
planetDistanceText.text = $"{planetDistanceM:F0} CM".Replace(",", ".");
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lesson_3/PlanetData.cs.meta
Normal file
11
Assets/Scripts/Lesson_3/PlanetData.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 42069086e00461f41846819e21a72624
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Assets/Scripts/Lesson_3/RocketButtonController.cs
Normal file
10
Assets/Scripts/Lesson_3/RocketButtonController.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class RocketButtonController : MonoBehaviour
|
||||
{
|
||||
public HighStrikerController HighStrikerController;
|
||||
public void Use()
|
||||
{
|
||||
HighStrikerController.FlyRocket();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lesson_3/RocketButtonController.cs.meta
Normal file
11
Assets/Scripts/Lesson_3/RocketButtonController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61bec933c407c374f9eaa351904b06e2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
32
Assets/Scripts/Lesson_3/ScrollOnHover.cs
Normal file
32
Assets/Scripts/Lesson_3/ScrollOnHover.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class ScrollOnHover : MonoBehaviour
|
||||
{
|
||||
|
||||
void Update()
|
||||
{
|
||||
float scroll = Input.mouseScrollDelta.y;
|
||||
|
||||
|
||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
if (Physics.Raycast(ray, out RaycastHit hit))
|
||||
{
|
||||
if (hit.collider.gameObject.tag == "LeverParent")
|
||||
{
|
||||
if (scroll == 0) return;
|
||||
StrikerLeverController slc = hit.collider.gameObject.GetComponent<StrikerLeverController>();
|
||||
if (slc != null)
|
||||
{
|
||||
slc.RotateLever(scroll);
|
||||
}
|
||||
}
|
||||
if (hit.collider.gameObject.tag == "FlyButton")
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.E) ) {
|
||||
hit.collider.gameObject.GetComponent<RocketButtonController>().Use();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Lesson_3/ScrollOnHover.cs.meta
Normal file
11
Assets/Scripts/Lesson_3/ScrollOnHover.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c84996350ec0abc40a5c53a98cdda431
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
63
Assets/Scripts/Lesson_3/StrikerLeverController.cs
Normal file
63
Assets/Scripts/Lesson_3/StrikerLeverController.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class StrikerLeverController : MonoBehaviour
|
||||
{
|
||||
public float endAngle = 8f;
|
||||
public float currentAngle;
|
||||
public Transform leverObject;
|
||||
|
||||
public Transform[] springsObjects;
|
||||
public float springMaxScaleZ = 3.3f;
|
||||
|
||||
public bool isLength = false;
|
||||
public TextMeshPro valueText;
|
||||
|
||||
public float springValue = 0f;
|
||||
public float maxSpringValue = 1000f;
|
||||
|
||||
public bool isBlocked = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
currentAngle = endAngle;
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
if (isLength)
|
||||
valueText.text = $"{springValue:F2} CM".Replace(",", ".");
|
||||
else
|
||||
valueText.text = $"{springValue:F2} N/m".Replace(",", ".");
|
||||
|
||||
if (isBlocked) SetAlpha(0.2f);
|
||||
}
|
||||
|
||||
|
||||
public void RotateLever(float angle)
|
||||
{
|
||||
if (isBlocked) return;
|
||||
|
||||
currentAngle += angle;
|
||||
if (currentAngle < endAngle) currentAngle = endAngle;
|
||||
if (currentAngle > 180f - endAngle) currentAngle = 180f - endAngle;
|
||||
|
||||
foreach (Transform t in springsObjects) {
|
||||
Vector3 newScale = t.localScale;
|
||||
newScale.z = Remap(currentAngle, endAngle, 180f - endAngle, 0f, springMaxScaleZ);
|
||||
t.localScale = newScale;
|
||||
}
|
||||
springValue = Remap(currentAngle, endAngle, 180f - endAngle, 0, maxSpringValue);
|
||||
leverObject.localRotation = Quaternion.Euler(0f, 0f, currentAngle);
|
||||
}
|
||||
|
||||
private float Remap(float v, float inMin, float inMax, float outMin, float outMax)
|
||||
{
|
||||
return (v - inMin) / (inMax - inMin) * (outMax - outMin) + outMin;
|
||||
}
|
||||
|
||||
private void SetAlpha(float alpha)
|
||||
{
|
||||
leverObject.GetChild(0).GetComponent<Renderer>().material.color = new UnityEngine.Color(1, 1, 1, alpha);
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Lesson_3/StrikerLeverController.cs.meta
Normal file
11
Assets/Scripts/Lesson_3/StrikerLeverController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d9bc61cf7cf93e49aa56bc60987cdd9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
25
Assets/Scripts/Lesson_3/ToyRocketController.cs
Normal file
25
Assets/Scripts/Lesson_3/ToyRocketController.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class ToyRocketController : MonoBehaviour
|
||||
{
|
||||
public TextMeshPro rocketMassText;
|
||||
public float rocketMass;
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void SetRocketMass(float newMass)
|
||||
{
|
||||
rocketMass = newMass;
|
||||
rocketMassText.text = $"{rocketMass:F2} GR".Replace(",", ".");
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lesson_3/ToyRocketController.cs.meta
Normal file
11
Assets/Scripts/Lesson_3/ToyRocketController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af3b4d0d8d872d54d9440503c4557b05
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Player.meta
Normal file
8
Assets/Scripts/Player.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e96bc71a5f3e9a344aad03c94616cfa8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Assets/Scripts/Player/PlayerAmbientSound.cs
Normal file
35
Assets/Scripts/Player/PlayerAmbientSound.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
public class PlayerAmbientSound : MonoBehaviour
|
||||
{
|
||||
public AudioSource ambientSource; // åìᳺíò (ôîíîâà ìóçèêà)
|
||||
public AudioSource cricketsSource; // ñâåð÷êè
|
||||
public Slider volumeSlider;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (ambientSource != null)
|
||||
{
|
||||
ambientSource.loop = true;
|
||||
ambientSource.Play();
|
||||
}
|
||||
|
||||
if (cricketsSource != null)
|
||||
{
|
||||
cricketsSource.loop = true;
|
||||
cricketsSource.Play();
|
||||
}
|
||||
if (volumeSlider != null)
|
||||
{
|
||||
volumeSlider.onValueChanged.AddListener(OnVolumeChange);
|
||||
}
|
||||
void OnVolumeChange(float value)
|
||||
{
|
||||
if (ambientSource != null)
|
||||
ambientSource.volume = value;
|
||||
|
||||
if (cricketsSource != null)
|
||||
cricketsSource.volume = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Player/PlayerAmbientSound.cs.meta
Normal file
11
Assets/Scripts/Player/PlayerAmbientSound.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 667fa0519c144254f92051f01717bf3f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
120
Assets/Scripts/Player/PlayerMovement.cs
Normal file
120
Assets/Scripts/Player/PlayerMovement.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
[RequireComponent(typeof(CharacterController))]
|
||||
public class PlayerMovement : MonoBehaviour
|
||||
{
|
||||
public float playerSpeed = 10.0f;
|
||||
private float earthSpeed = 10f;
|
||||
private float jumpHeight = 2.5f;
|
||||
private float gravityValue = -9.81f;
|
||||
|
||||
private CharacterController controller;
|
||||
private Vector3 playerVelocity;
|
||||
private bool groundedPlayer;
|
||||
|
||||
private float xRotation = 0f;
|
||||
|
||||
[Header("Input Actions")]
|
||||
public InputActionReference moveAction;
|
||||
public InputActionReference jumpAction;
|
||||
|
||||
[Header("Camera Settings")]
|
||||
public Transform playerCamera;
|
||||
public float mouseSensitivity = 3f;
|
||||
|
||||
[Header("Ground Checker")]
|
||||
public Transform groundCheck;
|
||||
public float groundDistance = 0.4f;
|
||||
public LayerMask groundMask;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
controller = gameObject.GetComponent<CharacterController>();
|
||||
//Cursor.lockState = CursorLockMode.Locked;
|
||||
//Cursor.visible = false;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SetPlayerRandomSpeed();
|
||||
earthSpeed = playerSpeed;
|
||||
}
|
||||
private void OnEnable()
|
||||
{
|
||||
moveAction.action.Enable();
|
||||
jumpAction.action.Enable();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
moveAction.action.Disable();
|
||||
jumpAction.action.Disable();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (MenuController.Instance.isPaused) return;
|
||||
MoveMouse();
|
||||
PlayerJump();
|
||||
MovePlayer();
|
||||
}
|
||||
|
||||
private void MoveMouse()
|
||||
{
|
||||
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity;
|
||||
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity;
|
||||
|
||||
xRotation -= mouseY;
|
||||
xRotation = Mathf.Clamp(xRotation, -80f, 80f);
|
||||
|
||||
playerCamera.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
|
||||
|
||||
transform.Rotate(Vector3.up * mouseX);
|
||||
}
|
||||
|
||||
private void PlayerJump()
|
||||
{
|
||||
groundedPlayer = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
|
||||
if (groundedPlayer && playerVelocity.y < 0)
|
||||
{
|
||||
playerVelocity.y = 0f;
|
||||
}
|
||||
|
||||
if (jumpAction.action.triggered && groundedPlayer)
|
||||
{
|
||||
playerVelocity.y = Mathf.Sqrt(jumpHeight * -2.0f * gravityValue);
|
||||
}
|
||||
}
|
||||
|
||||
private void MovePlayer()
|
||||
{
|
||||
float horizontal = Input.GetAxis("Horizontal");
|
||||
float vertical = Input.GetAxis("Vertical");
|
||||
|
||||
Vector3 move = transform.right * horizontal + transform.forward * vertical;
|
||||
controller.Move(move * playerSpeed * Time.deltaTime);
|
||||
|
||||
playerVelocity.y += gravityValue * Time.deltaTime;
|
||||
controller.Move(playerVelocity * Time.deltaTime);
|
||||
}
|
||||
|
||||
[ContextMenu("Set player random speed")]
|
||||
public void SetPlayerRandomSpeed()
|
||||
{
|
||||
playerSpeed = Random.Range(8, 15);
|
||||
earthSpeed = playerSpeed;
|
||||
}
|
||||
|
||||
public void SetPlayerEarthSpeed()
|
||||
{
|
||||
playerSpeed = earthSpeed;
|
||||
gravityValue = -9.81f;
|
||||
}
|
||||
|
||||
public void SetPlayerLunarSpeed()
|
||||
{
|
||||
playerSpeed *= Mathf.Sqrt(1.62f / 9.81f);
|
||||
gravityValue = -1.62f;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Player/PlayerMovement.cs.meta
Normal file
11
Assets/Scripts/Player/PlayerMovement.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41bcbf4d9bcf3ae41b3f58a4767d99f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
41
Assets/Scripts/Player/PlayerRaycastOnUI.cs
Normal file
41
Assets/Scripts/Player/PlayerRaycastOnUI.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
public class PlayerRaycastOnUI : MonoBehaviour
|
||||
{
|
||||
public Camera playerCamera;
|
||||
public Canvas worldCanvas;
|
||||
public KeyCode interactKey = KeyCode.E;
|
||||
|
||||
private GraphicRaycaster raycaster;
|
||||
private EventSystem eventSystem;
|
||||
|
||||
void Start()
|
||||
{
|
||||
raycaster = worldCanvas.GetComponent<GraphicRaycaster>();
|
||||
eventSystem = EventSystem.current;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Ñòâîðþºìî PointerEventData íà îñíîâ³ öåíòðó êàìåðè
|
||||
PointerEventData pointerData = new PointerEventData(eventSystem);
|
||||
pointerData.position = playerCamera.WorldToScreenPoint(playerCamera.transform.position + playerCamera.transform.forward * 2f);
|
||||
|
||||
List<RaycastResult> results = new List<RaycastResult>();
|
||||
raycaster.Raycast(pointerData, results);
|
||||
|
||||
foreach (var result in results)
|
||||
{
|
||||
Button button = result.gameObject.GetComponent<Button>();
|
||||
if (button != null)
|
||||
{
|
||||
if (Input.GetKeyDown(interactKey))
|
||||
{
|
||||
button.onClick.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Player/PlayerRaycastOnUI.cs.meta
Normal file
11
Assets/Scripts/Player/PlayerRaycastOnUI.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3963846b067083f428abc18078b33ab3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Project.meta
Normal file
8
Assets/Scripts/Project.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0bcf5238979dd7740b9acbea616ddc37
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15
Assets/Scripts/Project/GameManagerScript.cs
Normal file
15
Assets/Scripts/Project/GameManagerScript.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class GameManagerScript : MonoBehaviour
|
||||
{
|
||||
void Start()
|
||||
{
|
||||
Application.targetFrameRate = 60;
|
||||
QualitySettings.vSyncCount = 0;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Project/GameManagerScript.cs.meta
Normal file
11
Assets/Scripts/Project/GameManagerScript.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef601aec25fc12a43bfbe138d049212a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
63
Assets/Scripts/Project/MenuController.cs
Normal file
63
Assets/Scripts/Project/MenuController.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class MenuController : MonoBehaviour
|
||||
{
|
||||
public static MenuController Instance { get; private set; }
|
||||
|
||||
public GameObject pauseMenuPanel;
|
||||
public Button resumeButton;
|
||||
public Button quitButton;
|
||||
|
||||
public bool isPaused = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
else if (Instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
resumeButton.onClick.AddListener(TogglePause);
|
||||
quitButton.onClick.AddListener(CloseGame);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
TogglePause();
|
||||
}
|
||||
}
|
||||
void TogglePause()
|
||||
{
|
||||
isPaused = !isPaused;
|
||||
pauseMenuPanel.SetActive(isPaused);
|
||||
|
||||
if (isPaused)
|
||||
{
|
||||
Time.timeScale = 0f;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Time.timeScale = 1f;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void CloseGame()
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Project/MenuController.cs.meta
Normal file
11
Assets/Scripts/Project/MenuController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e09424ee66487a4c829b89df5fc3887
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
32
Assets/Scripts/Project/Screenshooter.cs
Normal file
32
Assets/Scripts/Project/Screenshooter.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Screenshooter : MonoBehaviour
|
||||
{
|
||||
public Camera cam;
|
||||
public int width = 3840;
|
||||
public int height = 2160;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.F12))
|
||||
{
|
||||
RenderTexture rt = new RenderTexture(width, height, 24);
|
||||
cam.targetTexture = rt;
|
||||
|
||||
Texture2D image = new Texture2D(width, height, TextureFormat.RGB24, false);
|
||||
cam.Render();
|
||||
RenderTexture.active = rt;
|
||||
image.ReadPixels(new Rect(0, 0, width, height), 0, 0);
|
||||
image.Apply();
|
||||
|
||||
cam.targetTexture = null;
|
||||
RenderTexture.active = null;
|
||||
Destroy(rt);
|
||||
|
||||
System.IO.File.WriteAllBytes(
|
||||
"screenshot_4k.png",
|
||||
image.EncodeToPNG()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Project/Screenshooter.cs.meta
Normal file
11
Assets/Scripts/Project/Screenshooter.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c666a8f574985443b3c7630ec3de08c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user