Skip to content

Commit 9885da8

Browse files
committed
Installation method improvements
1 parent 0df804f commit 9885da8

File tree

4 files changed

+64
-65
lines changed

4 files changed

+64
-65
lines changed

NewMonoBehaviour.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

ScriptHeader.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#region License
2+
// ====================================================
3+
// Product: TapEngine
4+
// Developer: Onur Tanrıkulu
5+
// Date: 24/05/2018 11:21
6+
// Copyright (c) 2018 Onur Tanrikulu. All rights reserved.
7+
// ====================================================
8+
#endregion
9+
10+
using System;
11+
using System.IO;
12+
using System.Text;
13+
using UnityEditor;
14+
15+
namespace TapEditor
16+
{
17+
internal sealed class ScriptHeader : UnityEditor.AssetModificationProcessor
18+
{
19+
////TODO: Use asset for settings.
20+
private const string TemplatePath = "Assets/ScriptHeader/Template.txt";
21+
private const string DeveloperName = "Onur Tanrıkulu";
22+
private const string ScriptExtension = ".cs";
23+
24+
public static void OnWillCreateAsset(string path)
25+
{
26+
string directory = Path.GetDirectoryName(path);
27+
string name = Path.GetFileNameWithoutExtension(path);
28+
string extension = Path.GetExtension(name);
29+
30+
if (extension.Equals(ScriptExtension))
31+
{
32+
path = Path.Combine(directory, name);
33+
string header = File.ReadAllText(TemplatePath);
34+
string body = File.ReadAllText(path);
35+
string file = BuildFile(header, body);
36+
File.WriteAllText(path, file);
37+
AssetDatabase.Refresh();
38+
}
39+
}
40+
41+
private static void ReplaceHeader(StringBuilder builder)
42+
{
43+
builder.Replace("#DATE#", DateTime.Now.ToString("dd/MM/yyyy HH:mm"));
44+
builder.Replace("#YEAR#", DateTime.Now.Year.ToString());
45+
builder.Replace("#PRODUCTNAME#", PlayerSettings.productName);
46+
builder.Replace("#DEVELOPERNAME#", DeveloperName);
47+
builder.Replace("#COMPANYNAME#", PlayerSettings.companyName);
48+
}
49+
50+
private static string BuildFile(string header, string body)
51+
{
52+
int capacity = header.Length + body.Length + 2;
53+
StringBuilder builder = new StringBuilder(capacity);
54+
builder.Append(header);
55+
ReplaceHeader(builder);
56+
builder.Append(Environment.NewLine);
57+
builder.Append(Environment.NewLine);
58+
builder.Append(body);
59+
60+
return builder.ToString();
61+
}
62+
}
63+
}

ScriptTemplate.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,4 @@
55
// Date: #DATE#
66
// Copyright (c) #YEAR# #COMPANYNAME#. All rights reserved.
77
// ====================================================
8-
#endregion
9-
10-
using UnityEngine;
11-
12-
namespace #PRODUCTNAME#
13-
{
14-
public class #SCRIPTNAME# : MonoBehaviour
15-
{
16-
17-
}
18-
}
8+
#endregion

0 commit comments

Comments
 (0)