Added Functions to slotSystem:

SpawnIndex_Object(int)
RemoveCurrent_Object()

SpawnIndex will spawn to parentObject variable
This commit is contained in:
N0S3ns3 2022-05-04 21:15:09 +02:00
parent ec89584e97
commit c6a6bf58f9
5 changed files with 281 additions and 5 deletions

View file

@ -1,6 +1,7 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Pool;
using TMPro; using TMPro;
// !! ========= NOTE ========= !! // !! ========= NOTE ========= !!
@ -29,6 +30,9 @@ using TMPro;
* -> UpdateIndex_Slotsobject * -> UpdateIndex_Slotsobject
* -> Update_Slotsobject * -> Update_Slotsobject
* *
* -> Spawn_Object
* -> RemoveCurrent_Object
*
* -> setupSlot * -> setupSlot
* *
* -> Debug_Slot * -> Debug_Slot
@ -50,6 +54,13 @@ public class SlotSystem : MonoBehaviour
} }
} }
[Header("Pooling Setting")]
[Space(10)]
[Header("Spawn Setting")]
public GameObject parentObject; // Used to spawn object to specific parent
[Space(10)]
[Header("Slot Setting")]
public List<Item> slots; public List<Item> slots;
public List<Item> slots_special; public List<Item> slots_special;
public List<GameObject> slots_object; public List<GameObject> slots_object;
@ -57,6 +68,8 @@ public class SlotSystem : MonoBehaviour
public int selectedSlot; public int selectedSlot;
public int selectedSlot_special; public int selectedSlot_special;
private GameObject currentGameObject = null; // Used to check stored current GameObject to destroy it later when not used or switching item
// TMP // TMP
public Item tmp_Item; // Tmp public Item tmp_Item; // Tmp
@ -285,7 +298,7 @@ public class SlotSystem : MonoBehaviour
} }
} }
// update[Name] will update all index text (might come more soon) // update_[Name] will update all index text (might come more soon)
void Update_Slotsobject() void Update_Slotsobject()
{ {
try try
@ -301,6 +314,45 @@ public class SlotSystem : MonoBehaviour
} }
} }
// Spawn_[Name] will spawn object to the game world to a specific parentObject
bool SpawnIndex_Object(int index)
{
try
{
if (GetIndex_ItemObject(index) != null)
{
currentGameObject = Instantiate(GetIndex_ItemObject(index)) as GameObject; // Pooling System on unity is way too confusing.. Ill research about it more later.
currentGameObject.transform.SetParent(parentObject.transform, false);
return true;
}
return false;
}
catch
{
Debug.LogError("Prefab could not be instantiated");
return false;
}
}
// removeCurrent_[Name] will remove current object if spawned any
bool RemoveCurrent_Object()
{
try
{
if (currentGameObject != null)
{
Destroy(currentGameObject);
return true;
}
return false;
}
catch
{
Debug.LogError("currentGameObject could not be destroyed");
return false;
}
}
// Other // Other
// Sets up slot types for different slot placement // Sets up slot types for different slot placement
void setupSlot() void setupSlot()
@ -387,6 +439,9 @@ public class SlotSystem : MonoBehaviour
setupSlot(); // Must setup before using any other functions setupSlot(); // Must setup before using any other functions
Set_Slot(tmp_Item); Set_Slot(tmp_Item);
Update_Slotsobject(); Update_Slotsobject();
SpawnIndex_Object(0);
//RemoveCurrent_Object();
} }
// Update is called once per frame // Update is called once per frame

View file

@ -16,4 +16,5 @@ MonoBehaviour:
ItemID: 1 ItemID: 1
ItemType: 0 ItemType: 0
SlotType: 0 SlotType: 0
ItemObject: {fileID: 0} ItemObject: {fileID: 2683428033455470680, guid: e4709fc7d46b73549bd76044d6991645,
type: 3}

View file

@ -0,0 +1,99 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2683428033455470680
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1313838828646285495}
- component: {fileID: 8069525578106397085}
- component: {fileID: 1984480388371953624}
- component: {fileID: 3378648774449670752}
m_Layer: 0
m_Name: TestItem
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1313838828646285495
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2683428033455470680}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &8069525578106397085
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2683428033455470680}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &1984480388371953624
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2683428033455470680}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!65 &3378648774449670752
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2683428033455470680}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e4709fc7d46b73549bd76044d6991645
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -455,14 +455,112 @@ RectTransform:
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: m_Children:
- {fileID: 513282457} - {fileID: 513282457}
m_Father: {fileID: 0} m_Father: {fileID: 1174856041}
m_RootOrder: 2 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0} m_Pivot: {x: 0, y: 0}
--- !u!1 &1174856037
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1174856041}
- component: {fileID: 1174856040}
- component: {fileID: 1174856039}
- component: {fileID: 1174856038}
m_Layer: 0
m_Name: Cube
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!65 &1174856038
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1174856037}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &1174856039
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1174856037}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &1174856040
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1174856037}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &1174856041
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1174856037}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -4.2, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 740122246}
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1484791041 --- !u!1 &1484791041
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -509,7 +607,7 @@ Transform:
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 3 m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1484791045 --- !u!114 &1484791045
MonoBehaviour: MonoBehaviour:
@ -557,11 +655,27 @@ PrefabInstance:
m_Modification: m_Modification:
m_TransformParent: {fileID: 740122246} m_TransformParent: {fileID: 740122246}
m_Modifications: m_Modifications:
- target: {fileID: 4618792495020702613, guid: a6c9897145ea93b41abf3c531f857e3b,
type: 3}
propertyPath: parentObject
value:
objectReference: {fileID: 1174856037}
- target: {fileID: 4618792495020702613, guid: a6c9897145ea93b41abf3c531f857e3b, - target: {fileID: 4618792495020702613, guid: a6c9897145ea93b41abf3c531f857e3b,
type: 3} type: 3}
propertyPath: maxNormalmSlots propertyPath: maxNormalmSlots
value: 6 value: 6
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4618792495020702613, guid: a6c9897145ea93b41abf3c531f857e3b,
type: 3}
propertyPath: simplifyObject.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4618792495020702613, guid: a6c9897145ea93b41abf3c531f857e3b,
type: 3}
propertyPath: simplifyObject.Array.data[0]
value:
objectReference: {fileID: 2683428033455470680, guid: e4709fc7d46b73549bd76044d6991645,
type: 3}
- target: {fileID: 4618792496510273084, guid: a6c9897145ea93b41abf3c531f857e3b, - target: {fileID: 4618792496510273084, guid: a6c9897145ea93b41abf3c531f857e3b,
type: 3} type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder