Make chest creating more flexible

This commit is contained in:
kabix09 2022-12-21 17:12:47 +01:00
parent 2280e5fc15
commit 8e3f89a6f7
14 changed files with 649 additions and 85 deletions

View File

@ -11,6 +11,7 @@ GameObject:
- component: {fileID: 4669568061092186073}
- component: {fileID: 4669568061092186078}
- component: {fileID: 4669568061092186079}
- component: {fileID: 2962987939110705530}
m_Layer: 0
m_Name: Gold Chest
m_TagString: Untagged
@ -28,6 +29,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 58.59589, y: 32.941498, z: 20}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
@ -43,6 +45,7 @@ SpriteRenderer:
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
@ -109,3 +112,22 @@ BoxCollider2D:
serializedVersion: 2
m_Size: {x: 0.95, y: 0.9}
m_EdgeRadius: 0
--- !u!114 &2962987939110705530
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4669568061092186072}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 89637c42dcc6baf4abb590f571640a32, type: 3}
m_Name:
m_EditorClassIdentifier:
Chest:
id: 0
name:
description:
chestModel: {fileID: 0}
ChestType: 0
Content: []

View File

@ -29,6 +29,7 @@ Transform:
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0.095890045, y: -0.058502197, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 4669568061092186073}
m_RootOrder: 0
@ -94,6 +95,7 @@ GameObject:
- component: {fileID: 4669568061092186073}
- component: {fileID: 4669568061092186078}
- component: {fileID: 4669568061092186079}
- component: {fileID: 330262631295867499}
m_Layer: 0
m_Name: Gold
m_TagString: Untagged
@ -111,6 +113,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 58.59589, y: 32.941498, z: 20}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 805898525}
m_Father: {fileID: 0}
@ -127,6 +130,7 @@ SpriteRenderer:
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
@ -193,3 +197,22 @@ BoxCollider2D:
serializedVersion: 2
m_Size: {x: 0.95, y: 0.9}
m_EdgeRadius: 0
--- !u!114 &330262631295867499
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4669568061092186072}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 89637c42dcc6baf4abb590f571640a32, type: 3}
m_Name:
m_EditorClassIdentifier:
Chest:
id: 0
name:
description:
chestModel: {fileID: 0}
ChestType: 0
Content: []

View File

@ -95,6 +95,7 @@ GameObject:
- component: {fileID: 5754902894522036728}
- component: {fileID: 5754902894522036731}
- component: {fileID: 5754902894522036730}
- component: {fileID: 1539754125081080905}
m_Layer: 0
m_Name: Prize Chest
m_TagString: Untagged
@ -196,3 +197,22 @@ BoxCollider2D:
serializedVersion: 2
m_Size: {x: 1.35, y: 1.1}
m_EdgeRadius: 0
--- !u!114 &1539754125081080905
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5754902894522036729}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 89637c42dcc6baf4abb590f571640a32, type: 3}
m_Name:
m_EditorClassIdentifier:
Chest:
id: 0
name:
description:
chestModel: {fileID: 0}
ChestType: 0
Content: []

View File

@ -96,6 +96,7 @@ GameObject:
- component: {fileID: 3972494989842158473}
- component: {fileID: 3972494989842158583}
- component: {fileID: 3972494989842158582}
- component: {fileID: 8326308579546157189}
m_Layer: 0
m_Name: Wood
m_TagString: Untagged
@ -223,3 +224,22 @@ BoxCollider2D:
serializedVersion: 2
m_Size: {x: 0.95, y: 1.5900776}
m_EdgeRadius: 0
--- !u!114 &8326308579546157189
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3972494989842158579}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 89637c42dcc6baf4abb590f571640a32, type: 3}
m_Name:
m_EditorClassIdentifier:
Chest:
id: 0
name:
description:
chestModel: {fileID: 0}
ChestType: 0
Content: []

View File

@ -12,6 +12,7 @@ GameObject:
- component: {fileID: 3972494989842158473}
- component: {fileID: 3972494989842158583}
- component: {fileID: 3972494989842158582}
- component: {fileID: 6216344267889095310}
m_Layer: 0
m_Name: Wooden Chest
m_TagString: Untagged
@ -29,6 +30,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -8.45, y: -3.9, z: 10}
m_LocalScale: {x: 1, y: 1, z: 2}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
@ -44,6 +46,7 @@ SpriteRenderer:
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
@ -136,3 +139,22 @@ BoxCollider2D:
serializedVersion: 2
m_Size: {x: 0.95, y: 1.5900776}
m_EdgeRadius: 0
--- !u!114 &6216344267889095310
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3972494989842158579}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 89637c42dcc6baf4abb590f571640a32, type: 3}
m_Name:
m_EditorClassIdentifier:
Chest:
id: 0
name:
description:
chestModel: {fileID: 0}
ChestType: 0
Content: []

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -3,12 +3,26 @@ using System.Collections;
using UnityEngine;
[Serializable]
public class SceneChestBuilder : SceneObjectBuilder<ChestPrefabAsset>
public class SceneChestBuilder : SceneObjectBuilder<ChestBuildModel>
{
[SerializeField] int trest = 0;
protected override string MODEL_SOURCE_PATH { get { return "Chests/"; } }
public override void Build(ChestPrefabAsset objectToBuild)
public override void Build(ChestBuildModel buildModel)
{
GameObject globalGUI = GameObject.FindGameObjectWithTag("ChestCollection");
if (!globalGUI)
Debug.LogError("GUI frame not found!!");
GameObject newObject = Instantiate(buildModel.ChestPrefab, buildModel.Position, Quaternion.identity, globalGUI.transform);
newObject.name = buildModel.ChestName;
newObject.transform.SetParent(globalGUI.transform);
}
/* public override void Build(ChestPrefabAsset objectToBuild)
{
GameObject globalGUI = GameObject.FindGameObjectWithTag("ChestCollection");
@ -40,7 +54,7 @@ public class SceneChestBuilder : SceneObjectBuilder<ChestPrefabAsset>
// in other words objects dont have full info about its data xd
// confuse and irrational but this way it will be easiet to maintain Data Consistency
}
*/
public override GameObject FindModel(string modelName)
{
var resource = Resources.Load<GameObject>(MODEL_SOURCE_PATH + modelName);

View File

@ -18,7 +18,9 @@ public class SceneChestDataManager : SceneBaseDataManager<ChestPrefabAsset>
[SerializeField] protected new ChestUIManager UiManager;
[SerializeField] public List<ChestPrefabAssetData> ElementsToBuildOnSceneList = new List<ChestPrefabAssetData>();
[SerializeField] public List<ChestBuildModel> ChestsToBuildOnScene = new List<ChestBuildModel>();
[SerializeField] List<ChestPrefabAsset> convertedData = new List<ChestPrefabAsset>();
@ -86,16 +88,18 @@ public class SceneChestDataManager : SceneBaseDataManager<ChestPrefabAsset>
protected override void UseDefaultSettings()
{
foreach (ChestPrefabAssetData asset in ElementsToBuildOnSceneList) { convertedData.Add((ChestPrefabAsset)asset.MapDataToPrefabAssetModel()); }
ChestBuilder.ElementsToBuildOnSceneList = convertedData;
ChestBuilder.ElementsToBuildOnSceneList = ChestsToBuildOnScene;
ChestBuilder.BuildList();
foreach(ChestBuildModel ChestToBuild in ChestsToBuildOnScene)
{
convertedData.Add(ChestToBuild.MapBuildModelToPrefabAssetModel());
}
DynamicDataList.SetList(convertedData);
List<Chest> tmp = new List<Chest>();
foreach (ChestPrefabAsset asset in ChestBuilder.ElementsToBuildOnSceneList) { tmp.Add(asset.Chest); }
foreach (ChestPrefabAsset asset in convertedData) { tmp.Add(asset.Chest); }
UiManager.SetList(tmp);
}
@ -118,11 +122,17 @@ public class SceneChestDataManager : SceneBaseDataManager<ChestPrefabAsset>
return;
}
ChestBuilder.ElementsToBuildOnSceneList = DynamicDataList.GetList();
ChestBuilder.ElementsToBuildOnSceneList = ChestsToBuildOnScene; // DynamicDataList.GetList();
ChestBuilder.BuildList();
foreach (ChestBuildModel ChestToBuild in ChestsToBuildOnScene)
{
convertedData.Add(ChestToBuild.MapBuildModelToPrefabAssetModel());
}
List<Chest> tmp = new List<Chest>();
foreach (ChestPrefabAsset asset in ChestBuilder.ElementsToBuildOnSceneList) { tmp.Add(asset.Chest); }
foreach (ChestPrefabAsset asset in convertedData) { tmp.Add(asset.Chest); }
UiManager.SetList(tmp);
}

View File

@ -35,7 +35,7 @@ public struct IndexValuePair<V, T>
}
[System.Serializable]
[CreateAssetMenu(fileName = "New Chest", menuName = "Inventory/Chest")]
//[CreateAssetMenu(fileName = "New Chest", menuName = "Inventory/Chest")]
public class Chest
{
public int id;
@ -68,6 +68,7 @@ public class Chest
public ChestTypeEnum ChestType;
[SerializeField]
public List<IndexValuePair<EquippableItem>> Content = new List<IndexValuePair<EquippableItem>>();

View File

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
[Serializable]
public class ChestBuildModel
{
[SerializeField] public string ChestName;
[SerializeField] public GameObject ChestPrefab;
[SerializeField] public Vector3 Position;
[SerializeField] public List<IndexValuePair<Item>> Content;
public ChestPrefabAsset MapBuildModelToPrefabAssetModel()
{
ChestPrefabAsset chestPrefabAsset = new ChestPrefabAsset(
ChestName,
ChestPrefab.gameObject.name,
Position
);
chestPrefabAsset.Chest = new Chest(ChestPrefab.GetComponent<ChestWrapper>().Chest);
Debug.Log(chestPrefabAsset.Chest);
chestPrefabAsset.Chest.Name = ChestName;
Debug.Log(chestPrefabAsset.Chest.Name);
chestPrefabAsset.Chest.Content = new List<IndexValuePair<EquippableItem>>();
foreach (var ChestElement in Content)
{
var castedObject = ChestElement.Value as EquippableItem;
if (castedObject == null)
chestPrefabAsset.Chest.Content.Add(
new IndexValuePair<EquippableItem>(ChestElement.Key, new EquippableItem(ChestElement.Value))
);
else
chestPrefabAsset.Chest.Content.Add(
new IndexValuePair<EquippableItem>(ChestElement.Key, castedObject)
);
}
Debug.Log(chestPrefabAsset.Chest.Content.Count);
Debug.Log(chestPrefabAsset.Chest);
return chestPrefabAsset;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 39c0403dd309dc745a96f7cea5bc4feb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
[Serializable]
class ChestWrapper : MonoBehaviour
{
[SerializeField]
public Chest Chest;
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 89637c42dcc6baf4abb590f571640a32
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: