mirror of
https://github.com/Siccity/xNode.git
synced 2026-03-26 22:49:02 +08:00
add known port types to variable enum; added variablepopup
This commit is contained in:
parent
ca86007745
commit
c10103eabb
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Collections.Generic;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@ -136,5 +137,29 @@ namespace XNodeEditor {
|
|||||||
GUI.DrawTexture(rect, NodeEditorResources.dot);
|
GUI.DrawTexture(rect, NodeEditorResources.dot);
|
||||||
GUI.color = col;
|
GUI.color = col;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Make a popup with all variable ids.</summary>
|
||||||
|
public static string VariablePopup(XNode.NodeGraph graph, string variableId, params GUILayoutOption[] options)
|
||||||
|
{
|
||||||
|
if (graph == null) return variableId;
|
||||||
|
|
||||||
|
List<string> variablesStrings = new List<string>();
|
||||||
|
|
||||||
|
foreach (var item in graph.variables)
|
||||||
|
variablesStrings.Add(item.id);
|
||||||
|
|
||||||
|
int originalIdx = variablesStrings.IndexOf(variableId);
|
||||||
|
int newIdx = EditorGUILayout.Popup(originalIdx, variablesStrings.ToArray(), options);
|
||||||
|
|
||||||
|
if (originalIdx == -1 && newIdx == -1)
|
||||||
|
{
|
||||||
|
EditorGUILayout.HelpBox("Looks like the variable that used to be here, doesn't exist anymore. \n id:" + variableId, MessageType.Error);
|
||||||
|
return variableId;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newIdx >= variablesStrings.Count)
|
||||||
|
return variableId;
|
||||||
|
return variablesStrings[newIdx];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -13,13 +13,22 @@ namespace XNodeEditor
|
|||||||
[CustomEditor(typeof(XNode.NodeGraph), true)]
|
[CustomEditor(typeof(XNode.NodeGraph), true)]
|
||||||
public class NodeGraphInspector : Editor
|
public class NodeGraphInspector : Editor
|
||||||
{
|
{
|
||||||
SerializedProperty nodesProp;
|
|
||||||
SerializedProperty variablesProp;
|
SerializedProperty variablesProp;
|
||||||
|
|
||||||
|
List<Type> _knownTypes = new List<Type>();
|
||||||
void OnEnable()
|
void OnEnable()
|
||||||
{
|
{
|
||||||
nodesProp = serializedObject.FindProperty("nodes");
|
|
||||||
variablesProp = serializedObject.FindProperty("variables");
|
variablesProp = serializedObject.FindProperty("variables");
|
||||||
|
NodeGraph graph = target as NodeGraph;
|
||||||
|
|
||||||
|
foreach (var node in graph.nodes)
|
||||||
|
{
|
||||||
|
foreach (var port in node.Ports)
|
||||||
|
{
|
||||||
|
if (!_knownTypes.Contains(port.ValueType))
|
||||||
|
_knownTypes.Add(port.ValueType);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnInspectorGUI()
|
public override void OnInspectorGUI()
|
||||||
@ -74,20 +83,12 @@ namespace XNodeEditor
|
|||||||
additionalTypes.Add(typeof(string).AssemblyQualifiedName);
|
additionalTypes.Add(typeof(string).AssemblyQualifiedName);
|
||||||
additionalTypes.Add(typeof(Vector3).AssemblyQualifiedName);
|
additionalTypes.Add(typeof(Vector3).AssemblyQualifiedName);
|
||||||
|
|
||||||
/*
|
foreach (var type in _knownTypes)
|
||||||
Assembly asm = typeof(Vector3).Assembly;
|
|
||||||
foreach (var colorPair in NodeEditorPreferences.typeColors)
|
|
||||||
{
|
{
|
||||||
var type = asm.GetType(colorPair.Key, false);
|
|
||||||
Debug.Log(colorPair.Key + " " + type);
|
|
||||||
|
|
||||||
if (type == null)
|
|
||||||
continue;
|
|
||||||
if (additionalTypes.Contains(type.AssemblyQualifiedName))
|
if (additionalTypes.Contains(type.AssemblyQualifiedName))
|
||||||
continue;
|
continue;
|
||||||
additionalTypes.Add(colorPair.Key);
|
additionalTypes.Add(type.AssemblyQualifiedName);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
foreach (var addType in additionalTypes)
|
foreach (var addType in additionalTypes)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user