123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using System.Collections;
- using System.Linq;
- using System.Collections.Generic;
- using UnityEngine;
- using Sirenix.OdinInspector;
- using KairoEngine.Core;
- using KairoEngine.Core.GameActions;
- using KairoEngine.StorySystem;
- namespace KairoEngine.StorySystem.GameActions
- {
- [System.Serializable, HideReferenceObjectPicker]
- public class OnStorylineGameActionTrigger : GameActionTriggerBase
- {
- public enum StorylineCondition
- {
- Contains,
- Equal,
- NotEqual
- }
- public override string name
- {
- get
- {
- return $"On Storyline";
- }
- }
- public override GameActionTriggersController controller {
- get => _controller;
- set
- {
- _controller = value;
- typeName = "OnStorylineGameActionTrigger";
- }
- }
- public override string GetTypeName() => "OnStorylineGameActionTrigger";
- public override string GetTriggerName() => "On Storyline";
- [IconFoldoutGroup("@name","Assets/Plugins/KairoEngine/StorySystem/Editor/Icons/OnStorylineGameActionTriggerIcon.png")]
- public string storyName = "Storyline";
- [IconFoldoutGroup("@name")] public StorylineCondition condition = StorylineCondition.Contains;
- [IconFoldoutGroup("@name")] public StoryStepType storyStepType = StoryStepType.Line;
- [IconFoldoutGroup("@name")] public string value = "";
- public override void OnEnable()
- {
- EventManager.broadcast.StartListening(storyName, OnStoryStep);
- }
- public override void Update()
- {
-
- }
- public override void OnDisable()
- {
- EventManager.broadcast.StopListening(storyName, OnStoryStep);
- }
- private void OnStoryStep(StoryStepData storyStep)
- {
- if(storyStep.category != storyStepType) return;
- switch (storyStep.category)
- {
- case StoryStepType.Line:
- if(condition == StorylineCondition.Equal && value == storyStep.text) TriggerActions();
- if(condition == StorylineCondition.Contains && storyStep.text.Contains(value)) TriggerActions();
- if(condition == StorylineCondition.NotEqual && value != storyStep.text) controller.TriggerActions();
- break;
- case StoryStepType.Branch:
- foreach (var branch in storyStep.branches)
- {
- if(condition == StorylineCondition.Equal && value == branch) TriggerActions();
- if(condition == StorylineCondition.Contains && branch.Contains(value)) TriggerActions();
- if(condition == StorylineCondition.NotEqual && value != branch) controller.TriggerActions();
- }
- break;
- case StoryStepType.Path:
- if(condition == StorylineCondition.Equal && value == storyStep.text) TriggerActions();
- if(condition == StorylineCondition.Contains && storyStep.text.Contains(value)) TriggerActions();
- if(condition == StorylineCondition.NotEqual && value != storyStep.text) TriggerActions();
- break;
- default:
- break;
- }
- }
- public void TriggerActions()
- {
- EventManager.broadcast.StopListening(storyName, OnStoryStep);
- controller.TriggerActions();
- }
- public static OnStorylineGameActionTrigger JSONToOnStorylineGameActionTrigger(string data)
- {
- return JsonUtility.FromJson<OnStorylineGameActionTrigger>(data);
- }
- private OnStorylineGameActionTrigger Duplicate()
- {
- OnStorylineGameActionTrigger trigger = new OnStorylineGameActionTrigger();
- trigger.controller = controller;
- return trigger;
- }
- }
- }
|