Selaa lähdekoodia

Resolved merge conflicts incorporating both solutions

TEST
Figg 4 vuotta sitten
vanhempi
commit
f56d7856f7

+ 129
- 0
FreeCam/Assets/BlockSpawner.cs Näytä tiedosto

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

+ 59
- 2
FreeCam/Assets/Controls.inputactions Näytä tiedosto

@@ -52,6 +52,30 @@
52 52
                     "expectedControlType": "Axis",
53 53
                     "processors": "",
54 54
                     "interactions": ""
55
+                },
56
+                {
57
+                    "name": "Enter Rotate Block",
58
+                    "type": "Button",
59
+                    "id": "b22358ff-4b1a-4885-b252-f3f61eb2e897",
60
+                    "expectedControlType": "Button",
61
+                    "processors": "",
62
+                    "interactions": "Press"
63
+                },
64
+                {
65
+                    "name": "Exit Rotate Block",
66
+                    "type": "Button",
67
+                    "id": "38b2fbd1-ab2b-49f0-b20c-12ede099fd44",
68
+                    "expectedControlType": "Button",
69
+                    "processors": "",
70
+                    "interactions": "Press(behavior=1)"
71
+                },
72
+                {
73
+                    "name": "Rotate Block",
74
+                    "type": "PassThrough",
75
+                    "id": "83900c91-8eb5-4324-aed3-52d0adf00fad",
76
+                    "expectedControlType": "Vector2",
77
+                    "processors": "",
78
+                    "interactions": ""
55 79
                 }
56 80
             ],
57 81
             "bindings": [
@@ -222,7 +246,7 @@
222 246
                 },
223 247
                 {
224 248
                     "name": "",
225
-                    "id": "b00386e1-8b81-4b23-add0-14dfd7c1fc48",
249
+                    "id": "a13b0893-b67b-4b60-819c-a2a88e0a551c",
226 250
                     "path": "<Mouse>/delta",
227 251
                     "interactions": "",
228 252
                     "processors": "",
@@ -362,9 +386,42 @@
362 386
                     "action": "Scroll",
363 387
                     "isComposite": false,
364 388
                     "isPartOfComposite": false
389
+                },
390
+                {
391
+                    "name": "",=======
392
+                    "id": "14041b54-6b2c-4248-8d13-d3652f618c8f",
393
+                    "path": "<Mouse>/middleButton",
394
+                    "interactions": "Press",
395
+                    "processors": "",
396
+                    "groups": "",
397
+                    "action": "Enter Rotate Block",
398
+                    "isComposite": false,
399
+                    "isPartOfComposite": false
400
+                },
401
+                {
402
+                    "name": "",
403
+                    "id": "3ce3e2d9-ec9a-4062-971e-3f524008af63",
404
+                    "path": "<Mouse>/middleButton",
405
+                    "interactions": "Press(behavior=1)",
406
+                    "processors": "",
407
+                    "groups": "",
408
+                    "action": "Exit Rotate Block",
409
+                    "isComposite": false,
410
+                    "isPartOfComposite": false
411
+                },
412
+                {
413
+                    "name": "",
414
+                    "id": "ccc8db9a-4581-4a39-9c88-6834536d8888",
415
+                    "path": "<Mouse>/delta",
416
+                    "interactions": "",
417
+                    "processors": "",
418
+                    "groups": "",
419
+                    "action": "Rotate Block",
420
+                    "isComposite": false,
421
+                    "isPartOfComposite": false
365 422
                 }
366 423
             ]
367 424
         }
368 425
     ],
369 426
     "controlSchemes": []
370
-}
427
+}

+ 8
- 0
FreeCam/Assets/Effects.meta Näytä tiedosto

@@ -0,0 +1,8 @@
1
+fileFormatVersion: 2
2
+guid: 41582cd70db64bd47b6745a4095c0395
3
+folderAsset: yes
4
+DefaultImporter:
5
+  externalObjects: {}
6
+  userData: 
7
+  assetBundleName: 
8
+  assetBundleVariant: 

+ 13
- 0
FreeCam/Assets/Effects/NewShaderVariants.shadervariants Näytä tiedosto

@@ -0,0 +1,13 @@
1
+%YAML 1.1
2
+%TAG !u! tag:unity3d.com,2011:
3
+--- !u!200 &20000000
4
+ShaderVariantCollection:
5
+  m_ObjectHideFlags: 0
6
+  m_CorrespondingSourceObject: {fileID: 0}
7
+  m_PrefabInstance: {fileID: 0}
8
+  m_PrefabAsset: {fileID: 0}
9
+  m_Name: NewShaderVariants
10
+  m_Shaders:
11
+  - first: {fileID: 10512, guid: 0000000000000000f000000000000000, type: 0}
12
+    second:
13
+      variants: []

+ 8
- 0
FreeCam/Assets/Effects/NewShaderVariants.shadervariants.meta Näytä tiedosto

@@ -0,0 +1,8 @@
1
+fileFormatVersion: 2
2
+guid: 1bac98432915ee94bafd6b815a8663d7
3
+NativeFormatImporter:
4
+  externalObjects: {}
5
+  mainObjectFileID: 0
6
+  userData: 
7
+  assetBundleName: 
8
+  assetBundleVariant: 

+ 53
- 0
FreeCam/Assets/Effects/standardSurfaceShader.shader Näytä tiedosto

@@ -0,0 +1,53 @@
1
+Shader "Custom/standardSurfaceShader"
2
+{
3
+    Properties
4
+    {
5
+        _Color ("Color", Color) = (1,1,1,1)
6
+        _MainTex ("Albedo (RGB)", 2D) = "white" {}
7
+        _Glossiness ("Smoothness", Range(0,1)) = 0.5
8
+        _Metallic ("Metallic", Range(0,1)) = 0.0
9
+    }
10
+    SubShader
11
+    {
12
+        Tags { "RenderType"="Opaque" }
13
+        LOD 200
14
+
15
+        CGPROGRAM
16
+        // Physically based Standard lighting model, and enable shadows on all light types
17
+        #pragma surface surf Standard fullforwardshadows
18
+
19
+        // Use shader model 3.0 target, to get nicer looking lighting
20
+        #pragma target 3.0
21
+
22
+        sampler2D _MainTex;
23
+
24
+        struct Input
25
+        {
26
+            float2 uv_MainTex;
27
+        };
28
+
29
+        half _Glossiness;
30
+        half _Metallic;
31
+        fixed4 _Color;
32
+
33
+        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
34
+        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
35
+        // #pragma instancing_options assumeuniformscaling
36
+        UNITY_INSTANCING_BUFFER_START(Props)
37
+            // put more per-instance properties here
38
+        UNITY_INSTANCING_BUFFER_END(Props)
39
+
40
+        void surf (Input IN, inout SurfaceOutputStandard o)
41
+        {
42
+            // Albedo comes from a texture tinted by color
43
+            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
44
+            o.Albedo = c.rgb;
45
+            // Metallic and smoothness come from slider variables
46
+            o.Metallic = _Metallic;
47
+            o.Smoothness = _Glossiness;
48
+            o.Alpha = c.a;
49
+        }
50
+        ENDCG
51
+    }
52
+    FallBack "Diffuse"
53
+}

+ 9
- 0
FreeCam/Assets/Effects/standardSurfaceShader.shader.meta Näytä tiedosto

@@ -0,0 +1,9 @@
1
+fileFormatVersion: 2
2
+guid: b0c691a25e854aa488e55c7de961b502
3
+ShaderImporter:
4
+  externalObjects: {}
5
+  defaultTextures: []
6
+  nonModifiableTextures: []
7
+  userData: 
8
+  assetBundleName: 
9
+  assetBundleVariant: 

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

@@ -0,0 +1,36 @@
1
+Shader "Custom/wMaillageShader"
2
+{
3
+	Properties
4
+	{
5
+	   _InnerColor("Inner Color", Color) = (0.0, 0.0, 0.0, 0.5)
6
+	   _RimColor("Rim Color", Color) = (1.0,1.0,1.0,0.5)
7
+	   _RimPower("Rim Power", Range(0.5,8.0)) = 2.47
8
+	}
9
+		SubShader
10
+	{
11
+	  Tags { "Queue" = "Transparent" }
12
+	  Cull Off ZWrite Off ZTest Less
13
+		//Blend based on output Alpha, not color value
14
+		Blend One OneMinusSrcAlpha
15
+		CGPROGRAM
16
+		#pragma surface surf Lambert alpha:fade
17
+		struct Input
18
+		{
19
+			float3 viewDir;
20
+		};
21
+		float4 _InnerColor;
22
+		float4 _RimColor;
23
+		float _RimPower;
24
+		void surf(Input IN, inout SurfaceOutput o)
25
+		{
26
+			half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal));
27
+			rim = pow(rim, _RimPower);
28
+			//Shift inner color to rim color by rim value adjusted by _InnerColor transparency to reduce its effect
29
+			//on semi-transparent part of rim color the more transparent inner color becomes.
30
+			o.Emission = lerp(_InnerColor.rgb, _RimColor.rgb, saturate(rim + (1 - _InnerColor.a) - (1 - _RimColor.a)));
31
+			o.Alpha = lerp(_InnerColor.a, _RimColor.a, rim);
32
+		}
33
+		ENDCG
34
+	}
35
+		Fallback "Diffuse"
36
+}

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

@@ -0,0 +1,10 @@
1
+fileFormatVersion: 2
2
+guid: 167cdc0b24acc2f449b7fb1756fbc873
3
+ShaderImporter:
4
+  externalObjects: {}
5
+  defaultTextures:
6
+  - _MainTex: {fileID: 10309, guid: 0000000000000000f000000000000000, type: 0}
7
+  nonModifiableTextures: []
8
+  userData: 
9
+  assetBundleName: 
10
+  assetBundleVariant: 

+ 2
- 0
FreeCam/Assets/Player.prefab Näytä tiedosto

@@ -362,3 +362,5 @@ MonoBehaviour:
362 362
   m_EditorClassIdentifier: 
363 363
   _blockToPlace: {fileID: 0}
364 364
   spawnDistance: 3
365
+  previewShader: {fileID: 4800000, guid: 167cdc0b24acc2f449b7fb1756fbc873, type: 3}
366
+  _blockRotating: 0

+ 2
- 0
FreeCam/Assets/Scripts/BlockSpawner.cs.meta Näytä tiedosto

@@ -4,6 +4,8 @@ MonoImporter:
4 4
   externalObjects: {}
5 5
   serializedVersion: 2
6 6
   defaultReferences: []
7
+  - _blockToPlace: {instanceID: 0}
8
+  - previewShader: {fileID: 4800000, guid: 167cdc0b24acc2f449b7fb1756fbc873, type: 3}
7 9
   executionOrder: 0
8 10
   icon: {instanceID: 0}
9 11
   userData: 

+ 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