コード例 #1
0
    public static T CreateGameObject <T>(GameObject parentObj) where T : MonoBehaviour
    {
        Type typeOfT = typeof(T);

        //1
        GameObject newGameObj = new GameObject(typeOfT.FullName);

        //2
        PFUtil.SetDefaultAttach(parentObj, newGameObj);

        //3
        T tObj = newGameObj.AddComponent <T>();

        return(tObj);
    }
コード例 #2
0
    public static T Instantiate <T>(T originalObj, GameObject parent) where T : MonoBehaviour
    {
        if (originalObj != null &&
            parent != null)
        {
            //1
            T newInstance = GameObject.Instantiate <T>(originalObj);

            //2
            Type typeOfT = typeof(T);
            newInstance.name = typeOfT.FullName;

            //3
            PFUtil.SetDefaultAttach(parent, newInstance.gameObject);

            return(newInstance);
        }

        return(null);
    }