using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Cyber.Util {
///
/// Prefab database, contains all the prefabs that might be needed at
/// runtime. Intended to be called through the static functions.
///
public class PrefabDB : MonoBehaviour {
private static PrefabDB Singleton;
///
/// The prefabs that can be used at runtime.
///
public GameObject[] Prefabs;
///
/// Sets the Singleton.
///
public PrefabDB() {
Singleton = this;
}
///
/// Creates a new prefab with the given position, rotation and parent.
///
/// The prefab.
/// Index.
/// The position (local, if parent is not null).
/// The rotation (local, if parent is not null).
/// The parent transform.
public static GameObject Create(int index, Transform parent,
Vector3 pos = new Vector3(), Quaternion rot = new Quaternion()) {
GameObject Result = Instantiate(Singleton.Prefabs[index], pos, rot, parent);
if (parent != null) {
Result.transform.localPosition = pos;
Result.transform.localRotation = rot;
}
return Result;
}
}
}