Browse Source

Fix

merge conflicts résolus, inputactions et blockSpawner script
ce dernier a été déplacé dans un sous-dossier Scripts
TEST
Figg 4 years ago
parent
commit
3fecdf82c0

+ 0
- 129
FreeCam/Assets/BlockSpawner.cs View File

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
-}

+ 1
- 1
FreeCam/Assets/Controls.inputactions View File

388
                     "isPartOfComposite": false
388
                     "isPartOfComposite": false
389
                 },
389
                 },
390
                 {
390
                 {
391
-                    "name": "",=======
391
+                    "name": "",
392
                     "id": "14041b54-6b2c-4248-8d13-d3652f618c8f",
392
                     "id": "14041b54-6b2c-4248-8d13-d3652f618c8f",
393
                     "path": "<Mouse>/middleButton",
393
                     "path": "<Mouse>/middleButton",
394
                     "interactions": "Press",
394
                     "interactions": "Press",

+ 60
- 4
FreeCam/Assets/Scripts/BlockSpawner.cs View File

5
 public class BlockSpawner : MonoBehaviour
5
 public class BlockSpawner : MonoBehaviour
6
 {
6
 {
7
     public Inventory inventory;
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
     [SerializeField] private UI_Inventory uiInventory;
12
     [SerializeField] private UI_Inventory uiInventory;
13
-    #pragma warning restore 0649
13
+#pragma warning restore 0649
14
     private GameObject _blockInstance;
14
     private GameObject _blockInstance;
15
+    private Quaternion _lastRotationState;
16
+
17
+
18
+    public float spawnDistance = 3f;
19
+    public bool _blockRotating = false;
15
 
20
 
16
     private bool _isPreview;
21
     private bool _isPreview;
17
 
22
 
23
+
24
+
18
     public void Awake()
25
     public void Awake()
19
     {
26
     {
20
         _isPreview = false;
27
         _isPreview = false;
28
         if (!_isPreview) return;
35
         if (!_isPreview) return;
29
         // todo remove in inventory
36
         // todo remove in inventory
30
         _blockInstance.transform.SetParent(null);
37
         _blockInstance.transform.SetParent(null);
38
+        SwitchToDefaultRender();
31
         _blockInstance = null;
39
         _blockInstance = null;
32
         DisablePreviewMode();
40
         DisablePreviewMode();
33
     }
41
     }
58
         Vector3 spawnPos = Vector3.forward * spawnDistance;
66
         Vector3 spawnPos = Vector3.forward * spawnDistance;
59
         _blockInstance = Instantiate(selectedItem.Prefab, spawnPos, Quaternion.identity);
67
         _blockInstance = Instantiate(selectedItem.Prefab, spawnPos, Quaternion.identity);
60
         _blockInstance.transform.SetParent(this.transform, false);
68
         _blockInstance.transform.SetParent(this.transform, false);
69
+        _blockInstance.transform.rotation = _lastRotationState;
61
         _isPreview = true;
70
         _isPreview = true;
71
+        SwitchToMeshRender();
62
     }
72
     }
63
 
73
 
64
     public void DisablePreviewMode()
74
     public void DisablePreviewMode()
66
         if (_blockInstance != null) Destroy(_blockInstance);
76
         if (_blockInstance != null) Destroy(_blockInstance);
67
         _isPreview = false;
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
 }

Loading…
Cancel
Save