fixed camera GUI options

This commit is contained in:
wangobango 2021-11-07 19:45:49 +01:00
parent 2ec510dbe0
commit 3f3a21401c
3 changed files with 19 additions and 188 deletions

Binary file not shown.

View File

@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1 m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0} m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0} m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} m_IndirectSpecularColor: {r: 0.37311953, g: 0.38074014, b: 0.3587274, a: 1}
m_UseRadianceAmbientProbe: 0 m_UseRadianceAmbientProbe: 0
--- !u!157 &3 --- !u!157 &3
LightmapSettings: LightmapSettings:
@ -174,99 +174,6 @@ MonoBehaviour:
tree5: {fileID: 6357631730651435771, guid: af9ecbdb4ad8c0e43a5229316504029e, type: 3} tree5: {fileID: 6357631730651435771, guid: af9ecbdb4ad8c0e43a5229316504029e, type: 3}
tree6: {fileID: 0} tree6: {fileID: 0}
renderedTrees: [] renderedTrees: []
--- !u!1 &691716470
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 691716472}
- component: {fileID: 691716471}
m_Layer: 0
m_Name: Directional Light
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!108 &691716471
Light:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 691716470}
m_Enabled: 1
serializedVersion: 10
m_Type: 1
m_Shape: 0
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Intensity: 1
m_Range: 10
m_SpotAngle: 30
m_InnerSpotAngle: 21.80208
m_CookieSize: 10
m_Shadows:
m_Type: 0
m_Resolution: -1
m_CustomResolution: -1
m_Strength: 1
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_CullingMatrixOverride:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
m_UseCullingMatrixOverride: 0
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingLayerMask: 1
m_Lightmapping: 4
m_LightShadowCasterMode: 0
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_UseViewFrustumForShadowCasterCull: 1
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &691716472
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 691716470}
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 143.3, y: 42.9, z: -2.571577}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &967854868 --- !u!1 &967854868
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -1,29 +1,21 @@
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using System.IO;
using System;
using UnityEngine.SceneManagement;
public class main : MonoBehaviour public class main : MonoBehaviour
{ {
//ground
float m_groundWidth = 10.0f;
float m_groundHeight = 10.0f;
Shader m_groundShader;
Texture m_groundTexture;
Color m_groundColor;
//camera GUI //camera GUI
float m_FieldOfView = 60.0f; float m_FieldOfView = 60.0f;
float m_camPosX = 0.0f; float m_camPosX = 0.0f;
float m_camPosY = 10.0f; float m_camPosY = 0.0f;
float m_camPosZ = 20.0f; float m_camPosZ = 0.0f;
float m_camLookAtX = 0.0f; float m_camLookAtX = 0.0f;
float m_camLookAtY = 0.0f; float m_camLookAtY = 0.0f;
float m_camLookAtZ = 0.0f; float m_camLookAtZ = 0.0f;
float newCameraPosX = 0.0f;
float newCameraPosY = 0.0f;
float newCameraPosZ = 0.0f;
float camera_rotation = 1.1f; float camera_rotation = 1.1f;
float camera_r = 20f; float camera_r = 20f;
@ -32,7 +24,6 @@ public class main : MonoBehaviour
//components //components
GameObject mainCamera; GameObject mainCamera;
GameObject directionalLight; GameObject directionalLight;
GameObject ground;
int numOfTrees; int numOfTrees;
int numOfRows; int numOfRows;
@ -49,7 +40,7 @@ public class main : MonoBehaviour
float treesZSlider = 0.0f; float treesZSlider = 0.0f;
float treesXSlider = 0.0f; float treesXSlider = 0.0f;
float lightIntensity = 4.0f; float lightIntensity = 2.0f;
GameObject selectRandomTree() GameObject selectRandomTree()
{ {
var list = new List<GameObject> { tree1, tree2, tree3, tree4, tree5, tree6 }; var list = new List<GameObject> { tree1, tree2, tree3, tree4, tree5, tree6 };
@ -81,7 +72,6 @@ public class main : MonoBehaviour
directionalLight.transform.position = new Vector3(10, 10.0f, 10.0f); directionalLight.transform.position = new Vector3(10, 10.0f, 10.0f);
directionalLight.transform.Rotate(lightDir.x, lightDir.y, lightDir.z, Space.Self); directionalLight.transform.Rotate(lightDir.x, lightDir.y, lightDir.z, Space.Self);
//---------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
// create prefabs // create prefabs
@ -112,82 +102,16 @@ public class main : MonoBehaviour
} }
//---------------------------------------------------------------------------------------------------------------------
//ground
/*
m_groundColor = new Color(1.0f, 0.4f, 0.6f, 1.0f);
m_groundShader = Shader.Find("Standard");
ground = new GameObject("Ground");
MeshRenderer groundMeshRenderer = ground.AddComponent<MeshRenderer>();
groundMeshRenderer.material = new Material(m_groundShader);
groundMeshRenderer.material.color = m_groundColor;
MeshFilter groundMeshFilter = ground.AddComponent<MeshFilter>();
Mesh groundMesh = new Mesh();
//dane wierzcho³ków
Vector3[] vertices = new Vector3[4]
{
new Vector3(-m_groundWidth/2.0f, -1.0f,-m_groundHeight/2.0f ),
new Vector3(m_groundWidth/2.0f, -1.0f, -m_groundHeight/2.0f),
new Vector3(m_groundWidth/2.0f,-1.0f, m_groundHeight/2.0f),
new Vector3(-m_groundWidth/2.0f, -1.0f, m_groundHeight/2.0f),
};
//bufor wierzcho³ków dla groundMesh
groundMesh.vertices = vertices;
//dane indeksów dla groundMesh
int[] indices = new int[6]
{
0, 3, 2,
0, 2, 1
};
//bufor indeksów
groundMesh.triangles = indices;
//dane normalnych dla groundMesh
Vector3[] normals = new Vector3[4]
{
new Vector3(0,1,0),
new Vector3(0,1,0),
new Vector3(0,1,0),
new Vector3(0,1,0),
};
//bufor normalnych dla groundMesh
groundMesh.normals = normals;
//dane wspó³rzêdnych tekstury dla groundMesh
Vector2[] uv = new Vector2[4]
{
new Vector2(0, 0),
new Vector2(1, 0),
new Vector2(0, 1),
new Vector2(1, 1)
};
//bufor wspó³rzêdnych tekstury dla groundMesh
groundMesh.uv = uv;
//mesh dla GameObject "Ground"
groundMeshFilter.mesh = groundMesh;
**/
} }
void Update() void Update()
{ {
mainCamera.GetComponent<Camera>().fieldOfView = m_FieldOfView; mainCamera.GetComponent<Camera>().fieldOfView = m_FieldOfView;
// mainCamera.GetComponent<Camera>().transform.position = new Vector3(m_camPosX,m_camPosY,m_camPosZ); newCameraPosX = camera_r * Mathf.Cos(camera_rotation) + 500f + m_camPosX;
mainCamera.GetComponent<Camera>().transform.position = new Vector3(camera_r * Mathf.Cos(camera_rotation) + 500f, 10f, camera_r * Mathf.Sin(camera_rotation) + 500f); newCameraPosY = 10f + m_camPosY;
mainCamera.GetComponent<Camera>().transform.LookAt(new Vector3(500f, 1f, 500f)); newCameraPosZ = camera_r * Mathf.Sin(camera_rotation) + 500f + m_camPosZ;
mainCamera.GetComponent<Camera>().transform.position = new Vector3(newCameraPosX, newCameraPosY, newCameraPosZ);
mainCamera.GetComponent<Camera>().transform.LookAt(new Vector3(500f + m_camLookAtX, 1f + m_camLookAtY, 500f + m_camLookAtZ));
camera_rotation += 0.001f; camera_rotation += 0.001f;
int index = 0; int index = 0;
@ -211,22 +135,22 @@ public class main : MonoBehaviour
m_FieldOfView = GUI.HorizontalSlider(new Rect(70, 20, 150, 20), m_FieldOfView, 20.0f, 150.0f); m_FieldOfView = GUI.HorizontalSlider(new Rect(70, 20, 150, 20), m_FieldOfView, 20.0f, 150.0f);
GUI.Label(new Rect(10, 45, 60, 20), "camPosX"); GUI.Label(new Rect(10, 45, 60, 20), "camPosX");
m_camPosX = GUI.HorizontalSlider(new Rect(70, 45, 150, 20), m_camPosX, -30.0f, 30.0f); m_camPosX = GUI.HorizontalSlider(new Rect(70, 45, 150, 20), m_camPosX, -300.0f, 300.0f);
GUI.Label(new Rect(10, 70, 60, 20), "camPosY"); GUI.Label(new Rect(10, 70, 60, 20), "camPosY");
m_camPosY = GUI.HorizontalSlider(new Rect(70, 70, 150, 20), m_camPosY, -30.0f, 30.0f); m_camPosY = GUI.HorizontalSlider(new Rect(70, 70, 150, 20), m_camPosY, -300.0f, 300.0f);
GUI.Label(new Rect(10, 95, 60, 20), "camPosZ"); GUI.Label(new Rect(10, 95, 60, 20), "camPosZ");
m_camPosZ = GUI.HorizontalSlider(new Rect(70, 95, 150, 20), m_camPosZ, -30.0f, 30.0f); m_camPosZ = GUI.HorizontalSlider(new Rect(70, 95, 150, 20), m_camPosZ, -300.0f, 300.0f);
GUI.Label(new Rect(10, 120, 60, 20), "LookAtX"); GUI.Label(new Rect(10, 120, 60, 20), "LookAtX");
m_camLookAtX = GUI.HorizontalSlider(new Rect(70, 120, 150, 20), m_camLookAtX, -30.0f, 30.0f); m_camLookAtX = GUI.HorizontalSlider(new Rect(70, 120, 150, 20), m_camLookAtX, -300.0f, 300.0f);
GUI.Label(new Rect(10, 150, 60, 20), "LookAtY"); GUI.Label(new Rect(10, 150, 60, 20), "LookAtY");
m_camLookAtY = GUI.HorizontalSlider(new Rect(70, 145, 150, 20), m_camLookAtY, -30.0f, 30.0f); m_camLookAtY = GUI.HorizontalSlider(new Rect(70, 145, 150, 20), m_camLookAtY, -300.0f, 300.0f);
GUI.Label(new Rect(10, 170, 60, 20), "LookAtZ"); GUI.Label(new Rect(10, 170, 60, 20), "LookAtZ");
m_camLookAtZ = GUI.HorizontalSlider(new Rect(70, 170, 150, 20), m_camLookAtZ, -30.0f, 30.0f); m_camLookAtZ = GUI.HorizontalSlider(new Rect(70, 170, 150, 20), m_camLookAtZ, -300.0f, 300.0f);
GUI.Label(new Rect(10, 190, 60, 20), "CameraR"); GUI.Label(new Rect(10, 190, 60, 20), "CameraR");
camera_r = GUI.HorizontalSlider(new Rect(70, 190, 150, 20), camera_r, -150.0f, 150.0f); camera_r = GUI.HorizontalSlider(new Rect(70, 190, 150, 20), camera_r, -150.0f, 150.0f);