Exemple #1
0
    // For respawning a prefab in the sow cycle
    public static GameObject Recreate(string prefabPath, string prefabName, string registeredID, string parentID)
    {
        if (prefabPath == "" || prefabName == "")
        {
            throw new ArgumentException("Cannot create prefab with empty path and/or name");
        }

        GameObject go = ABU.LoadAsset <GameObject> (prefabPath, prefabName);
        GameObject inst;

        if (parentID == "")
        {
            inst = Instantiate(go, Vector3.zero, Quaternion.identity);
        }
        else
        {
            RegisteredObject parent = RegisteredObject.FindObject(parentID);
            if (parent == null)
            {
                throw new ArgumentException("[RO] " + parentID + " does not exist!");
            }
            inst = Instantiate(go, Vector3.zero, Quaternion.identity, parent.transform);
        }
        RegisteredObject ro = inst.GetComponent <RegisteredObject> ();

        ro.registeredID = registeredID;
        ro.prefabPath   = prefabPath;
        ro.prefabName   = prefabName;
        return(inst);
    }