mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 10:46:17 +00:00
提交确定性AI案例
This commit is contained in:
3
JNFrame2/Assets/Scripts/GASSamples/AI.meta
Normal file
3
JNFrame2/Assets/Scripts/GASSamples/AI.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab04e85d18a64d29b5421265826a98cf
|
||||
timeCreated: 1731647384
|
39
JNFrame2/Assets/Scripts/GASSamples/AI/AiDemo1.txt
Normal file
39
JNFrame2/Assets/Scripts/GASSamples/AI/AiDemo1.txt
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0"?>
|
||||
<Entry xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<x>
|
||||
<rawValue>9620000000</rawValue>
|
||||
</x>
|
||||
<y>
|
||||
<rawValue>5420000000</rawValue>
|
||||
</y>
|
||||
<childs>
|
||||
<TreeNode xsi:type="Sequence">
|
||||
<x>
|
||||
<rawValue>9620000000</rawValue>
|
||||
</x>
|
||||
<y>
|
||||
<rawValue>5620000000</rawValue>
|
||||
</y>
|
||||
<childs>
|
||||
<TreeNode xsi:type="AiLog">
|
||||
<x>
|
||||
<rawValue>9480000000</rawValue>
|
||||
</x>
|
||||
<y>
|
||||
<rawValue>5860000000</rawValue>
|
||||
</y>
|
||||
<log>你好</log>
|
||||
</TreeNode>
|
||||
<TreeNode xsi:type="AiLog">
|
||||
<x>
|
||||
<rawValue>9740000000</rawValue>
|
||||
</x>
|
||||
<y>
|
||||
<rawValue>5860000000</rawValue>
|
||||
</y>
|
||||
<log>好个屁</log>
|
||||
</TreeNode>
|
||||
</childs>
|
||||
</TreeNode>
|
||||
</childs>
|
||||
</Entry>
|
7
JNFrame2/Assets/Scripts/GASSamples/AI/AiDemo1.txt.meta
Normal file
7
JNFrame2/Assets/Scripts/GASSamples/AI/AiDemo1.txt.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: efbb9ae85b44479fac84562240d86ac3
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -25,8 +25,8 @@ MonoBehaviour:
|
||||
rawValue: 0
|
||||
end:
|
||||
x:
|
||||
rawValue: 10000000
|
||||
rawValue: 1000000
|
||||
y:
|
||||
rawValue: 0
|
||||
rawValue: 1000000
|
||||
z:
|
||||
rawValue: 0
|
||||
rawValue: 1000000
|
||||
|
@@ -1,9 +1,7 @@
|
||||
using DG.Tweening;
|
||||
using GAS.Runtime;
|
||||
using GASSamples.Scripts.Game.GAS;
|
||||
using JNGame.Math;
|
||||
using JNGame.Runtime.GAS.Runtime;
|
||||
using JNGame.Runtime.Util;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -13,10 +11,10 @@ namespace Demo.Scripts.GAS.GameplayCue
|
||||
{
|
||||
|
||||
[BoxGroup]
|
||||
[LabelText("开始位置")]
|
||||
[LabelText("开始大小")]
|
||||
public LVector3 start;
|
||||
[BoxGroup]
|
||||
[LabelText("结束位置")]
|
||||
[LabelText("结束大小")]
|
||||
public LVector3 end;
|
||||
|
||||
protected override GameplayCueDurationalSpec CreateSpec(GameplayCueParameters parameters)
|
||||
@@ -29,10 +27,13 @@ namespace Demo.Scripts.GAS.GameplayCue
|
||||
{
|
||||
Debug.Log($"GameplayCueDurational_PlayerDemo01 {previewObject} {frameIndex}");
|
||||
|
||||
// if (frameIndex >= startFrame && frameIndex <= endFrame)
|
||||
// {
|
||||
// previewObject.transform.position = Vector3.Lerp(start.ToVector3(), end.ToVector3(), (float)(frameIndex - startFrame) / endFrame);
|
||||
// }
|
||||
var TotalTime = frameIndex - startFrame;
|
||||
var durationTime = endFrame - startFrame;
|
||||
|
||||
if (frameIndex >= startFrame && frameIndex <= endFrame)
|
||||
{
|
||||
previewObject.transform.localScale = start.ToVector3() + ((end.ToVector3() - start.ToVector3()) * ((float)TotalTime / durationTime));
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -72,22 +73,18 @@ namespace Demo.Scripts.GAS.GameplayCue
|
||||
{
|
||||
|
||||
// Debug.Log($"GameplayCueDurational_PlayerDemo01_Spec OnTick {frame}");
|
||||
// ((GAbilitySystemComponent)Owner).Entity.Transform.Position = LVector3.Lerp(cue.start, cue.end, (LFloat)(frame - startFrame) / endFrame);
|
||||
// ((GAbilitySystemComponent)Owner).Entity.Transform.Position = LVector3.Lerp(cue. start, cue.end, (LFloat)(frame - startFrame) / endFrame);
|
||||
|
||||
}
|
||||
|
||||
public override void OnTick(int deltaTime)
|
||||
{
|
||||
TotalTime += deltaTime;
|
||||
|
||||
TotalTime += deltaTime;
|
||||
var view = _parameters.customArguments[0] as GameObject;
|
||||
var durationTime = ((int)_parameters.customArguments[1]) * JexGasManager.TimeLineAbilityTickTime;
|
||||
view.transform.DOScale(cue.start.ToVector3() + ((cue.end.ToVector3() - cue.start.ToVector3()) * ((float)TotalTime / durationTime)),0.15f);
|
||||
|
||||
UnityMainThreadDispatcher.Instance.Enqueue(() =>
|
||||
{
|
||||
// view.transform.localScale = new Vector3((float)TotalTime / durationTime,(float)TotalTime / durationTime,(float)TotalTime / durationTime);
|
||||
view.transform.DOScale(new Vector3((float)TotalTime / durationTime,(float)TotalTime / durationTime,(float)TotalTime / durationTime),0.15f);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e95c0d34f640b2d468717505731caa9a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,27 @@
|
||||
using BehaviorTreeSlayer;
|
||||
using GASSamples.Scripts.Game.Entity.Nodes.Component.Components;
|
||||
using JNGame.Sync.Entity;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GASSamples.Scripts.Game.Logic.AI
|
||||
{
|
||||
public class AiLog : ActionNode
|
||||
{
|
||||
|
||||
[OutField]
|
||||
public string log;
|
||||
|
||||
private JNBehaviorTree _tree;
|
||||
public JNBehaviorTree Tree => _tree;
|
||||
|
||||
public IJNEntity Entity => Tree.Get<JNAIComponent>().Entity;
|
||||
|
||||
public override void Enter(object args)
|
||||
{
|
||||
base.Enter(args);
|
||||
_tree = args as JNBehaviorTree;
|
||||
Debug.Log($"[AiLog] {Entity.Id} {log}");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11fd831585c84672a7b5f00e86be7d26
|
||||
timeCreated: 1731663272
|
@@ -0,0 +1,29 @@
|
||||
using BehaviorTreeSlayer;
|
||||
using JNGame.Math;
|
||||
using JNGame.Sync.Entity.Component;
|
||||
using JNGame.Sync.Frame.Service;
|
||||
|
||||
namespace GASSamples.Scripts.Game.Entity.Nodes.Component.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// AI组件
|
||||
/// </summary>
|
||||
public class JNAIComponent : JNComponent
|
||||
{
|
||||
|
||||
private JNBehaviorTree _behaviorTree = new();
|
||||
|
||||
public void Init(string config)
|
||||
{
|
||||
_behaviorTree["JNAIComponent"] = this;
|
||||
_behaviorTree.OnInit(GetSystem<JNRandomSystem>().Int(0,100000),config);
|
||||
}
|
||||
|
||||
public override void OnSyncUpdate(int dt)
|
||||
{
|
||||
base.OnSyncUpdate(dt);
|
||||
_behaviorTree.Update(new LFloat("",dt));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0b266c8a7b440ff93787430b9773489
|
||||
timeCreated: 1731646412
|
@@ -11,12 +11,27 @@ namespace GASSamples.Scripts.Game.Entity.Nodes.Component.Controller
|
||||
{
|
||||
|
||||
public JNGASComponent GAS => Entity.GetComponent<JNGASComponent>();
|
||||
public JNAIComponent AI => Entity.GetComponent<JNAIComponent>();
|
||||
|
||||
public override void OnSyncStart()
|
||||
{
|
||||
|
||||
base.OnSyncStart();
|
||||
|
||||
//初始化GAS
|
||||
OnGASInit();
|
||||
|
||||
//初始化AI
|
||||
OnAIInit();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化GAS
|
||||
/// </summary>
|
||||
private void OnGASInit()
|
||||
{
|
||||
|
||||
//设置GAS 角色
|
||||
GAS.InitWithPreset(GetSystem<DGASSystem>().GetASCPresetAsset("ASC_Demo1"),1);
|
||||
|
||||
@@ -25,8 +40,16 @@ namespace GASSamples.Scripts.Game.Entity.Nodes.Component.Controller
|
||||
|
||||
//释放技能
|
||||
GAS.TryActivateAbility(GAbilityLib.JisolDemo1.Name);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化AI
|
||||
/// </summary>
|
||||
private void OnAIInit()
|
||||
{
|
||||
AI.Init(Entity.GetSystem<DDataSystem>().AI);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -11,10 +11,12 @@ namespace GASSamples.Scripts.Game.Entity.Nodes.Component.Lookup
|
||||
|
||||
public int Controller { get; set; }
|
||||
public int GAS { get; set; }
|
||||
public int AI { get; set; }
|
||||
|
||||
protected override void BindIndex()
|
||||
{
|
||||
base.BindIndex();
|
||||
AI = Next();
|
||||
GAS = Next();
|
||||
Controller = Next();
|
||||
}
|
||||
@@ -22,6 +24,7 @@ namespace GASSamples.Scripts.Game.Entity.Nodes.Component.Lookup
|
||||
protected override void BindType(KeyValue<int, Type> types)
|
||||
{
|
||||
base.BindType(types);
|
||||
types.Add(AI,typeof(JNAIComponent));
|
||||
types.Add(GAS,typeof(JNGASComponent));
|
||||
types.Add(Controller,typeof(JNGASBoxController));
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ namespace GASSamples.Scripts.Game.Entity.Contexts
|
||||
protected override JNGASBox BindComponent(JNGASBox entity)
|
||||
{
|
||||
base.BindComponent(entity);
|
||||
entity.AddComponent<JNAIComponent>();
|
||||
entity.AddComponent<JNGASComponent>();
|
||||
entity.AddComponent<JNGASBoxController>();
|
||||
return entity;
|
||||
|
@@ -9,6 +9,7 @@ namespace GASSamples.Scripts.Game.Entity.Nodes
|
||||
public class JNGASBox : JNEntity
|
||||
{
|
||||
|
||||
public JNAIComponent AI => CLookup.Query<JNAIComponent>(this);
|
||||
public JNGASComponent GAS => CLookup.Query<JNGASComponent>(this);
|
||||
public JNGASBoxController Controller => CLookup.Query<JNGASBoxController>(this);
|
||||
|
||||
|
@@ -18,6 +18,8 @@ namespace Game.Logic.System.Usual
|
||||
public byte[] GE { get; private set; }
|
||||
public byte[] ASC { get; private set; }
|
||||
|
||||
public string AI { get; private set; }
|
||||
|
||||
|
||||
public Dictionary<string,GameplayCueDurational> CuesDurational { get; private set; }
|
||||
public Dictionary<string,GameplayCueInstant> CuesInstant { get; private set; }
|
||||
@@ -35,6 +37,8 @@ namespace Game.Logic.System.Usual
|
||||
CuesDurational = App.Resource.CuesDurational;
|
||||
CuesInstant = App.Resource.CuesInstant;
|
||||
|
||||
AI = App.Resource.AI;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,6 +2,7 @@ using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using Game.Logic.System.Usual;
|
||||
using GAS.Runtime;
|
||||
using JNGame.Runtime.Util;
|
||||
using JNGame.Serialization;
|
||||
using JNGame.Sync.System;
|
||||
|
||||
@@ -56,7 +57,7 @@ namespace GASSamples.Scripts.Game.View
|
||||
base.OnSyncUpdate(dt);
|
||||
foreach (var spec in CueMap.Values)
|
||||
{
|
||||
spec.OnTick(dt);
|
||||
UnityMainThreadDispatcher.Instance.Enqueue(() => spec.OnTick(dt));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -27,6 +27,8 @@ namespace GASSamples.Scripts
|
||||
|
||||
public Dictionary<string,GameplayCueDurational> CuesDurational;
|
||||
public Dictionary<string,GameplayCueInstant> CuesInstant;
|
||||
|
||||
public string AI;
|
||||
|
||||
public override Task OnInit()
|
||||
{
|
||||
|
@@ -1,10 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using DefaultNamespace;
|
||||
using GAS.Runtime;
|
||||
using JNGame.Runtime;
|
||||
using Sirenix.OdinInspector;
|
||||
using Sirenix.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GASSamples.Scripts
|
||||
@@ -22,6 +20,8 @@ namespace GASSamples.Scripts
|
||||
|
||||
public Dictionary<string,GameplayCueDurational> CuesDurational;
|
||||
public Dictionary<string,GameplayCueInstant> CuesInstant;
|
||||
|
||||
public TextAsset AI;
|
||||
|
||||
|
||||
private JNGASFrameSystem _frameSystem;
|
||||
@@ -43,8 +43,8 @@ namespace GASSamples.Scripts
|
||||
|
||||
App.Resource.CuesDurational = CuesDurational;
|
||||
App.Resource.CuesInstant = CuesInstant;
|
||||
|
||||
|
||||
|
||||
App.Resource.AI = AI.text;
|
||||
|
||||
_frameSystem = new JNGASFrameSystem();
|
||||
_frameSystem.Initialize();
|
||||
|
Reference in New Issue
Block a user