-
Notifications
You must be signed in to change notification settings - Fork 425
Expand file tree
/
Copy pathNodeGraphProcessorMenuItems.cs
More file actions
82 lines (75 loc) · 2.12 KB
/
NodeGraphProcessorMenuItems.cs
File metadata and controls
82 lines (75 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Reflection;
using UnityEditor.ProjectWindowCallback;
namespace GraphProcessor
{
/// <summary>
/// To add the menu items that create node C# script templates files you can inherit from this class and use it's API combined with [MenuItem]
/// See GraphProcessorMenuItems.cs in examples for implementation details
/// </summary>
public class NodeGraphProcessorMenuItems
{
static readonly string nodeBaseName = "Node.cs";
static readonly string nodeViewBaseName = "NodeView.cs";
static string _nodeTemplatePath = null;
static string nodeTemplatePath
{
get
{
if (_nodeTemplatePath == null)
{
var template = Resources.Load<TextAsset>("NodeTemplate.cs");
_nodeTemplatePath = AssetDatabase.GetAssetPath(template);
}
return _nodeTemplatePath;
}
}
static string _nodeViewTemplatePath;
static string nodeViewTemplatePath
{
get
{
if (_nodeViewTemplatePath == null)
{
var template = Resources.Load<TextAsset>("NodeViewTemplate.cs");
_nodeViewTemplatePath = AssetDatabase.GetAssetPath(template);
}
return _nodeViewTemplatePath;
}
}
protected static class MenuItemPosition
{
public const int afterCreateScript = 81;
public const int beforeCreateScript = 79;
}
protected static string GetCurrentProjectWindowPath()
{
var path = "";
var obj = Selection.activeObject;
if (obj == null)
return null;
else
path = AssetDatabase.GetAssetPath(obj.GetInstanceID());
if (path.Length > 0)
{
if (Directory.Exists(path))
return path;
else
return new FileInfo(path).Directory.FullName;
}
return null;
}
protected static void CreateDefaultNodeCSharpScript()
{
ProjectWindowUtil.CreateScriptAssetFromTemplateFile(nodeTemplatePath, nodeBaseName);
}
protected static void CreateDefaultNodeViewCSharpScript()
{
ProjectWindowUtil.CreateScriptAssetFromTemplateFile(nodeViewTemplatePath, nodeViewBaseName);
}
}
}