2022-11-19 17:02:31 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
2022-12-22 03:38:00 +01:00
|
|
|
|
using System.Collections.Generic;
|
2022-11-19 17:02:31 +01:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
2022-12-21 17:12:47 +01:00
|
|
|
|
public class SceneChestBuilder : SceneObjectBuilder<ChestBuildModel>
|
2022-11-19 17:02:31 +01:00
|
|
|
|
{
|
|
|
|
|
[SerializeField] int trest = 0;
|
|
|
|
|
protected override string MODEL_SOURCE_PATH { get { return "Chests/"; } }
|
|
|
|
|
|
2022-12-21 17:12:47 +01:00
|
|
|
|
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)
|
2022-11-19 17:02:31 +01:00
|
|
|
|
{
|
2022-12-13 01:03:03 +01:00
|
|
|
|
GameObject globalGUI = GameObject.FindGameObjectWithTag("ChestCollection");
|
2022-11-19 17:02:31 +01:00
|
|
|
|
|
|
|
|
|
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;
|
2022-12-13 01:03:03 +01:00
|
|
|
|
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;
|
2022-11-19 17:02:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
}
|
2022-12-21 17:12:47 +01:00
|
|
|
|
*/
|
2022-11-19 17:02:31 +01:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|