Remove obsolete generator stuff

This commit is contained in:
CaseyDeCoder 2021-07-06 17:39:41 +02:00
parent 7323c0c99e
commit a675035965
40 changed files with 0 additions and 1064 deletions

View File

@ -1,44 +0,0 @@
using System;
namespace UnityAtoms.Editor
{
/// <summary>
/// Internal module class that holds that regarding an Atom type.
/// </summary>
[Obsolete("Atom Receipe is outdated.", false)]
public struct AtomRecipe : IEquatable<AtomRecipe>
{
public AtomType AtomType { get; set; }
public string ValueType { get; set; }
public AtomRecipe(AtomType atomType, string valueType)
{
this.AtomType = atomType;
this.ValueType = valueType;
}
public bool Equals(AtomRecipe other)
{
return this.AtomType.Equals(other) && this.ValueType == other.ValueType;
}
public override bool Equals(object obj)
{
return Equals((AtomRecipe)obj);
}
public override int GetHashCode()
{
var hash = 17;
hash = hash * 23 + this.AtomType.GetHashCode();
hash = hash * 23 + this.ValueType.GetHashCode();
return hash;
}
public void Deconstruct(out AtomType atomType, out string valueType)
{
atomType = this.AtomType;
valueType = this.ValueType;
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 3ed536fe3c22347dc94887d832218ebc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,72 +0,0 @@
using System;
using System.Text.RegularExpressions;
using System.IO;
namespace UnityAtoms.Editor
{
/// <summary>
/// Internal module class that holds that regarding an Atom type.
/// </summary>
[Obsolete("AtomType is being deprecated for a Type based workflow.", false)]
public struct AtomType : IEquatable<AtomType>
{
public string DisplayName { get; set; }
public string Name { get; set; }
public string TemplateName { get; set; }
public string RelativeFileNameAndPath { get; set; }
public string DrawerTemplateName { get; set; }
public string RelativeDrawerFileNameAndPath { get; set; }
public string EditorTemplateName { get; set; }
public string RelativeEditorFileNameAndPath { get; set; }
public bool IsValuePair { get; set; }
private static string CreateRelativeFilePath(string atomName) => Path.Combine(Runtime.IsUnityAtomsRepo ? "Runtime" : "", $"{atomName}s", $"{{VALUE_TYPE_NAME}}{atomName}.cs");
private static string CreateRelativeDrawerPath(string atomName) => Path.Combine("Editor", Runtime.IsUnityAtomsRepo ? "Drawers" : "AtomDrawers", $"{atomName}s", $"{{VALUE_TYPE_NAME}}{atomName}Drawer.cs");
private static string CreateEditorDrawerPath(string atomName) => Path.Combine("Editor", Runtime.IsUnityAtomsRepo ? "Editors" : "AtomEditors", $"{atomName}s", $"{{VALUE_TYPE_NAME}}{atomName}Editor.cs");
public AtomType(
string displayName,
string templateName,
string name = "",
string relativeFileNameAndPath = "",
string drawerTemplateName = "",
string relativeDrawerFileNameAndPath = "",
string editorTemplateName = "",
string relativeEditorFileNameAndPath = "",
bool isValuePair = false
)
{
this.DisplayName = displayName;
this.TemplateName = templateName;
this.IsValuePair = isValuePair;
this.Name = string.IsNullOrEmpty(name) ? Regex.Replace(displayName, @"\s+", "") : name;
this.RelativeFileNameAndPath = string.IsNullOrEmpty(relativeFileNameAndPath) ? CreateRelativeFilePath(this.Name) : relativeFileNameAndPath;
this.DrawerTemplateName = drawerTemplateName;
this.RelativeDrawerFileNameAndPath = string.IsNullOrEmpty(relativeDrawerFileNameAndPath) ? CreateRelativeDrawerPath(this.Name) : relativeDrawerFileNameAndPath;
this.EditorTemplateName = editorTemplateName;
this.RelativeEditorFileNameAndPath = string.IsNullOrEmpty(relativeEditorFileNameAndPath) ? CreateEditorDrawerPath(this.Name) : relativeEditorFileNameAndPath;
}
public bool HasDrawerTemplate => !string.IsNullOrWhiteSpace(DrawerTemplateName);
public bool HasEditorTemplate => !string.IsNullOrWhiteSpace(EditorTemplateName);
public bool Equals(AtomType other)
{
return this.Name == other.Name && this.IsValuePair == other.IsValuePair;
}
public override bool Equals(object obj)
{
return Equals((AtomType)obj);
}
public override int GetHashCode()
{
var hash = 17;
hash = hash * 23 + this.Name.GetHashCode();
hash = hash * 23 + this.IsValuePair.GetHashCode();
return hash;
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 36d16077f53804e1e91b386e34f752c7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,100 +0,0 @@
using System.IO;
using System.Collections.Generic;
using System;
namespace UnityAtoms.Editor
{
/// <summary>
/// Internal static class holding predefined static `AtomType`s.
/// </summary>
[Obsolete("AtomTypes is being deprecated for a Type based workflow.", false)]
internal static class AtomTypes
{
public static readonly AtomType CONSTANT = new AtomType(
displayName: "Constant",
templateName: "UA_Template__Constant.txt"
);
public static readonly AtomType EVENT = new AtomType(
displayName: "Event",
templateName: "UA_Template__Event.txt"
);
public static readonly AtomType PAIR_EVENT = new AtomType(
displayName: "Pair Event",
name: "Event",
templateName: "UA_Template__Event.txt"
);
public static readonly AtomType VALUE_LIST = new AtomType(
displayName: "Value List",
templateName: "UA_Template__ValueList.txt"
);
// BASE_EVENT_REFERENCE_LISTENER is only used in thoses cases where a Variable does not make sense, eg. Void.
public static readonly AtomType BASE_EVENT_REFERENCE_LISTENER = new AtomType(
displayName: "Base Event Reference Listener",
templateName: "UA_Template__BaseEventReferenceListener.txt"
);
public static readonly AtomType EVENT_REFERENCE_LISTENER = new AtomType(
displayName: "Event Reference Listener",
templateName: "UA_Template__EventReferenceListener.txt"
);
public static readonly AtomType PAIR_EVENT_REFERENCE_LISTENER = new AtomType(
displayName: "Pair Event Reference Listener",
name: "EventReferenceListener",
templateName: "UA_Template__EventReferenceListener.txt"
);
// EVENT_LISTENER is only used in thoses cases where a Event Reference listener does not make sense, eg. AtomBaseVariable.
public static readonly AtomType EVENT_LISTENER = new AtomType(
displayName: "Event Listener",
name: "EventListener",
templateName: "UA_Template__EventListener.txt"
);
public static readonly AtomType SET_VARIABLE_VALUE = new AtomType(
displayName: "Set Variable Value (string) => {}",
name: "SetVariableValue",
templateName: "UA_Template__SetVariableValue.txt",
relativeFileNameAndPath: Path.Combine(Runtime.IsUnityAtomsRepo ? "Runtime" : "", "Actions", "SetVariableValue", $"Set{{VALUE_TYPE_NAME}}VariableValue.cs")
);
public static readonly AtomType SYNC_VARIABLE_INSTANCER_TO_COLLECTION = new AtomType(
displayName: "Sync Variable Instancer To Collection",
templateName: "UA_Template__SyncVariableInstancerToCollection.txt",
relativeFileNameAndPath: Path.Combine(Runtime.IsUnityAtomsRepo ? "Runtime" : "", "SyncVariableInstancerToCollection", $"Sync{{VALUE_TYPE_NAME}}VariableInstancerToCollection.cs")
);
public static readonly AtomType VARIABLE = new AtomType(
displayName: "Variable",
templateName: "UA_Template__Variable.txt"
);
public static readonly AtomType VARIABLE_INSTANCER = new AtomType(
displayName: "Variable Instancer",
name: "VariableInstancer",
templateName: "UA_Template__VariableInstancer.txt"
);
public static readonly AtomType EVENT_INSTANCER = new AtomType(
displayName: "Event Instancer",
templateName: "UA_Template__EventInstancer.txt",
editorTemplateName: "UA_Template_AtomEditor__EventInstancer.txt"
);
public static readonly AtomType PAIR_EVENT_INSTANCER = new AtomType(
displayName: "Pair Event Instancer",
name: "EventInstancer",
templateName: "UA_Template__EventInstancer.txt"
);
/// <summary>
/// Containes all common atom types that are usually generated for a type.
/// </summary>
public static readonly List<AtomType> ALL_ATOM_TYPES = new List<AtomType>()
{
AtomTypes.CONSTANT,
AtomTypes.EVENT,
AtomTypes.PAIR_EVENT,
AtomTypes.VALUE_LIST,
AtomTypes.EVENT_REFERENCE_LISTENER,
AtomTypes.PAIR_EVENT_REFERENCE_LISTENER,
AtomTypes.SET_VARIABLE_VALUE,
AtomTypes.SYNC_VARIABLE_INSTANCER_TO_COLLECTION,
AtomTypes.VARIABLE,
AtomTypes.VARIABLE_INSTANCER,
AtomTypes.EVENT_INSTANCER,
AtomTypes.PAIR_EVENT_INSTANCER,
};
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 101d3d313e64c4c8a807e83f01250bc7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -2,7 +2,6 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEditor.Compilation;
using UnityEngine;
@ -229,240 +228,5 @@ namespace UnityAtoms.Editor
return AssetDatabase.LoadAssetAtPath<MonoScript>(path);
}
#endregion
#region Template Methods
[Obsolete("This methods makes the legacy generator methods work with types. It is strongly recommended however to use the Generate methods instead.", false)]
public static string[] GetTemplatePaths()
{
var templateSearchPath = Runtime.IsUnityAtomsRepo ?
Directory.GetParent(Application.dataPath).Parent.FullName : // "Packages"
Directory.GetParent(Application.dataPath).FullName;
return Directory.GetFiles(templateSearchPath, "UA_Template*.txt", SearchOption.AllDirectories);
}
[Obsolete("This methods makes the legacy generator methods work with types. It is strongly recommended however to use the Generate methods instead.", false)]
public static Dictionary<string, string> CreateTemplateVariablesMap(Type type, bool asPair, string withNamespace = default)
{
var typeName = type.FullName.Replace('+', '.'); // This accounts for nested types.
var displayNameNoPair = type.Name.Capitalize();
var displayName = displayNameNoPair;
if (asPair)
{
typeName = $"Pair<{typeName}>";
displayName += "Pair";
}
// Add Types.
var templateVariables = new Dictionary<string, string>()
{
{ "VALUE_TYPE", typeName },
{ "VALUE_TYPE_NAME", displayName },
{ "VALUE_TYPE_NAME_NO_PAIR", displayNameNoPair }
};
// Add Namespaces if applicable.
var typeNamespace = type.Namespace;
if (!string.IsNullOrEmpty(typeNamespace))
{
templateVariables.Add("TYPE_NAMESPACE", typeNamespace);
}
if (!string.IsNullOrEmpty(withNamespace))
{
templateVariables.Add("SUB_UA_NAMESPACE", withNamespace);
}
return templateVariables;
}
[Obsolete("This methods makes the legacy generator methods work with types. It is strongly recommended however to use the Generate methods instead.", false)]
public static List<string> CreateTemplateConditions(Type type, string withNamespace = default)
{
var typeName = type.FullName.Replace('+', '.'); // This accounts for nested types.
// Add type.
var templateConditions = new List<string>
{
$"TYPE_IS_{typeName.ToUpper()}"
};
// Add Type code condition if applicable.
if (type.IsNumeric())
{
templateConditions.Add("IS_NUMERIC");
}
if (type.IsVector())
{
templateConditions.Add("IS_VECTOR");
}
// Add Equatable condition if applicable.
var isTypeEquatable = type.GetInterfaces().Contains(typeof(IEquatable<>).MakeGenericType(type));
if (isTypeEquatable)
{
templateConditions.Add("EQUATABLE");
}
// Add Namespace conditions if applicable.
var typeNamespace = type.Namespace;
if (!string.IsNullOrEmpty(typeNamespace))
{
templateConditions.Add("TYPE_HAS_NAMESPACE");
}
if (!string.IsNullOrEmpty(withNamespace))
{
templateConditions.Add("HAS_SUB_UA_NAMESPACE");
}
return templateConditions;
}
#endregion
#region Deprecated
[Obsolete("Use the same method with a Type parameter instead.", false)]
public static List<string> CreateTemplateConditions(bool isValueTypeEquatable, string valueTypeNamespace, string subUnityAtomsNamespace, string valueType)
{
var templateConditions = new List<string>();
templateConditions.Add("TYPE_IS_" + valueType.ToUpper());
if (valueType == "int" || valueType == "float") { templateConditions.Add("IS_NUMERIC"); }
if (valueType == "Vector2" || valueType == "Vector3") { templateConditions.Add("IS_VECTOR"); }
if (isValueTypeEquatable) { templateConditions.Add("EQUATABLE"); }
if (!string.IsNullOrEmpty(valueTypeNamespace)) { templateConditions.Add("TYPE_HAS_NAMESPACE"); }
if (!string.IsNullOrEmpty(subUnityAtomsNamespace)) { templateConditions.Add("HAS_SUB_UA_NAMESPACE"); }
return templateConditions;
}
[Obsolete("Use the same method with a Type parameter instead.", false)]
public static Dictionary<string, string> CreateTemplateVariablesMap(string valueType, string valueTypeNamespace, string subUnityAtomsNamespace)
{
var templateVariables = new Dictionary<string, string>() {
{ "VALUE_TYPE_NAME", valueType.Replace('.', '_').Capitalize() },
{ "VALUE_TYPE", valueType },
{ "VALUE_TYPE_NAME_NO_PAIR", valueType.Contains("Pair") ? valueType.Capitalize().Remove(valueType.IndexOf("Pair")) : valueType.Capitalize() }
};
if (!string.IsNullOrEmpty(valueTypeNamespace)) { templateVariables.Add("TYPE_NAMESPACE", valueTypeNamespace); }
if (!string.IsNullOrEmpty(subUnityAtomsNamespace)) { templateVariables.Add("SUB_UA_NAMESPACE", subUnityAtomsNamespace); }
return templateVariables;
}
/// <summary>
/// Generate new Atoms based on the input data.
/// </summary>
/// <param name="valueType">The type of Atom to generate.abstract Eg. double, byte, MyStruct, MyClass.</param>
/// <param name="baseWritePath">Base write path (relative to the Asset folder) where the Atoms are going to be written to.</param>
/// <param name="isEquatable">Is the `type` provided implementing `IEquatable`?</param>
/// <param name="atomTypesToGenerate">A list of `AtomType`s to be generated.</param>
/// <param name="typeNamespace">If the `type` provided is defined under a namespace, provide that namespace here.</param>
/// <param name="subUnityAtomsNamespace">By default the Atoms that gets generated will be under the namespace `UnityAtoms`. If you for example like it to be under `UnityAtoms.MyNamespace` you would then enter `MyNamespace` in this field.</param>
/// <example>
/// <code>
/// namespace MyNamespace
/// {
/// public struct MyStruct
/// {
/// public string Text;
/// public int Number;
/// }
/// }
/// var generator = new Generator();
/// generator.Generate("MyStruct", "", false, new List&lt;AtomType&gt;() { AtomTypes.ACTION }, "MyNamespace", ""); // Generates an Atom Action of type MyStruct
/// </code>
/// </example>
[Obsolete("Use the same method with a Type parameter instead.", false)]
public static void Generate(AtomRecipe atomReceipe, string baseWritePath, string[] templatePaths, List<string> templateConditions, Dictionary<string, string> templateVariables)
{
var (atomType, valueType) = atomReceipe;
// TODO: More validation of that the type exists / is correct.
if (string.IsNullOrEmpty(valueType))
{
Debug.LogWarning($"{Runtime.Constants.LOG_PREFIX} You need to specify a value type. Aborting!");
return;
}
if (string.IsNullOrEmpty(baseWritePath) || !Directory.Exists(baseWritePath))
{
Debug.LogWarning($"{Runtime.Constants.LOG_PREFIX} You need to specify a valid base write path. Aborting!");
return;
}
Debug.Log($"{Runtime.Constants.LOG_PREFIX} Generating atom {atomType.Name} for value type {valueType}");
List<Tuple<string, string>> filesToGenerate = new List<Tuple<string, string>>() { new Tuple<string, string>(atomType.TemplateName, atomType.RelativeFileNameAndPath) };
if (atomType.HasDrawerTemplate) filesToGenerate.Add(new Tuple<string, string>(atomType.DrawerTemplateName, atomType.RelativeDrawerFileNameAndPath));
if (atomType.HasEditorTemplate) filesToGenerate.Add(new Tuple<string, string>(atomType.EditorTemplateName, atomType.RelativeEditorFileNameAndPath));
foreach (var (templateName, relativeFilePath) in filesToGenerate)
{
var templatePath = templatePaths.FirstOrDefault((path) => path.EndsWith(templateName));
if (string.IsNullOrEmpty(templatePath))
{
Debug.Log($"{Runtime.Constants.LOG_PREFIX} Template {templateName} for {atomType.DisplayName} not found. Skipping!");
return;
}
var resolvedRelativeFilePath = Templating.ResolveVariables(templateVariables: templateVariables, toResolve: relativeFilePath);
var template = File.ReadAllText(templatePath);
var filePath = Path.Combine(baseWritePath, resolvedRelativeFilePath);
var fileDirectory = Path.GetDirectoryName(filePath);
// Create write directory
Directory.CreateDirectory(fileDirectory);
// Adjust content
var content = Templating.ResolveVariables(templateVariables: templateVariables, toResolve: template);
content = Templating.ResolveConditionals(template: content, trueConditions: templateConditions);
content = RemoveDuplicateNamespaces(template: content);
// Write to file
File.WriteAllText(filePath, content);
AssetDatabase.ImportAsset(filePath);
}
}
/// <summary>
/// Removes duplicate namespaces, given content from a template.
/// </summary>
/// <param name="template">The content template to remove namespace from.</param>
/// <returns>A copy of `content`, but without duplicate namespaces.</returns>
[Obsolete("Outdated method.", false)]
private static string RemoveDuplicateNamespaces(string template)
{
var currentIndex = 0;
var countNamespaces = new Dictionary<string, int>();
while (true)
{
currentIndex = template.IndexOf("using ", currentIndex);
if (currentIndex == -1) break;
var namespaceStartIndex = currentIndex + 6;
var namespaceEndIndex = template.IndexOf(";", namespaceStartIndex);
var ns = template.Substring(namespaceStartIndex, namespaceEndIndex - namespaceStartIndex);
if (countNamespaces.ContainsKey(ns))
{
countNamespaces[ns] = countNamespaces[ns] + 1;
}
else
{
countNamespaces.Add(ns, 1);
}
currentIndex = namespaceEndIndex;
}
var contentCopy = String.Copy(template);
foreach (var kvp in countNamespaces)
{
if (kvp.Value > 1)
{
var usingStr = $"using {kvp.Key};";
contentCopy = contentCopy.Remove(contentCopy.IndexOf(usingStr), usingStr.Length + 1);
}
}
return contentCopy;
}
#endregion
}
}

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: f5ad8e318fa5e4d62aca09285964db11
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,17 +0,0 @@
using UnityEditor;
using UnityEngine.UIElements;
using UnityAtoms.Editor;
<%IF TYPE_HAS_NAMESPACE%>using {TYPE_NAMESPACE};<%ENDIF%>
<%IF HAS_SUB_UA_NAMESPACE%>
namespace UnityAtoms.{SUB_UA_NAMESPACE}.Editor
<%ELSE%>
namespace UnityAtoms.Editor
<%ENDIF%>
{
/// <summary>
/// Event property drawer of type `{VALUE_TYPE}`. Inherits from `AtomEventEditor&lt;{VALUE_TYPE}&gt;`.
/// </summary>
[CustomEditor(typeof({VALUE_TYPE_NAME}Event))]
public sealed class {VALUE_TYPE_NAME}EventEditor : AtomEventEditor<{VALUE_TYPE}> { }
}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: b0da24b9cd61c4f5a83420ce5971b871
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,19 +0,0 @@
#if UNITY_2019_1_OR_NEWER
using UnityEditor;
using UnityEngine.UIElements;
using UnityAtoms.Editor;
<%IF TYPE_HAS_NAMESPACE%>using {TYPE_NAMESPACE};<%ENDIF%>
<%IF HAS_SUB_UA_NAMESPACE%>
namespace UnityAtoms.{SUB_UA_NAMESPACE}.Editor
<%ELSE%>
namespace UnityAtoms.Editor
<%ENDIF%>
{
/// <summary>
/// Event property drawer of type `{VALUE_TYPE}`. Inherits from `AtomEventInstancerEditor&lt;{VALUE_TYPE}, {VALUE_TYPE_NAME}Event&gt;`. Only availble in `UNITY_2019_1_OR_NEWER`.
/// </summary>
[CustomEditor(typeof({VALUE_TYPE_NAME}Event))]
public sealed class {VALUE_TYPE_NAME}EventInstancerEditor : AtomEventInstancerEditor<{VALUE_TYPE}, {VALUE_TYPE_NAME}Event> { }
}
#endif

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 64e895f0a21bf3644a484862531edaa2
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,16 +0,0 @@
using UnityEditor;
using UnityAtoms.Editor;
<%IF TYPE_HAS_NAMESPACE%>using {TYPE_NAMESPACE};<%ENDIF%>
<%IF HAS_SUB_UA_NAMESPACE%>
namespace UnityAtoms.{SUB_UA_NAMESPACE}.Editor
<%ELSE%>
namespace UnityAtoms.Editor
<%ENDIF%>
{
/// <summary>
/// Variable Inspector of type `{VALUE_TYPE}`. Inherits from `AtomVariableEditor&lt;{VALUE_TYPE}&gt;`
/// </summary>
[CustomEditor(typeof({VALUE_TYPE_NAME}Variable))]
public sealed class {VALUE_TYPE_NAME}VariableEditor : AtomVariableEditor<{VALUE_TYPE}> { }
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 88c6cd99584540a0b9996d60416193d3
timeCreated: 1572554920

View File

@ -1,16 +0,0 @@
using UnityEngine;
<%IF TYPE_HAS_NAMESPACE%>using {TYPE_NAMESPACE};<%ENDIF%>
<%IF HAS_SUB_UA_NAMESPACE%>
namespace UnityAtoms.{SUB_UA_NAMESPACE}
<%ELSE%>
namespace UnityAtoms
<%ENDIF%>
{
/// <summary>
/// Event Reference Listener of type `{VALUE_TYPE}`. Inherits from `AtomEventReferenceListener&lt;{VALUE_TYPE}&gt;`.
/// </summary>
[EditorIcon("atom-icon-orange")]
[AddComponentMenu("Unity Atoms/Listeners/{VALUE_TYPE_NAME} Base Event Reference Listener")]
public sealed class {VALUE_TYPE_NAME}BaseEventReferenceListener : AtomEventReferenceListener<{VALUE_TYPE}> { }
}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 13f7eeecc4636455fbab807286695953
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,16 +0,0 @@
<%IF TYPE_HAS_NAMESPACE%>
using {TYPE_NAMESPACE};
<%ENDIF%>
<%IF HAS_SUB_UA_NAMESPACE%>
namespace UnityAtoms.{SUB_UA_NAMESPACE}
<%ELSE%>
namespace UnityAtoms
<%ENDIF%>
{
/// <summary>
/// Condition of type `{VALUE_TYPE}`. Inherits from `AtomCondition&lt;{VALUE_TYPE}&gt;`.
/// </summary>
[EditorIcon("atom-icon-teal")]
public abstract class {VALUE_TYPE_NAME}Condition : AtomCondition<{VALUE_TYPE}> { }
}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: f0b6c5bacec9a3f4992b85928c75535a
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,16 +0,0 @@
using UnityEngine;
<%IF TYPE_HAS_NAMESPACE%>using {TYPE_NAMESPACE};<%ENDIF%>
<%IF HAS_SUB_UA_NAMESPACE%>
namespace UnityAtoms.{SUB_UA_NAMESPACE}
<%ELSE%>
namespace UnityAtoms
<%ENDIF%>
{
/// <summary>
/// Constant of type `{VALUE_TYPE}`. Inherits from `AtomBaseVariable {VALUE_TYPE} `.
/// </summary>
[EditorIcon("atom-icon-teal")]
[CreateAssetMenu(menuName = "Unity Atoms/Constants/{VALUE_TYPE_NAME}", fileName = "{VALUE_TYPE_NAME}Constant")]
public sealed class {VALUE_TYPE_NAME}Constant : AtomBaseVariable<{VALUE_TYPE}> {}
}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 530918e3b8d934544bf6a0c73be35f83
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,24 +0,0 @@
using UnityEngine;
<%IF TYPE_HAS_NAMESPACE%>using {TYPE_NAMESPACE};<%ENDIF%>
<%IF HAS_SUB_UA_NAMESPACE%>
namespace UnityAtoms.{SUB_UA_NAMESPACE}
<%ELSE%>
namespace UnityAtoms
<%ENDIF%>
{
/// <summary>
/// Event of type `{VALUE_TYPE}`. Inherits from `AtomEvent&lt;{VALUE_TYPE}&gt;`.
/// </summary>
[EditorIcon("atom-icon-cherry")]
[CreateAssetMenu(menuName = "Unity Atoms/Events/{VALUE_TYPE_NAME}", fileName = "{VALUE_TYPE_NAME}Event")]
public sealed class {VALUE_TYPE_NAME}Event : AtomEvent<{VALUE_TYPE}>
{
<%IF TYPE_IS_VOID%>
public override void Raise()
{
Raise(new Void());
}
<%ENDIF%>
}
}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 0d9f59eb67e3a45cc92183651c0f206f
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,16 +0,0 @@
using UnityEngine;
<%IF TYPE_HAS_NAMESPACE%>using {TYPE_NAMESPACE};<%ENDIF%>
<%IF HAS_SUB_UA_NAMESPACE%>
namespace UnityAtoms.{SUB_UA_NAMESPACE}
<%ELSE%>
namespace UnityAtoms
<%ENDIF%>
{
/// <summary>
/// Event Instancer of type `{VALUE_TYPE}`. Inherits from `AtomEventInstancer&lt;{VALUE_TYPE}&gt;`.
/// </summary>
[EditorIcon("atom-icon-sign-blue")]
[AddComponentMenu("Unity Atoms/Event Instancers/{VALUE_TYPE_NAME} Event Instancer")]
public class {VALUE_TYPE_NAME}EventInstancer : AtomEventInstancer<{VALUE_TYPE}> { }
}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 66953febaa4a84673bb48e58766ce2cb
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,16 +0,0 @@
using UnityEngine;
<%IF TYPE_HAS_NAMESPACE%>using {TYPE_NAMESPACE};<%ENDIF%>
<%IF HAS_SUB_UA_NAMESPACE%>
namespace UnityAtoms.{SUB_UA_NAMESPACE}
<%ELSE%>
namespace UnityAtoms
<%ENDIF%>
{
/// <summary>
/// Event Listener of type `{VALUE_TYPE}`. Inherits from `AtomEventListener&lt;{VALUE_TYPE}&gt;`.
/// </summary>
[EditorIcon("atom-icon-orange")]
[AddComponentMenu("Unity Atoms/Listeners/{VALUE_TYPE_NAME} Event Listener")]
public sealed class {VALUE_TYPE_NAME}EventListener : AtomEventListener<{VALUE_TYPE}> { }
}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 8315ba48bcbf64b2fb8366524797d23a
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,16 +0,0 @@
using UnityEngine;
<%IF TYPE_HAS_NAMESPACE%>using {TYPE_NAMESPACE};<%ENDIF%>
<%IF HAS_SUB_UA_NAMESPACE%>
namespace UnityAtoms.{SUB_UA_NAMESPACE}
<%ELSE%>
namespace UnityAtoms
<%ENDIF%>
{
/// <summary>
/// Event Reference Listener of type `{VALUE_TYPE}`. Inherits from `AtomEventReferenceListener&lt;{VALUE_TYPE}&gt;`.
/// </summary>
[EditorIcon("atom-icon-orange")]
[AddComponentMenu("Unity Atoms/Listeners/{VALUE_TYPE_NAME} Event Reference Listener")]
public sealed class {VALUE_TYPE_NAME}EventReferenceListener : AtomListener<{VALUE_TYPE}> { }
}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: bd8d42ec4f8b24d0c83a8a487fe7a29a
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,17 +0,0 @@
using UnityEngine;
using UnityAtoms.BaseAtoms;
<%IF TYPE_HAS_NAMESPACE%>using {TYPE_NAMESPACE};<%ENDIF%>
<%IF HAS_SUB_UA_NAMESPACE%>
namespace UnityAtoms.{SUB_UA_NAMESPACE}
<%ELSE%>
namespace UnityAtoms
<%ENDIF%>
{
/// <summary>
/// Set variable value Action of type `{VALUE_TYPE}`. Inherits from `SetVariableValue&lt;{VALUE_TYPE}&gt;`.
/// </summary>
[EditorIcon("atom-icon-purple")]
[CreateAssetMenu(menuName = "Unity Atoms/Actions/Set Variable Value/{VALUE_TYPE_NAME}", fileName = "Set{VALUE_TYPE_NAME}VariableValue")]
public sealed class Set{VALUE_TYPE_NAME}VariableValue : SetVariableValue<{VALUE_TYPE}> { }
}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 858f7f2859b28438d980ccaa2a655d3a
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,17 +0,0 @@
using UnityEngine;
using UnityAtoms.BaseAtoms;
<%IF TYPE_HAS_NAMESPACE%>using {TYPE_NAMESPACE};<%ENDIF%>
<%IF HAS_SUB_UA_NAMESPACE%>
namespace UnityAtoms.{SUB_UA_NAMESPACE}
<%ELSE%>
namespace UnityAtoms
<%ENDIF%>
{
/// <summary>
/// Adds Variable Instancer's Variable of type {VALUE_TYPE} to a Collection or List on OnEnable and removes it on OnDestroy.
/// </summary>
[AddComponentMenu("Unity Atoms/Sync Variable Instancer to Collection/Sync {VALUE_TYPE_NAME} Variable Instancer to Collection")]
[EditorIcon("atom-icon-delicate")]
public class Sync{VALUE_TYPE_NAME}VariableInstancerToCollection : SyncVariableInstancerToCollection<{VALUE_TYPE}> { }
}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: cf6a161b0fbad45fab39780ebd140c99
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,16 +0,0 @@
using UnityEngine;
<%IF TYPE_HAS_NAMESPACE%>using {TYPE_NAMESPACE};<%ENDIF%>
<%IF HAS_SUB_UA_NAMESPACE%>
namespace UnityAtoms.{SUB_UA_NAMESPACE}
<%ELSE%>
namespace UnityAtoms
<%ENDIF%>
{
/// <summary>
/// Value List of type `{VALUE_TYPE}`. Inherits from `AtomValueList&lt;{VALUE_TYPE}&gt;`.
/// </summary>
[EditorIcon("atom-icon-piglet")]
[CreateAssetMenu(menuName = "Unity Atoms/Value Lists/{VALUE_TYPE_NAME}", fileName = "{VALUE_TYPE_NAME}ValueList")]
public sealed class {VALUE_TYPE_NAME}ValueList : AtomValueList<{VALUE_TYPE}> { }
}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: e17f6abc30aa84fbb8d1fd7464da130b
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,126 +0,0 @@
using UnityEngine;
<%IF !EQUATABLE%>using System;<%ENDIF%>
<%IF TYPE_HAS_NAMESPACE%>using {TYPE_NAMESPACE};<%ENDIF%>
<%IF HAS_SUB_UA_NAMESPACE%>
namespace UnityAtoms.{SUB_UA_NAMESPACE}
<%ELSE%>
namespace UnityAtoms
<%ENDIF%>
{
<%IF EQUATABLE%>
/// <summary>
/// Variable of type `{VALUE_TYPE}`. Inherits from `EquatableAtomVariable&lt;{VALUE_TYPE}&gt;`.
/// </summary>
[EditorIcon("atom-icon-lush")]
[CreateAssetMenu(menuName = "Unity Atoms/Variables/{VALUE_TYPE_NAME}", fileName = "{VALUE_TYPE_NAME}Variable")]
public sealed class {VALUE_TYPE_NAME}Variable : EquatableAtomVariable<{VALUE_TYPE}>
{
<%IF TYPE_IS_COLOR%>
/// <summary>
/// Set Alpha of Color by value.
/// </summary>
/// <param name="value">New alpha value.</param>
public void SetAlpha(float value) => Value = new Color(Value.r, Value.g, Value.b, value);
/// <summary>
/// Set Alpha of Color by Variable value.
/// </summary>
/// <param name="variable">New alpha Variable value.</param>
public void SetAlpha(AtomBaseVariable<float> variable) => SetAlpha(variable.Value);
<%ENDIF%>
<%IF IS_NUMERIC%>
/// <summary>
/// Add value to Variable.
/// </summary>
/// <param name="value">Value to add.</param>
public void Add({VALUE_TYPE} value) => Value += value;
/// <summary>
/// Add variable value to Variable.
/// </summary>
/// <param name="variable">Variable with value to add.</param>
public void Add(AtomBaseVariable<{VALUE_TYPE}> variable) => Add(variable.Value);
/// <summary>
/// Subtract value from Variable.
/// </summary>
/// <param name="value">Value to subtract.</param>
public void Subtract({VALUE_TYPE} value) => Value -= value;
/// <summary>
/// Subtract variable value from Variable.
/// </summary>
/// <param name="variable">Variable with value to subtract.</param>
public void Subtract(AtomBaseVariable<{VALUE_TYPE}> variable) => Subtract(variable.Value);
/// <summary>
/// Multiply variable by value.
/// </summary>
/// <param name="value">Value to multiple by.</param>
public void MultiplyBy({VALUE_TYPE} value) => Value *= value;
/// <summary>
/// Multiply variable by Variable value.
/// </summary>
/// <param name="variable">Variable with value to multiple by.</param>
public void MultiplyBy(AtomBaseVariable<{VALUE_TYPE}> variable) => MultiplyBy(variable.Value);
/// <summary>
/// Divide Variable by value.
/// </summary>
/// <param name="value">Value to divide by.</param>
public void DivideBy({VALUE_TYPE} value) => Value /= value;
/// <summary>
/// Divide Variable by Variable value.
/// </summary>
/// <param name="variable">Variable value to divide by.</param>
public void DivideBy(AtomBaseVariable<{VALUE_TYPE}> variable) => DivideBy(variable.Value);
<%ENDIF%>
<%IF IS_VECTOR%>
/// <summary>
/// Multiply variable by value.
/// </summary>
/// <param name="value">Value to multiple by.</param>
public void MultiplyBy(float value) => Value *= value;
/// <summary>
/// Multiply variable by Variable value.
/// </summary>
/// <param name="variable">Variable with value to multiple by.</param>
public void MultiplyBy(AtomBaseVariable<float> variable) => MultiplyBy(variable.Value);
/// <summary>
/// Divide Variable by value.
/// </summary>
/// <param name="value">Value to divide by.</param>
public void DivideBy(float value) => Value /= value;
/// <summary>
/// Divide Variable by Variable value.
/// </summary>
/// <param name="variable">Variable value to divide by.</param>
public void DivideBy(AtomBaseVariable<float> variable) => DivideBy(variable.Value);
<%ENDIF%>
}
<%ELSE%>
/// <summary>
/// Variable of type `{VALUE_TYPE}`. Inherits from `AtomVariable&lt;{VALUE_TYPE}&gt;`.
/// </summary>
[EditorIcon("atom-icon-lush")]
[CreateAssetMenu(menuName = "Unity Atoms/Variables/{VALUE_TYPE_NAME}", fileName = "{VALUE_TYPE_NAME}Variable")]
public sealed class {VALUE_TYPE_NAME}Variable : AtomVariable<{VALUE_TYPE}>
{
protected override bool ValueEquals({VALUE_TYPE} other)
{
<%IF TYPE_IS_GAMEOBJECT|TYPE_IS_COLLIDER|TYPE_IS_COLLIDER2D|TYPE_IS_COLLISION|TYPE_IS_COLLISION2D%>
return _value == other;
<%ELSE%>
throw new NotImplementedException();
<%ENDIF%>
}
}
<%ENDIF%>
}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 14cb10b2f60934207847f7c377054be3
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,17 +0,0 @@
using UnityEngine;
using UnityAtoms.BaseAtoms;
<%IF TYPE_HAS_NAMESPACE%>using {TYPE_NAMESPACE};<%ENDIF%>
<%IF HAS_SUB_UA_NAMESPACE%>
namespace UnityAtoms.{SUB_UA_NAMESPACE}
<%ELSE%>
namespace UnityAtoms
<%ENDIF%>
{
/// <summary>
/// Variable Instancer of type `{VALUE_TYPE}`. Inherits from `AtomVariableInstancer&lt;{VALUE_TYPE}&gt;`.
/// </summary>
[EditorIcon("atom-icon-hotpink")]
[AddComponentMenu("Unity Atoms/Variable Instancers/{VALUE_TYPE_NAME} Variable Instancer")]
public class {VALUE_TYPE_NAME}VariableInstancer : AtomVariableInstancer<{VALUE_TYPE}> { }
}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: cdbca62dab0b745b3b4b99f62c179857
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,94 +0,0 @@
using System;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
namespace UnityAtoms.Editor
{
/// <summary>
/// Internal class used for templating when generating new Atoms using the `Generator`.
/// </summary>
internal class Templating
{
/// <summary>
/// Resolve conditionals from the provided tempalte.
/// </summary>
/// <param name="template">Template to resolve the conditionals from.</param>
/// <param name="trueConditions">A list of conditionals that are `true`.</param>
/// <returns>A new template string resolved and based on the provided `template`.</returns>
public static string ResolveConditionals(string template, List<string> trueConditions)
{
var templateCopy = String.Copy(template);
templateCopy = templateCopy.Replace("\r\n", "\n");
var indexIfOpened = templateCopy.LastIndexOf("<%IF ", StringComparison.Ordinal);
if (indexIfOpened == -1) return templateCopy; // No IF blocks left and nothing else to resolve. Return template.
var indexIfClosed = templateCopy.IndexOf("%>", indexIfOpened + 5, StringComparison.Ordinal);
if (indexIfClosed == -1) throw new Exception("Found <%IF block but it was never closed (missing %>)");
// NOTE: Only supports OR:ed conditions ATM
var conditions = new List<Tuple<string, bool>>();
var conditionStrings = templateCopy.Substring(indexIfOpened + 5, indexIfClosed - (indexIfOpened + 5)).Split('|').ToList();
conditionStrings.ForEach((c) => {
var isNegated = c.Substring(0, 1) == "!";
conditions.Add(new Tuple<string, bool>(
isNegated ? c.Substring(1) : c,
isNegated
));
});
var indexOfNextEndIf = templateCopy.IndexOf("<%ENDIF%>", indexIfClosed, StringComparison.Ordinal);
if (indexOfNextEndIf == -1) throw new Exception("No closing <%ENDIF%> for condition.");
// NOTE: We are assuming that when the next char after the conditional is a new line char that it's not inline.
// However, this is not always true (you can have an inline conditional at the end of a line). This implementation
// works for our cases for now, but we might need to come back and change this in the future for other use cases.
var indexOfNextCharAfterEndIf = indexOfNextEndIf + "<%ENDIF%>".Length;
var indexOfLFAfterEndIf =
templateCopy.IndexOf("\n", indexOfNextEndIf, StringComparison.Ordinal);
var inline = true;
if (indexOfLFAfterEndIf == indexOfNextCharAfterEndIf)
{
indexOfNextCharAfterEndIf = indexOfLFAfterEndIf + 1;
inline = false;
}
var indexOfNextElse = templateCopy.IndexOf("<%ELSE%>", indexIfClosed, StringComparison.Ordinal);
if (indexOfNextElse >= indexOfNextEndIf) indexOfNextElse = -1;
var endThenBlock = indexOfNextElse != -1 ? indexOfNextElse : indexOfNextEndIf;
var resolved = "";
if (conditions.Any((condition) => trueConditions.Contains(condition.Item1) ^ condition.Item2))
{
resolved = templateCopy.Substring(indexIfClosed + 2, endThenBlock - (indexIfClosed + 2));
}
else if (indexOfNextElse != -1)
{
resolved = templateCopy.Substring(indexOfNextElse + 8, indexOfNextEndIf - (indexOfNextElse + 8));
}
resolved = resolved.Trim('\n');
templateCopy = templateCopy.Remove(indexIfOpened, indexOfNextCharAfterEndIf - indexIfOpened);
templateCopy = templateCopy.Insert(indexIfOpened, string.IsNullOrEmpty(resolved) ? "" : $"{resolved}" + (inline ? "" : "\n"));
return ResolveConditionals(templateCopy, trueConditions);
}
/// <summary>
/// Resolve variables in the provided string.
/// </summary>
/// <param name="templateVariables">Dictionay mapping template variables and their resolutions.</param>
/// <param name="toResolve">The string to resolve.</param>
/// <returns>A new template string resolved and based on the provided `toResolve` string.</returns>
public static string ResolveVariables(Dictionary<string, string> templateVariables, string toResolve)
{
var resolvedString = toResolve;
foreach (var kvp in templateVariables)
{
resolvedString = resolvedString.Replace("{" + kvp.Key + "}", kvp.Value);
}
return resolvedString;
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 12e425fc7f0694a75ae44667e8a67b2a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: