47 lines
1.5 KiB
C#
47 lines
1.5 KiB
C#
using UnityEngine;
|
|
|
|
namespace BitStrap
|
|
{
|
|
public static class Create
|
|
{
|
|
public static GameObject Prefab(GameObject prefab, Transform parent = null)
|
|
{
|
|
GameObject gameObject = Object.Instantiate(prefab);
|
|
if (parent != null)
|
|
{
|
|
gameObject.transform.SetParent(parent, false);
|
|
}
|
|
gameObject.transform.localPosition = prefab.transform.localPosition;
|
|
gameObject.transform.localRotation = prefab.transform.localRotation;
|
|
gameObject.transform.localScale = prefab.transform.localScale;
|
|
return gameObject;
|
|
}
|
|
|
|
public static T Behaviour<T>(Transform parent = null) where T : MonoBehaviour
|
|
{
|
|
GameObject gameObject = new GameObject(typeof(T).Name);
|
|
if (parent != null)
|
|
{
|
|
gameObject.transform.SetParent(parent, false);
|
|
}
|
|
gameObject.transform.localPosition = Vector3.zero;
|
|
gameObject.transform.localRotation = Quaternion.identity;
|
|
gameObject.transform.localScale = Vector3.one;
|
|
return gameObject.AddComponent<T>();
|
|
}
|
|
|
|
public static T Behaviour<T>(T behaviourPrefab, Transform parent = null) where T : MonoBehaviour
|
|
{
|
|
GameObject gameObject = Object.Instantiate(behaviourPrefab.gameObject);
|
|
if (parent != null)
|
|
{
|
|
gameObject.transform.SetParent(parent, false);
|
|
}
|
|
gameObject.transform.localPosition = behaviourPrefab.transform.localPosition;
|
|
gameObject.transform.localRotation = behaviourPrefab.transform.localRotation;
|
|
gameObject.transform.localScale = behaviourPrefab.transform.localScale;
|
|
return gameObject.GetComponent<T>();
|
|
}
|
|
}
|
|
}
|