DemiSel 4 vuotta sitten
vanhempi
commit
ae719f53c8

+ 58
- 2
FreeCam/Assets/BlockSpawner.cs Näytä tiedosto

@@ -6,6 +6,13 @@ using UnityEngine.InputSystem;
6 6
 public class BlockSpawner : MonoBehaviour
7 7
 {
8 8
 
9
+<<<<<<< HEAD
10
+=======
11
+    private void Start()
12
+    {
13
+        _playerInput = GetComponent<PlayerInput>();
14
+    }
15
+>>>>>>> shader
9 16
     [SerializeField]
10 17
     private GameObject _blockToPlace;
11 18
     public GameObject BlockToPlace
@@ -20,6 +27,7 @@ public class BlockSpawner : MonoBehaviour
20 27
             _blockToPlace = value;
21 28
         }
22 29
     }
30
+    PlayerInput _playerInput;
23 31
 
24 32
     public float spawnDistance = 3f;
25 33
 
@@ -30,6 +38,11 @@ public class BlockSpawner : MonoBehaviour
30 38
     private bool _isPreview = false;
31 39
     private Shader _initialShader;
32 40
 
41
+    public bool _blockRotating = false;
42
+    private Quaternion _lastRotationState;
43
+
44
+    private Shader _initialShader;
45
+
33 46
     public void OnPlaceBlock()
34 47
     {
35 48
         if (!_isPreview) return;
@@ -43,8 +56,44 @@ public class BlockSpawner : MonoBehaviour
43 56
     {
44 57
         float valueAsFloat = value.Get<float>();
45 58
 
46
-        if (valueAsFloat == 1f) EnablePreviewMode();
47
-        else DisablePreviewMode();
59
+        if (valueAsFloat == 1f)
60
+        {
61
+            EnablePreviewMode();
62
+        }
63
+        else
64
+        {
65
+            DisablePreviewMode();
66
+        }
67
+    }
68
+
69
+    public void OnEnterRotateBlock(InputValue value)
70
+    {
71
+        float valueAsFloat = value.Get<float>();
72
+        Debug.Log(valueAsFloat);
73
+        _blockRotating = true;
74
+    }
75
+
76
+    public void OnExitRotateBlock(InputValue value)
77
+    {
78
+        float valueAsFloat = value.Get<float>();
79
+        Debug.Log(valueAsFloat);
80
+        _blockRotating = false;
81
+    }
82
+
83
+    public void OnRotateBlock(InputValue value)
84
+    {
85
+        if (_isPreview && _blockRotating)
86
+        {
87
+            Vector2 iMouseMovement = value.Get<Vector2>();
88
+
89
+            Transform vTransform = _blockInstance.transform;
90
+            //vTransform.Rotate(iMouseMovement.y / 10, iMouseMovement.x / 10, 0);
91
+            vTransform.RotateAround(vTransform.position, transform.right, iMouseMovement.y / 10.0f);
92
+            vTransform.RotateAround(vTransform.position, transform.up, iMouseMovement.x / 10.0f);
93
+            //vTransform.eulerAngles += vTransform.worldToLocalMatrix.MultiplyVector(new Vector3(iMouseMovement.y / 10, iMouseMovement.x / 10, 0));
94
+            //vTransform.Rotate(iMouseMovement.y/10, iMouseMovement.x/10, 0);
95
+            _lastRotationState = vTransform.rotation;
96
+        } 
48 97
     }
49 98
 
50 99
     private void EnablePreviewMode()
@@ -52,8 +101,10 @@ public class BlockSpawner : MonoBehaviour
52 101
         if (_blockToPlace == null) return;
53 102
 
54 103
         Vector3 spawnPos = Vector3.forward * spawnDistance;
104
+
55 105
         _blockInstance = Instantiate(_blockToPlace, spawnPos, Quaternion.identity);
56 106
         _blockInstance.transform.SetParent(this.transform, false);
107
+        _blockInstance.transform.rotation = _lastRotationState;
57 108
         _isPreview = true;
58 109
         SwitchToMeshRender();
59 110
     }
@@ -78,4 +129,9 @@ public class BlockSpawner : MonoBehaviour
78 129
         Material vMaterial = vRenderer.material;
79 130
         vMaterial.shader = _initialShader;
80 131
     }
132
+<<<<<<< HEAD
133
+=======
134
+
135
+    
136
+>>>>>>> shader
81 137
 }

+ 58
- 1
FreeCam/Assets/Controls.inputactions Näytä tiedosto

@@ -44,6 +44,30 @@
44 44
                     "expectedControlType": "Button",
45 45
                     "processors": "",
46 46
                     "interactions": ""
47
+                },
48
+                {
49
+                    "name": "Enter Rotate Block",
50
+                    "type": "Button",
51
+                    "id": "b22358ff-4b1a-4885-b252-f3f61eb2e897",
52
+                    "expectedControlType": "Button",
53
+                    "processors": "",
54
+                    "interactions": "Press"
55
+                },
56
+                {
57
+                    "name": "Exit Rotate Block",
58
+                    "type": "Button",
59
+                    "id": "38b2fbd1-ab2b-49f0-b20c-12ede099fd44",
60
+                    "expectedControlType": "Button",
61
+                    "processors": "",
62
+                    "interactions": "Press(behavior=1)"
63
+                },
64
+                {
65
+                    "name": "Rotate Block",
66
+                    "type": "PassThrough",
67
+                    "id": "83900c91-8eb5-4324-aed3-52d0adf00fad",
68
+                    "expectedControlType": "Vector2",
69
+                    "processors": "",
70
+                    "interactions": ""
47 71
                 }
48 72
             ],
49 73
             "bindings": [
@@ -214,7 +238,7 @@
214 238
                 },
215 239
                 {
216 240
                     "name": "",
217
-                    "id": "b00386e1-8b81-4b23-add0-14dfd7c1fc48",
241
+                    "id": "a13b0893-b67b-4b60-819c-a2a88e0a551c",
218 242
                     "path": "<Mouse>/delta",
219 243
                     "interactions": "",
220 244
                     "processors": "",
@@ -343,6 +367,39 @@
343 367
                     "action": "Sprint",
344 368
                     "isComposite": false,
345 369
                     "isPartOfComposite": false
370
+                },
371
+                {
372
+                    "name": "",
373
+                    "id": "14041b54-6b2c-4248-8d13-d3652f618c8f",
374
+                    "path": "<Mouse>/middleButton",
375
+                    "interactions": "Press",
376
+                    "processors": "",
377
+                    "groups": "",
378
+                    "action": "Enter Rotate Block",
379
+                    "isComposite": false,
380
+                    "isPartOfComposite": false
381
+                },
382
+                {
383
+                    "name": "",
384
+                    "id": "3ce3e2d9-ec9a-4062-971e-3f524008af63",
385
+                    "path": "<Mouse>/middleButton",
386
+                    "interactions": "Press(behavior=1)",
387
+                    "processors": "",
388
+                    "groups": "",
389
+                    "action": "Exit Rotate Block",
390
+                    "isComposite": false,
391
+                    "isPartOfComposite": false
392
+                },
393
+                {
394
+                    "name": "",
395
+                    "id": "ccc8db9a-4581-4a39-9c88-6834536d8888",
396
+                    "path": "<Mouse>/delta",
397
+                    "interactions": "",
398
+                    "processors": "",
399
+                    "groups": "",
400
+                    "action": "Rotate Block",
401
+                    "isComposite": false,
402
+                    "isPartOfComposite": false
346 403
                 }
347 404
             ]
348 405
         }

+ 36
- 0
FreeCam/Assets/Effects/wMaillageShader.shader Näytä tiedosto

@@ -1,5 +1,6 @@
1 1
 Shader "Custom/wMaillageShader"
2 2
 {
3
+<<<<<<< HEAD
3 4
     Properties
4 5
     {
5 6
 		_MainTex("Texture", 2D) = "white" {}
@@ -131,4 +132,39 @@
131 132
 			ENDCG
132 133
 		}
133 134
     }
135
+=======
136
+	Properties
137
+	{
138
+	   _InnerColor("Inner Color", Color) = (0.0, 0.0, 0.0, 0.5)
139
+	   _RimColor("Rim Color", Color) = (1.0,1.0,1.0,0.5)
140
+	   _RimPower("Rim Power", Range(0.5,8.0)) = 2.47
141
+	}
142
+		SubShader
143
+	{
144
+	  Tags { "Queue" = "Transparent" }
145
+	  Cull Off ZWrite Off ZTest Less
146
+		//Blend based on output Alpha, not color value
147
+		Blend One OneMinusSrcAlpha
148
+		CGPROGRAM
149
+		#pragma surface surf Lambert alpha:fade
150
+		struct Input
151
+		{
152
+			float3 viewDir;
153
+		};
154
+		float4 _InnerColor;
155
+		float4 _RimColor;
156
+		float _RimPower;
157
+		void surf(Input IN, inout SurfaceOutput o)
158
+		{
159
+			half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal));
160
+			rim = pow(rim, _RimPower);
161
+			//Shift inner color to rim color by rim value adjusted by _InnerColor transparency to reduce its effect
162
+			//on semi-transparent part of rim color the more transparent inner color becomes.
163
+			o.Emission = lerp(_InnerColor.rgb, _RimColor.rgb, saturate(rim + (1 - _InnerColor.a) - (1 - _RimColor.a)));
164
+			o.Alpha = lerp(_InnerColor.a, _RimColor.a, rim);
165
+		}
166
+		ENDCG
167
+	}
168
+		Fallback "Diffuse"
169
+>>>>>>> shader
134 170
 }

+ 4
- 0
FreeCam/Assets/Effects/wMaillageShader.shader.meta Näytä tiedosto

@@ -3,7 +3,11 @@ guid: 167cdc0b24acc2f449b7fb1756fbc873
3 3
 ShaderImporter:
4 4
   externalObjects: {}
5 5
   defaultTextures:
6
+<<<<<<< HEAD
6 7
   - _MainTex: {fileID: 10300, guid: 0000000000000000f000000000000000, type: 0}
8
+=======
9
+  - _MainTex: {fileID: 10309, guid: 0000000000000000f000000000000000, type: 0}
10
+>>>>>>> shader
7 11
   nonModifiableTextures: []
8 12
   userData: 
9 13
   assetBundleName: 

+ 11
- 1
FreeCam/Assets/Materials/New Material.mat Näytä tiedosto

@@ -8,7 +8,11 @@ Material:
8 8
   m_PrefabInstance: {fileID: 0}
9 9
   m_PrefabAsset: {fileID: 0}
10 10
   m_Name: New Material
11
+<<<<<<< HEAD
11 12
   m_Shader: {fileID: 4800000, guid: b0c691a25e854aa488e55c7de961b502, type: 3}
13
+=======
14
+  m_Shader: {fileID: 4800000, guid: 167cdc0b24acc2f449b7fb1756fbc873, type: 3}
15
+>>>>>>> shader
12 16
   m_ShaderKeywords: 
13 17
   m_LightmapFlags: 4
14 18
   m_EnableInstancingVariants: 0
@@ -40,7 +44,7 @@ Material:
40 44
         m_Scale: {x: 0.85, y: 0.85}
41 45
         m_Offset: {x: 0.075, y: 0.075}
42 46
     - _MainTex:
43
-        m_Texture: {fileID: 10906, guid: 0000000000000000f000000000000000, type: 0}
47
+        m_Texture: {fileID: 10305, guid: 0000000000000000f000000000000000, type: 0}
44 48
         m_Scale: {x: 0.85, y: 0.85}
45 49
         m_Offset: {x: 0.075, y: 0.075}
46 50
     - _MetallicGlossMap:
@@ -67,12 +71,18 @@ Material:
67 71
     - _Mode: 0
68 72
     - _OcclusionStrength: 1
69 73
     - _Parallax: 0.02
74
+    - _RimPower: 0.91
70 75
     - _SmoothnessTextureChannel: 0
71 76
     - _SpecularHighlights: 1
72 77
     - _SrcBlend: 1
78
+    - _Threshold: 0.01
73 79
     - _UVSec: 0
74 80
     - _ZWrite: 1
75 81
     m_Colors:
76 82
     - _Color: {r: 0.42955682, g: 0.4301132, b: 0.46226418, a: 1}
83
+    - _EdgeColor: {r: 1, g: 0, b: 0, a: 1}
77 84
     - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
85
+    - _InnerColor: {r: 0, g: 0, b: 0, a: 1}
86
+    - _MainTex: {r: 0.5, g: 0.5, b: 1, a: 1}
87
+    - _RimColor: {r: 1, g: 1, b: 1, a: 1}
78 88
   m_BuildTextureStacks: []

+ 19
- 3
FreeCam/Assets/Scripts/FreeCam.cs Näytä tiedosto

@@ -23,6 +23,8 @@ public class FreeCam : MonoBehaviour
23 23
     private Vector2 _inputMouse;
24 24
     private Vector2 _velocity;
25 25
     private CharacterController _controller;
26
+    private BlockSpawner _blockSpawner;
27
+
26 28
 
27 29
     private float _rotationX;
28 30
     private bool _isSprinting;
@@ -37,7 +39,7 @@ public class FreeCam : MonoBehaviour
37 39
         _inputMouse = Vector2.zero;
38 40
         _velocity = Vector2.zero;
39 41
         _controller = gameObject.GetComponent<CharacterController>();
40
-
42
+        _blockSpawner = gameObject.GetComponent<BlockSpawner>();
41 43
         _rotationX = 0;
42 44
         _isSprinting = false;
43 45
     }
@@ -77,8 +79,17 @@ public class FreeCam : MonoBehaviour
77 79
     public void OnLook(InputValue value)
78 80
     {
79 81
         Vector2 valueAsVector2 = value.Get<Vector2>();
80
-        _inputMouse.x = valueAsVector2.x;
81
-        _inputMouse.y = valueAsVector2.y;
82
+        float xVelocity = valueAsVector2.x;
83
+        float yVelocity = valueAsVector2.y;
84
+
85
+        if (_blockSpawner._blockRotating)
86
+        {
87
+            xVelocity *= 0.05f;
88
+            yVelocity *= 0.05f;
89
+        }
90
+        _inputMouse.x = xVelocity;
91
+        _inputMouse.y = yVelocity;
92
+
82 93
     }
83 94
 
84 95
     public void OnMovement(InputValue value)
@@ -88,6 +99,11 @@ public class FreeCam : MonoBehaviour
88 99
         _velocity.y = valueAsVector2.y;
89 100
     }
90 101
 
102
+    public void OnMovementBlockRotating(InputValue value)
103
+    {
104
+        OnMovement(value);
105
+    }
106
+
91 107
     public void OnSprint(InputValue value)
92 108
     {
93 109
         float valueAsFloat = value.Get<float>();

Loading…
Peruuta
Tallenna