12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Sirenix.OdinInspector;
- using KairoEngine.Core;
- namespace KairoEngine.Core.GameActions
- {
- [HideMonoScript, AddComponentMenu("KairoEngine/Actions Controller")]
- public class GameActionsComponent : MonoBehaviour
- {
- [InlineProperty, HideLabel]
- [PropertySpace(0, 3)]
- public GameActionTriggersController triggersController = new GameActionTriggersController();
- [InlineProperty, HideLabel]
- [OnInspectorInit("Initialize")]
- public GameActionsController controller;
- private void OnEnable()
- {
- Initialize();
- if(triggersController != null) triggersController.OnEnable();
- }
- private void OnDisable()
- {
- if(controller != null) controller.Stop();
- if(triggersController != null) triggersController.OnDisable();
- }
- private void Start()
- {
- Initialize();
- if(controller == null)
- {
- controller = new GameActionsController();
- controller.actions = new List<GameAction>();
- }
- }
- private void Update()
- {
- if(triggersController != null) triggersController.Update();
- }
- private void Initialize()
- {
- if(controller == null) return;
- controller.showContext = true;
- triggersController.actionsController = controller;
- if(!controller.context.HasVariable("GameObject"))
- {
- var variable = new GameActionContextGameObject();
- variable.name = "GameObject";
- variable.value = this.gameObject;
- variable.canEdit = false;
- controller.context.AddVariable(variable);
- }
- }
- public void StartGameActionsController()
- {
- if(controller != null)
- {
- controller.Start();
- }
- }
- public void ResetGameActionsController()
- {
- if(controller != null)
- {
- controller.Restart();
- }
- }
- }
- }
|