Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Assets/ScriptTemplates.meta

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 @@
#SIGNATURE#using UnityEngine;

#NAMESPACE#public class #SCRIPTNAME# : MonoBehaviour
{

}

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 @@
#SIGNATURE#using UnityEngine;

#NAMESPACE#public class #SCRIPTNAME# : ScriptableObject
{

}

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 @@
#SIGNATURE#using Unity.Entities;

#NAMESPACE#public partial struct #SCRIPTNAME# : ISystem
{

}

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 @@
#SIGNATURE#using Unity.Entities;

#NAMESPACE#public struct #SCRIPTNAME# : IComponentData
{

}

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,13 @@
#SIGNATURE#using Unity.Entities;
using UnityEngine;

#NAMESPACE#public class #SCRIPTNAME# : MonoBehaviour
{
# #public class #SCRIPTNAME#Baker : Baker<#SCRIPTNAME#>
# #{
# ## #public override void Bake(#SCRIPTNAME# authoring)
# ## #{
# ## ## #
# ## #}
# #}
}

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,9 @@
#SIGNATURE#using Unity.Entities;

#NAMESPACE#public partial class #SCRIPTNAME# : SystemBase
{
# #protected override void OnUpdate()
# #{
# ## #
# #}
}

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 @@
#SIGNATURE#using Unity.Entities;

#NAMESPACE#public class #SCRIPTNAME# : IComponentData
{

}

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 @@
#SIGNATURE#using System;

#NAMESPACE#public class #SCRIPTNAME#
{

}

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 @@
#SIGNATURE#using System;

#NAMESPACE#public struct #SCRIPTNAME#
{

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Assets/ScriptTemplates/80-My Scripts__C# Enum-NewEnum.cs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#SIGNATURE##NAMESPACE#public enum #SCRIPTNAME#
{

}

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 @@
#SIGNATURE#using System;

#NAMESPACE#public interface #SCRIPTNAME#
{

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"dependencies": {
"com.unity.entities": "1.0.0-pre.65",
"com.unity.feature.development": "1.0.1",
"com.unity.ide.visualstudio": "2.0.20",
"com.unity.ugui": "1.0.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
Expand Down
8 changes: 8 additions & 0 deletions Packages/mygamedevtools-script-template/Editor/Data.meta

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,50 @@
/**
* IndentationSettings.cs
* Created by: João Borks [joao.borks@gmail.com]
* Created on: 2023-08-19
*/

using System;

namespace MyGameDevTools.ScriptTemplates
{
[Serializable]
public struct IndentationSettings
{
public IndentPattern IndentPattern;
public int IndentMultiplier;

public override bool Equals(object obj)
{
return obj is IndentationSettings settings &&
IndentPattern == settings.IndentPattern &&
IndentMultiplier == settings.IndentMultiplier;
}

public static IndentationSettings Default()
{
return new IndentationSettings
{
IndentPattern = IndentPattern.Spaces,
IndentMultiplier = 4
};
}

public override int GetHashCode()
{
return HashCode.Combine(IndentPattern, IndentMultiplier);
}

public bool IsEmpty() => this == new IndentationSettings();

public static bool operator ==(IndentationSettings left, IndentationSettings right)
{
return left.Equals(right);
}

public static bool operator !=(IndentationSettings left, IndentationSettings right)
{
return !(left == right);
}
}
}

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
Expand Up @@ -14,22 +14,18 @@ public struct NamespaceSettings
public bool Enabled;
public bool UseAssemblyDefinition;
public string DefaultNamespace;
public IndentPattern IndentPattern;
public int IndentMultiplier;

public override bool Equals(object obj)
{
return obj is NamespaceSettings settings &&
Enabled == settings.Enabled &&
UseAssemblyDefinition == settings.UseAssemblyDefinition &&
DefaultNamespace == settings.DefaultNamespace &&
IndentPattern == settings.IndentPattern &&
IndentMultiplier == settings.IndentMultiplier;
DefaultNamespace == settings.DefaultNamespace;
}

public override int GetHashCode()
{
return HashCode.Combine(Enabled, UseAssemblyDefinition, DefaultNamespace, IndentPattern, IndentMultiplier);
return HashCode.Combine(Enabled, UseAssemblyDefinition, DefaultNamespace);
}

public bool IsValid() => !Enabled || !string.IsNullOrWhiteSpace(DefaultNamespace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace MyGameDevTools.ScriptTemplates
public class ScriptKeywordReplacer
{
const string _scriptNameKeyword = "#SCRIPTNAME#";
const string _whitespaceKeyword = "# #";
const string _namespaceKeyword = "#NAMESPACE#";
const string _signatureKeyword = "#SIGNATURE#";
const string _authorKeyword = "#AUTHOR#";
Expand Down Expand Up @@ -56,7 +57,7 @@ public string ProcessScriptTemplate(string scriptContent, string path)
if (regex.IsMatch(scriptContent))
{
var match = regex.Match(scriptContent);
var indentString = GetIndentReplacement();
var indentString = "\n" + GetIndentReplacement();
var indentedMatch = match.Value.Replace("\n", indentString);
scriptContent = scriptContent
.Replace(match.Value, indentedMatch)
Expand All @@ -71,16 +72,17 @@ public string ProcessScriptTemplate(string scriptContent, string path)
var stringBuilder = new StringBuilder(scriptContent);
stringBuilder
.Replace(_signatureKeyword, _templateSettings.Signature.Enabled ? _signatureTemplate.Replace(_authorKeyword, AuthorString).Replace(_dateKeyword, DateString) : string.Empty)
.Replace(_scriptNameKeyword, System.IO.Path.GetFileNameWithoutExtension(path));
.Replace(_scriptNameKeyword, System.IO.Path.GetFileNameWithoutExtension(path))
.Replace(_whitespaceKeyword, GetIndentReplacement());
return Regex.Replace(stringBuilder.ToString(), @"\r\n|\n\r|\n|\r", Environment.NewLine);
}

string GetIndentReplacement()
{
string indentValue = _templateSettings.Namespace.IndentPattern == IndentPattern.Spaces ? " " : "\t";
var stringBuilder = new StringBuilder("\n");
string indentValue = _templateSettings.Indentation.IndentPattern == IndentPattern.Spaces ? " " : "\t";
var stringBuilder = new StringBuilder();

for (int i = 0; i < _templateSettings.Namespace.IndentMultiplier; i++)
for (int i = 0; i < _templateSettings.Indentation.IndentMultiplier; i++)
stringBuilder.Append(indentValue);
return stringBuilder.ToString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ScriptTemplateSettings
{
const string _editorPrefsKey = "com.myunitytools.script-template:settings";

public IndentationSettings Indentation;
public SignatureSettings Signature;
public NamespaceSettings Namespace;

Expand All @@ -29,12 +30,13 @@ public override bool Equals(object obj)
{
return obj is ScriptTemplateSettings settings &&
EqualityComparer<SignatureSettings>.Default.Equals(Signature, settings.Signature) &&
EqualityComparer<NamespaceSettings>.Default.Equals(Namespace, settings.Namespace);
EqualityComparer<NamespaceSettings>.Default.Equals(Namespace, settings.Namespace) &&
EqualityComparer<IndentationSettings>.Default.Equals(Indentation, settings.Indentation);
}

public override int GetHashCode()
{
return HashCode.Combine(Signature, Namespace);
return HashCode.Combine(Signature, Namespace, Indentation);
}

public bool IsEmpty() => Signature.IsEmpty() && Namespace.IsEmpty();
Expand Down
Loading