Gameplay Ingredients是一组用于 Unity 游戏的运行时和编辑器工具:一组脚本的集合,可在制作游戏和原型时简化简单的任务。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

81 行
1.6 KiB

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEditor;
using UnityEngine.Assertions;
using UnityEngine.Experimental.UIElements;
using UnityEditor.Experimental.UIElements;
using UnityEditor.Experimental.UIElements.GraphView;
namespace GraphProcessor
{
[System.Serializable]
public abstract class BaseGraphWindow : EditorWindow
{
protected VisualElement rootView;
protected BaseGraphView graphView;
[SerializeField]
protected BaseGraph graph;
public bool isGraphLoaded
{
get { return graphView != null && graphView.graph != null; }
}
protected void OnEnable()
{
InitializeRootView();
if (graph != null)
InitializeGraph(graph);
}
protected void OnDisable()
{
if (graph != null)
graphView.SaveGraphToDisk();
}
void InitializeRootView()
{
rootView = this.GetRootVisualContainer();
rootView.name = "graphRootView";
rootView.AddStyleSheetPath("GraphProcessorStyles/BaseGraphView");
}
public void InitializeGraph(BaseGraph graph)
{
this.graph = graph;
if (graphView != null)
rootView.Remove(graphView);
//Initialize will provide the BaseGraphView
Initialize(graph);
graphView = rootView.Children().FirstOrDefault(e => e is BaseGraphView) as BaseGraphView;
if (graphView == null)
{
Debug.LogError("GraphView has not been added to the BaseGraph root view !");
return ;
}
graphView.Initialize(graph);
}
public virtual void OnGraphDeleted()
{
if (graph != null)
rootView.Remove(graphView);
graphView = null;
}
protected abstract void Initialize(BaseGraph graph);
}
}