public static bool CreateTemplate(IList <CGModule> modules, string absFilePath) { if (!Directory.Exists(Path.GetDirectoryName(absFilePath))) { Directory.CreateDirectory(Path.GetDirectoryName(absFilePath)); } // Convert absolute to relative path absFilePath = absFilePath.Replace(Application.dataPath, "Assets"); if (modules.Count == 0 || string.IsNullOrEmpty(absFilePath)) { return(false); } var assetGenerator = CurvyGenerator.Create(); assetGenerator.name = Path.GetFileNameWithoutExtension(absFilePath); CopyModules(modules, assetGenerator, Vector2.zero); foreach (var mod in assetGenerator.Modules) { mod.OnTemplateCreated(); } assetGenerator.ArrangeModules(); var prefab = PrefabUtility.CreateEmptyPrefab(absFilePath); PrefabUtility.ReplacePrefab(assetGenerator.gameObject, prefab, ReplacePrefabOptions.ConnectToPrefab); GameObject.DestroyImmediate(assetGenerator.gameObject); AssetDatabase.Refresh(); return(true); }
// build a generator CurvyGenerator buildGenerator() { // Create the Curvy Generator var gen = CurvyGenerator.Create(); gen.AutoRefresh = false; // Create Modules var path = gen.AddModule <InputSplinePath>(); var shape = gen.AddModule <InputSplineShape>(); var extrude = gen.AddModule <BuildShapeExtrusion>(); var vol = gen.AddModule <BuildVolumeMesh>(); var msh = gen.AddModule <CreateMesh>(); // Create Links between modules path.OutputByName["Path"].LinkTo(extrude.InputByName["Path"]); shape.OutputByName["Shape"].LinkTo(extrude.InputByName["Cross"]); extrude.OutputByName["Volume"].LinkTo(vol.InputByName["Volume"]); vol.OutputByName["VMesh"].LinkTo(msh.InputByName["VMesh"]); // Set module properties path.Spline = TrackSpline; path.UseCache = true; var rectShape = shape.SetManagedShape <CSRectangle>(); rectShape.Width = 20; rectShape.Height = 2; extrude.Optimize = false; vol.Split = false; vol.SetMaterial(0, RoadMaterial); vol.MaterialSetttings[0].SwapUV = true; msh.Collider = CGColliderEnum.None; return(gen); }