Skip to content

Commit ce1d171

Browse files
Release/0.9.5 (#123)
* Began looking into the prospect of supporting transitions with params * Transitions with params are functional. I want to explore explicit connections based on typed transition types * Working on transitions with params * Added support for switching models on SubStateMachineStates * I think i've landed on a good implementation. Implemented type safe transitions. * Changed the HandleDeleteSelection method in StateGraphView to remove all selected items but the data is not removed from the StateMachineModel so this still needs some work * Fix for deletion of selected items from context menu * Added selection deletion from context menu * Abstracted validation * brough the NodeGraphStateManager updates in * Scheduler * Updated validation * Making progress. Issue with adding transitin data for netry node to Test node at the moment * Fix for type comparison to creat transitions and fix for executing enter methods * Updated the package.json to include tests * Updated change log and package manifest to include additional notes and test assemblies * Updated the readme * Updated the Readme * Update README.md * Added a counter with target state * Updated chage log * Simplified the uss by importing shared styles * uss is now simplified * Removed a preprocessor * Updated the readme * Updated the Readme to include migration steps * Changed the naming process of entry ports * Further refactoring of method names * Added additional icons * Added support for LateUpdate in States * Added a cache for event info obtained via reflection to reduce the use of reflection * Update README.md * Added a migration tool for upgrading to 0.9.0-beta * Added back the obsolete methods to improve migration * Added additional obsolete methods back in to support migration * Updated the changelog * updated package.json * Added a migration step to transition validation * . * Added a method to migrate node ports * Added support for migrating all state machine models * . * . * . * added support for migrating generic states * Finalised migration tool * Updated migration tools
1 parent 257fd29 commit ce1d171

155 files changed

Lines changed: 3093 additions & 1175 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.idea/indexLayout.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/material_theme_project_new.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/projectSettingsUpdater.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
# Change Log
22

3+
# [0.9.4-beta] - Dec 22, 2024
4+
- Added a method to migrate all state machine model assets
5+
6+
# [0.9.3-beta] - Dec 22, 2024
7+
- Added a migration step to fix transitions to OnEnterState methods
8+
9+
# [0.9.2-beta] - Dec 22, 2024
10+
- Added a migration step to add missing using statements
11+
12+
# [0.9.1-beta] - Dec 22, 2024
13+
- Added a migration tool to upgrade to 0.9.1-beta
14+
- Added obsolete methods back in and marked as obsolete to allow for a smoother migration to the new version
15+
- Added support for LateUpdate in states
16+
- Added a cache for event info obtained via reflection to reduce the runtime overhead of reflection
17+
18+
# [0.9.0-beta] - Sept 20, 2024
19+
- BREAKING - State enter methods now require an [Enter] attribute.
20+
- States now support typed transitions
21+
- Example ```[Transition] public event Action<int> OnTransitionWithInt```
22+
- Example ```[Enter] public void OnEnterWithInt(int value){}```
23+
- Abstracted validation methods to a separate class
24+
- Added a CounterWithTargetState.
25+
- Simplified the uss files used to style the basic states
26+
27+
# [0.8.5-beta] - Sept 17, 2024
28+
- Fix for deleting a selection via the context menu
29+
330
## [0.8.4-beta] - Sept 11, 2024
431
- SharedData.ClearData is now Obsolete and will be removed in a future release. Use SharedData.ClearAllData instead.
532
- Added SharedData.ClearAllData method to clear all shared data.
@@ -67,7 +94,7 @@ Added support for switching SubStateMachine models at runtime
6794

6895
## [0.5.1-beta] - Jul 18, 2024
6996
- Added a protected setter to the Model accessor of BaseSubStateMachineState
70-
- This will allow for derived states to switch the model in the OnAwakeState
97+
- This will allow for derived states to switch the model in the OnAwake
7198

7299
## [0.5.0-beta] - Jul 17, 2024
73100
- Removal of the StateMachineController.Model setter.

Editor/Migration.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System.Text.RegularExpressions;
2+
3+
namespace Nonatomic.VSM2.Editor.Migration
4+
{
5+
public static class MethodAttributeInserter
6+
{
7+
/*
8+
* Explanation of this pattern (in Multiline mode):
9+
*
10+
* ^(?<indent>[^\S\r\n]*)
11+
* - '^[^\S\r\n]*' means at the start of a line (^), capture any whitespace
12+
* that is *not* a newline or carriage return. (i.e. spaces or tabs)
13+
*
14+
* (?<body>(\[[^\]]*\]\s*)*(public|protected|private|internal)?\s*
15+
* (virtual|abstract|override|static|sealed|async|\s)*[^\s]+\s+
16+
* (<METHOD_NAME_HERE>)\s*\([^)]*\)\s*\{)
17+
* - Captures the rest of the line (any existing attributes, modifiers, method name, etc.)
18+
* - <METHOD_NAME_HERE> is a placeholder that we'll replace with the actual method name.
19+
*
20+
* RegexOptions.Multiline => '^' and '$' match the start/end of *each* line in the input.
21+
*/
22+
private static readonly Regex _methodRegexTemplate = new Regex(
23+
@"^(?<indent>[^\S\r\n]*)(?<body>(\[[^\]]*\]\s*)*(public|protected|private|internal)?\s*(virtual|abstract|override|static|sealed|async|\s)*[^\s]+\s+(<METHOD_NAME_HERE>)\s*\([^)]*\)\s*\{)",
24+
RegexOptions.Compiled | RegexOptions.Multiline
25+
);
26+
27+
/// <summary>
28+
/// Inserts <paramref name="attributeToInsert"/> above each matching method (by exact name),
29+
/// preserving indentation and ensuring no duplicate attributes or extra blank lines.
30+
/// </summary>
31+
public static string InsertAttributeAboveMethod(
32+
string sourceCode,
33+
string methodName,
34+
string attributeToInsert)
35+
{
36+
if (string.IsNullOrEmpty(sourceCode)) return sourceCode;
37+
if (string.IsNullOrEmpty(methodName)) return sourceCode;
38+
if (string.IsNullOrEmpty(attributeToInsert)) return sourceCode;
39+
40+
// Build a new regex by substituting the actual method name
41+
var pattern = _methodRegexTemplate
42+
.ToString()
43+
.Replace("<METHOD_NAME_HERE>", Regex.Escape(methodName));
44+
45+
var methodRegex = new Regex(pattern, RegexOptions.Compiled | RegexOptions.Multiline);
46+
47+
// Perform the replacement
48+
return methodRegex.Replace(sourceCode, match =>
49+
{
50+
var indent = match.Groups["indent"].Value; // Only spaces or tabs
51+
var body = match.Groups["body"].Value;
52+
53+
// If we already have the attribute in the body, don't add it again
54+
if (body.Contains(attributeToInsert))
55+
{
56+
return match.Value;
57+
}
58+
59+
/*
60+
* We rebuild:
61+
* <indent>[Attribute]
62+
* <indent>public void OnEnter() {
63+
* ...
64+
* }
65+
*/
66+
return $"{indent}{attributeToInsert}\n{indent}{body}";
67+
});
68+
}
69+
}
70+
}

Editor/Migration/MethodAttributeInserter.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Migration/MigrationUtils.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using UnityEngine;
2+
using UnityEditor;
3+
using System;
4+
using System.IO;
5+
6+
public static class MigrationUtils
7+
{
8+
public static string GetPathForType(Type type)
9+
{
10+
var guids = AssetDatabase.FindAssets("t:MonoScript");
11+
12+
// Figure out the "base" name if this is an open generic type definition
13+
var isOpenGeneric = type.IsGenericTypeDefinition;
14+
var strippedBaseName = isOpenGeneric ? StripBacktick(type.Name) : null;
15+
16+
foreach (var guid in guids)
17+
{
18+
var path = AssetDatabase.GUIDToAssetPath(guid);
19+
20+
// 1. If we see an open generic, fallback to checking filename
21+
if (isOpenGeneric && !string.IsNullOrEmpty(strippedBaseName))
22+
{
23+
var fileName = Path.GetFileName(path);
24+
if (fileName.Equals(strippedBaseName + ".cs", StringComparison.OrdinalIgnoreCase))
25+
{
26+
var fullPath = Application.dataPath.Replace("Assets", "") + path;
27+
if (File.Exists(fullPath))
28+
{
29+
return fullPath;
30+
}
31+
}
32+
}
33+
34+
// 2. Otherwise, do the usual closed-generic / normal type check
35+
var monoScript = AssetDatabase.LoadAssetAtPath<MonoScript>(path);
36+
if (monoScript == null) continue;
37+
38+
var scriptClass = monoScript.GetClass();
39+
if (scriptClass == null) continue;
40+
41+
if (IsSameOrOpenGenericEquivalent(scriptClass, type))
42+
{
43+
var fullPath = Application.dataPath.Replace("Assets", "") + path;
44+
if (File.Exists(fullPath))
45+
{
46+
return fullPath;
47+
}
48+
}
49+
}
50+
51+
Debug.LogWarning($"Could not find a .cs file for type: {type.FullName}");
52+
return null;
53+
}
54+
55+
private static bool IsSameOrOpenGenericEquivalent(Type scriptClass, Type targetType)
56+
{
57+
if (scriptClass.IsGenericType && targetType.IsGenericType)
58+
{
59+
return scriptClass.GetGenericTypeDefinition() == targetType.GetGenericTypeDefinition();
60+
}
61+
62+
return scriptClass == targetType;
63+
}
64+
65+
private static string StripBacktick(string typeName)
66+
{
67+
// e.g. "RoundListState`1" => "RoundListState"
68+
var index = typeName.IndexOf('`');
69+
return (index >= 0)
70+
? typeName.Substring(0, index)
71+
: typeName;
72+
}
73+
}

0 commit comments

Comments
 (0)