195 lines
6.0 KiB
C#
195 lines
6.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
namespace Framework.ProcessMode
|
|
{
|
|
/// <summary>
|
|
/// 动作类型枚举
|
|
/// </summary>
|
|
public enum ProcessActionType
|
|
{
|
|
默认, // 默认类型
|
|
选择题, // 判断题类型
|
|
多选题 // 多选题类型
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断题配置
|
|
/// </summary>
|
|
public class JudgmentQuestionConfig
|
|
{
|
|
public string Question { get; set; } // 题目
|
|
public string CorrectAnswer { get; set; } // 正确答案
|
|
}
|
|
|
|
/// <summary>
|
|
/// 多选题配置
|
|
/// </summary>
|
|
public class MultipleChoiceConfig
|
|
{
|
|
public string Question { get; set; } // 题目
|
|
public List<string> Options { get; set; } // 选项列表
|
|
public List<string> CorrectAnswers { get; set; } // 正确答案列表(可以多选)
|
|
|
|
public MultipleChoiceConfig()
|
|
{
|
|
Options = new List<string>();
|
|
CorrectAnswers = new List<string>();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 流程步骤描述类
|
|
/// </summary>
|
|
public enum ProcessTargetType
|
|
{
|
|
Model, // 目标类型:模型
|
|
Event // 目标类型:事件
|
|
}
|
|
|
|
public class ProcessStepDescription
|
|
{
|
|
/// <summary>
|
|
/// 动作类型
|
|
/// </summary>
|
|
public ProcessActionType ActionType { get; set; }
|
|
|
|
/// <summary>
|
|
/// 判断题配置列表
|
|
/// </summary>
|
|
public List<JudgmentQuestionConfig> JudgmentQuestions { get; set; }
|
|
|
|
/// <summary>
|
|
/// 多选题配置列表
|
|
/// </summary>
|
|
public List<MultipleChoiceConfig> MultipleChoiceQuestions { get; set; }
|
|
|
|
/// <summary>
|
|
/// 动作标题,用于对动作的简单描述
|
|
/// </summary>
|
|
public string Title { get; set; }
|
|
|
|
/// <summary>
|
|
/// 目标对象列表,包含目标的名称和类型
|
|
/// </summary>
|
|
public List<(string ObjectName, ProcessTargetType Type)> TargetObjects { get; set; }
|
|
|
|
/// <summary>
|
|
/// 动作执行逻辑
|
|
/// </summary>
|
|
public Action Action { get; set; }
|
|
|
|
/// <summary>
|
|
/// 动作的详细描述信息
|
|
/// </summary>
|
|
public string Description { get; set; }
|
|
|
|
/// <summary>
|
|
/// 是否需要按顺序点击目标对象
|
|
/// </summary>
|
|
public bool IsSequential { get; set; }
|
|
|
|
/// <summary>
|
|
/// 已点击的目标对象集合
|
|
/// </summary>
|
|
public HashSet<string> ClickedObjects { get; set; }
|
|
|
|
/// <summary>
|
|
/// 当前正在处理的目标对象索引
|
|
/// </summary>
|
|
public int CurrentObjectIndex { get; set; }
|
|
|
|
/// <summary>
|
|
/// 是否已显示过反馈
|
|
/// </summary>
|
|
public bool FeedbackDisplayed { get; set; }
|
|
|
|
/// <summary>
|
|
/// 当前动作所属步骤的描述
|
|
/// </summary>
|
|
public string StepDescription { get; set; }
|
|
|
|
/// <summary>
|
|
/// 动作评分
|
|
/// </summary>
|
|
public float Score { get; set; }
|
|
|
|
public string SceneName { get; set; } // 场景名称
|
|
public bool RequiresSceneSwitch { get; set; } // 是否需要切换场景
|
|
/// <summary>
|
|
/// 目标物体及其事件的映射
|
|
/// </summary>
|
|
public Dictionary<string, Action> TargetObjectEvents { get; private set; }
|
|
|
|
/// <summary>
|
|
/// 动作编号
|
|
/// </summary>
|
|
public int ProcessStepIndex { get; set; }
|
|
|
|
/// <summary>
|
|
/// 是否需要正确完成该动作
|
|
/// </summary>
|
|
public bool RequireCorrectCompletion { get; set; }
|
|
|
|
/// <summary>
|
|
/// 构造函数,初始化动作描述
|
|
/// </summary>
|
|
/// <param name="targetObjects">目标对象列表</param>
|
|
/// <param name="action">动作逻辑</param>
|
|
/// <param name="description">动作详细描述</param>
|
|
/// <param name="isSequential">是否按顺序点击</param>
|
|
/// <param name="stepDescription">所属步骤描述</param>
|
|
/// <param name="score">动作评分</param>
|
|
/// <param name="title">动作标题</param>
|
|
public ProcessStepDescription(List<(string ObjectName, ProcessTargetType Type)> targetObjects, Action action, string description, bool isSequential, string stepDescription, float score = 0, string title = "新动作")
|
|
{
|
|
Title = title;
|
|
TargetObjects = targetObjects ?? new List<(string, ProcessTargetType)>();
|
|
Action = action;
|
|
Description = description;
|
|
IsSequential = isSequential;
|
|
ClickedObjects = new HashSet<string>();
|
|
CurrentObjectIndex = 0;
|
|
FeedbackDisplayed = false;
|
|
StepDescription = stepDescription;
|
|
Score = score;
|
|
RequireCorrectCompletion = true;
|
|
TargetObjectEvents = new Dictionary<string, Action>();
|
|
|
|
// 初始化新增字段
|
|
ActionType = ProcessActionType.默认;
|
|
JudgmentQuestions = new List<JudgmentQuestionConfig>();
|
|
MultipleChoiceQuestions = new List<MultipleChoiceConfig>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 绑定目标物体的事件
|
|
/// </summary>
|
|
public void BindEventToObject(string objectName, Action customEvent)
|
|
{
|
|
if (!TargetObjectEvents.ContainsKey(objectName))
|
|
{
|
|
TargetObjectEvents.Add(objectName,customEvent);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 执行目标物体的事件
|
|
/// </summary>
|
|
public void ExecuteObjectEvent(string objectName)
|
|
{
|
|
if (TargetObjectEvents.TryGetValue(objectName, out var customEvent))
|
|
{
|
|
customEvent.Invoke();
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning($"目标物体 {objectName} 没有绑定事件!");
|
|
}
|
|
}
|
|
}
|
|
}
|