using System; using System.Collections; using UnityEngine; [Serializable] public class SceneChestBuilder : SceneObjectBuilder { [SerializeField] int trest = 0; protected override string MODEL_SOURCE_PATH { get { return "Chests/"; } } public override void Build(ChestPrefabAsset objectToBuild) { GameObject globalGUI = GameObject.FindGameObjectsWithTag("GUI")[0]; 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.localScale = new Vector3(0.5f, 0.5f, 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(MODEL_SOURCE_PATH + modelName); if (!resource) throw new System.Exception($"Resource {MODEL_SOURCE_PATH + modelName} not found!!"); return resource; } }