Browse Source

Add inventory system

Ajout d'un "backend" pour un systeme d'inventaire
reste a faire le cablage et a afficher une UI a l'ecran
pour avoir un retour de l'etat de l'inventaire
Le remplissage de l'inventaire du joueur est censé se faire
via un gameobject GameManager qui n'existe pas encore, il reste donc
vide jusqu'a nouvel ordre.
Le code n'a pas été testé donc je balance un code de schrodinger B)
TEST
Figg 4 years ago
parent
commit
0e88d51a53

+ 0
- 60
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
-    [SerializeField]
9
-    private GameObject _blockToPlace;
10
-    public GameObject BlockToPlace
11
-    {
12
-        get
13
-        {
14
-            return _blockToPlace;
15
-        }
16
-        set
17
-        {
18
-            DisablePreviewMode();
19
-            _blockToPlace = value;
20
-        }
21
-    }
22
-
23
-    public float spawnDistance = 3f;
24
-
25
-    private GameObject _blockInstance;
26
-
27
-    private bool _isPreview = false;
28
-
29
-    public void OnPlaceBlock()
30
-    {
31
-        if (!_isPreview) return;
32
-        _blockInstance.transform.SetParent(null);
33
-        _blockInstance = null;
34
-        DisablePreviewMode();
35
-    }
36
-
37
-    public void OnTogglePreviewMode(InputValue value)
38
-    {
39
-        float valueAsFloat = value.Get<float>();
40
-
41
-        if (valueAsFloat == 1f) EnablePreviewMode();
42
-        else DisablePreviewMode();
43
-    }
44
-
45
-    private void EnablePreviewMode()
46
-    {
47
-        if (_blockToPlace == null) return;
48
-
49
-        Vector3 spawnPos = Vector3.forward * spawnDistance;
50
-        _blockInstance = Instantiate(_blockToPlace, spawnPos, Quaternion.identity);
51
-        _blockInstance.transform.SetParent(this.transform, false);
52
-        _isPreview = true;
53
-    }
54
-
55
-    private void DisablePreviewMode()
56
-    {
57
-        if (_blockInstance != null) Destroy(_blockInstance);
58
-        _isPreview = false;
59
-    }
60
-}

FreeCam/Assets/Block_test.prefab → FreeCam/Assets/Block_test01.prefab View File


FreeCam/Assets/Block_test.prefab.meta → FreeCam/Assets/Block_test01.prefab.meta View File


+ 98
- 0
FreeCam/Assets/Block_test02.prefab View File

1
+%YAML 1.1
2
+%TAG !u! tag:unity3d.com,2011:
3
+--- !u!1 &4071370194869356435
4
+GameObject:
5
+  m_ObjectHideFlags: 0
6
+  m_CorrespondingSourceObject: {fileID: 0}
7
+  m_PrefabInstance: {fileID: 0}
8
+  m_PrefabAsset: {fileID: 0}
9
+  serializedVersion: 6
10
+  m_Component:
11
+  - component: {fileID: 6082380134508414474}
12
+  - component: {fileID: 1275378843345810038}
13
+  - component: {fileID: 7850862662254572156}
14
+  - component: {fileID: 7910293329758150995}
15
+  m_Layer: 0
16
+  m_Name: Cylinder
17
+  m_TagString: Untagged
18
+  m_Icon: {fileID: 0}
19
+  m_NavMeshLayer: 0
20
+  m_StaticEditorFlags: 0
21
+  m_IsActive: 1
22
+--- !u!4 &6082380134508414474
23
+Transform:
24
+  m_ObjectHideFlags: 0
25
+  m_CorrespondingSourceObject: {fileID: 0}
26
+  m_PrefabInstance: {fileID: 0}
27
+  m_PrefabAsset: {fileID: 0}
28
+  m_GameObject: {fileID: 4071370194869356435}
29
+  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
30
+  m_LocalPosition: {x: 0, y: 0, z: 0}
31
+  m_LocalScale: {x: 2, y: 0.3, z: 2}
32
+  m_Children: []
33
+  m_Father: {fileID: 0}
34
+  m_RootOrder: 0
35
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
36
+--- !u!33 &1275378843345810038
37
+MeshFilter:
38
+  m_ObjectHideFlags: 0
39
+  m_CorrespondingSourceObject: {fileID: 0}
40
+  m_PrefabInstance: {fileID: 0}
41
+  m_PrefabAsset: {fileID: 0}
42
+  m_GameObject: {fileID: 4071370194869356435}
43
+  m_Mesh: {fileID: 10206, guid: 0000000000000000e000000000000000, type: 0}
44
+--- !u!23 &7850862662254572156
45
+MeshRenderer:
46
+  m_ObjectHideFlags: 0
47
+  m_CorrespondingSourceObject: {fileID: 0}
48
+  m_PrefabInstance: {fileID: 0}
49
+  m_PrefabAsset: {fileID: 0}
50
+  m_GameObject: {fileID: 4071370194869356435}
51
+  m_Enabled: 1
52
+  m_CastShadows: 1
53
+  m_ReceiveShadows: 1
54
+  m_DynamicOccludee: 1
55
+  m_MotionVectors: 1
56
+  m_LightProbeUsage: 1
57
+  m_ReflectionProbeUsage: 1
58
+  m_RayTracingMode: 2
59
+  m_RayTraceProcedural: 0
60
+  m_RenderingLayerMask: 1
61
+  m_RendererPriority: 0
62
+  m_Materials:
63
+  - {fileID: 2100000, guid: 7a1df68ff2cb2814088ca3c160bfdf17, type: 2}
64
+  m_StaticBatchInfo:
65
+    firstSubMesh: 0
66
+    subMeshCount: 0
67
+  m_StaticBatchRoot: {fileID: 0}
68
+  m_ProbeAnchor: {fileID: 0}
69
+  m_LightProbeVolumeOverride: {fileID: 0}
70
+  m_ScaleInLightmap: 1
71
+  m_ReceiveGI: 1
72
+  m_PreserveUVs: 0
73
+  m_IgnoreNormalsForChartDetection: 0
74
+  m_ImportantGI: 0
75
+  m_StitchLightmapSeams: 1
76
+  m_SelectedEditorRenderState: 3
77
+  m_MinimumChartSize: 4
78
+  m_AutoUVMaxDistance: 0.5
79
+  m_AutoUVMaxAngle: 89
80
+  m_LightmapParameters: {fileID: 0}
81
+  m_SortingLayerID: 0
82
+  m_SortingLayer: 0
83
+  m_SortingOrder: 0
84
+  m_AdditionalVertexStreams: {fileID: 0}
85
+--- !u!136 &7910293329758150995
86
+CapsuleCollider:
87
+  m_ObjectHideFlags: 0
88
+  m_CorrespondingSourceObject: {fileID: 0}
89
+  m_PrefabInstance: {fileID: 0}
90
+  m_PrefabAsset: {fileID: 0}
91
+  m_GameObject: {fileID: 4071370194869356435}
92
+  m_Material: {fileID: 0}
93
+  m_IsTrigger: 0
94
+  m_Enabled: 1
95
+  m_Radius: 0.5000001
96
+  m_Height: 2
97
+  m_Direction: 1
98
+  m_Center: {x: 0.000000059604645, y: 0, z: -0.00000008940697}

+ 7
- 0
FreeCam/Assets/Block_test02.prefab.meta View File

1
+fileFormatVersion: 2
2
+guid: 7a4e0ab2ed5b03449a1bca4b95ab4f73
3
+PrefabImporter:
4
+  externalObjects: {}
5
+  userData: 
6
+  assetBundleName: 
7
+  assetBundleVariant: 

+ 97
- 0
FreeCam/Assets/Block_test03.prefab View File

1
+%YAML 1.1
2
+%TAG !u! tag:unity3d.com,2011:
3
+--- !u!1 &621968338841797389
4
+GameObject:
5
+  m_ObjectHideFlags: 0
6
+  m_CorrespondingSourceObject: {fileID: 0}
7
+  m_PrefabInstance: {fileID: 0}
8
+  m_PrefabAsset: {fileID: 0}
9
+  serializedVersion: 6
10
+  m_Component:
11
+  - component: {fileID: 5816973045559326948}
12
+  - component: {fileID: 6149340876649010622}
13
+  - component: {fileID: 6566159884074761983}
14
+  - component: {fileID: 5170382868620429168}
15
+  m_Layer: 0
16
+  m_Name: Cube
17
+  m_TagString: Untagged
18
+  m_Icon: {fileID: 0}
19
+  m_NavMeshLayer: 0
20
+  m_StaticEditorFlags: 0
21
+  m_IsActive: 1
22
+--- !u!4 &5816973045559326948
23
+Transform:
24
+  m_ObjectHideFlags: 0
25
+  m_CorrespondingSourceObject: {fileID: 0}
26
+  m_PrefabInstance: {fileID: 0}
27
+  m_PrefabAsset: {fileID: 0}
28
+  m_GameObject: {fileID: 621968338841797389}
29
+  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
30
+  m_LocalPosition: {x: 0, y: 0, z: 0}
31
+  m_LocalScale: {x: 2, y: 0.5, z: 1}
32
+  m_Children: []
33
+  m_Father: {fileID: 0}
34
+  m_RootOrder: 0
35
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
36
+--- !u!33 &6149340876649010622
37
+MeshFilter:
38
+  m_ObjectHideFlags: 0
39
+  m_CorrespondingSourceObject: {fileID: 0}
40
+  m_PrefabInstance: {fileID: 0}
41
+  m_PrefabAsset: {fileID: 0}
42
+  m_GameObject: {fileID: 621968338841797389}
43
+  m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
44
+--- !u!23 &6566159884074761983
45
+MeshRenderer:
46
+  m_ObjectHideFlags: 0
47
+  m_CorrespondingSourceObject: {fileID: 0}
48
+  m_PrefabInstance: {fileID: 0}
49
+  m_PrefabAsset: {fileID: 0}
50
+  m_GameObject: {fileID: 621968338841797389}
51
+  m_Enabled: 1
52
+  m_CastShadows: 1
53
+  m_ReceiveShadows: 1
54
+  m_DynamicOccludee: 1
55
+  m_MotionVectors: 1
56
+  m_LightProbeUsage: 1
57
+  m_ReflectionProbeUsage: 1
58
+  m_RayTracingMode: 2
59
+  m_RayTraceProcedural: 0
60
+  m_RenderingLayerMask: 1
61
+  m_RendererPriority: 0
62
+  m_Materials:
63
+  - {fileID: 2100000, guid: 7a1df68ff2cb2814088ca3c160bfdf17, type: 2}
64
+  m_StaticBatchInfo:
65
+    firstSubMesh: 0
66
+    subMeshCount: 0
67
+  m_StaticBatchRoot: {fileID: 0}
68
+  m_ProbeAnchor: {fileID: 0}
69
+  m_LightProbeVolumeOverride: {fileID: 0}
70
+  m_ScaleInLightmap: 1
71
+  m_ReceiveGI: 1
72
+  m_PreserveUVs: 0
73
+  m_IgnoreNormalsForChartDetection: 0
74
+  m_ImportantGI: 0
75
+  m_StitchLightmapSeams: 1
76
+  m_SelectedEditorRenderState: 3
77
+  m_MinimumChartSize: 4
78
+  m_AutoUVMaxDistance: 0.5
79
+  m_AutoUVMaxAngle: 89
80
+  m_LightmapParameters: {fileID: 0}
81
+  m_SortingLayerID: 0
82
+  m_SortingLayer: 0
83
+  m_SortingOrder: 0
84
+  m_AdditionalVertexStreams: {fileID: 0}
85
+--- !u!65 &5170382868620429168
86
+BoxCollider:
87
+  m_ObjectHideFlags: 0
88
+  m_CorrespondingSourceObject: {fileID: 0}
89
+  m_PrefabInstance: {fileID: 0}
90
+  m_PrefabAsset: {fileID: 0}
91
+  m_GameObject: {fileID: 621968338841797389}
92
+  m_Material: {fileID: 0}
93
+  m_IsTrigger: 0
94
+  m_Enabled: 1
95
+  serializedVersion: 2
96
+  m_Size: {x: 1, y: 1, z: 1}
97
+  m_Center: {x: 0, y: 0, z: 0}

+ 7
- 0
FreeCam/Assets/Block_test03.prefab.meta View File

1
+fileFormatVersion: 2
2
+guid: 17a61cbbe7d1b5c4ea25f8367e40d349
3
+PrefabImporter:
4
+  externalObjects: {}
5
+  userData: 
6
+  assetBundleName: 
7
+  assetBundleVariant: 

+ 19
- 0
FreeCam/Assets/Controls.inputactions View File

44
                     "expectedControlType": "Button",
44
                     "expectedControlType": "Button",
45
                     "processors": "",
45
                     "processors": "",
46
                     "interactions": ""
46
                     "interactions": ""
47
+                },
48
+                {
49
+                    "name": "Scroll",
50
+                    "type": "Value",
51
+                    "id": "40fedfa7-6a1a-4fca-9d4f-b84ca6ee1159",
52
+                    "expectedControlType": "Axis",
53
+                    "processors": "",
54
+                    "interactions": ""
47
                 }
55
                 }
48
             ],
56
             ],
49
             "bindings": [
57
             "bindings": [
343
                     "action": "Sprint",
351
                     "action": "Sprint",
344
                     "isComposite": false,
352
                     "isComposite": false,
345
                     "isPartOfComposite": false
353
                     "isPartOfComposite": false
354
+                },
355
+                {
356
+                    "name": "",
357
+                    "id": "2186c4b0-7170-4ece-8710-808cbb276599",
358
+                    "path": "<Mouse>/scroll/y",
359
+                    "interactions": "",
360
+                    "processors": "",
361
+                    "groups": "",
362
+                    "action": "Scroll",
363
+                    "isComposite": false,
364
+                    "isPartOfComposite": false
346
                 }
365
                 }
347
             ]
366
             ]
348
         }
367
         }

+ 202
- 0
FreeCam/Assets/Scenes/SampleScene.unity View File

123
     debug:
123
     debug:
124
       m_Flags: 0
124
       m_Flags: 0
125
   m_NavMeshData: {fileID: 0}
125
   m_NavMeshData: {fileID: 0}
126
+--- !u!1 &284468234
127
+GameObject:
128
+  m_ObjectHideFlags: 0
129
+  m_CorrespondingSourceObject: {fileID: 0}
130
+  m_PrefabInstance: {fileID: 0}
131
+  m_PrefabAsset: {fileID: 0}
132
+  serializedVersion: 6
133
+  m_Component:
134
+  - component: {fileID: 284468235}
135
+  - component: {fileID: 284468238}
136
+  - component: {fileID: 284468237}
137
+  - component: {fileID: 284468236}
138
+  m_Layer: 0
139
+  m_Name: Canvas
140
+  m_TagString: Untagged
141
+  m_Icon: {fileID: 0}
142
+  m_NavMeshLayer: 0
143
+  m_StaticEditorFlags: 0
144
+  m_IsActive: 1
145
+--- !u!224 &284468235
146
+RectTransform:
147
+  m_ObjectHideFlags: 0
148
+  m_CorrespondingSourceObject: {fileID: 0}
149
+  m_PrefabInstance: {fileID: 0}
150
+  m_PrefabAsset: {fileID: 0}
151
+  m_GameObject: {fileID: 284468234}
152
+  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
153
+  m_LocalPosition: {x: 0, y: 0, z: 0}
154
+  m_LocalScale: {x: 0, y: 0, z: 0}
155
+  m_Children:
156
+  - {fileID: 987571942}
157
+  m_Father: {fileID: 1130402112}
158
+  m_RootOrder: 0
159
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
160
+  m_AnchorMin: {x: 0, y: 0}
161
+  m_AnchorMax: {x: 0, y: 0}
162
+  m_AnchoredPosition: {x: 0, y: 0}
163
+  m_SizeDelta: {x: 0, y: 0}
164
+  m_Pivot: {x: 0, y: 0}
165
+--- !u!114 &284468236
166
+MonoBehaviour:
167
+  m_ObjectHideFlags: 0
168
+  m_CorrespondingSourceObject: {fileID: 0}
169
+  m_PrefabInstance: {fileID: 0}
170
+  m_PrefabAsset: {fileID: 0}
171
+  m_GameObject: {fileID: 284468234}
172
+  m_Enabled: 1
173
+  m_EditorHideFlags: 0
174
+  m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3}
175
+  m_Name: 
176
+  m_EditorClassIdentifier: 
177
+  m_IgnoreReversedGraphics: 1
178
+  m_BlockingObjects: 0
179
+  m_BlockingMask:
180
+    serializedVersion: 2
181
+    m_Bits: 4294967295
182
+--- !u!114 &284468237
183
+MonoBehaviour:
184
+  m_ObjectHideFlags: 0
185
+  m_CorrespondingSourceObject: {fileID: 0}
186
+  m_PrefabInstance: {fileID: 0}
187
+  m_PrefabAsset: {fileID: 0}
188
+  m_GameObject: {fileID: 284468234}
189
+  m_Enabled: 1
190
+  m_EditorHideFlags: 0
191
+  m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
192
+  m_Name: 
193
+  m_EditorClassIdentifier: 
194
+  m_UiScaleMode: 0
195
+  m_ReferencePixelsPerUnit: 100
196
+  m_ScaleFactor: 1
197
+  m_ReferenceResolution: {x: 800, y: 600}
198
+  m_ScreenMatchMode: 0
199
+  m_MatchWidthOrHeight: 0
200
+  m_PhysicalUnit: 3
201
+  m_FallbackScreenDPI: 96
202
+  m_DefaultSpriteDPI: 96
203
+  m_DynamicPixelsPerUnit: 1
204
+--- !u!223 &284468238
205
+Canvas:
206
+  m_ObjectHideFlags: 0
207
+  m_CorrespondingSourceObject: {fileID: 0}
208
+  m_PrefabInstance: {fileID: 0}
209
+  m_PrefabAsset: {fileID: 0}
210
+  m_GameObject: {fileID: 284468234}
211
+  m_Enabled: 1
212
+  serializedVersion: 3
213
+  m_RenderMode: 0
214
+  m_Camera: {fileID: 0}
215
+  m_PlaneDistance: 100
216
+  m_PixelPerfect: 0
217
+  m_ReceivesEvents: 1
218
+  m_OverrideSorting: 0
219
+  m_OverridePixelPerfect: 0
220
+  m_SortingBucketNormalizedSize: 0
221
+  m_AdditionalShaderChannelsFlag: 0
222
+  m_SortingLayerID: 0
223
+  m_SortingOrder: 0
224
+  m_TargetDisplay: 0
126
 --- !u!1 &329252534
225
 --- !u!1 &329252534
127
 GameObject:
226
 GameObject:
128
   m_ObjectHideFlags: 0
227
   m_ObjectHideFlags: 0
534
   m_PrefabAsset: {fileID: 0}
633
   m_PrefabAsset: {fileID: 0}
535
   m_GameObject: {fileID: 560509547}
634
   m_GameObject: {fileID: 560509547}
536
   m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
635
   m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
636
+--- !u!1 &987571941
637
+GameObject:
638
+  m_ObjectHideFlags: 0
639
+  m_CorrespondingSourceObject: {fileID: 0}
640
+  m_PrefabInstance: {fileID: 0}
641
+  m_PrefabAsset: {fileID: 0}
642
+  serializedVersion: 6
643
+  m_Component:
644
+  - component: {fileID: 987571942}
645
+  - component: {fileID: 987571943}
646
+  m_Layer: 0
647
+  m_Name: UI_Inventory
648
+  m_TagString: Untagged
649
+  m_Icon: {fileID: 0}
650
+  m_NavMeshLayer: 0
651
+  m_StaticEditorFlags: 0
652
+  m_IsActive: 1
653
+--- !u!224 &987571942
654
+RectTransform:
655
+  m_ObjectHideFlags: 0
656
+  m_CorrespondingSourceObject: {fileID: 0}
657
+  m_PrefabInstance: {fileID: 0}
658
+  m_PrefabAsset: {fileID: 0}
659
+  m_GameObject: {fileID: 987571941}
660
+  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
661
+  m_LocalPosition: {x: 0, y: 0, z: 0}
662
+  m_LocalScale: {x: 1, y: 1, z: 1}
663
+  m_Children: []
664
+  m_Father: {fileID: 284468235}
665
+  m_RootOrder: 0
666
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
667
+  m_AnchorMin: {x: 0.5, y: 0.5}
668
+  m_AnchorMax: {x: 0.5, y: 0.5}
669
+  m_AnchoredPosition: {x: 0, y: 0}
670
+  m_SizeDelta: {x: 100, y: 100}
671
+  m_Pivot: {x: 0.5, y: 0.5}
672
+--- !u!114 &987571943
673
+MonoBehaviour:
674
+  m_ObjectHideFlags: 0
675
+  m_CorrespondingSourceObject: {fileID: 0}
676
+  m_PrefabInstance: {fileID: 0}
677
+  m_PrefabAsset: {fileID: 0}
678
+  m_GameObject: {fileID: 987571941}
679
+  m_Enabled: 1
680
+  m_EditorHideFlags: 0
681
+  m_Script: {fileID: 11500000, guid: 4202bab9555130c47b13e955ea38a9bd, type: 3}
682
+  m_Name: 
683
+  m_EditorClassIdentifier: 
684
+--- !u!1 &1130402111
685
+GameObject:
686
+  m_ObjectHideFlags: 0
687
+  m_CorrespondingSourceObject: {fileID: 0}
688
+  m_PrefabInstance: {fileID: 0}
689
+  m_PrefabAsset: {fileID: 0}
690
+  serializedVersion: 6
691
+  m_Component:
692
+  - component: {fileID: 1130402112}
693
+  m_Layer: 0
694
+  m_Name: UI
695
+  m_TagString: Untagged
696
+  m_Icon: {fileID: 0}
697
+  m_NavMeshLayer: 0
698
+  m_StaticEditorFlags: 0
699
+  m_IsActive: 1
700
+--- !u!4 &1130402112
701
+Transform:
702
+  m_ObjectHideFlags: 0
703
+  m_CorrespondingSourceObject: {fileID: 0}
704
+  m_PrefabInstance: {fileID: 0}
705
+  m_PrefabAsset: {fileID: 0}
706
+  m_GameObject: {fileID: 1130402111}
707
+  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
708
+  m_LocalPosition: {x: 799.99994, y: 473, z: 0}
709
+  m_LocalScale: {x: 1, y: 1, z: 1}
710
+  m_Children:
711
+  - {fileID: 284468235}
712
+  m_Father: {fileID: 0}
713
+  m_RootOrder: 3
714
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
537
 --- !u!1 &1217514443
715
 --- !u!1 &1217514443
538
 GameObject:
716
 GameObject:
539
   m_ObjectHideFlags: 0
717
   m_ObjectHideFlags: 0
684
       propertyPath: m_Name
862
       propertyPath: m_Name
685
       value: Player
863
       value: Player
686
       objectReference: {fileID: 0}
864
       objectReference: {fileID: 0}
865
+    - target: {fileID: 5739138180788424124, guid: 37333bbc22b455449a05fcf8aa6b9a8f, type: 3}
866
+      propertyPath: m_Height
867
+      value: 1
868
+      objectReference: {fileID: 0}
869
+    - target: {fileID: 6193258497320629589, guid: 37333bbc22b455449a05fcf8aa6b9a8f, type: 3}
870
+      propertyPath: bla.Array.size
871
+      value: 3
872
+      objectReference: {fileID: 0}
687
     - target: {fileID: 6193258497320629589, guid: 37333bbc22b455449a05fcf8aa6b9a8f, type: 3}
873
     - target: {fileID: 6193258497320629589, guid: 37333bbc22b455449a05fcf8aa6b9a8f, type: 3}
688
       propertyPath: _blockToPlace
874
       propertyPath: _blockToPlace
689
       value: 
875
       value: 
690
       objectReference: {fileID: 3300812737117657924, guid: 7b30a4c90d614f747872471cf43b8e56, type: 3}
876
       objectReference: {fileID: 3300812737117657924, guid: 7b30a4c90d614f747872471cf43b8e56, type: 3}
877
+    - target: {fileID: 6193258497320629589, guid: 37333bbc22b455449a05fcf8aa6b9a8f, type: 3}
878
+      propertyPath: uiInventory
879
+      value: 
880
+      objectReference: {fileID: 987571943}
881
+    - target: {fileID: 6193258497320629589, guid: 37333bbc22b455449a05fcf8aa6b9a8f, type: 3}
882
+      propertyPath: bla.Array.data[0]
883
+      value: 
884
+      objectReference: {fileID: 3300812737117657924, guid: 7b30a4c90d614f747872471cf43b8e56, type: 3}
885
+    - target: {fileID: 6193258497320629589, guid: 37333bbc22b455449a05fcf8aa6b9a8f, type: 3}
886
+      propertyPath: bla.Array.data[1]
887
+      value: 
888
+      objectReference: {fileID: 4071370194869356435, guid: 7a4e0ab2ed5b03449a1bca4b95ab4f73, type: 3}
889
+    - target: {fileID: 6193258497320629589, guid: 37333bbc22b455449a05fcf8aa6b9a8f, type: 3}
890
+      propertyPath: bla.Array.data[2]
891
+      value: 
892
+      objectReference: {fileID: 621968338841797389, guid: 17a61cbbe7d1b5c4ea25f8367e40d349, type: 3}
691
     m_RemovedComponents: []
893
     m_RemovedComponents: []
692
   m_SourcePrefab: {fileID: 100100000, guid: 37333bbc22b455449a05fcf8aa6b9a8f, type: 3}
894
   m_SourcePrefab: {fileID: 100100000, guid: 37333bbc22b455449a05fcf8aa6b9a8f, type: 3}

+ 69
- 0
FreeCam/Assets/Scripts/BlockSpawner.cs View File

1
+using System.Collections.Generic;
2
+using UnityEngine;
3
+using UnityEngine.InputSystem;
4
+
5
+public class BlockSpawner : MonoBehaviour
6
+{
7
+    public Inventory inventory;
8
+
9
+    public float spawnDistance = 3f;
10
+    
11
+    #pragma warning disable 0649
12
+    [SerializeField] private UI_Inventory uiInventory;
13
+    #pragma warning restore 0649
14
+    private GameObject _blockInstance;
15
+
16
+    private bool _isPreview;
17
+
18
+    public void Awake()
19
+    {
20
+        _isPreview = false;
21
+
22
+        inventory = new Inventory();
23
+        uiInventory.SetInventory(inventory);
24
+    }
25
+
26
+    public void OnPlaceBlock ()
27
+    {
28
+        if (!_isPreview) return;
29
+        // todo remove in inventory
30
+        _blockInstance.transform.SetParent(null);
31
+        _blockInstance = null;
32
+        DisablePreviewMode();
33
+    }
34
+
35
+    public void OnTogglePreviewMode(InputValue value)
36
+    {
37
+        float valueAsFloat = value.Get<float>();
38
+
39
+        if (valueAsFloat == 1f) EnablePreviewMode();
40
+        else DisablePreviewMode();
41
+    }
42
+
43
+    public void OnScroll(InputValue value)
44
+    {
45
+        DisablePreviewMode();
46
+
47
+        float valueAsFloat = value.Get<float>();
48
+        if (valueAsFloat > 0) inventory.SelectPreviousItem();
49
+        if (valueAsFloat < 0) inventory.SelectNextItem();
50
+    }
51
+
52
+    public void EnablePreviewMode()
53
+    {
54
+        Item selectedItem = inventory.GetSelectedItem();
55
+
56
+        if (selectedItem == null) return;
57
+
58
+        Vector3 spawnPos = Vector3.forward * spawnDistance;
59
+        _blockInstance = Instantiate(selectedItem.Prefab, spawnPos, Quaternion.identity);
60
+        _blockInstance.transform.SetParent(this.transform, false);
61
+        _isPreview = true;
62
+    }
63
+
64
+    public void DisablePreviewMode()
65
+    {
66
+        if (_blockInstance != null) Destroy(_blockInstance);
67
+        _isPreview = false;
68
+    }
69
+}

FreeCam/Assets/BlockSpawner.cs.meta → FreeCam/Assets/Scripts/BlockSpawner.cs.meta View File


+ 103
- 0
FreeCam/Assets/Scripts/Inventory.cs View File

1
+using System;
2
+using System.Collections;
3
+using System.Collections.Generic;
4
+using UnityEngine;
5
+
6
+public class Inventory
7
+{
8
+    public event EventHandler OnItemListChanged;
9
+
10
+    private List<Item> itemList;
11
+    private Item selectedItem;
12
+
13
+    public Inventory()
14
+    {
15
+        itemList = new List<Item>();
16
+        selectedItem = null;
17
+    }
18
+
19
+    public void AddItem(Item item)
20
+    {
21
+        bool itemAlreadyInInventory = false;
22
+
23
+        foreach (Item itemSlot in itemList)
24
+        {
25
+            if (itemSlot.Prefab == item.Prefab)
26
+            {
27
+                itemSlot.Increase(item.Amount);
28
+                itemAlreadyInInventory = true;
29
+            }
30
+        }
31
+
32
+        if (!itemAlreadyInInventory) itemList.Add(item);
33
+        if (selectedItem == null) selectedItem = item;
34
+
35
+        OnItemListChanged?.Invoke(this, EventArgs.Empty);
36
+    }
37
+
38
+    public void RemoveItem(Item item)
39
+    {
40
+        Item itemInInventory = null;
41
+
42
+        foreach (Item inventoryItem in itemList)
43
+        {
44
+            if (inventoryItem.Prefab == item.Prefab)
45
+            {
46
+                inventoryItem.Decrease(item.Amount);
47
+                itemInInventory = inventoryItem;
48
+            }
49
+        }
50
+
51
+        if (itemInInventory != null && itemInInventory.IsEmpty())
52
+        {
53
+            if (itemInInventory == selectedItem)
54
+                selectedItem = ItemAfter(selectedItem) ?? ItemBefore(selectedItem);
55
+
56
+            itemList.Remove(itemInInventory);
57
+        }
58
+
59
+        OnItemListChanged?.Invoke(this, EventArgs.Empty);
60
+    }
61
+
62
+    public List<Item> GetItemList()
63
+    {
64
+        return itemList;
65
+    }
66
+
67
+    public Item GetSelectedItem()
68
+    {
69
+        return selectedItem;
70
+    }
71
+
72
+    public Item ItemBefore(Item item)
73
+    {
74
+        int idx = itemList.IndexOf(item);
75
+
76
+        if (idx == -1 || idx == 0) return null;
77
+        return itemList[idx - 1];
78
+    }
79
+
80
+    public Item ItemAfter(Item item)
81
+    {
82
+        int idx = itemList.IndexOf(item);
83
+
84
+        if (idx == -1 || idx == itemList.Count) return null;
85
+        return itemList[idx + 1];
86
+    }
87
+
88
+    public void SelectPreviousItem()
89
+    {
90
+        Item newSelected = ItemBefore(selectedItem);
91
+        if (newSelected == null) return;
92
+
93
+        OnItemListChanged?.Invoke(this, EventArgs.Empty);
94
+    }
95
+
96
+    public void SelectNextItem()
97
+    {
98
+        Item newSelected = ItemAfter(selectedItem);
99
+        if (newSelected == null) return;
100
+
101
+        OnItemListChanged?.Invoke(this, EventArgs.Empty);
102
+    }
103
+}

+ 11
- 0
FreeCam/Assets/Scripts/Inventory.cs.meta View File

1
+fileFormatVersion: 2
2
+guid: ec3d79877253fcb41abb245d3f2e07f9
3
+MonoImporter:
4
+  externalObjects: {}
5
+  serializedVersion: 2
6
+  defaultReferences: []
7
+  executionOrder: 0
8
+  icon: {instanceID: 0}
9
+  userData: 
10
+  assetBundleName: 
11
+  assetBundleVariant: 

+ 47
- 0
FreeCam/Assets/Scripts/Item.cs View File

1
+using System;
2
+using System.Collections;
3
+using System.Collections.Generic;
4
+using UnityEngine;
5
+
6
+[Serializable]
7
+public class Item
8
+{
9
+    public GameObject Prefab { get; private set; }
10
+    public int Amount { get; private set; }
11
+    private Sprite sprite;
12
+
13
+    public Item(GameObject _prefab, int _amount)
14
+    {
15
+        Prefab = _prefab;
16
+        Amount = _amount;
17
+        InitiateSprite();
18
+    }
19
+
20
+    public Sprite GetSprite()
21
+    {
22
+        return sprite;
23
+    }
24
+
25
+    private void InitiateSprite()
26
+    {
27
+        Texture2D texture = UnityEditor.AssetPreview.GetMiniThumbnail(Prefab);
28
+        Rect rect = new Rect(0, 0, texture.width, texture.height);
29
+        Vector2 pivot = new Vector2(0.5f, 0.5f);
30
+        sprite = Sprite.Create(texture, rect, pivot);
31
+    }
32
+
33
+    public void Increase(int _amount)
34
+    {
35
+        Amount += _amount;
36
+    }
37
+
38
+    public void Decrease(int _amount)
39
+    {
40
+        Amount -= _amount;
41
+    }
42
+
43
+    public bool IsEmpty()
44
+    {
45
+        return Amount <= 0;
46
+    }
47
+}

+ 11
- 0
FreeCam/Assets/Scripts/Item.cs.meta View File

1
+fileFormatVersion: 2
2
+guid: d955f3cb1be5bcf45a17f8bf49133023
3
+MonoImporter:
4
+  externalObjects: {}
5
+  serializedVersion: 2
6
+  defaultReferences: []
7
+  executionOrder: 0
8
+  icon: {instanceID: 0}
9
+  userData: 
10
+  assetBundleName: 
11
+  assetBundleVariant: 

+ 35
- 0
FreeCam/Assets/Scripts/UI_Inventory.cs View File

1
+using System.Collections;
2
+using System.Collections.Generic;
3
+using UnityEngine;
4
+
5
+public class UI_Inventory : MonoBehaviour
6
+{
7
+
8
+    private Inventory inventory;
9
+
10
+    private void Awake()
11
+    {
12
+        
13
+    }
14
+
15
+    public void SetInventory(Inventory _inventory)
16
+    {
17
+        inventory = _inventory;
18
+
19
+        inventory.OnItemListChanged += Inventory_OnItemListChanged;
20
+
21
+        RefreshInventoryItems();
22
+    }
23
+
24
+    private void Inventory_OnItemListChanged(object sender, System.EventArgs e)
25
+    {
26
+        RefreshInventoryItems();
27
+    }
28
+
29
+    private void RefreshInventoryItems()
30
+    {
31
+        // TODO refresh UI
32
+    }
33
+
34
+
35
+}

+ 11
- 0
FreeCam/Assets/Scripts/UI_Inventory.cs.meta View File

1
+fileFormatVersion: 2
2
+guid: 4202bab9555130c47b13e955ea38a9bd
3
+MonoImporter:
4
+  externalObjects: {}
5
+  serializedVersion: 2
6
+  defaultReferences: []
7
+  executionOrder: 0
8
+  icon: {instanceID: 0}
9
+  userData: 
10
+  assetBundleName: 
11
+  assetBundleVariant: 

Loading…
Cancel
Save