// 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); }
void OnSelectionChange() { CurvyGenerator gen = null; var mod = DTSelection.GetAllAs <CGModule>(); if (mod.Count > 0) { gen = mod[0].Generator; } if (gen == null) { gen = DTSelection.GetAs <CurvyGenerator>(); } if (gen != null && (Generator == null || gen != Generator)) { Initialize(gen); Repaint(); } else if (mod.Count > 0 && CurvyProject.Instance.CGSynchronizeSelection) { Sel.Select(mod); Canvas.FocusSelection(); Repaint(); } }
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); }
public void Initialize(CurvyGenerator generator) { destroyEditors(); if (generator) { mShowDebug.speed = 3; mShowDebug.value = generator.ShowDebug; mShowDebug.valueChanged.RemoveAllListeners(); mShowDebug.valueChanged.AddListener(Repaint); #if UNITY_5_0 || UNITY_4_6 title = generator.name; #else titleContent.text = generator.name; #endif Generator = generator; Generator.ArrangeModules(); Sel.Clear(); Show(); if (Generator.Modules.Count == 0) { StatusBar.SetInfo("Welcome to the Curvy Generator! Right click or drag a CurvySpline on the canvas to get started!", "", 10); } else { StatusBar.SetMessage(Generator.Modules.Count + " modules loaded!", "", MessageType.None, 3); } } }
static List<CGModuleOutputSlot> findOutputSlots(CurvyGenerator generator, System.Type filterSlotDataType = null) { var modules = generator.GetModules(); var res = new List<CGModuleOutputSlot>(); foreach (var mod in modules) res.AddRange(mod.GetOutputSlots(filterSlotDataType)); return res; }
void hookCGEvents(CurvyGenerator cg) { if (CGOnRefresh.IsSetup) { cg.OnRefresh.AddListener(onCGRefresh); setupEventTarget(CGOnRefresh, ref cgOnRefreshEventTarget); } }
internal static CGGraph Open(CurvyGenerator generator) { generator.Initialize(true); var win = EditorWindow.GetWindow <CGGraph>("", true); win.Initialize(generator); win.wantsMouseMove = true; win.autoRepaintOnSceneChange = true; return(win); }
static List <CGModuleOutputSlot> findOutputSlots(CurvyGenerator generator, System.Type filterSlotDataType = null) { var modules = generator.GetModules(); var res = new List <CGModuleOutputSlot>(); foreach (var mod in modules) { res.AddRange(mod.GetOutputSlots(filterSlotDataType)); } return(res); }
public static List <CGModule> LoadTemplate(CurvyGenerator generator, string path, Vector2 canvasPosition) { var srcGen = AssetDatabase.LoadAssetAtPath(path, typeof(CurvyGenerator)) as CurvyGenerator; if (srcGen) { return(CGEditorUtility.CopyModules(srcGen.Modules, generator, canvasPosition)); } else { return(null); } }
/// <summary> /// Paste all Clipboard modules /// </summary> /// <param name="target">the generator to paste to</param> /// <param name="positionOffset">Canvas offset to use</param> /// <returns>the new modules</returns> public List <CGModule> PasteModules(CurvyGenerator target, Vector2 positionOffset) { var res = CGEditorUtility.CopyModules(Modules, target, positionOffset); if (Mode == ClipboardMode.Cut) { foreach (var mod in Modules) { ParentGenerator.DeleteModule(mod); } } Clear(); return(res); }
// set a CG to render only a portion of a spline void updateSectionGenerator(CurvyGenerator gen, int startCP, int endCP) { // Set Track segment we want to use var path = gen.FindModules <InputSplinePath>(true)[0]; path.StartCP = TrackSpline.ControlPoints[startCP]; path.EndCP = TrackSpline.ControlPoints[endCP]; // Set UV-Offset to match var vol = gen.FindModules <BuildVolumeMesh>()[0]; vol.MaterialSetttings[0].UVOffset.y = lastSectionEndV % 1; timeCG.Start(); gen.Refresh(); timeCG.Stop(); // fetch the ending V to be used by next section var vmesh = vol.OutVMesh.GetData <CGVMesh>(); lastSectionEndV = vmesh.UV[vmesh.Count - 1].y; }
public CurvyCGEventArgs(CurvyGenerator generator, CGModule module) { Sender = generator; Generator = generator; Module = module; }
internal static CGGraph Open(CurvyGenerator generator) { generator.Initialize(true); var win = EditorWindow.GetWindow<CGGraph>("",true); win.Initialize(generator); win.wantsMouseMove = true; win.autoRepaintOnSceneChange = true; return win; }
public static List<CGModule> CopyModules(IList<CGModule> sourceModules, CurvyGenerator target, Vector2 canvasPosition) { var res = new List<CGModule>(); Dictionary<int, int> IDMapping = new Dictionary<int, int>(); // I. Copy Module, store mapping from old to new ID foreach (var mod in sourceModules) { int oldID = mod.UniqueID; // Duplicate module GameObject and parent it to the target Generator, also ensure a unique module name and module id var newMod = mod.CopyTo(target); res.Add(newMod); IDMapping.Add(oldID, newMod.UniqueID); newMod.Properties.Dimensions.position += canvasPosition; // ! Handle managed Resources ! /* var resourceFields = DTUtility.GetFieldsWithAttribute(mod.GetType(), typeof(CGResourceManagerAttribute), BindingFlags.Instance | BindingFlags.NonPublic); foreach (var fi in resourceFields) { var v = fi.GetValue(mod) as Component; // Managed? if (v != null && v.transform.parent == mod.transform) { var newV = v.DuplicateGameObject(newMod.transform); if (newV != null) fi.SetValue(newMod, newV); } }*/ //newMod.renameManagedResourcesINTERNAL(); } // II. Update Links to use the new IDs for (int m=0;m<res.Count;m++) { var mod = res[m]; int newID = mod.UniqueID; for (int i=mod.InputLinks.Count-1;i>=0;i--) { // if target module was copied as well, change both IDs int newTargetID; if (IDMapping.TryGetValue(mod.InputLinks[i].TargetModuleID, out newTargetID)) { mod.InputLinks[i].SetModuleIDIINTERNAL(newID, newTargetID); } else // otherwise delete link mod.InputLinks.RemoveAt(i); } for (int i = mod.OutputLinks.Count - 1; i >= 0; i--) { // if target module was copied as well, change both IDs int newTargetID; if (IDMapping.TryGetValue(mod.OutputLinks[i].TargetModuleID, out newTargetID)) { mod.OutputLinks[i].SetModuleIDIINTERNAL(newID, newTargetID); } else // otherwise delete link mod.OutputLinks.RemoveAt(i); } mod.ReInitializeLinkedSlots(); } /// III. Reinitialize target generator target.Initialize(true); return res; }
public static List<CGModule> LoadTemplate(CurvyGenerator generator, string path,Vector2 canvasPosition) { var srcGen = AssetDatabase.LoadAssetAtPath(path, typeof(CurvyGenerator)) as CurvyGenerator; if (srcGen) return CGEditorUtility.CopyModules(srcGen.Modules, generator,canvasPosition); else return null; }
/// <summary> /// Paste all Clipboard modules /// </summary> /// <param name="target">the generator to paste to</param> /// <param name="positionOffset">Canvas offset to use</param> /// <returns>the new modules</returns> public List<CGModule> PasteModules(CurvyGenerator target, Vector2 positionOffset) { var res = CGEditorUtility.CopyModules(Modules, target, positionOffset); if (Mode == ClipboardMode.Cut) foreach (var mod in Modules) ParentGenerator.DeleteModule(mod); Clear(); return res; }
public static List <CGModule> CopyModules(IList <CGModule> sourceModules, CurvyGenerator target, Vector2 canvasPosition) { var res = new List <CGModule>(); Dictionary <int, int> IDMapping = new Dictionary <int, int>(); // I. Copy Module, store mapping from old to new ID foreach (var mod in sourceModules) { int oldID = mod.UniqueID; // Duplicate module GameObject and parent it to the target Generator, also ensure a unique module name and module id var newMod = mod.CopyTo(target); res.Add(newMod); IDMapping.Add(oldID, newMod.UniqueID); newMod.Properties.Dimensions.position += canvasPosition; // ! Handle managed Resources ! /* * var resourceFields = DTUtility.GetFieldsWithAttribute(mod.GetType(), typeof(CGResourceManagerAttribute), BindingFlags.Instance | BindingFlags.NonPublic); * foreach (var fi in resourceFields) * { * var v = fi.GetValue(mod) as Component; * // Managed? * if (v != null && v.transform.parent == mod.transform) * { * var newV = v.DuplicateGameObject(newMod.transform); * if (newV != null) * fi.SetValue(newMod, newV); * } * }*/ //newMod.renameManagedResourcesINTERNAL(); } // II. Update Links to use the new IDs for (int m = 0; m < res.Count; m++) { var mod = res[m]; int newID = mod.UniqueID; for (int i = mod.InputLinks.Count - 1; i >= 0; i--) { // if target module was copied as well, change both IDs int newTargetID; if (IDMapping.TryGetValue(mod.InputLinks[i].TargetModuleID, out newTargetID)) { mod.InputLinks[i].SetModuleIDIINTERNAL(newID, newTargetID); } else // otherwise delete link { mod.InputLinks.RemoveAt(i); } } for (int i = mod.OutputLinks.Count - 1; i >= 0; i--) { // if target module was copied as well, change both IDs int newTargetID; if (IDMapping.TryGetValue(mod.OutputLinks[i].TargetModuleID, out newTargetID)) { mod.OutputLinks[i].SetModuleIDIINTERNAL(newID, newTargetID); } else // otherwise delete link { mod.OutputLinks.RemoveAt(i); } } mod.ReInitializeLinkedSlots(); } /// III. Reinitialize target generator target.Initialize(true); return(res); }
public CurvyCGEventArgs(CGModule module) { Sender = module; Generator = module.Generator; Module = module; }
public CurvyCGEventArgs(CurvyGenerator generator) { Sender = generator; Generator = generator; }
public void Initialize(CurvyGenerator generator) { destroyEditors(); if (generator) { mShowDebug.speed = 3; mShowDebug.value = generator.ShowDebug; mShowDebug.valueChanged.RemoveAllListeners(); mShowDebug.valueChanged.AddListener(Repaint); #if UNITY_5_0 || UNITY_4_6 title=generator.name; #else titleContent.text=generator.name; #endif Generator = generator; Generator.ArrangeModules(); Sel.Clear(); Show(); if (Generator.Modules.Count == 0) StatusBar.SetInfo("Welcome to the Curvy Generator! Right click or drag a CurvySpline on the canvas to get started!", "", 10); else StatusBar.SetMessage(Generator.Modules.Count + " modules loaded!", "", MessageType.None, 3); } }