114 lines
2.0 KiB
C#
114 lines
2.0 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2020-11-30
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "Cha_AI" company="Kunpo"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
#if BT_AI
|
|
using BehaviorDesigner.Runtime;
|
|
#endif
|
|
using UnityEngine;
|
|
|
|
namespace G
|
|
{
|
|
/// <summary>
|
|
/// 类功能描述
|
|
/// </summary>
|
|
public class Cha_AI : MonoBehaviour
|
|
{
|
|
#region Field
|
|
|
|
#endregion
|
|
|
|
#region Property
|
|
|
|
#if BT_AI
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public BehaviorTree behaviorTree
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
#endif
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
#if BT_AI
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="externalBehaviorTree"></param>
|
|
public void InitBehaviorTree(ExternalBehaviorTree externalBehaviorTree)
|
|
{
|
|
behaviorTree = this.gameObject.AddComponent<BehaviorTree>();
|
|
behaviorTree.ExternalBehavior = externalBehaviorTree;
|
|
}
|
|
|
|
public void SetVariable(string name, SharedVariable value)
|
|
{
|
|
behaviorTree.SetVariable(name, value);
|
|
}
|
|
|
|
public void SetVariableValue(string name, object value)
|
|
{
|
|
behaviorTree.SetVariableValue(name, value);
|
|
}
|
|
|
|
|
|
public void StartAI()
|
|
{
|
|
if (behaviorTree)
|
|
StartCoroutine(nameof(AICoroutine));
|
|
}
|
|
|
|
public void StopAI()
|
|
{
|
|
|
|
}
|
|
|
|
private IEnumerator AICoroutine()
|
|
{
|
|
yield return new WaitForSeconds(0.1f);
|
|
while (true)
|
|
{
|
|
UpdateAI();
|
|
yield return new WaitForSeconds(0.5f);
|
|
}
|
|
}
|
|
|
|
private void UpdateAI()
|
|
{
|
|
BehaviorManager.instance.EnableBehavior(behaviorTree);
|
|
}
|
|
#endif
|
|
|
|
#endregion
|
|
|
|
#region Unity
|
|
|
|
// Use this for initialization
|
|
private void Start()
|
|
{
|
|
}
|
|
|
|
// Update is called once per frame
|
|
private void Update()
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|