Beispiel #1
0
    public static T CreateGO <T>(string newPath) where T : Component
    {
        if (!newPath.StartsWith("Assets/"))
        {
            newPath = "Assets/" + newPath;
        }
        T          ret = null;
        GameObject go  = new GameObject();

        try
        {
            FileAdapter.RequestFilePath(newPath);
            go.AddComponent <T>();

            if (!FileAdapter.Exists(newPath + ".prefab") || EditorUtility.DisplayDialog("Warning!", "File (" + newPath + ".prefab" + ") already exists you want to replace that file? This will delete the already existing Prefab", "Yes", "No"))
            {
                var refGo = PrefabUtility.SaveAsPrefabAsset(go, newPath + ".prefab", out var success);
                ret = refGo.GetComponent <T>();
            }
        }
        finally
        {
            GameObject.DestroyImmediate(go);
        }

        return(ret);
    }
Beispiel #2
0
    public static TerrainData CreateTerrainData(string path, Vector3 size, int hResolution, int bResolution)
    {
        TerrainData terrainData = new TerrainData();

        terrainData.size = size;

        terrainData.heightmapResolution = hResolution;
        terrainData.baseMapResolution   = bResolution;
        terrainData.SetDetailResolution(1024, 16);

        FileAdapter.RequestFilePath(path);
        AssetDatabase.CreateAsset(terrainData, path);
        return(terrainData);
    }