// ------------------------------------------------------------------------- /// Deletes the generate code files. /// /// @param iStorage The VS storage to convert to code. /// public void DeleteGeneratedFilesFor(iCS_IStorage iStorage) { var fileName = NameUtility.ToTypeName(iStorage.TypeName); var folder = CodeGenerationUtility.GetCodeGenerationFolder(iStorage); CSharpFileUtils.DeleteCSharpFile(folder, fileName); }
// ======================================================================== /// Extracts the engine namespace from the project name. public string GetEngineNamespace() { // -- Translate '-' to '_' for the namespace. -- var formattedProjectName = NameUtility.ToTypeName(myPackageName.Replace('-', '_')); if (myParentPackage == null) { return(formattedProjectName); } return(myParentPackage.EngineNamespace + "." + formattedProjectName); }
// ------------------------------------------------------------------- /// Builds a code context to share among all CodeBase of the same /// visual script. /// /// @param vsObjects A visual script object from which to extract the /// visual script storage. /// @return The newly created code context. /// public CodeContext(iCS_EditorObject vsObject) { // Allocate conversion tables. var iStorage = vsObject.IStorage; AllocateObjectToCodeTable(iStorage); // Clear any pending code generation error. myVisualScript = iStorage.VisualScript; myServiceKey = "C# Code Generation: " + NameUtility.ToTypeName(vsObject.CodeName); ErrorController.Clear(myServiceKey); }
// ------------------------------------------------------------------- /// Display port value type information protected void EditPortValueType() { var typeName = NameUtility.ToTypeName(iCS_Types.TypeName(vsObject.RuntimeType)); if (!string.IsNullOrEmpty(typeName)) { var label = "Port is a"; if (iCS_TextUtility.StartsWithAVowel(typeName)) { label += "n"; } EditorGUILayout.LabelField(label, typeName); } }
// ================================================================================= /// Saves the visual script. /// /// @param The IStorage to save. /// public static void Save(iCS_IStorage iStorage) { if (iStorage == null) { return; } var package = iStorage.Package; var folder = iStorage.IsEditorScript ? package.GetEditorVisualScriptFolder(true) : package.GetEngineVisualScriptFolder(true); var path = folder + "/" + NameUtility.ToTypeName(iStorage.TypeName) + ".ics2"; iCS_VisualScriptImportExport.Export(iStorage.Storage, path); }
// ======================================================================== /// Parse project name. /// /// @param projectName The full name of the project. /// @return An array of the project name constituents. /// static string[] SplitPackageName(string projectName) { // -- Convert file path to namespace format. -- projectName = projectName.Replace('/', '.'); // -- Remove all illegal characters. -- var cleanName = new StringBuilder(64); var len = projectName.Length; for (int i = 0; i < len; ++i) { char c = projectName[i]; if (cleanName.Length == 0) { if (ParsingUtility.IsFirstIdent(c)) { cleanName.Append(c); } } else if (Char.IsWhiteSpace(c) || c == '.' || ParsingUtility.IsIdent(c)) { cleanName.Append(c); } else { cleanName.Append(' '); } } // -- Split the name into its parts. -- var splitName = cleanName.ToString().Split(new Char[] { '.' }); // -- Convert each part to a type format. -- for (int i = 0; i < splitName.Length; ++i) { splitName[i] = NameUtility.ToTypeName(splitName[i]); } return(splitName); }
FileDefinition myCodeRoot = null; ///< Code global definition. // ------------------------------------------------------------------------- /// Builds global scope code definition. /// /// @param iStorage The VS storage to convert to code. /// @return The complete visual script code. /// public void GenerateCodeFor(iCS_IStorage iStorage) { // -- Nothing to do if no or empty Visual Script. -- if (iStorage == null || iStorage.EditorObjects.Count == 0) { return; } // -- Build code global scope. -- var typeName = NameUtility.ToTypeName(iStorage.TypeName); var namespaceName = CodeGenerationUtility.GetNamespace(iStorage); var baseType = CodeGenerationUtility.GetBaseType(iStorage); myCodeRoot = new FileDefinition(typeName, namespaceName, baseType, iStorage); // -- Generate code. -- var result = myCodeRoot.GenerateCode(0); // -- Write final code to file. -- var fileName = typeName; var folder = CodeGenerationUtility.GetCodeGenerationFolder(iStorage); CSharpFileUtils.WriteCSharpFile(folder, fileName, result.ToString()); }
// =================================================================== // EDITOR ENTRY POINT // ------------------------------------------------------------------- /// Edit node specific information. public void OnGUI() { var node = vsObject; // Display node name. EditName("Node Name"); // Show parent type. var parentTypeName = iCS_Types.TypeName(vsObject.RuntimeType); EditorGUILayout.LabelField("Member of Type", NameUtility.ToTypeName(parentTypeName)); // Show function name (if it exists). if (vsObject.IsKindOfFunction) { var functionName = vsObject.MethodName; if (!string.IsNullOrEmpty(functionName)) { EditorGUILayout.LabelField("Function", functionName); } } // Node specific editor OnNodeSpecificGUI(); // Show Iconic image configuration. Texture2D iconicTexture = TextureCache.GetIconFromGUID(node.IconGUID); Texture2D newTexture = EditorGUILayout.ObjectField("Iconic Texture", iconicTexture, typeof(Texture2D), false) as Texture2D; if (newTexture != iconicTexture) { iCS_UserCommands.ChangeIcon(node, newTexture); } EditDescription(); }