|
@@ -5,16 +5,23 @@ using UnityEngine.InputSystem;
|
5
|
5
|
public class BlockSpawner : MonoBehaviour
|
6
|
6
|
{
|
7
|
7
|
public Inventory inventory;
|
8
|
|
-
|
9
|
|
- public float spawnDistance = 3f;
|
|
8
|
+ public Shader previewShader;
|
10
|
9
|
|
11
|
|
- #pragma warning disable 0649
|
|
10
|
+ private Shader _initialShader;
|
|
11
|
+#pragma warning disable 0649
|
12
|
12
|
[SerializeField] private UI_Inventory uiInventory;
|
13
|
|
- #pragma warning restore 0649
|
|
13
|
+#pragma warning restore 0649
|
14
|
14
|
private GameObject _blockInstance;
|
|
15
|
+ private Quaternion _lastRotationState;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+ public float spawnDistance = 3f;
|
|
19
|
+ public bool _blockRotating = false;
|
15
|
20
|
|
16
|
21
|
private bool _isPreview;
|
17
|
22
|
|
|
23
|
+
|
|
24
|
+
|
18
|
25
|
public void Awake()
|
19
|
26
|
{
|
20
|
27
|
_isPreview = false;
|
|
@@ -28,6 +35,7 @@ public class BlockSpawner : MonoBehaviour
|
28
|
35
|
if (!_isPreview) return;
|
29
|
36
|
// todo remove in inventory
|
30
|
37
|
_blockInstance.transform.SetParent(null);
|
|
38
|
+ SwitchToDefaultRender();
|
31
|
39
|
_blockInstance = null;
|
32
|
40
|
DisablePreviewMode();
|
33
|
41
|
}
|
|
@@ -58,7 +66,9 @@ public class BlockSpawner : MonoBehaviour
|
58
|
66
|
Vector3 spawnPos = Vector3.forward * spawnDistance;
|
59
|
67
|
_blockInstance = Instantiate(selectedItem.Prefab, spawnPos, Quaternion.identity);
|
60
|
68
|
_blockInstance.transform.SetParent(this.transform, false);
|
|
69
|
+ _blockInstance.transform.rotation = _lastRotationState;
|
61
|
70
|
_isPreview = true;
|
|
71
|
+ SwitchToMeshRender();
|
62
|
72
|
}
|
63
|
73
|
|
64
|
74
|
public void DisablePreviewMode()
|
|
@@ -66,4 +76,50 @@ public class BlockSpawner : MonoBehaviour
|
66
|
76
|
if (_blockInstance != null) Destroy(_blockInstance);
|
67
|
77
|
_isPreview = false;
|
68
|
78
|
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+ private void SwitchToMeshRender()
|
|
82
|
+ {
|
|
83
|
+ MeshRenderer vRenderer = _blockInstance.GetComponent<MeshRenderer>();
|
|
84
|
+ Material vMaterial = vRenderer.material;
|
|
85
|
+ _initialShader = vMaterial.shader;
|
|
86
|
+ vMaterial.shader = previewShader;
|
|
87
|
+ }
|
|
88
|
+
|
|
89
|
+ private void SwitchToDefaultRender()
|
|
90
|
+ {
|
|
91
|
+ MeshRenderer vRenderer = _blockInstance.GetComponent<MeshRenderer>();
|
|
92
|
+ Material vMaterial = vRenderer.material;
|
|
93
|
+ vMaterial.shader = _initialShader;
|
|
94
|
+ }
|
|
95
|
+
|
|
96
|
+ public void OnEnterRotateBlock(InputValue value)
|
|
97
|
+ {
|
|
98
|
+ float valueAsFloat = value.Get<float>();
|
|
99
|
+ Debug.Log(valueAsFloat);
|
|
100
|
+ _blockRotating = true;
|
|
101
|
+ }
|
|
102
|
+
|
|
103
|
+ public void OnExitRotateBlock(InputValue value)
|
|
104
|
+ {
|
|
105
|
+ float valueAsFloat = value.Get<float>();
|
|
106
|
+ Debug.Log(valueAsFloat);
|
|
107
|
+ _blockRotating = false;
|
|
108
|
+ }
|
|
109
|
+
|
|
110
|
+ public void OnRotateBlock(InputValue value)
|
|
111
|
+ {
|
|
112
|
+ if (_isPreview && _blockRotating)
|
|
113
|
+ {
|
|
114
|
+ Vector2 iMouseMovement = value.Get<Vector2>();
|
|
115
|
+
|
|
116
|
+ Transform vTransform = _blockInstance.transform;
|
|
117
|
+ //vTransform.Rotate(iMouseMovement.y / 10, iMouseMovement.x / 10, 0);
|
|
118
|
+ vTransform.RotateAround(vTransform.position, transform.right, iMouseMovement.y / 10.0f);
|
|
119
|
+ vTransform.RotateAround(vTransform.position, transform.up, iMouseMovement.x / 10.0f);
|
|
120
|
+ //vTransform.eulerAngles += vTransform.worldToLocalMatrix.MultiplyVector(new Vector3(iMouseMovement.y / 10, iMouseMovement.x / 10, 0));
|
|
121
|
+ //vTransform.Rotate(iMouseMovement.y/10, iMouseMovement.x/10, 0);
|
|
122
|
+ _lastRotationState = vTransform.rotation;
|
|
123
|
+ }
|
|
124
|
+ }
|
69
|
125
|
}
|