提交确定性AI案例

This commit is contained in:
DESKTOP-5RP3AKU\Jisol
2024-11-15 19:21:14 +08:00
parent ae81ee6c84
commit a0a8751aa5
47 changed files with 18242 additions and 4024 deletions

View File

@@ -38,7 +38,6 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.12731749, g: 0.13414757, b: 0.1210787, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
@@ -154,7 +153,6 @@ RectTransform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1704056725}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
@@ -300,7 +298,6 @@ RectTransform:
m_Children:
- {fileID: 1704056725}
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
@@ -339,7 +336,6 @@ RectTransform:
m_Children:
- {fileID: 1561392802}
m_Father: {fileID: 1704056725}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
@@ -420,7 +416,6 @@ RectTransform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1675717780}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.5}
m_AnchorMax: {x: 0, y: 0.5}
@@ -493,7 +488,6 @@ RectTransform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 959240196}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.5}
m_AnchorMax: {x: 0, y: 0.5}
@@ -632,13 +626,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 716990035}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &847152543
GameObject:
@@ -700,13 +694,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 847152543}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &959240195
GameObject:
@@ -740,7 +734,6 @@ RectTransform:
m_Children:
- {fileID: 710005109}
m_Father: {fileID: 1704056725}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
@@ -877,13 +870,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 963194225}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1561392801
GameObject:
@@ -916,7 +909,6 @@ RectTransform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 311335929}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.5}
m_AnchorMax: {x: 0, y: 0.5}
@@ -990,7 +982,6 @@ RectTransform:
m_Children:
- {fileID: 452860052}
m_Father: {fileID: 1704056725}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
@@ -1076,7 +1067,6 @@ RectTransform:
- {fileID: 311335929}
- {fileID: 12615224}
m_Father: {fileID: 307949393}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
@@ -1139,7 +1129,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
AutoRun: 1
config: {fileID: 4900000, guid: 2ae8dd65757eda9499fd4559acc7d26f, type: 3}
config: {fileID: 4900000, guid: efbb9ae85b44479fac84562240d86ac3, type: 3}
Obj:
- {fileID: 716990035}
--- !u!4 &1742566310
@@ -1149,11 +1139,20 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1742566308}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1660057539 &9223372036854775807
SceneRoots:
m_ObjectHideFlags: 0
m_Roots:
- {fileID: 963194228}
- {fileID: 847152546}
- {fileID: 716990039}
- {fileID: 1742566310}
- {fileID: 307949393}

View File

@@ -1,57 +1,34 @@
<?xml version="1.0"?>
<Entry xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<x>
<rawValue>380000000</rawValue>
<rawValue>620000000</rawValue>
</x>
<y>
<rawValue>-60000000</rawValue>
<rawValue>20000000</rawValue>
</y>
<childs>
<TreeNode xsi:type="Repeat">
<x>
<rawValue>380000000</rawValue>
<rawValue>620000000</rawValue>
</x>
<y>
<rawValue>60000000</rawValue>
<rawValue>160000000</rawValue>
</y>
<childs>
<TreeNode xsi:type="Sequence">
<x>
<rawValue>320000000</rawValue>
<rawValue>620000000</rawValue>
</x>
<y>
<rawValue>220000000</rawValue>
<rawValue>380000000</rawValue>
</y>
<childs>
<TreeNode xsi:type="MoveTo">
<x>
<rawValue>160000000</rawValue>
</x>
<y>
<rawValue>340000000</rawValue>
</y>
<ItemName>Cube</ItemName>
<Pos>
<x>
<rawValue>10000000</rawValue>
</x>
<y>
<rawValue>0</rawValue>
</y>
<z>
<rawValue>0</rawValue>
</z>
</Pos>
<Speed>
<rawValue>1000000</rawValue>
</Speed>
</TreeNode>
<TreeNode xsi:type="ChangeColor">
<x>
<rawValue>320000000</rawValue>
<rawValue>560000000</rawValue>
</x>
<y>
<rawValue>420000000</rawValue>
<rawValue>540000000</rawValue>
</y>
<color>
<r>0.2166667</r>
@@ -62,10 +39,10 @@
</TreeNode>
<TreeNode xsi:type="MoveTo">
<x>
<rawValue>500000000</rawValue>
<rawValue>780000000</rawValue>
</x>
<y>
<rawValue>400000000</rawValue>
<rawValue>540000000</rawValue>
</y>
<ItemName>Cube</ItemName>
<Pos>
@@ -85,10 +62,10 @@
</TreeNode>
<TreeNode xsi:type="ChangeColor">
<x>
<rawValue>680000000</rawValue>
<rawValue>980000000</rawValue>
</x>
<y>
<rawValue>360000000</rawValue>
<rawValue>540000000</rawValue>
</y>
<color>
<r>0</r>
@@ -97,6 +74,29 @@
<a>1</a>
</color>
</TreeNode>
<TreeNode xsi:type="MoveTo">
<x>
<rawValue>320000000</rawValue>
</x>
<y>
<rawValue>540000000</rawValue>
</y>
<ItemName>Cube</ItemName>
<Pos>
<x>
<rawValue>10000000</rawValue>
</x>
<y>
<rawValue>0</rawValue>
</y>
<z>
<rawValue>0</rawValue>
</z>
</Pos>
<Speed>
<rawValue>1000000</rawValue>
</Speed>
</TreeNode>
</childs>
</TreeNode>
</childs>

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ab04e85d18a64d29b5421265826a98cf
timeCreated: 1731647384

View 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>

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: efbb9ae85b44479fac84562240d86ac3
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -25,8 +25,8 @@ MonoBehaviour:
rawValue: 0
end:
x:
rawValue: 10000000
rawValue: 1000000
y:
rawValue: 0
rawValue: 1000000
z:
rawValue: 0
rawValue: 1000000

View File

@@ -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);
});
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e95c0d34f640b2d468717505731caa9a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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}");
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 11fd831585c84672a7b5f00e86be7d26
timeCreated: 1731663272

View File

@@ -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));
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d0b266c8a7b440ff93787430b9773489
timeCreated: 1731646412

View File

@@ -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);
}
}
}

View File

@@ -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));
}

View File

@@ -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;

View File

@@ -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);

View File

@@ -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;
}
}
}

View File

@@ -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));
}
}

View File

@@ -27,6 +27,8 @@ namespace GASSamples.Scripts
public Dictionary<string,GameplayCueDurational> CuesDurational;
public Dictionary<string,GameplayCueInstant> CuesInstant;
public string AI;
public override Task OnInit()
{

View File

@@ -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();