-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using UnityEngine; | ||
using UnityEditor; | ||
|
||
namespace EsnyaFactory { | ||
[CustomEditor(typeof(CreditGenerator))] | ||
public class CreditGeneratorInspector : Editor { | ||
public bool filesFoldout, addFoldout = false; | ||
public List<string> files = new List<string>(); | ||
|
||
static List<string> GetFileList(CreditGenerator generator) | ||
{ | ||
return generator.fileNames | ||
.Split(' ') | ||
.SelectMany(AssetDatabase.FindAssets) | ||
.Select(AssetDatabase.GUIDToAssetPath) | ||
.ToList(); | ||
} | ||
|
||
public override void OnInspectorGUI() { | ||
var generator = target as CreditGenerator; | ||
using (var change = new EditorGUI.ChangeCheckScope()) { | ||
base.OnInspectorGUI(); | ||
|
||
if (change.changed) files = GetFileList(generator); | ||
} | ||
|
||
|
||
EditorGUILayout.Space(); | ||
|
||
filesFoldout = EditorGUILayout.Foldout(filesFoldout, "License Files"); | ||
if (filesFoldout) { | ||
generator.files = generator.files | ||
.Where(file => { | ||
using (new EditorGUILayout.HorizontalScope()) { | ||
EditorGUILayout.LabelField(file); | ||
return !GUILayout.Button("Remove"); | ||
} | ||
}) | ||
.ToList(); | ||
} | ||
|
||
EditorGUILayout.Space(); | ||
|
||
addFoldout = EditorGUILayout.Foldout(addFoldout, "Add License Files"); | ||
if (addFoldout) { | ||
using (var change = new EditorGUI.ChangeCheckScope()) { | ||
var added = files | ||
.Where(file => !generator.files.Contains(file)) | ||
.Where(file => { | ||
using (new EditorGUILayout.HorizontalScope()) { | ||
EditorGUILayout.LabelField(file); | ||
return GUILayout.Button("Add"); | ||
} | ||
}) | ||
.ToList(); | ||
|
||
if (change.changed) { | ||
generator.files = generator.files.Where(files.Contains).Concat(added).OrderBy(f => f).ToList(); | ||
} | ||
} | ||
} | ||
|
||
EditorGUILayout.Space(); | ||
|
||
if (GUILayout.Button("Refresh File List")) { | ||
files = GetFileList(generator); | ||
} | ||
|
||
if (GUILayout.Button("Update Text")) { | ||
var lines = generator.files | ||
.Where(File.Exists) | ||
.Select(file => ( | ||
Path.GetFileName(Path.GetDirectoryName(file)), | ||
File.ReadAllLines(file).Select(line => line.Trim()) | ||
)) | ||
.Select(t => { | ||
var name = t.Item1; | ||
var license = t.Item2.FirstOrDefault(line => line.ToLower().Contains("license")); | ||
if (license.Contains("SIL Open Font License")) license = "SIL Open Font License"; | ||
var copyright = license == "Apache License" | ||
? "" | ||
: t.Item2.FirstOrDefault(line => line.ToLower().Contains("copyright")); | ||
return generator.format.Replace("%name%", name).Replace("%license%", license).Replace("%copyright%", copyright); | ||
}) | ||
.Prepend(generator.prefix) | ||
.Append(generator.suffix) | ||
.Where(line => !string.IsNullOrWhiteSpace(line)); | ||
generator.targetText.text = string.Join("\n", lines); | ||
generator.targetText.ForceMeshUpdate(); | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/EsnyaUnityTools/Editor/CreditGeneratorInspector.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using TMPro; | ||
|
||
namespace EsnyaFactory { | ||
public class CreditGenerator : MonoBehaviour { | ||
public TMP_Text targetText; | ||
public string fileNames = "LICENSE OFL"; | ||
public string prefix = "Credits:"; | ||
public string suffix = ""; | ||
public string format = " %name% [%license%]: %copyright%"; | ||
[HideInInspector] public List<string> files; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters