Skip to content

Commit

Permalink
- Added integrated Examples (Samples~). To use: Copy contents from Sa…
Browse files Browse the repository at this point in the history
…mples~ folder into you Assets project.

- Added ability to add new window/ graph types to the graph window lookup
  • Loading branch information
Doppelkeks committed Apr 24, 2023
1 parent c0a292f commit d0ea7bd
Show file tree
Hide file tree
Showing 16 changed files with 147 additions and 11 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.3.3] - 2023-04-18
### Added
- Added more stable method to retrieve all attributes for a serialized property. [#14](https://github.com/Gentlymad-Studios/NewGraph/issues/14)

### Fixed
- Fixed wrong window size for all SearchWindows [#10](https://github.com/Gentlymad-Studios/NewGraph/issues/10)
- wrapped UnityEditor in #if UNITY_EDITOR preprocessor directives in all graph models

## [0.3.4] - 2023-04-24
### Added
- Added integrated Examples (Samples~). To use: Copy contents from Samples~ folder into you Assets project.
- Added ability to add new window/ graph types to the graph window lookup

2 changes: 1 addition & 1 deletion Documentation~
19 changes: 13 additions & 6 deletions Editor/Views/GraphWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class GraphWindow : EditorWindow {
{ typeof(MonoGraphModel), typeof(MonoInspectorController) },
};

private static readonly Dictionary<Type, Func<string, IGraphModelData>> lastGraphCreationLookup = new Dictionary<Type, Func<string, IGraphModelData>>() {
private static readonly Dictionary<Type, Func<string, IGraphModelData>> lastGraphCreationStrategies = new Dictionary<Type, Func<string, IGraphModelData>>() {
{ typeof(ScriptableGraphModel), ScriptableGraphModel.GetGraphData },
{ typeof(MonoGraphModel), MonoGraphModel.GetGraphData },
};
Expand Down Expand Up @@ -57,12 +57,19 @@ private static Type CurrentWindowType {
[NonSerialized]
private static bool loadRequested = false;

[MenuItem(menuItemBase + nameof(GraphWindow))]
private static void InitializeScriptableWindow() {
//[MenuItem(menuItemBase + nameof(GraphWindow))]
/*private static void InitializeScriptableWindow() {
InitializeWindowBase(typeof(ScriptableGraphModel));
}*/

public static void AddWindowType(Type windowType, Type inspectorControllerType, Func<string, IGraphModelData> lastGraphCreationStrategy) {
if (!inspectorControllerLookup.ContainsKey(windowType)) {
inspectorControllerLookup.Add(windowType, inspectorControllerType);
lastGraphCreationStrategies.Add(windowType, lastGraphCreationStrategy);
}
}
private static void InitializeWindowBase(Type windowType) {

public static void InitializeWindowBase(Type windowType) {
if (window != null && CurrentWindowType != windowType) {
window.Close();
}
Expand Down Expand Up @@ -135,7 +142,7 @@ public static void LoadGraph(IGraphModelData graph =null) {
} else {
LastGraphInfo lastGraphInfo = LastOpenedGraphInfo;
if (lastGraphInfo != null) {
graph = lastGraphCreationLookup[lastGraphInfo.graphType](lastGraphInfo.GUID);
graph = lastGraphCreationStrategies[lastGraphInfo.graphType](lastGraphInfo.GUID);
}
}

Expand Down
6 changes: 4 additions & 2 deletions Models/MonoGraphModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public class MonoGraphModel : MonoBehaviour, IGraphModelData {

#if UNITY_EDITOR
private const string lastOpenedMonoGraphPrefsKey = nameof(NewGraph) + "." + nameof(lastOpenedMonoGraphPrefsKey);

public List<NodeModel> UtilityNodes => baseModel.utilityNodes;

public SerializedObject SerializedGraphData {
get {
if (baseModel.serializedGraphData == null) {
Expand Down Expand Up @@ -97,13 +99,13 @@ private int CreateID() {
return id;
}

private void OnValidate() {
protected virtual void OnValidate() {
CreateID();
}

public static IGraphModelData GetGraphData(string GUID) {
if (!string.IsNullOrEmpty(GUID)) {
MonoGraphModel[] graphModels = UnityEngine.Object.FindObjectsByType<MonoGraphModel>(FindObjectsInactive.Include, FindObjectsSortMode.None);
MonoGraphModel[] graphModels = FindObjectsByType<MonoGraphModel>(FindObjectsInactive.Include, FindObjectsSortMode.None);
foreach (var gm in graphModels) {
if (gm.GUID == GUID) {
return gm;
Expand Down
7 changes: 7 additions & 0 deletions Samples~/CustomMonoGraphModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace NewGraph.Samples {
public class CustomMonoGraphModel : MonoGraphModel {
protected override void OnValidate() {
base.OnValidate();
}
}
}
11 changes: 11 additions & 0 deletions Samples~/CustomMonoGraphModel.cs.meta

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

8 changes: 8 additions & 0 deletions Samples~/Editor.meta

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

8 changes: 8 additions & 0 deletions Samples~/Editor/CustomMonoGraphModelEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using UnityEditor;

namespace NewGraph.Samples {
[CustomEditor(typeof(CustomMonoGraphModel))]
public class CustomMonoGraphModelEditor : MonoGraphModelEditor {

}
}
11 changes: 11 additions & 0 deletions Samples~/Editor/CustomMonoGraphModelEditor.cs.meta

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

16 changes: 16 additions & 0 deletions Samples~/Editor/CustomMonoGraphModelInitializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using UnityEditor;

namespace NewGraph.Samples {
public class CustomMonoGraphModelInitializer {

[InitializeOnLoadMethod]
private static void AddWindowType() {
GraphWindow.AddWindowType(typeof(CustomMonoGraphModel), typeof(MonoInspectorController), MonoGraphModel.GetGraphData);
}

[MenuItem(GraphSettings.menuItemBase + "CustomWindow")]
private static void AddMenu() {
GraphWindow.InitializeWindowBase(typeof(CustomMonoGraphModel));
}
}
}
11 changes: 11 additions & 0 deletions Samples~/Editor/CustomMonoGraphModelInitializer.cs.meta

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

20 changes: 20 additions & 0 deletions Samples~/Editor/Samples.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "Samples.Editor",
"rootNamespace": "",
"references": [
"GUID:7a19ff388de17fe459f8d1303f265e19",
"GUID:8cb24aa76bfc1e0478428cd510709af1",
"GUID:f5337683be0c9ed49824f4d1e7862f29"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions Samples~/Editor/Samples.Editor.asmdef.meta

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

16 changes: 16 additions & 0 deletions Samples~/Samples.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "Samples",
"rootNamespace": "",
"references": [
"GUID:f5337683be0c9ed49824f4d1e7862f29"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions Samples~/Samples.asmdef.meta

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.gentlymad.newgraph",
"version": "0.3.3",
"version": "0.3.4",
"displayName": "NewGraph",
"description": "A general data oriented node graph solution. This is build upon the idea to visualize complex data structures as graph networks without having to modify already established data classes, except adding [Node], [Port] and [SerializeReference] attributes to call classes that should show in the Graph View.",
"unity": "2022.2",
Expand Down

0 comments on commit d0ea7bd

Please sign in to comment.