Skip to content

ActionModel

muxigame edited this page Nov 24, 2021 · 1 revision

活动模型 Action Model

$\textcolor{RedOrange}{GalForUnity.Model.ActionModel:MonoBehavior}$

GalForUnity.Model.ActionModel是剧情流结束后要执行的操作,它由PlotModel管理,继承自MonoBehavior

功能

GalForUnity.Model.ActionModel:结束活动模型是1.0r更新的一个非常重要的功能,他允许用户定义剧情结束后进行的操作

正常情况下,当您为一个对象附加剧情模型,他只会附加剧情要求和剧情流,结束活动模型需要手动附加和引用

字段

**活动模型类型(Model.ActionModel.ActionModelType actionModelType):**剧情的实体,装载着剧情内容,如对话,动作,配音等等,剧情模型会将剧情流与剧情要求绑定,当对应的剧情流满足要求后,对应的剧情流会开始执行。

**目标场景(Model.Scene.SceneModel directionSceneModel):**这里的场景要求是指剧情结束之后要跳转的场景,仅当actionModelType的值为ActionModelType.GotoScene时在Inspector可见

**目标剧情(Model.Plot.PlotModel directionPlotModel):**这里的剧情要求是指剧情结束之后要跳转的剧情,仅当actionModelType的值为ActionModelType.JumpPlot时在Inspector可见

**角色数值(Model.RoleData roleData):**这里的角色数值是指剧情结束之后要变更的角色数值,并不是变更到目标数值,而是在当前数值的基础上加减,仅当actionModelType的值为ActionModelType.GrowUp时在Inspector可见

UnityEvent<PlotModel,SceneModel> customEvent:用户自定义的带参事件,仅当actionModelType的值为ActionModelType.Custom时在Inspector可见

UnityEvent customEventNoParam:用户自定义的带参事件,仅当actionModelType的值为ActionModelType.Custom时在Inspector可见

方法

**DoAction(PlotModel plotModel,SceneModel sceneModel):**执行ActionModel

**void DoAction(PlotModel plotModel):**执行当前活动模型

**void GotoScene() :**前往指定场景

**void GrowUp(RoleData otherRoleData) :**变更主角数值

**void JumpPlot([NotNull] ref PlotModel plotModel):**跳转指定剧情

**ExecuteCustom([NotNull] PlotModel plotModel,[NotNull] SceneModel sceneModel):**执行用户的自定义方法

源代码

using System;
using GalForUnity.Attribute;
using GalForUnity.Model.Plot;
using GalForUnity.Model.Scene;
using GalForUnity.System;
using JetBrains.Annotations;
using UnityEngine;
using UnityEngine.Events;

namespace GalForUnity.Model{
    /// <summary>
    /// ActionModel游戏中剧情流结束后的活动类,负责各种游戏逻辑的跳转和调用
    /// </summary>
    // ReSharper disable once ClassWithVirtualMembersNeverInherited.Global
    public class ActionModel : MonoBehaviour
    {
        public enum ActionModelType{
            [Rename("不处理")]
            None,
            [Rename("前往场景")]
            GotoScene,
            [Rename("跳转剧情")]
            JumpPlot,
            [Rename("变更数值")]
            GrowUp,
            [Rename("自定义")]
            Custom,
        }
        [Rename("执行的活动类型")]
        public ActionModelType actionModelType = ActionModelType.None;
        [RenameInEditor("目标场景")]
        public SceneModel directionSceneModel;
        [RenameInEditor("目标剧情")]
        public PlotModel directionPlotModel;
        [RenameInEditor("要变更的数值")]
        public RoleData roleData;
        [RenameInEditor("带参事件<PlotModel,SceneModel>")]
        public UnityEvent<PlotModel,SceneModel> customEvent;
        [RenameInEditor("无参事件")]
        public UnityEvent customEventNoParam;

        public virtual void DoAction(PlotModel plotModel,SceneModel sceneModel){
            switch (actionModelType){
                case ActionModelType.GotoScene:
                    GotoScene();
                    break;
                case ActionModelType.JumpPlot:
                    JumpPlot(ref plotModel);
                    break;
                case ActionModelType.Custom:
                    ExecuteCustom(plotModel,sceneModel);
                    break;
                case ActionModelType.GrowUp:
                    GrowUp(roleData);
                    break;
                default:
                    break;
            }
        }

        public virtual void DoAction(PlotModel plotModel){
            DoAction(plotModel,GameSystem.Data.CurrentSceneModel);
        }
        
        /// <summary>
        /// 以默认操作执行活动
        /// </summary>
        public virtual void DoAction(){
            DoAction(GameSystem.Data.PlotFlowController._currentPlotModel);
        }

        public void GotoScene(){
            GameSystem.Data.CurrentSceneModel = directionSceneModel ? directionSceneModel : GameSystem.Data.CurrentSceneModel;
        }

        public void GrowUp(RoleData otherRoleData){
            GameSystem.Data.CurrentRoleModel.Add(otherRoleData);
        }

        public void JumpPlot([NotNull] ref PlotModel plotModel){
            if (plotModel == null) throw new ArgumentNullException(nameof(plotModel));
            plotModel = directionPlotModel;
        }

        public void ExecuteCustom([NotNull] PlotModel plotModel,[NotNull] SceneModel sceneModel){
            customEvent.Invoke(plotModel,sceneModel);
            customEventNoParam.Invoke();
        }
        
    }
}

Clone this wiki locally