【a】可视化剧本编辑器 10.StoryEditor
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
using XNode;
|
||||
|
||||
namespace Stary.Evo.StoryEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// 剧本自然段
|
||||
/// </summary>
|
||||
[Serializable, CreateNodeMenu("创建剧本自然段", order = 5)]
|
||||
public class ScriptParagraphNode : FlowNode
|
||||
{
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// (仅供辨识,不起实际作用)
|
||||
/// </summary>
|
||||
[BoxGroup("Info", order:10, showLabel:false)]
|
||||
[LabelText("名称"),LabelWidth(30)]
|
||||
public string displayName;
|
||||
|
||||
/// <summary>
|
||||
/// 字幕
|
||||
/// </summary>
|
||||
[BoxGroup("Info")]
|
||||
[LabelText("字幕"),LabelWidth(30)]
|
||||
public Sprite caption;
|
||||
/// <summary>
|
||||
/// 语音
|
||||
/// </summary>
|
||||
[BoxGroup("Info")]
|
||||
[LabelText("音频"),LabelWidth(30)]
|
||||
public AudioClip audio;
|
||||
|
||||
/// <summary>
|
||||
/// 创建新的剧本段落节点
|
||||
/// </summary>
|
||||
/// <param name="graph">所在的块</param>
|
||||
/// <param name="name">节点名称</param>
|
||||
/// <param name="position">节点位置</param>
|
||||
/// <param name="prePorts">节点前部连接</param>
|
||||
/// <param name="nextPorts">节点后部连接</param>
|
||||
/// <param name="caption">字幕</param>
|
||||
/// <param name="audio">音频</param>
|
||||
public static ScriptParagraphNode Create(NodeGraph graph, string name = null, Vector2 position = default, List<NodePort> prePorts = null, List<NodePort> nextPorts = null, Sprite caption = null, AudioClip audio = null)
|
||||
{
|
||||
// 创建节点
|
||||
var node = Create<ScriptParagraphNode>(graph,name,position, prePorts, nextPorts);
|
||||
if (node == null)
|
||||
return null;
|
||||
|
||||
// 设置变量
|
||||
node.caption = caption;
|
||||
node.audio = audio;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
UpdateName();
|
||||
}
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
if (graph == null)
|
||||
{
|
||||
Debug.LogWarning($"项目中存在幽灵节点:{name}");
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateName();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新名称
|
||||
/// </summary>
|
||||
private void UpdateName()
|
||||
{
|
||||
if (string.IsNullOrEmpty(displayName))
|
||||
{
|
||||
displayName = graph.name + "_para";
|
||||
}
|
||||
|
||||
name = displayName;
|
||||
}
|
||||
|
||||
public new async UniTask<ScriptParagraphNodeData> Export()
|
||||
{
|
||||
var node = new ScriptParagraphNodeData(await base.Export());
|
||||
var sGraph = (ScriptGraph)graph;
|
||||
|
||||
// 记录音频资源地址
|
||||
if (audio)
|
||||
node.audioPath = await sGraph.Loader.Save(audio,sGraph.packageID);
|
||||
|
||||
// 记录字幕资源地址
|
||||
if (caption)
|
||||
node.captionPath = await sGraph.Loader.Save(caption,sGraph.packageID);
|
||||
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user