1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using System;
- using System.Collections;
- using System.Linq;
- using System.Collections.Generic;
- using UnityEngine;
- using Sirenix.OdinInspector;
- using KairoEngine.Core;
- namespace KairoEngine.Core.GameActions
- {
- [System.Serializable, HideReferenceObjectPicker]
- public class InstantiateGameAction : GameActionBase
- {
- public override string name
- {
- get
- {
- return $"Instantiate {GetObjName(prefab)}";
- }
- }
- public override GameActionsController controller {
- get => _controller;
- set
- {
- _controller = value;
- typeName = "InstantiateGameAction";
- }
- }
- public override string GetTypeName() => "InstantiateGameAction";
- public override string GetActionName() => "Core/Instantiate GameObject";
- [IconFoldoutGroup("@name", "Assets/Plugins/KairoEngine/Core/Editor/Icons/InstantiateGameActionIcon.png")]
- [NonSerialized, ShowInInspector, AssetsOnly, LabelText("Prefab")] public GameObject prefab;
- public InstantiateGameAction(GameActionsController controller) : base(controller)
- {
- this.controller = controller;
- className = this.GetType().AssemblyQualifiedName;
- }
- private string GetObjName(GameObject obj)
- {
- if(obj == null) return "NULL";
- else return $"\'{obj.name}\'";
- }
- public override void Start()
- {
- GameObject.Instantiate(prefab);
- _done = true;
- _started = true;
- }
- public override void Update() { }
- public override void Restart()
- {
- _done = false;
- _started = false;
- }
- public static InstantiateGameAction JSONToInstantiateGameAction(string data)
- {
- return JsonUtility.FromJson<InstantiateGameAction>(data);
- }
- private InstantiateGameAction Duplicate(GameActionsController controller)
- {
- InstantiateGameAction action = new InstantiateGameAction(controller == null ? this.controller : controller);
- action.controller = controller;
- return action;
- }
- private T GetVariable<T>(string title, T defaultValue)
- {
- for (int i = 0; i < controller.context.variables.Count; i++)
- {
- if(controller.context.variables[i].name == title)
- {
- return controller.context.variables[i].GetValue<T>(defaultValue);
- }
- }
- return defaultValue;
- }
- public override void OnBeforeSerialize(GameActionObjectSerializer serializer, int n, int depth)
- {
- serializer.SerializeGameObject($"{depth}-{n}-Prefab", prefab);
- }
- public override void OnBeforeDeserialize(GameActionObjectSerializer serializer, int n, int depth)
- {
- prefab = serializer.DeserializeGameObject($"{depth}-{n}-Prefab");
- }
- }
- }
|