Quellcode durchsuchen

Added TriggerGenericEvent GameAction

James Peret vor 2 Jahren
Ursprung
Commit
6eb61bc492

+ 5 - 2
Readme.md

@@ -1,4 +1,4 @@
-# 📦 KairoEngine.Core v0.2.0
+# 📦 KairoEngine.Core v0.2.1
 
 
 This contains the base code that other packages will use. It includes code for the module system, event system and common interfaces.
 This contains the base code that other packages will use. It includes code for the module system, event system and common interfaces.
 
 
@@ -23,7 +23,10 @@ This contains the base code that other packages will use. It includes code for t
 
 
 - `KairoEngine.Core.ModuleSystem`
 - `KairoEngine.Core.ModuleSystem`
 
 
-### Changelog
+### 📄Changelog
+
+##### v0.2.1
+- Added TriggerGenericEvent GameAction
 
 
 ##### v0.2.0
 ##### v0.2.0
 
 

+ 117 - 0
Runtime/GameActions/Actions/TriggerGenericEventGameAction.cs

@@ -0,0 +1,117 @@
+using System.Collections;
+using System.Linq;
+using System.Collections.Generic;
+using UnityEngine;
+using Sirenix.OdinInspector;
+using KairoEngine.Core;
+
+namespace KairoEngine.Core.GameActions
+{
+    public enum GameActionStringType
+    {
+        String,
+        Variable
+    }
+
+    [System.Serializable, HideReferenceObjectPicker]
+    public class TriggerGenericEventGameAction : GameActionBase
+    {
+        public override string name 
+        { 
+            get
+            {
+                return "Trigger Generic Event";
+            }
+        }
+
+        public override GameActionsController controller { 
+            get => _controller; 
+            set 
+            {
+                _controller = value;
+                typeName = "TriggerGenericEventGameAction";
+                className =  this.GetType().AssemblyQualifiedName;
+                GetCompatibleVariablenames();
+            }
+        }
+        public override string GetTypeName() => "TriggerGenericEventGameAction";
+        public override string GetActionName() => "Core/Trigger Generic Event";
+
+        [FoldoutGroup("@name")] 
+        public GameActionStringType actionType = GameActionStringType.String;
+        
+        [FoldoutGroup("@name"), ShowIf("@actionType == GameActionStringType.String")]
+        public string eventName = "EventName";
+
+        [FoldoutGroup("@name"), ShowIf("@actionType == GameActionStringType.Variable")]
+        [ValueDropdown("possibleVariables", IsUniqueList = false)]
+        public string eventNameVariable;
+
+        private IEnumerable possibleVariables = new ValueDropdownList<string>();
+
+        public TriggerGenericEventGameAction(GameActionsController controller) : base(controller)
+        {
+            this.controller = controller;
+            className =  this.GetType().AssemblyQualifiedName;
+        }
+
+        public override void Start()
+        {
+            string targetEvent = "";
+            if(actionType == GameActionStringType.String) targetEvent = eventName;
+            else if(actionType == GameActionStringType.Variable) targetEvent = GetVariable(eventNameVariable);
+            GenericEvents.Trigger(targetEvent);
+            _done = true;
+            _started = true;
+        }
+
+        public override void Update() { }
+
+        public override void Restart()
+        {
+            _done = false;
+            _started = false;
+        }
+
+        private void GetCompatibleVariablenames()
+        {
+            if(_controller == null) return;
+            if(_controller.context == null) return;
+            possibleVariables = _controller.context.variables
+                //.Where(x => x.data is GameActionContextString)
+                .Select(x => new ValueDropdownItem(x.name, x.name)); 
+        }
+
+        public static TriggerGenericEventGameAction JSONToTriggerGenericEventGameAction(string data)
+        {
+            return JsonUtility.FromJson<TriggerGenericEventGameAction>(data);
+        }
+
+        private TriggerGenericEventGameAction Duplicate(GameActionsController controller = null)
+        {
+            TriggerGenericEventGameAction action = new TriggerGenericEventGameAction(controller == null ? this.controller : controller);
+            action.controller = controller;
+            action.actionType = actionType;
+            action.eventName = eventName;
+            action.eventNameVariable = eventNameVariable;
+            return action;
+        }
+
+        private string GetVariable(string title)
+        {
+            if(controller == null) return "";
+            if(controller.context == null) return "";
+            for (int i = 0; i < controller.context.variables.Count; i++)
+            {
+                if(controller.context.variables[i].name == title)
+                {
+                    string value = controller.context.variables[i].GetValue<string>("");
+                    if(value != "") return value;
+                }
+            }
+            return "";
+        }
+
+    }
+}
+

+ 11 - 0
Runtime/GameActions/Actions/TriggerGenericEventGameAction.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 4e0e3fedb430a7048b0ca060e9a472e9
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 4 - 0
Runtime/GameActions/GameActionsController.cs

@@ -175,6 +175,10 @@ namespace KairoEngine.Core.GameActions
         private void InitializeActionList()
         private void InitializeActionList()
         {
         {
             if(actions == null) actions = new List<GameAction>();
             if(actions == null) actions = new List<GameAction>();
+            foreach (var action in actions)
+            {
+                action.controller = this;
+            }
         }
         }
 
 
         public GameActionsController Duplicate()
         public GameActionsController Duplicate()

+ 1 - 1
package.json

@@ -1,7 +1,7 @@
 {
 {
   "name": "at.kairoscope.kairoengine.core",
   "name": "at.kairoscope.kairoengine.core",
   "displayName" : "KairoEngine Core",
   "displayName" : "KairoEngine Core",
-  "version": "0.2.0",
+  "version": "0.2.1",
   "unity": "2020.3",
   "unity": "2020.3",
   "description": "Base package for the KairoEngine library by Kairoscope",
   "description": "Base package for the KairoEngine library by Kairoscope",
   "repository": {
   "repository": {