Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
Discontinuation, last update
Browse files Browse the repository at this point in the history
  • Loading branch information
LurkingNinjaDev committed Oct 25, 2024
1 parent 26ec073 commit 1fa01a4
Show file tree
Hide file tree
Showing 16 changed files with 1,314 additions and 2,238 deletions.
1,057 changes: 1,057 additions & 0 deletions Assets/InputSystem_Actions.inputactions

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions Assets/InputSystem_Actions.inputactions.meta

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

12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Changelog
# * Discontinued *
> Due to Unity improved their own codegen in the Input System package this is discontinued!
> Check out the "new" unified [CodeGen library](https://github.com/LurkingNinja/com.lurking-ninja.codegen).
---
## Changelog
All notable changes to this project will be documented in this file.

## [0.1.3] - 2024-10-25
### Changed
- General AssetProcessor util added
- Repository changed to an archive, unified [CodeGen](https://github.com/LurkingNinja/com.lurking-ninja.codegen) library

## [0.1.2] - 2024-01-16
### Added
- Added support for ProjectWide Actions.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/***
* Input System Codegen
* Copyright (c) 2022-2024 Lurking Ninja.
*
* MIT License
* https://github.com/LurkingNinja/com.lurking-ninja.input-codegen
*/
namespace LurkingNinja.Input.Editor
{
using System;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;

public static class AssetPostProcessorHelper
{
private static string GetFullPath(string fileName, string path) =>
$"{Application.dataPath}/../{path}{fileName}.cs";

private static string GetPath(string fileName, string path) =>
$"{path}{fileName}.cs";

public static string KeyToCSharpWithoutAt(string key) => KeyToCSharp(key, false);

public static string KeyToCSharp(string key, bool addAt = true)
{
if(string.IsNullOrEmpty(key))
throw new ArgumentOutOfRangeException(nameof(key), "Key cannot be empty or null.");

var outKey = "";
if (!char.IsLetter(key[0]) && key[0] != '_')
outKey = $"_{key}";
outKey = key.Where(t1 => char.IsLetterOrDigit(t1) || t1 != '_').Aggregate(outKey, (current, t1) => current + t1);
outKey = addAt ? $"@{outKey}" : outKey;
var isValidIdentifier = new Microsoft.CSharp.CSharpCodeProvider().IsValidIdentifier(outKey);

return !isValidIdentifier
? throw new ArgumentOutOfRangeException(nameof(key),
"Key should be resolvable into a valid C# identifier.")
: outKey;
}

private static string GetFileName(string fileName) =>
Path.GetFileNameWithoutExtension(fileName).Replace(" ", "_");

public static void DeleteFile(string fileName, string path) =>
AssetDatabase.DeleteAsset(GetPath(GetFileName(fileName), path));

public static void WriteFile(string fileName, string path, string content)
{
fileName = GetFileName(fileName);
var genPath = GetFullPath(fileName, path);
var folderOnly = Path.GetDirectoryName(genPath);
if (!Directory.Exists(folderOnly) && folderOnly != null)
Directory.CreateDirectory(folderOnly);
using var writer = new StreamWriter(genPath, false);
writer.WriteLine(content);
AssetDatabase.ImportAsset($"{path}{fileName}.cs");
}
}
}

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 @@ -5,16 +5,16 @@
* MIT License
* https://github.com/LurkingNinja/com.lurking-ninja.input-codegen
*/
using System.IO;
using UnityEditor;
using UnityEngine;

namespace LurkingNinja.Input.Editor
{
using System.IO;
using UnityEditor;
using UnityEngine;

public class InputCodegenSettings : ScriptableObject
{
private const string INPUT_CODEGEN_CONFIG_FOLDER = "Assets/Plugins/LurkingNinja/Editor";
private const string INPUT_CODEGEN_CONFIG_FILE = INPUT_CODEGEN_CONFIG_FOLDER + "/InputCodegenConfig.asset";
private const string _INPUT_CODEGEN_CONFIG_FOLDER = "Assets/Plugins/LurkingNinja/Editor";
private const string _INPUT_CODEGEN_CONFIG_FILE = _INPUT_CODEGEN_CONFIG_FOLDER + "/InputCodegenConfig.asset";

public bool inputCodegenEnabled = true;

Expand Down Expand Up @@ -79,12 +79,12 @@ public struct {1}
private static InputCodegenSettings GenerateConfigFile()
{
if (_config != null) return _config;
_config = AssetDatabase.LoadAssetAtPath<InputCodegenSettings>(INPUT_CODEGEN_CONFIG_FILE);
_config = AssetDatabase.LoadAssetAtPath<InputCodegenSettings>(_INPUT_CODEGEN_CONFIG_FILE);
if (_config != null) return _config;
if (!Directory.Exists(INPUT_CODEGEN_CONFIG_FOLDER))
Directory.CreateDirectory(INPUT_CODEGEN_CONFIG_FOLDER);
if (!Directory.Exists(_INPUT_CODEGEN_CONFIG_FOLDER))
Directory.CreateDirectory(_INPUT_CODEGEN_CONFIG_FOLDER);
_config = CreateInstance<InputCodegenSettings>();
AssetDatabase.CreateAsset(_config, INPUT_CODEGEN_CONFIG_FILE);
AssetDatabase.CreateAsset(_config, _INPUT_CODEGEN_CONFIG_FILE);
return _config;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/***
* Input System Codegen
* Copyright (c) 2022-2024 Lurking Ninja.
*
* MIT License
* https://github.com/LurkingNinja/com.lurking-ninja.input-codegen
*/
namespace LurkingNinja.Input.Editor
{
using System;
using System.Collections.Generic;
using UnityEditor;
using Object = UnityEngine.Object;

// To detect creation and saving an asset. We do not care about moving.
public class OnAssetPostProcessor : AssetPostprocessor
{
private static readonly Dictionary<Type, List<Action<Object, string>>> _CHANGE_CALLBACKS = new();
internal static readonly Dictionary<Type, List<Action<Object, string>>> DELETE_CALLBACKS = new();

private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets,
string[] movedAssets, string[] movedFromAssetPaths)
{
foreach (var path in importedAssets)
{
foreach (var keyValue in _CHANGE_CALLBACKS)
{
var asset = AssetDatabase.LoadAssetAtPath(path, keyValue.Key);
if (asset is null) continue;
foreach (var action in keyValue.Value)
{
action?.Invoke(asset, path);
}
}
}
}

public static void AddListener(Type key,
Action<Object, string> changeCallback, Action<Object, string> deleteCallback)
{
AddChangeListener(key, changeCallback);
AddDeletionListener(key, deleteCallback);
}

public static void RemoveListener(Type key,
Action<Object, string> changeCallback, Action<Object, string> deleteCallback)
{
RemoveChangeListener(key, changeCallback);
RemoveDeletionListener(key, deleteCallback);
}

private static void AddChangeListener(Type key, Action<Object, string> callback)
{
if (!_CHANGE_CALLBACKS.ContainsKey(key)) _CHANGE_CALLBACKS[key] = new List<Action<Object, string>>();
if (_CHANGE_CALLBACKS[key].Contains(callback)) return;
_CHANGE_CALLBACKS[key].Add(callback);
}

private static void RemoveChangeListener(Type key, Action<Object, string> callback)
{
if (!_CHANGE_CALLBACKS.TryGetValue(key, out var changeCallback)) return;
changeCallback.Remove(callback);
}

private static void AddDeletionListener(Type key, Action<Object, string> callback)
{
if (!DELETE_CALLBACKS.ContainsKey(key)) DELETE_CALLBACKS[key] = new List<Action<Object, string>>();
if (DELETE_CALLBACKS[key].Contains(callback)) return;
DELETE_CALLBACKS[key].Add(callback);
}

private static void RemoveDeletionListener(Type key, Action<Object, string> callback)
{
if (!DELETE_CALLBACKS.TryGetValue(key, out var deleteCallback)) return;
deleteCallback.Remove(callback);
}
}

// To detect asset removal.
public class CustomAssetModificationProcessor : AssetModificationProcessor
{
private static AssetDeleteResult OnWillDeleteAsset(string path, RemoveAssetOptions rao)
{
foreach (var keyValue in OnAssetPostProcessor.DELETE_CALLBACKS)
{
var asset = AssetDatabase.LoadAssetAtPath(path, keyValue.Key);
if (asset is null) continue;
foreach (var action in keyValue.Value)
{
action?.Invoke(asset, path);
}
}
return AssetDeleteResult.DidNotDelete;
}
}
}

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 @@ -5,12 +5,11 @@
* MIT License
* https://github.com/LurkingNinja/com.lurking-ninja.input-codegen
*/
using UnityEditor;
#if INPUT_SYSTEM_ENABLED

#if INPUT_SYSTEM_ENABLED && LN_CODEGEN_PRESENT
using UnityEditor;
using System;
using System.Text;
using LurkingNinja.CodeGen.Editor;
using UnityEngine.InputSystem;
using Object = UnityEngine.Object;

Expand Down Expand Up @@ -49,18 +48,18 @@ private static string GenerateFileContent(InputActionAsset inputActionAsset)
var variables = new StringBuilder();
var classes = new StringBuilder();

const string oneDefinition = "\t\t\t{0} = new {0}Actions(asset);";
const string oneVariable = "\t\tpublic {0}Actions {0} {{ get; }}";
const string oneAction = "public InputAction {0} => {2}Map.FindAction(\"{1}\");";
const string oneActionDefinition = "\t\t\tpublic InputAction {0};";
const string oneActionLet = "\t\t\t\t{0} = _actionMap.FindAction(\"{1}\");";
const string ONE_DEFINITION = "\t\t\t{0} = new {0}Actions(asset);";
const string ONE_VARIABLE = "\t\tpublic {0}Actions {0} {{ get; }}";
const string ONE_ACTION = "public InputAction {0} => {2}Map.FindAction(\"{1}\");";
const string ONE_ACTION_DEFINITION = "\t\t\tpublic InputAction {0};";
const string ONE_ACTION_LET = "\t\t\t\t{0} = _actionMap.FindAction(\"{1}\");";

foreach(var actionMap in inputActionAsset.actionMaps)
{
definitions.Append(string.Format(oneDefinition,
definitions.Append(string.Format(ONE_DEFINITION,
/*{0}*/AssetPostProcessorHelper.KeyToCSharp(actionMap.name)));
definitions.Append(Environment.NewLine);
variables.Append(string.Format(oneVariable,
variables.Append(string.Format(ONE_VARIABLE,
/*{0}*/AssetPostProcessorHelper.KeyToCSharp(actionMap.name)));
variables.Append(Environment.NewLine);

Expand All @@ -70,15 +69,15 @@ private static string GenerateFileContent(InputActionAsset inputActionAsset)

foreach(var inputAction in actionMap.actions)
{
actions.Append(string.Format(oneAction,
actions.Append(string.Format(ONE_ACTION,
/*{0}*/AssetPostProcessorHelper.KeyToCSharp(inputAction.name),
/*{1}*/AssetPostProcessorHelper.KeyToCSharpWithoutAt(inputAction.name),
/*{2}*/AssetPostProcessorHelper.KeyToCSharp(actionMap.name)));
actions.Append(Environment.NewLine);
actionsDefinitions.Append(string.Format(oneActionDefinition,
actionsDefinitions.Append(string.Format(ONE_ACTION_DEFINITION,
/*{0}*/AssetPostProcessorHelper.KeyToCSharp(inputAction.name)));
actionsDefinitions.Append(Environment.NewLine);
actionsLets.Append(string.Format(oneActionLet,
actionsLets.Append(string.Format(ONE_ACTION_LET,
/*{0}*/AssetPostProcessorHelper.KeyToCSharp(inputAction.name),
/*{1}*/AssetPostProcessorHelper.KeyToCSharpWithoutAt(inputAction.name)));
actionsLets.Append(Environment.NewLine);
Expand Down Expand Up @@ -106,16 +105,17 @@ private static string GenerateFileContent(InputActionAsset inputActionAsset)
}
}
#else
using UnityEditor.PackageManager;

namespace LurkingNinja.Input.Editor
{
[InitializeOnLoad]
using UnityEditor;
using UnityEditor.PackageManager;

[InitializeOnLoad]
public static class OnAssetPostProcessorInputInstall
{
static OnAssetPostProcessorInputInstall()
{
Client.Add("https://github.com/LurkingNinja/com.lurking-ninja.codegen.git?path=Packages/com.lurking-ninja.codegen");
Client.Add("com.unity.inputsystem");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"name": "com.lurking-ninja.input-codegen",
"rootNamespace": "LurkingNinja.Input",
"references": [
"com.unity.inputsystem",
"com.lurking-ninja.codegen"
"Unity.InputSystem"
],
"includePlatforms": [
"Editor"
Expand All @@ -15,11 +14,6 @@
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [
{
"name": "com.lurkingninja.codegen",
"expression": "",
"define": "LN_CODEGEN_PRESENT"
},
{
"name": "com.unity.inputsystem",
"expression": "",
Expand Down
12 changes: 3 additions & 9 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
{
"dependencies": {
"com.lurking-ninja.codegen": "https://github.com/LurkingNinja/com.lurking-ninja.codegen.git?path=Packages/com.lurking-ninja.codegen",
"com.unity.burst": "1.8.11",
"com.unity.collections": "2.1.4",
"com.unity.ide.rider": "3.0.27",
"com.unity.inputsystem": "1.8.0-pre.2",
"com.unity.localization": "1.4.5",
"com.unity.mathematics": "1.3.1",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.7.6",
"com.unity.ide.rider": "3.0.34",
"com.unity.inputsystem": "1.11.2",
"com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.9",
"com.unity.ugui": "1.0.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
Expand Down
Loading

0 comments on commit 1fa01a4

Please sign in to comment.