Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Nova | ||
{ | ||
public sealed class ViewController : UIViewController | ||
{ | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System.IO; | ||
using System.Text; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Nova.Editor | ||
{ | ||
internal class CreateNavigationControllerEditorWindow : EditorWindow | ||
{ | ||
private string m_navigationControllerInput = "NavigationController"; | ||
|
||
[MenuItem( "Assets/Create/Nova/NavigationController" )] | ||
private static void CreateUINavigationController( MenuCommand menuCommand ) | ||
{ | ||
CreateNavigationControllerEditorWindow window = CreateInstance<CreateNavigationControllerEditorWindow>(); | ||
window.position = new Rect( Screen.width / 2f, Screen.height / 2f, 300f, 100f ); | ||
window.titleContent = new GUIContent( "Create a NavigationController" ); | ||
window.ShowUtility(); | ||
} | ||
|
||
private void OnGUI() | ||
{ | ||
m_navigationControllerInput = EditorGUILayout.TextField( "Class Name: ", m_navigationControllerInput ); | ||
|
||
GUILayout.Space( 15f ); | ||
GUILayout.BeginHorizontal(); | ||
|
||
if ( GUILayout.Button( "Create" ) || Event.current.keyCode == KeyCode.Return ) | ||
{ | ||
MakeViewController( m_navigationControllerInput ); | ||
Close(); | ||
} | ||
|
||
if ( GUILayout.Button( "Cancel" ) ) | ||
{ | ||
Close(); | ||
} | ||
|
||
GUILayout.EndHorizontal(); | ||
Repaint(); | ||
} | ||
|
||
private void MakeViewController( string className ) | ||
{ | ||
string selectedPath = AssetDatabase.GUIDToAssetPath( Selection.assetGUIDs[0] ); | ||
|
||
// generate code text | ||
StringBuilder stringBuilder = new StringBuilder(); | ||
TextIndentHelper indent = TextIndentHelper.StandardSpacesHelper; | ||
|
||
stringBuilder.Append( "using Nova;\n" ); | ||
stringBuilder.Append( "\n" ); | ||
stringBuilder.Append( $"namespace {ScriptingPreferences.NamespaceName}\n" ); | ||
stringBuilder.Append( "{\n" ); | ||
indent.IndentLevel++; | ||
|
||
stringBuilder.Append( indent.ApplyIndent( $"public sealed class {className} : UINavigationController\n" ) ); | ||
stringBuilder.Append( indent.ApplyIndent( "{\n" ) ); | ||
indent.IndentLevel++; | ||
|
||
stringBuilder.Append( indent.ApplyIndent( "\n" ) ); | ||
indent.IndentLevel--; | ||
|
||
stringBuilder.Append( indent.ApplyIndent( "}\n" ) ); | ||
|
||
indent.IndentLevel--; | ||
stringBuilder.Append( indent.ApplyIndent( "}\n" ) ); | ||
|
||
string fullPath = $"{selectedPath}/{className}.cs"; | ||
|
||
// save to file | ||
using ( StreamWriter writer = new StreamWriter( fullPath, false ) ) | ||
{ | ||
writer.Write( stringBuilder.ToString() ); | ||
} | ||
|
||
AssetDatabase.ImportAsset( fullPath, ImportAssetOptions.ForceUpdate ); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System.IO; | ||
using System.Text; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Nova.Editor | ||
{ | ||
internal class CreateViewControllerEditorWindow : EditorWindow | ||
{ | ||
private string m_viewControllerInput = "ViewController"; | ||
|
||
[MenuItem( "Assets/Create/Nova/ViewController" )] | ||
private static void CreateUIViewController( MenuCommand menuCommand ) | ||
{ | ||
CreateViewControllerEditorWindow window = CreateInstance<CreateViewControllerEditorWindow>(); | ||
window.position = new Rect( Screen.width / 2f, Screen.height / 2f, 300f, 100f ); | ||
window.titleContent = new GUIContent( "Create a ViewController" ); | ||
window.ShowUtility(); | ||
} | ||
|
||
private void OnGUI() | ||
{ | ||
m_viewControllerInput = EditorGUILayout.TextField( "Class Name: ", m_viewControllerInput ); | ||
|
||
GUILayout.Space( 15f ); | ||
GUILayout.BeginHorizontal(); | ||
|
||
if ( GUILayout.Button( "Create" ) || Event.current.keyCode == KeyCode.Return ) | ||
{ | ||
MakeViewController( m_viewControllerInput ); | ||
Close(); | ||
} | ||
|
||
if ( GUILayout.Button( "Cancel" ) ) | ||
{ | ||
Close(); | ||
} | ||
|
||
GUILayout.EndHorizontal(); | ||
Repaint(); | ||
} | ||
|
||
private void MakeViewController( string className ) | ||
{ | ||
string selectedPath = AssetDatabase.GUIDToAssetPath( Selection.assetGUIDs[0] ); | ||
|
||
// generate code text | ||
StringBuilder stringBuilder = new StringBuilder(); | ||
TextIndentHelper indent = TextIndentHelper.StandardSpacesHelper; | ||
|
||
stringBuilder.Append( "using Nova;\n" ); | ||
stringBuilder.Append( "\n" ); | ||
stringBuilder.Append( $"namespace {ScriptingPreferences.NamespaceName}\n" ); | ||
stringBuilder.Append( "{\n" ); | ||
indent.IndentLevel++; | ||
|
||
stringBuilder.Append( indent.ApplyIndent( $"public sealed class {className} : UIViewController\n" ) ); | ||
stringBuilder.Append( indent.ApplyIndent( "{\n" ) ); | ||
indent.IndentLevel++; | ||
|
||
stringBuilder.Append( indent.ApplyIndent( "\n" ) ); | ||
indent.IndentLevel--; | ||
|
||
stringBuilder.Append( indent.ApplyIndent( "}\n" ) ); | ||
|
||
indent.IndentLevel--; | ||
stringBuilder.Append( indent.ApplyIndent( "}\n" ) ); | ||
|
||
string fullPath = $"{selectedPath}/{className}.cs"; | ||
|
||
// save to file | ||
using ( StreamWriter writer = new StreamWriter( fullPath, false ) ) | ||
{ | ||
writer.Write( stringBuilder.ToString() ); | ||
} | ||
|
||
AssetDatabase.ImportAsset( fullPath, ImportAssetOptions.ForceUpdate ); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Nova.Editor | ||
{ | ||
internal interface IPreferenceItem | ||
{ | ||
string Name { get; } | ||
|
||
void OnInitialize(); | ||
void OnGUI(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.IO; | ||
using UnityEditor; | ||
using UnityEngine; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace Nova.Editor | ||
{ | ||
internal sealed class ScriptingPreferences : IPreferenceItem | ||
{ | ||
public static string NamespaceName => NovaPreferences.Get( c_namespacePrefKey, c_defaultNamespace ); | ||
public static string NovaPath => NovaPreferences.Get( c_novaPathPrefKey, $"{Environment.CurrentDirectory}/Packages/Nova" ); | ||
|
||
#region IPreferenceItem | ||
|
||
public string Name => "Scripting"; | ||
|
||
public void OnInitialize() | ||
{ | ||
m_namespaceName = NamespaceName; | ||
m_novaPath = NovaPath; | ||
} | ||
|
||
public void OnGUI() | ||
{ | ||
// namespace | ||
EditorGUI.BeginChangeCheck(); | ||
GUIContent namespaceContent = new GUIContent( "Namespace", "Namespace to use when generating code" ); | ||
m_namespaceName = EditorGUILayout.TextField( namespaceContent, m_namespaceName ); | ||
if ( EditorGUI.EndChangeCheck() ) | ||
{ | ||
m_namespaceName = ValidateCodeName( m_namespaceName ); | ||
if ( string.IsNullOrEmpty( m_namespaceName ) ) | ||
{ | ||
m_namespaceName = c_defaultNamespace; | ||
} | ||
|
||
NovaPreferences.Set( c_namespacePrefKey, m_namespaceName ); | ||
} | ||
|
||
// nova path | ||
EditorGUI.BeginChangeCheck(); | ||
GUIContent novaPathContent = new GUIContent( "Nova Package Path", "Path to the Nova package folder" ); | ||
m_novaPath = EditorGUILayout.TextField( novaPathContent, m_novaPath ); | ||
if ( EditorGUI.EndChangeCheck() ) | ||
{ | ||
m_novaPath = ValidatePath( m_novaPath ); | ||
if ( m_novaPath.EndsWith( "/" ) == false ) | ||
{ | ||
m_novaPath += "/"; | ||
} | ||
|
||
NovaPreferences.Set( c_novaPathPrefKey, m_novaPath ); | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
private const string c_defaultNamespace = "Nova"; | ||
private const string c_namespacePrefKey = "Scripting_Namespace"; | ||
private const string c_novaPathPrefKey = "Scripting_NovaPath"; | ||
|
||
private string m_namespaceName; | ||
private string m_novaPath; | ||
|
||
private static string ValidateCodeName( string str ) | ||
{ | ||
return Regex.Replace( str, @"^\s*[0-9]+|\s+|\W", string.Empty ); | ||
} | ||
|
||
private string ValidatePath( string str ) | ||
{ | ||
string format = | ||
$"[{Regex.Escape( new string( Path.GetInvalidPathChars() ) )}]|[{Regex.Escape( ( ":*?|\"<>|" ) )}]"; | ||
return Regex.Replace( str, format, string.Empty ); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.