Scriptum/Assets/Scripts/REFACTORING/Application/Chest/SceneChestBuilder.cs
2022-12-13 01:03:03 +01:00

54 lines
2.1 KiB
C#

using System;
using System.Collections;
using UnityEngine;
[Serializable]
public class SceneChestBuilder : SceneObjectBuilder<ChestPrefabAsset>
{
[SerializeField] int trest = 0;
protected override string MODEL_SOURCE_PATH { get { return "Chests/"; } }
public override void Build(ChestPrefabAsset objectToBuild)
{
GameObject globalGUI = GameObject.FindGameObjectWithTag("ChestCollection");
if (!globalGUI)
Debug.LogError("GUI frame not found!!");
GameObject newObject = FindModel(objectToBuild.Chest.chestModel.name);
Debug.Log($"Chest {newObject} - name: {objectToBuild.Chest.chestModel.name}");
if (!newObject)
Debug.LogError("Can't find prefarb by name " + objectToBuild.Chest.chestModel.name);
// Build chest on map
GameObject chest = Instantiate(newObject, objectToBuild.Position, Quaternion.identity, globalGUI.transform);
chest.name = objectToBuild.Chest.Name;
chest.transform.SetParent(globalGUI.transform);
//Debug.Log("Chest Name: " + chest.name + " Positions: " + chest.transform.position.x + " + " + chest.transform.position.y + " + " + chest.transform.position.z);
//Debug.Log("Chest Name: " + chest.name + " Local Positions: " + chest.transform.localPosition.x + " + " + chest.transform.localPosition.y + " + " + chest.transform.localPosition.z);
//chest.transform.localScale = new Vector3(1f, 1f, 1f);
//chest.transform.localPosition = objectToBuild.Position;
// data about chest cpontent should be handled in SceneChestManager class and pass to ChestUIPanel only after opening Panel by Player
// 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);
if (!resource)
throw new System.Exception($"Resource {MODEL_SOURCE_PATH + modelName} not found!!");
return resource;
}
}