basicly finished car customization screen

This commit is contained in:
2024-04-22 14:04:50 +02:00
parent e79bc755d9
commit bcc9d14450
38 changed files with 4434 additions and 1062 deletions

View File

@@ -1,29 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CarCustomizationCamera : MonoBehaviour
{
new Transform transform;
public Transform car;
public float rotateSpeed;
public Vector3 startPosition;
public Quaternion startRotation;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.LookAt(car);
transform.position += transform.right * Time.deltaTime * rotateSpeed;
}
private void OnEnable() {
transform = GetComponent<Transform>();
transform.position = startPosition;
transform.rotation = startRotation;
}
}

View File

@@ -1,24 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.UI;
public class Garage : MonoBehaviour
{
GameObject CurrentCar;
public Button HotrodButton;
public GameObject HotrodGarage;
public GameObject Hotrod;
public Button RacecarButton;
public GameObject RacecarGarage;
public GameObject Racecar;
public Button[] CarButtons;
public GameObject[] Garages;
public GameObject[] CarBodies;
public Button[] ColorButtons;
public Material[] Colors;
// Start is called before the first frame update
quaternion currentRotation;
void Start()
{
HotrodButton.onClick.AddListener(SelectHotrod);
RacecarButton.onClick.AddListener(SelectRacecar);
CarButtons[0].onClick.AddListener(SelectHotrod);
CarButtons[1].onClick.AddListener(SelectCoupe);
CarButtons[2].onClick.AddListener(SelectBolide);
CarButtons[3].onClick.AddListener(SelectIcecreamTruck);
CarButtons[4].onClick.AddListener(SelectSportscar);
CarButtons[5].onClick.AddListener(SelectSchoolBus);
CarButtons[6].onClick.AddListener(SelectBulldozer);
CarButtons[7].onClick.AddListener(SelectPicupTruck);
ColorButtons[0].onClick.AddListener(SelectBlack);
ColorButtons[1].onClick.AddListener(SelectBlue);
@@ -33,34 +37,69 @@ public class Garage : MonoBehaviour
ColorButtons[10].onClick.AddListener(SelectWhite);
ColorButtons[11].onClick.AddListener(SelectYellow);
disable();
SelectHotrod();
}
void enable(GameObject carGarage)
{
carGarage.SetActive(true);
private void FixedUpdate() {
CurrentCar.transform.eulerAngles += Vector3.up * 0.7f;
currentRotation = CurrentCar.transform.rotation;
}
void disable()
{
HotrodGarage.SetActive(false);
RacecarGarage.SetActive(false);
foreach (GameObject carGarage in Garages)
{
carGarage.SetActive(false);
}
}
void SelectCar(int i)
{
disable();
Garages[i].SetActive(true);
CurrentCar = CarBodies[i];
CurrentCar.transform.rotation = currentRotation;
}
void SelectHotrod()
{
disable();
enable(HotrodGarage);
CurrentCar = Hotrod;
SelectCar(0);
}
void SelectRacecar()
void SelectCoupe()
{
disable();
enable(RacecarGarage);
CurrentCar = Racecar;
SelectCar(1);
}
void SelectBolide()
{
SelectCar(2);
}
void SelectIcecreamTruck()
{
SelectCar(3);
}
void SelectSportscar()
{
SelectCar(4);
}
void SelectSchoolBus()
{
SelectCar(5);
}
void SelectBulldozer()
{
SelectCar(6);
}
void SelectPicupTruck()
{
SelectCar(7);
}
void SelectBlack()

View File

@@ -0,0 +1,150 @@
using UnityEngine;
using System.Collections;
using System.IO;
//https://gist.github.com/bitbutter/302da1c840b7c93bc789
/*
Usage:
1. Attach this script to your chosen camera's game object.
2. Set that camera's Clear Flags field to Solid Color.
3. Use the inspector to set frameRate and framesToCapture
4. Choose your desired resolution in Unity's Game window (must be less than or equal to your screen resolution)
5. Turn on "Maximise on Play"
6. Play your scene. Screenshots will be saved to YourUnityProject/Screenshots by default.
*/
public class TransparentBackgroundScreenshotRecorder : MonoBehaviour {
#region public fields
[Tooltip("A folder will be created with this base name in your project root")]
public string folderBaseName = "Screenshots";
[Tooltip("How many frames should be captured per second of game time")]
public int frameRate = 24;
[Tooltip("How many frames should be captured before quitting")]
public int framesToCapture = 24;
#endregion
#region private fields
private string folderName = "";
private GameObject whiteCamGameObject;
private Camera whiteCam;
private GameObject blackCamGameObject;
private Camera blackCam;
private Camera mainCam;
private int videoFrame = 0; // how many frames we've rendered
private float originalTimescaleTime;
private bool done=false;
private int screenWidth;
private int screenHeight;
private Texture2D textureBlack;
private Texture2D textureWhite;
private Texture2D textureTransparentBackground;
#endregion
void Awake () {
mainCam = gameObject.GetComponent<Camera>();
CreateBlackAndWhiteCameras ();
CreateNewFolderForScreenshots ();
CacheAndInitialiseFields ();
Time.captureFramerate = frameRate;
}
void LateUpdate () {
if(!done){
StartCoroutine(CaptureFrame());
} else {
Debug.Log("Complete! "+videoFrame+" videoframes rendered. File names are 0 indexed)");
Debug.Break();
}
}
IEnumerator CaptureFrame (){
yield return new WaitForEndOfFrame();
if(videoFrame < framesToCapture) {
RenderCamToTexture(blackCam,textureBlack);
RenderCamToTexture(whiteCam,textureWhite);
CalculateOutputTexture ();
SavePng ();
videoFrame++;
Debug.Log("Rendered frame " +videoFrame);
videoFrame++;
} else {
done=true;
StopCoroutine("CaptureFrame");
}
}
void RenderCamToTexture (Camera cam, Texture2D tex){
cam.enabled=true;
cam.Render();
WriteScreenImageToTexture(tex);
cam.enabled=false;
}
void CreateBlackAndWhiteCameras (){
whiteCamGameObject = (GameObject) new GameObject();
whiteCamGameObject.name="White Background Camera";
whiteCam=whiteCamGameObject.AddComponent<Camera>();
whiteCam.CopyFrom(mainCam);
whiteCam.backgroundColor=Color.white;
whiteCamGameObject.transform.SetParent(gameObject.transform, true);
blackCamGameObject = (GameObject) new GameObject();
blackCamGameObject.name="Black Background Camera";
blackCam=blackCamGameObject.AddComponent<Camera>();
blackCam.CopyFrom(mainCam);
blackCam.backgroundColor=Color.black;
blackCamGameObject.transform.SetParent(gameObject.transform, true);
}
void CreateNewFolderForScreenshots (){
// Find a folder name that doesn't exist yet. Append number if necessary.
folderName = folderBaseName;
int count = 1;
while (System.IO.Directory.Exists (folderName)) {
folderName = folderBaseName + count;
count++;
}
System.IO.Directory.CreateDirectory (folderName); // Create the folder
}
void WriteScreenImageToTexture (Texture2D tex){
tex.ReadPixels (new Rect (0, 0, screenWidth, screenHeight), 0, 0);
tex.Apply ();
}
void CalculateOutputTexture (){
Color color;
for (int y = 0; y < textureTransparentBackground.height; ++y) {
// each row
for (int x = 0; x < textureTransparentBackground.width; ++x) {
// each column
float alpha = textureWhite.GetPixel (x, y).r - textureBlack.GetPixel (x, y).r;
alpha = 1.0f - alpha;
if (alpha == 0) {
color = Color.clear;
}
else {
color = textureBlack.GetPixel (x, y) / alpha;
}
color.a = alpha;
textureTransparentBackground.SetPixel (x, y, color);
}
}
}
void SavePng (){
string name = string.Format ("{0}/{1:D04} shot.png", folderName, videoFrame);
var pngShot = textureTransparentBackground.EncodeToPNG ();
File.WriteAllBytes (name, pngShot);
}
void CacheAndInitialiseFields (){
originalTimescaleTime = Time.timeScale;
screenWidth = Screen.width;
screenHeight = Screen.height;
textureBlack = new Texture2D (screenWidth, screenHeight, TextureFormat.RGB24, false);
textureWhite = new Texture2D (screenWidth, screenHeight, TextureFormat.RGB24, false);
textureTransparentBackground = new Texture2D (screenWidth, screenHeight, TextureFormat.ARGB32, false);
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: cc607b4c1721b87489346376014622d5
guid: 10b47492e0f2c4f46a754608e4e9a985
MonoImporter:
externalObjects: {}
serializedVersion: 2