﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public abstract class BaseSceneItem 
{
    [SerializeField]
    protected GameObject prefab;

    public GameObject Prefab
    {
        get { return prefab; }
    }

    public GameObject CreateItem(Vector3 position)
    {
        return CreateGameObject(position, new Bounds());
    }

    public GameObject CreateItem(Bounds bounds)
    {
        return CreateGameObject(prefab.transform.position, bounds);
    }

    private GameObject CreateGameObject(Vector3 position, Bounds bounds)
    {
        // Instantiate a new game object from the prefab
        GameObject go = MonoBehaviour.Instantiate(prefab);

        // Position the object
        if (bounds.size == Vector3.zero)
        {
            go.transform.position = position;
        } else
        {
            go.transform.position = GetPosition(position, bounds);
        }

        return go;
    }

    protected abstract Vector3 GetPosition(Vector3 currentPosition, Bounds bounds);
}
