Initial Commit
This commit is contained in:
commit
ee5c2f922d
2255 changed files with 547750 additions and 0 deletions
3
Assets/Scripts/AI.meta
Normal file
3
Assets/Scripts/AI.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f48c6391e74a4d1fb5fbf1ae63c95349
|
||||
timeCreated: 1532858094
|
||||
8
Assets/Scripts/AI/AttackPlayerGoapAction.cs
Normal file
8
Assets/Scripts/AI/AttackPlayerGoapAction.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
using Unity.Entities;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
public struct AttackPlayerGoapAction : IComponentData
|
||||
{
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/AttackPlayerGoapAction.cs.meta
Normal file
3
Assets/Scripts/AI/AttackPlayerGoapAction.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 90a049afea3f43b2b5df5e855985a475
|
||||
timeCreated: 1532860293
|
||||
105
Assets/Scripts/AI/AttackPlayerGoapSystem.cs
Normal file
105
Assets/Scripts/AI/AttackPlayerGoapSystem.cs
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
using AI.FSM;
|
||||
using DefaultNamespace;
|
||||
using System;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
using Zenject;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
[UpdateAfter(typeof(PerformActionStateSystem)), UpdateBefore(typeof(IdleSystem)), UpdateInGroup(typeof(PresentationSystemGroup))]
|
||||
public class AttackPlayerGoapSystem : GoapActionInjectableSystem<AttackPlayerGoapAction>
|
||||
{
|
||||
[Serializable]
|
||||
public class Settings
|
||||
{
|
||||
public ParticleSystem StabBloodParticles;
|
||||
public SoundLibrary StabSounds;
|
||||
}
|
||||
|
||||
[Inject] private readonly Settings settings;
|
||||
[Inject] private readonly SoundManager soundManager;
|
||||
|
||||
protected override void OnProcess(
|
||||
ref AttackPlayerGoapAction action,
|
||||
ref GoapSharedAction goapSharedAction,
|
||||
GoapAction goapAction,
|
||||
GoapActionActor actor,
|
||||
ref GoapActiveAction active)
|
||||
{
|
||||
if (active.InRange)
|
||||
{
|
||||
var animationEvent = GetComponentDataFromEntity<ActorAnimationEventData>();
|
||||
var animationGetter = GetComponentDataFromEntity<ActorAnimationData>();
|
||||
var actorGetter = GetComponentDataFromEntity<ActorData>();
|
||||
var meleeGetter = GetComponentDataFromEntity<ActorMeleeData>();
|
||||
|
||||
var actorEntity = actor.Actor;
|
||||
var animation = animationGetter[actorEntity];
|
||||
|
||||
var targetEntity = goapAction.Target;
|
||||
var animEvent = animationEvent[actorEntity];
|
||||
var prefab = EntityManager.GetComponentObject<EnemyPrefabComponent>(actorEntity);
|
||||
var rigidBody = EntityManager.GetComponentObject<Rigidbody2D>(actorEntity);
|
||||
animation.Triggers |= AnimationTriggerType.Attack;
|
||||
if (animEvent.Attacked)
|
||||
{
|
||||
var assetLoadingOperation = prefab.Prefab.OperationHandle.Convert<EnemyPrefab>();
|
||||
if (assetLoadingOperation.IsDone)
|
||||
{
|
||||
if (actorGetter.Exists(targetEntity) && EntityManager.HasComponent<Transform>(targetEntity))
|
||||
{
|
||||
var actorData = actorGetter[targetEntity];
|
||||
var transform = EntityManager.GetComponentObject<Transform>(targetEntity);
|
||||
var hit = Physics2D.Linecast(rigidBody.position, transform.position, LayerMask.GetMask("Player"));
|
||||
if (hit && hit.distance <= assetLoadingOperation.Result.AttackRange)
|
||||
{
|
||||
actorData.Health -= assetLoadingOperation.Result.Damage;
|
||||
EntityManager.SetComponentData(targetEntity, actorData);
|
||||
soundManager.PlayClip(PostUpdateCommands, settings.StabSounds, hit.point);
|
||||
settings.StabBloodParticles.Emit(new ParticleSystem.EmitParams { position = hit.point }, 1);
|
||||
}
|
||||
|
||||
active.Done = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
active.Fail = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
animationGetter[actorEntity] = animation;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnInitialize(ref AttackPlayerGoapAction action, ref GoapSharedAction goapSharedAction)
|
||||
{
|
||||
goapSharedAction.Cost = 10;
|
||||
goapSharedAction.Effects.Add(((int)GoapKeys.Attacks, true));
|
||||
goapSharedAction.RequiresInRange = true;
|
||||
}
|
||||
|
||||
protected override bool OnValidate(
|
||||
ref AttackPlayerGoapAction action,
|
||||
ref GoapSharedAction goapSharedAction,
|
||||
ref GoapAction goapAction,
|
||||
GoapActionActor actor)
|
||||
{
|
||||
if (!EntityManager.HasComponents<ActorAnimationEventData, Rigidbody2D, EnemyPrefabComponent>(actor.Actor))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var playerEntity = GetSingletonEntity<PlayerData>();
|
||||
var playerRigidbody = EntityManager.GetComponentObject<Rigidbody2D>(playerEntity);
|
||||
|
||||
var actorRigidbody = EntityManager.GetComponentObject<Rigidbody2D>(actor.Actor);
|
||||
var d = Vector2.Distance(actorRigidbody.position, playerRigidbody.position);
|
||||
goapSharedAction.Cost = d;
|
||||
goapAction.Target = playerEntity;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/AttackPlayerGoapSystem.cs.meta
Normal file
3
Assets/Scripts/AI/AttackPlayerGoapSystem.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: dea9267da89148aba9fabbb278c4521f
|
||||
timeCreated: 1532860315
|
||||
88
Assets/Scripts/AI/AttackTargetMeleeGoapAction.cs
Normal file
88
Assets/Scripts/AI/AttackTargetMeleeGoapAction.cs
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
using DefaultNamespace;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
public struct AttackTargetMeleeGoapAction : IComponentData
|
||||
{
|
||||
}
|
||||
|
||||
public class AttackPlayerMeleeGoapActionSystem : GoapActionSystem<AttackTargetMeleeGoapAction>
|
||||
{
|
||||
protected override void OnInitialize(ref AttackTargetMeleeGoapAction action, ref GoapSharedAction goapSharedAction)
|
||||
{
|
||||
goapSharedAction.Cost = 10;
|
||||
goapSharedAction.Preconditions.Add((GoapKeys.HasTarget, true));
|
||||
goapSharedAction.Effects.Add((GoapKeys.Attacks, true));
|
||||
}
|
||||
|
||||
protected override void OnProcess(
|
||||
ref AttackTargetMeleeGoapAction action,
|
||||
ref GoapSharedAction goapSharedAction,
|
||||
GoapAction goapAction,
|
||||
GoapActionActor actor,
|
||||
ref GoapActiveAction active)
|
||||
{
|
||||
var actorEntity = actor.Actor;
|
||||
var animation = EntityManager.GetComponentData<ActorAnimationData>(actorEntity);
|
||||
var melee = EntityManager.GetComponentData<ActorMeleeData>(actorEntity);
|
||||
var meleeShared = EntityManager.GetSharedComponentData<ActorMeleeSharedData>(actor.Actor);
|
||||
var target = EntityManager.GetComponentData<ActorTargetData>(actorEntity);
|
||||
|
||||
if (!EntityManager.Exists(target.Target))
|
||||
{
|
||||
active.MarkFailed();
|
||||
return;
|
||||
}
|
||||
|
||||
if (melee.MeleeTimer <= 0)
|
||||
{
|
||||
animation.Triggers |= AnimationTriggerType.Melee;
|
||||
melee.MeleeTimer += meleeShared.Cooldown;
|
||||
EntityManager.SetComponentData(actorEntity, melee);
|
||||
EntityManager.SetComponentData(actorEntity, animation);
|
||||
}
|
||||
else
|
||||
{
|
||||
active.MarkFailed();
|
||||
}
|
||||
|
||||
active.MarkDone();
|
||||
}
|
||||
|
||||
protected override bool OnValidate(
|
||||
ref AttackTargetMeleeGoapAction action,
|
||||
ref GoapSharedAction goapSharedAction,
|
||||
ref GoapAction goapAction,
|
||||
GoapActionActor actor)
|
||||
{
|
||||
if (!EntityManager.HasComponents<ActorMeleeData, ActorMeleeSharedData, Rigidbody2D, ActorAnimationData, ActorTargetData>(actor.Actor))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var melee = EntityManager.GetComponentData<ActorMeleeData>(actor.Actor);
|
||||
|
||||
if (melee.MeleeTimer > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var meleeShared = EntityManager.GetSharedComponentData<ActorMeleeSharedData>(actor.Actor);
|
||||
var actorRigidBody = EntityManager.GetComponentObject<Rigidbody2D>(actor.Actor);
|
||||
var target = EntityManager.GetComponentData<ActorTargetData>(actor.Actor);
|
||||
|
||||
if (EntityManager.TryGetComponentObject<Rigidbody2D>(target.Target, out var targetRigidBody))
|
||||
{
|
||||
var d = Vector2.Distance(actorRigidBody.position, targetRigidBody.position);
|
||||
if (d < meleeShared.Range)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/AttackTargetMeleeGoapAction.cs.meta
Normal file
3
Assets/Scripts/AI/AttackTargetMeleeGoapAction.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d50ffa59d77a40ed86cef71992500ce7
|
||||
timeCreated: 1533311558
|
||||
3
Assets/Scripts/AI/FSM.meta
Normal file
3
Assets/Scripts/AI/FSM.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e412c313c4bf462083c745b6c8b124ac
|
||||
timeCreated: 1532858449
|
||||
290
Assets/Scripts/AI/FSM/IdleSystem.cs
Normal file
290
Assets/Scripts/AI/FSM/IdleSystem.cs
Normal file
|
|
@ -0,0 +1,290 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Collections;
|
||||
using Unity.Entities;
|
||||
|
||||
namespace AI.FSM
|
||||
{
|
||||
public class IdleSystem : ComponentSystem
|
||||
{
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
var toRemove = new NativeList<KeyValuePair<Entity, ComponentType>>(8, Allocator.Temp);
|
||||
var toAdd = new List<ValueTuple<Entity, NativeArray<GoapActionReference>>>();
|
||||
var actionValidation = GetComponentDataFromEntity<GoapActionValidation>();
|
||||
|
||||
Entities.ForEach(
|
||||
(Entity entity, GoapAgentData agent, ref IdleInitializedState idleInitialized) =>
|
||||
{
|
||||
var hasValidatingFlag = false;
|
||||
for (var j = 0; j < agent.Actions.Count; j++)
|
||||
{
|
||||
if (EntityManager.Exists(agent.Actions[j]) &&
|
||||
actionValidation.Exists(agent.Actions[j]) &&
|
||||
actionValidation[agent.Actions[j]].Validating)
|
||||
{
|
||||
hasValidatingFlag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasValidatingFlag)
|
||||
{
|
||||
//remove validation component as all elements have been validated
|
||||
agent.Actions.ForEach(PostUpdateCommands.RemoveComponent<GoapActionValidation>);
|
||||
|
||||
var usableActions = new List<GoapActionReference>(agent.Actions.Count);
|
||||
for (var j = 0; j < agent.Actions.Count; j++)
|
||||
{
|
||||
if (actionValidation[agent.Actions[j]].Valid)
|
||||
{
|
||||
usableActions.Add(new GoapActionReference { Entity = agent.Actions[j] });
|
||||
}
|
||||
}
|
||||
|
||||
var leaves = new List<Node>();
|
||||
var worldState = new HashSet<(GoapKeys, object)>(agent.States);
|
||||
var goal = new HashSet<(GoapKeys, object)>(agent.Goals);
|
||||
var start = new Node(null, 0, worldState, new GoapActionReference { Entity = Entity.Null });
|
||||
var success = buildGraph(start, leaves, usableActions, goal);
|
||||
|
||||
if (!success)
|
||||
{
|
||||
//no valid action path, reset to idle
|
||||
PostUpdateCommands.RemoveComponent<IdleInitializedState>(entity);
|
||||
PostUpdateCommands.AddComponent(entity, new IdleState());
|
||||
return;
|
||||
}
|
||||
|
||||
Node cheapest = null;
|
||||
foreach (var leaf in leaves)
|
||||
{
|
||||
if (cheapest == null)
|
||||
{
|
||||
cheapest = leaf;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (leaf.RunningCost < cheapest.RunningCost)
|
||||
{
|
||||
cheapest = leaf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get its node and work back through the parents
|
||||
var result = new List<GoapActionReference>();
|
||||
var n = cheapest;
|
||||
while (n != null)
|
||||
{
|
||||
if (n.Action.Entity != Entity.Null)
|
||||
{
|
||||
result.Insert(0, n.Action); // insert the action in the front
|
||||
}
|
||||
n = n.Parent;
|
||||
}
|
||||
|
||||
//start processing the action chain
|
||||
PostUpdateCommands.RemoveComponent<IdleInitializedState>(entity);
|
||||
PostUpdateCommands.AddComponent(entity, new PerformActionState());
|
||||
var ar = new NativeArray<GoapActionReference>(result.Count, Allocator.Temp);
|
||||
for (var j = 0; j < result.Count; j++)
|
||||
{
|
||||
if (j == 0)
|
||||
{
|
||||
PostUpdateCommands.AddComponent(result[j].Entity, new GoapActiveAction());
|
||||
}
|
||||
ar[j] = result[j];
|
||||
}
|
||||
|
||||
toAdd.Add(new ValueTuple<Entity, NativeArray<GoapActionReference>>(entity, ar));
|
||||
}
|
||||
});
|
||||
|
||||
Entities.ForEach(
|
||||
(Entity agentEntity, GoapAgentData agent, ref IdleState idleState) =>
|
||||
{
|
||||
for (var j = 0; j < agent.Actions.Count; j++)
|
||||
{
|
||||
var actionEntity = agent.Actions[j];
|
||||
//only add validation if none is present
|
||||
if (!actionValidation.Exists(actionEntity))
|
||||
{
|
||||
var validationData = new GoapActionValidation { Validating = true };
|
||||
PostUpdateCommands.AddComponent(actionEntity, validationData);
|
||||
//reset the action
|
||||
PostUpdateCommands.SetComponent(actionEntity, new GoapAction());
|
||||
if (EntityManager.HasComponent<GoapActiveAction>(actionEntity))
|
||||
{
|
||||
PostUpdateCommands.RemoveComponent<GoapActiveAction>(actionEntity);
|
||||
}
|
||||
if (EntityManager.HasComponent<GoapProcessingAction>(actionEntity))
|
||||
{
|
||||
PostUpdateCommands.RemoveComponent<GoapProcessingAction>(actionEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PostUpdateCommands.RemoveComponent<IdleState>(agentEntity);
|
||||
PostUpdateCommands.AddComponent(agentEntity, new IdleInitializedState());
|
||||
});
|
||||
|
||||
for (var i = 0; i < toRemove.Length; i++)
|
||||
{
|
||||
EntityManager.RemoveComponent(toRemove[i].Key, toRemove[i].Value);
|
||||
}
|
||||
|
||||
for (var i = 0; i < toAdd.Count; i++)
|
||||
{
|
||||
EntityManager.AddBuffer<GoapActionReference>(toAdd[i].Item1);
|
||||
var ar = EntityManager.GetBuffer<GoapActionReference>(toAdd[i].Item1);
|
||||
ar.CopyFrom(toAdd[i].Item2);
|
||||
toAdd[i].Item2.Dispose();
|
||||
}
|
||||
|
||||
toRemove.Dispose();
|
||||
}
|
||||
|
||||
private bool buildGraph(Node parent, List<Node> leaves, List<GoapActionReference> usableActions, HashSet<(GoapKeys, object)> goal)
|
||||
{
|
||||
var foundOne = false;
|
||||
|
||||
// go through each action available at this node and see if we can use it here
|
||||
for (var i = 0; i < usableActions.Count; i++)
|
||||
{
|
||||
var actionReference = usableActions[i];
|
||||
var action = EntityManager.GetSharedComponentData<GoapSharedAction>(actionReference.Entity);
|
||||
|
||||
// if the parent state has the conditions for this action's preconditions, we can use it here
|
||||
if (inState(action.Preconditions, parent.State))
|
||||
{
|
||||
// apply the action's effects to the parent state
|
||||
var currentState = populateState(parent.State, action.Effects);
|
||||
//Debug.Log(GoapAgent.prettyPrint(currentState));
|
||||
var node = new Node(parent, parent.RunningCost + action.Cost, currentState, actionReference);
|
||||
|
||||
if (inState(goal, currentState))
|
||||
{
|
||||
// we found a solution!
|
||||
leaves.Add(node);
|
||||
foundOne = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// not at a solution yet, so test all the remaining actions and branch out the tree
|
||||
var subset = actionSubset(usableActions, actionReference);
|
||||
var found = buildGraph(node, leaves, subset, goal);
|
||||
if (found)
|
||||
{
|
||||
foundOne = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return foundOne;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a subset of the actions excluding the removeMe one. Creates a new set.
|
||||
*/
|
||||
private List<GoapActionReference> actionSubset(List<GoapActionReference> actions, GoapActionReference removeMe)
|
||||
{
|
||||
var subset = new List<GoapActionReference>();
|
||||
foreach (var a in actions)
|
||||
{
|
||||
if (!a.Equals(removeMe))
|
||||
{
|
||||
subset.Add(a);
|
||||
}
|
||||
}
|
||||
return subset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that all items in 'test' are in 'state'. If just one does not match or is not there
|
||||
* then this returns false.
|
||||
*/
|
||||
private bool inState(HashSet<(GoapKeys, object)> test, HashSet<(GoapKeys, object)> state)
|
||||
{
|
||||
var allMatch = true;
|
||||
foreach (var t in test)
|
||||
{
|
||||
var match = false;
|
||||
foreach (var s in state)
|
||||
{
|
||||
if (s.Equals(t))
|
||||
{
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!match)
|
||||
{
|
||||
allMatch = false;
|
||||
}
|
||||
}
|
||||
|
||||
return allMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the stateChange to the currentState
|
||||
*/
|
||||
private HashSet<(GoapKeys, object)> populateState(HashSet<(GoapKeys, object)> currentState, HashSet<(GoapKeys, object)> stateChange)
|
||||
{
|
||||
var state = new HashSet<(GoapKeys, object)>();
|
||||
// copy the KVPs over as new objects
|
||||
foreach (var s in currentState)
|
||||
{
|
||||
state.Add((s.Item1, s.Item2));
|
||||
}
|
||||
|
||||
foreach (var change in stateChange)
|
||||
{
|
||||
// if the key exists in the current state, update the Value
|
||||
var exists = false;
|
||||
|
||||
foreach (var s in state)
|
||||
{
|
||||
if (s.Equals(change))
|
||||
{
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (exists)
|
||||
{
|
||||
state.RemoveWhere(kvp => kvp.Item1.Equals(change.Item1));
|
||||
var updated = (change.Item1, change.Item2);
|
||||
state.Add(updated);
|
||||
}
|
||||
// if it does not exist in the current state, add it
|
||||
else
|
||||
{
|
||||
state.Add((change.Item1, change.Item2));
|
||||
}
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
private class Node
|
||||
{
|
||||
public readonly GoapActionReference Action;
|
||||
public readonly Node Parent;
|
||||
public readonly float RunningCost;
|
||||
public readonly HashSet<(GoapKeys, object)> State;
|
||||
|
||||
public Node(Node parent, float runningCost, HashSet<(GoapKeys, object)> state, GoapActionReference action)
|
||||
{
|
||||
Parent = parent;
|
||||
RunningCost = runningCost;
|
||||
State = state;
|
||||
Action = action;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/FSM/IdleSystem.cs.meta
Normal file
3
Assets/Scripts/AI/FSM/IdleSystem.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ec32660a0628497583d8fa68b96a6045
|
||||
timeCreated: 1532865956
|
||||
111
Assets/Scripts/AI/FSM/MoveStateSystem.cs
Normal file
111
Assets/Scripts/AI/FSM/MoveStateSystem.cs
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
using DefaultNamespace;
|
||||
using DefaultNamespace.Navigation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
using Zenject;
|
||||
|
||||
namespace AI.FSM
|
||||
{
|
||||
public class MoveStateSystem : InjectableComponentSystem
|
||||
{
|
||||
[Serializable]
|
||||
public class Settings
|
||||
{
|
||||
public float AirControl;
|
||||
public float DefaultReachTime;
|
||||
public float JumpMinHeight;
|
||||
public float MaxForce;
|
||||
public float MinTargetDistance;
|
||||
public float MoveForce;
|
||||
public Vector3 MovePidParams;
|
||||
public float NodeMinDistance;
|
||||
public float RepathCooldown;
|
||||
public float ViewDistance;
|
||||
public LayerMask VisibilityLayerMask;
|
||||
}
|
||||
|
||||
[Inject] private readonly Settings settings;
|
||||
|
||||
protected override void OnSystemUpdate()
|
||||
{
|
||||
var timeDelta = Time.DeltaTime;
|
||||
var typesToRemove = new List<ValueTuple<Entity, ComponentType>>();
|
||||
|
||||
Entities.ForEach(
|
||||
(
|
||||
Entity entity,
|
||||
Rigidbody2D rigidBody,
|
||||
ref ActorNpcData npc,
|
||||
ref MoveState move,
|
||||
ref ActorData actor,
|
||||
ref ActorAnimationData animation,
|
||||
ref NavigationAgentData navigationAgent) =>
|
||||
{
|
||||
var actions = EntityManager.GetBuffer<GoapActionReference>(entity);
|
||||
|
||||
for (var j = 0; j < actions.Length; j++)
|
||||
{
|
||||
var actionEntity = actions[j].Entity;
|
||||
if (EntityManager.Exists(actionEntity) &&
|
||||
EntityManager.TryGetComponentData<GoapAction>(actionEntity, out var action) &&
|
||||
EntityManager.TryGetComponentData<GoapActiveAction>(actionEntity, out var active) &&
|
||||
EntityManager.TryGetSharedComponentData<GoapSharedAction>(actionEntity, out var sharedAction))
|
||||
{
|
||||
if (sharedAction.RequiresInRange && !EntityManager.Exists(action.Target))
|
||||
{
|
||||
//Action requires a target but has none. Planning failed.
|
||||
ReturnToPlanning(typesToRemove, entity, actions);
|
||||
continue;
|
||||
}
|
||||
|
||||
var targetTransform = EntityManager.GetComponentObject<Transform>(action.Target);
|
||||
|
||||
var distanceToTarget = Vector2.Distance(targetTransform.position, rigidBody.position);
|
||||
|
||||
if (distanceToTarget <= settings.MinTargetDistance && npc.JumpingTimer <= 0 && actor.Grounded && navigationAgent.Grounded)
|
||||
{
|
||||
active.InRange = true;
|
||||
PostUpdateCommands.SetComponent(actionEntity, active);
|
||||
PostUpdateCommands.RemoveComponent<MoveState>(entity);
|
||||
PostUpdateCommands.AddComponent(entity, new PerformActionState());
|
||||
navigationAgent.destination = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
navigationAgent.destination = (Vector2)targetTransform.position;
|
||||
}
|
||||
|
||||
animation.AttackSpeed = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
foreach (var tuple in typesToRemove)
|
||||
{
|
||||
EntityManager.RemoveComponent(tuple.Item1, tuple.Item2);
|
||||
}
|
||||
}
|
||||
|
||||
private void ReturnToPlanning(
|
||||
IList<ValueTuple<Entity, ComponentType>> typesToRemove,
|
||||
Entity entity,
|
||||
DynamicBuffer<GoapActionReference> actions)
|
||||
{
|
||||
PostUpdateCommands.RemoveComponent<MoveState>(entity);
|
||||
PostUpdateCommands.AddComponent(entity, new IdleState());
|
||||
RemoveCurrentActions(typesToRemove, entity, actions);
|
||||
}
|
||||
|
||||
private void RemoveCurrentActions(
|
||||
IList<ValueTuple<Entity, ComponentType>> typesToRemove,
|
||||
Entity entity,
|
||||
DynamicBuffer<GoapActionReference> actions)
|
||||
{
|
||||
var bufferType = ComponentType.ReadWrite<GoapActionReference>();
|
||||
typesToRemove.Add(new ValueTuple<Entity, ComponentType>(entity, bufferType));
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/FSM/MoveStateSystem.cs.meta
Normal file
3
Assets/Scripts/AI/FSM/MoveStateSystem.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 964301ce9f5d410cb3b2dabccdb0ec6d
|
||||
timeCreated: 1532858466
|
||||
116
Assets/Scripts/AI/FSM/PerformActionStateSystem.cs
Normal file
116
Assets/Scripts/AI/FSM/PerformActionStateSystem.cs
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
using DefaultNamespace;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Collections;
|
||||
using Unity.Entities;
|
||||
|
||||
namespace AI.FSM
|
||||
{
|
||||
[UpdateInGroup(typeof(SimulationSystemGroup)), UpdateAfter(typeof(EventRemovalSystem))]
|
||||
public class PerformActionStateSystem : ComponentSystem
|
||||
{
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
using (var typesToRemove = new NativeList<KeyValuePair<Entity, ComponentType>>(8, Allocator.Temp))
|
||||
{
|
||||
Entities.ForEach(
|
||||
(Entity entity, GoapAgentData agent, ref PerformActionState performAction) =>
|
||||
{
|
||||
var actions = EntityManager.GetBuffer<GoapActionReference>(entity);
|
||||
|
||||
var hasActions = actions.Length > 0;
|
||||
|
||||
if (!hasActions)
|
||||
{
|
||||
//finished actions
|
||||
PostUpdateCommands.RemoveComponent<PerformActionState>(entity);
|
||||
PostUpdateCommands.AddComponent(entity, new IdleState());
|
||||
ClearCurrentActions(typesToRemove, entity, actions);
|
||||
return;
|
||||
}
|
||||
|
||||
for (var j = 0; j < actions.Length; j++)
|
||||
{
|
||||
var actionEntity = actions[j].Entity;
|
||||
if (EntityManager.Exists(actionEntity) &&
|
||||
EntityManager.TryGetComponentData<GoapActiveAction>(actionEntity, out var active) &&
|
||||
EntityManager.TryGetSharedComponentData<GoapSharedAction>(actionEntity, out var action))
|
||||
{
|
||||
if (!EntityManager.HasComponent<GoapProcessingAction>(actionEntity))
|
||||
{
|
||||
PostUpdateCommands.AddComponent(actionEntity, new GoapProcessingAction());
|
||||
}
|
||||
|
||||
if (active.Done)
|
||||
{
|
||||
var nextActionIndex = j + 1;
|
||||
hasActions = nextActionIndex < actions.Length;
|
||||
if (hasActions)
|
||||
{
|
||||
//make next tha action active
|
||||
PostUpdateCommands.AddComponent(actions[nextActionIndex].Entity, new GoapActiveAction());
|
||||
//remove active and processing from current action
|
||||
PostUpdateCommands.RemoveComponent<GoapActiveAction>(actionEntity);
|
||||
PostUpdateCommands.RemoveComponent<GoapProcessingAction>(actionEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
//finished actions
|
||||
PostUpdateCommands.RemoveComponent<PerformActionState>(entity);
|
||||
PostUpdateCommands.AddComponent(entity, new IdleState());
|
||||
ClearCurrentActions(typesToRemove, entity, actions);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (action.RequiresInRange && !active.InRange)
|
||||
{
|
||||
// we need to move there first
|
||||
PostUpdateCommands.RemoveComponent<PerformActionState>(entity);
|
||||
PostUpdateCommands.RemoveComponent<GoapProcessingAction>(actionEntity);
|
||||
PostUpdateCommands.AddComponent(entity, new MoveState());
|
||||
break;
|
||||
}
|
||||
|
||||
if (active.Fail)
|
||||
{
|
||||
// action failed, we need to plan again
|
||||
PostUpdateCommands.RemoveComponent<PerformActionState>(entity);
|
||||
PostUpdateCommands.AddComponent(entity, new IdleState());
|
||||
ClearCurrentActions(typesToRemove, entity, actions);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (var i = 0; i < typesToRemove.Length; i++)
|
||||
{
|
||||
EntityManager.RemoveComponent(typesToRemove[i].Key, typesToRemove[i].Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearCurrentActions(
|
||||
NativeList<KeyValuePair<Entity, ComponentType>> typesToRemove,
|
||||
Entity entity,
|
||||
DynamicBuffer<GoapActionReference> actions)
|
||||
{
|
||||
var componentType = ComponentType.ReadWrite<GoapActionReference>();
|
||||
typesToRemove.Add(new KeyValuePair<Entity, ComponentType>(entity, componentType));
|
||||
|
||||
//remove processing or active tags
|
||||
for (var i = 0; i < actions.Length; i++)
|
||||
{
|
||||
if (EntityManager.HasComponent<GoapActiveAction>(actions[i].Entity))
|
||||
{
|
||||
PostUpdateCommands.RemoveComponent<GoapActiveAction>(actions[i].Entity);
|
||||
}
|
||||
if (EntityManager.HasComponent<GoapProcessingAction>(actions[i].Entity))
|
||||
{
|
||||
PostUpdateCommands.RemoveComponent<GoapProcessingAction>(actions[i].Entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/FSM/PerformActionStateSystem.cs.meta
Normal file
3
Assets/Scripts/AI/FSM/PerformActionStateSystem.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c8cc368d88ea43ffb12189f5b626c050
|
||||
timeCreated: 1532861738
|
||||
24
Assets/Scripts/AI/FSM/States.cs
Normal file
24
Assets/Scripts/AI/FSM/States.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
using Unity.Entities;
|
||||
|
||||
namespace AI.FSM
|
||||
{
|
||||
public struct FsmState : IComponentData
|
||||
{
|
||||
}
|
||||
|
||||
public struct MoveState : IComponentData
|
||||
{
|
||||
}
|
||||
|
||||
public struct IdleState : IComponentData
|
||||
{
|
||||
}
|
||||
|
||||
public struct IdleInitializedState : IComponentData
|
||||
{
|
||||
}
|
||||
|
||||
public struct PerformActionState : IComponentData
|
||||
{
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/FSM/States.cs.meta
Normal file
3
Assets/Scripts/AI/FSM/States.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9237a4be0aef4fa5b6b7bc50b118d303
|
||||
timeCreated: 1532858500
|
||||
59
Assets/Scripts/AI/FindTargetPlayerGoapAction.cs
Normal file
59
Assets/Scripts/AI/FindTargetPlayerGoapAction.cs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
using DefaultNamespace;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
public struct FindTargetPlayerGoapAction : IComponentData
|
||||
{
|
||||
}
|
||||
|
||||
public class FindTargetPlayerGoapActionSystem : GoapActionSystem<FindTargetPlayerGoapAction>
|
||||
{
|
||||
protected override void OnInitialize(ref FindTargetPlayerGoapAction action, ref GoapSharedAction goapSharedAction)
|
||||
{
|
||||
goapSharedAction.Cost = 10;
|
||||
goapSharedAction.Effects.Add((GoapKeys.HasTarget, true));
|
||||
}
|
||||
|
||||
protected override void OnProcess(
|
||||
ref FindTargetPlayerGoapAction action,
|
||||
ref GoapSharedAction goapSharedAction,
|
||||
GoapAction goapAction,
|
||||
GoapActionActor actor,
|
||||
ref GoapActiveAction active)
|
||||
{
|
||||
EntityManager.SetComponentData(actor.Actor, new ActorTargetData { Target = goapAction.Target });
|
||||
active.Done = true;
|
||||
}
|
||||
|
||||
protected override bool OnValidate(
|
||||
ref FindTargetPlayerGoapAction action,
|
||||
ref GoapSharedAction goapSharedAction,
|
||||
ref GoapAction goapAction,
|
||||
GoapActionActor actor)
|
||||
{
|
||||
if (!EntityManager.HasComponents<Rigidbody2D, ActorTargetData>(actor.Actor))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var closestDist = float.MaxValue;
|
||||
var actorRigidBody = EntityManager.GetComponentObject<Rigidbody2D>(actor.Actor);
|
||||
var playerEntity = Entity.Null;
|
||||
|
||||
Entities.ForEach(
|
||||
(Entity entity, Rigidbody2D rigidbody, ref PlayerData playerData) =>
|
||||
{
|
||||
var d = Vector2.SqrMagnitude(actorRigidBody.position - rigidbody.position);
|
||||
if (d < closestDist)
|
||||
{
|
||||
closestDist = d;
|
||||
playerEntity = entity;
|
||||
}
|
||||
});
|
||||
|
||||
return playerEntity != Entity.Null;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/FindTargetPlayerGoapAction.cs.meta
Normal file
3
Assets/Scripts/AI/FindTargetPlayerGoapAction.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7a6760f22510409881c278b1c5c07284
|
||||
timeCreated: 1533316257
|
||||
9
Assets/Scripts/AI/GoapAction.cs
Normal file
9
Assets/Scripts/AI/GoapAction.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
using Unity.Entities;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
public struct GoapAction : IComponentData
|
||||
{
|
||||
public Entity Target;
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/GoapAction.cs.meta
Normal file
3
Assets/Scripts/AI/GoapAction.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7b70258323e9451985a12955bfda4f63
|
||||
timeCreated: 1532986154
|
||||
9
Assets/Scripts/AI/GoapActionActor.cs
Normal file
9
Assets/Scripts/AI/GoapActionActor.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
using Unity.Entities;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
public struct GoapActionActor : IComponentData
|
||||
{
|
||||
public Entity Actor;
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/GoapActionActor.cs.meta
Normal file
3
Assets/Scripts/AI/GoapActionActor.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ebd976f080014bb0970004151e44170d
|
||||
timeCreated: 1532986264
|
||||
21
Assets/Scripts/AI/GoapActionDeleteSystem.cs
Normal file
21
Assets/Scripts/AI/GoapActionDeleteSystem.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
using DefaultNamespace;
|
||||
using Unity.Entities;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
[UpdateInGroup(typeof(LateSimulationSystemGroup)), UpdateAfter(typeof(EntityDeathSystem))]
|
||||
public class GoapActionDeleteSystem : ComponentSystem
|
||||
{
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
Entities.ForEach(
|
||||
(Entity entity, ref GoapActionActor action) =>
|
||||
{
|
||||
if (!EntityManager.Exists(action.Actor))
|
||||
{
|
||||
PostUpdateCommands.DestroyEntity(entity);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/GoapActionDeleteSystem.cs.meta
Normal file
3
Assets/Scripts/AI/GoapActionDeleteSystem.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: eead5bdbdf5740959e21183214b6419b
|
||||
timeCreated: 1532980250
|
||||
9
Assets/Scripts/AI/GoapActionEntry.cs
Normal file
9
Assets/Scripts/AI/GoapActionEntry.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
using Unity.Entities;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
public struct GoapActionEntry
|
||||
{
|
||||
public ComponentType ActionType;
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/GoapActionEntry.cs.meta
Normal file
3
Assets/Scripts/AI/GoapActionEntry.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2a688d1d7e1b4bd79b6856f9bf061fb6
|
||||
timeCreated: 1532893857
|
||||
9
Assets/Scripts/AI/GoapActionReference.cs
Normal file
9
Assets/Scripts/AI/GoapActionReference.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
using Unity.Entities;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
public struct GoapActionReference : IBufferElementData
|
||||
{
|
||||
public Entity Entity;
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/GoapActionReference.cs.meta
Normal file
3
Assets/Scripts/AI/GoapActionReference.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5df3d618587a4c0fa27d5f0bc5ad3673
|
||||
timeCreated: 1532895480
|
||||
132
Assets/Scripts/AI/GoapActionSystem.cs
Normal file
132
Assets/Scripts/AI/GoapActionSystem.cs
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
using System.Collections.Generic;
|
||||
using Unity.Entities;
|
||||
using Zenject;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
public abstract class GoapActionInjectableSystem<T> : GoapActionSystem<T> where T : struct, IComponentData
|
||||
{
|
||||
private bool injected;
|
||||
|
||||
[Inject]
|
||||
private void OnInject()
|
||||
{
|
||||
injected = true;
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
if (!injected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
base.OnUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class GoapActionSystem<T> : ComponentSystem where T : struct, IComponentData
|
||||
{
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
OnBeforeUpdate();
|
||||
|
||||
Entities.WithNone<GoapSharedAction>()
|
||||
.ForEach(
|
||||
(Entity entity, ref T action) =>
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EntityManager.SetName(entity, action.GetType().Name);
|
||||
#endif
|
||||
OnInitializeInternal(entity, ref action);
|
||||
});
|
||||
|
||||
Entities.ForEach(
|
||||
(
|
||||
Entity entity,
|
||||
GoapSharedAction goapSharedAction,
|
||||
ref GoapActiveAction activeAction,
|
||||
ref GoapProcessingAction processing,
|
||||
ref T action,
|
||||
ref GoapAction goapAction,
|
||||
ref GoapActionActor actor) =>
|
||||
{
|
||||
OnProcessInternal(entity, goapSharedAction, ref activeAction, ref processing, ref action, ref goapAction, ref actor);
|
||||
});
|
||||
|
||||
Entities.ForEach(
|
||||
(
|
||||
Entity entity,
|
||||
GoapSharedAction goapSharedAction,
|
||||
ref GoapActionValidation validation,
|
||||
ref GoapAction goapAction,
|
||||
ref T action,
|
||||
ref GoapActionActor actor) =>
|
||||
{
|
||||
OnValidateInternal(entity, goapSharedAction, ref validation, ref goapAction, ref action, ref actor);
|
||||
});
|
||||
|
||||
OnAfterUpdate();
|
||||
}
|
||||
|
||||
private void OnInitializeInternal(Entity entity, ref T action)
|
||||
{
|
||||
var a = new GoapSharedAction { Effects = new HashSet<(GoapKeys, object)>(), Preconditions = new HashSet<(GoapKeys, object)>() };
|
||||
OnInitialize(ref action, ref a);
|
||||
|
||||
PostUpdateCommands.AddSharedComponent(entity, a);
|
||||
}
|
||||
|
||||
private void OnProcessInternal(
|
||||
Entity entity,
|
||||
GoapSharedAction goapSharedAction,
|
||||
ref GoapActiveAction active,
|
||||
ref GoapProcessingAction processing,
|
||||
ref T action,
|
||||
ref GoapAction goapAction,
|
||||
ref GoapActionActor actor)
|
||||
{
|
||||
if (EntityManager.Exists(actor.Actor))
|
||||
{
|
||||
OnProcess(ref action, ref goapSharedAction, goapAction, actor, ref active);
|
||||
}
|
||||
|
||||
PostUpdateCommands.SetSharedComponent(entity, goapSharedAction);
|
||||
}
|
||||
|
||||
private void OnValidateInternal(
|
||||
Entity entity,
|
||||
GoapSharedAction goapSharedAction,
|
||||
ref GoapActionValidation validation,
|
||||
ref GoapAction goapAction,
|
||||
ref T action,
|
||||
ref GoapActionActor actor)
|
||||
{
|
||||
if (validation.Validating)
|
||||
{
|
||||
validation.Valid = EntityManager.Exists(actor.Actor) && OnValidate(ref action, ref goapSharedAction, ref goapAction, actor);
|
||||
validation.Validating = false;
|
||||
}
|
||||
|
||||
PostUpdateCommands.SetSharedComponent(entity, goapSharedAction);
|
||||
}
|
||||
|
||||
protected abstract void OnInitialize(ref T action, ref GoapSharedAction goapSharedAction);
|
||||
|
||||
protected abstract void OnProcess(
|
||||
ref T action,
|
||||
ref GoapSharedAction goapSharedAction,
|
||||
GoapAction goapAction,
|
||||
GoapActionActor actor,
|
||||
ref GoapActiveAction active);
|
||||
|
||||
protected abstract bool OnValidate(ref T action, ref GoapSharedAction goapSharedAction, ref GoapAction goapAction, GoapActionActor actor);
|
||||
|
||||
protected virtual void OnBeforeUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void OnAfterUpdate()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/GoapActionSystem.cs.meta
Normal file
3
Assets/Scripts/AI/GoapActionSystem.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c347eb66e6ae46839572d75aecbc62b9
|
||||
timeCreated: 1532972122
|
||||
11
Assets/Scripts/AI/GoapActionValidation.cs
Normal file
11
Assets/Scripts/AI/GoapActionValidation.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using DefaultNamespace;
|
||||
using Unity.Entities;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
public struct GoapActionValidation : IComponentData
|
||||
{
|
||||
public bool1 Validating;
|
||||
public bool1 Valid;
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/GoapActionValidation.cs.meta
Normal file
3
Assets/Scripts/AI/GoapActionValidation.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d04d5743e54f4b728cc08a7475cb4f0b
|
||||
timeCreated: 1532894851
|
||||
22
Assets/Scripts/AI/GoapActiveAction.cs
Normal file
22
Assets/Scripts/AI/GoapActiveAction.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using DefaultNamespace;
|
||||
using Unity.Entities;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
public struct GoapActiveAction : IComponentData
|
||||
{
|
||||
public bool1 InRange;
|
||||
public bool1 Done;
|
||||
public bool1 Fail;
|
||||
|
||||
public void MarkFailed()
|
||||
{
|
||||
Fail = true;
|
||||
}
|
||||
|
||||
public void MarkDone()
|
||||
{
|
||||
Done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/GoapActiveAction.cs.meta
Normal file
3
Assets/Scripts/AI/GoapActiveAction.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c428527a44b14269a972e2a1a7b71f22
|
||||
timeCreated: 1532897400
|
||||
53
Assets/Scripts/AI/GoapAgentDataComponent.cs
Normal file
53
Assets/Scripts/AI/GoapAgentDataComponent.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
public struct GoapAgentData : ISharedComponentData, IEquatable<GoapAgentData>
|
||||
{
|
||||
public List<Entity> Actions;
|
||||
public HashSet<(GoapKeys key, object value)> Goals;
|
||||
public HashSet<(GoapKeys key, object value)> States;
|
||||
|
||||
public bool Equals(GoapAgentData other)
|
||||
{
|
||||
return Equals(Actions, other.Actions) && Equals(Goals, other.Goals) && Equals(States, other.States);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
var hashCode = Actions != null ? Actions.GetHashCode() : 0;
|
||||
hashCode = (hashCode * 397) ^ (Goals != null ? Goals.GetHashCode() : 0);
|
||||
hashCode = (hashCode * 397) ^ (States != null ? States.GetHashCode() : 0);
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class GoapAgentDataComponent : MonoBehaviour, IConvertGameObjectToEntity
|
||||
{
|
||||
public string[] Types;
|
||||
|
||||
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
|
||||
{
|
||||
var value = new GoapAgentData
|
||||
{
|
||||
Goals = new HashSet<(GoapKeys, object)>(), States = new HashSet<(GoapKeys, object)>(), Actions = new List<Entity>()
|
||||
};
|
||||
foreach (var type in Types)
|
||||
{
|
||||
var e = dstManager.CreateEntity(
|
||||
ComponentType.FromTypeIndex(TypeManager.GetTypeIndex(Type.GetType(type, true))),
|
||||
ComponentType.ReadWrite<GoapAction>());
|
||||
dstManager.AddComponentData(e, new GoapActionActor { Actor = entity });
|
||||
value.Actions.Add(e);
|
||||
}
|
||||
|
||||
dstManager.AddSharedComponentData(entity, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/GoapAgentDataComponent.cs.meta
Normal file
3
Assets/Scripts/AI/GoapAgentDataComponent.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c1e89ea26d1549da91c44ae3d4f71c54
|
||||
timeCreated: 1532858159
|
||||
30
Assets/Scripts/AI/GoapInitializationSystem.cs
Normal file
30
Assets/Scripts/AI/GoapInitializationSystem.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
using AI.FSM;
|
||||
using Unity.Entities;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
[UpdateInGroup(typeof(InitializationSystemGroup))]
|
||||
public class GoapInitializationSystem : ComponentSystem
|
||||
{
|
||||
private EntityQuery query;
|
||||
|
||||
protected override void OnCreate()
|
||||
{
|
||||
query = GetEntityQuery(ComponentType.Exclude<FsmState>(), ComponentType.ReadOnly<GoapAgentData>());
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
Entities.With(query)
|
||||
.ForEach(
|
||||
(Entity entity, GoapAgentData agent) =>
|
||||
{
|
||||
if (agent.Actions != null)
|
||||
{
|
||||
PostUpdateCommands.AddComponent(entity, new FsmState());
|
||||
PostUpdateCommands.AddComponent(entity, new IdleState());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/GoapInitializationSystem.cs.meta
Normal file
3
Assets/Scripts/AI/GoapInitializationSystem.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ddf6596e115c492fb3a93e81af8066c6
|
||||
timeCreated: 1532867416
|
||||
4
Assets/Scripts/AI/GoapKeys.cs
Normal file
4
Assets/Scripts/AI/GoapKeys.cs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
namespace AI
|
||||
{
|
||||
public enum GoapKeys { Attacks, SeesTarget, HasTarget, HasAmmo }
|
||||
}
|
||||
3
Assets/Scripts/AI/GoapKeys.cs.meta
Normal file
3
Assets/Scripts/AI/GoapKeys.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3ec34de789d14324a4382835bd4d5aa6
|
||||
timeCreated: 1533238619
|
||||
8
Assets/Scripts/AI/GoapProcessingAction.cs
Normal file
8
Assets/Scripts/AI/GoapProcessingAction.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
using Unity.Entities;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
public struct GoapProcessingAction : IComponentData
|
||||
{
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/GoapProcessingAction.cs.meta
Normal file
3
Assets/Scripts/AI/GoapProcessingAction.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4d18a8e45b574bc0a895aa9f553b3ff6
|
||||
timeCreated: 1532901302
|
||||
40
Assets/Scripts/AI/GoapSharedAction.cs
Normal file
40
Assets/Scripts/AI/GoapSharedAction.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
using DefaultNamespace;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Entities;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
public struct GoapSharedAction : ISharedComponentData, IEquatable<GoapSharedAction>
|
||||
{
|
||||
public HashSet<(GoapKeys, object)> Preconditions;
|
||||
public HashSet<(GoapKeys, object)> Effects;
|
||||
public bool1 RequiresInRange;
|
||||
public float Cost;
|
||||
|
||||
public bool Equals(GoapSharedAction other)
|
||||
{
|
||||
return Equals(Preconditions, other.Preconditions) &&
|
||||
Equals(Effects, other.Effects) &&
|
||||
RequiresInRange.Equals(other.RequiresInRange) &&
|
||||
Cost.Equals(other.Cost);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is GoapSharedAction other && Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
var hashCode = Preconditions != null ? Preconditions.GetHashCode() : 0;
|
||||
hashCode = (hashCode * 397) ^ (Effects != null ? Effects.GetHashCode() : 0);
|
||||
hashCode = (hashCode * 397) ^ RequiresInRange.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ Cost.GetHashCode();
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/GoapSharedAction.cs.meta
Normal file
3
Assets/Scripts/AI/GoapSharedAction.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 96be20bf7b8d45988d20749ee7b46f0d
|
||||
timeCreated: 1532858748
|
||||
101
Assets/Scripts/AI/RangeAttackPlayerGoapAction.cs
Normal file
101
Assets/Scripts/AI/RangeAttackPlayerGoapAction.cs
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
using DefaultNamespace;
|
||||
using Events;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
public struct RangeAttackPlayerGoapAction : IComponentData
|
||||
{
|
||||
}
|
||||
|
||||
[UpdateBefore(typeof(WeaponFiringSystem))]
|
||||
public class RangeAttackPlayerGoapActionSystem : GoapActionInjectableSystem<RangeAttackPlayerGoapAction>
|
||||
{
|
||||
protected override void OnInitialize(ref RangeAttackPlayerGoapAction action, ref GoapSharedAction goapSharedAction)
|
||||
{
|
||||
goapSharedAction.Cost = 10;
|
||||
goapSharedAction.Preconditions.Add((GoapKeys.SeesTarget, true));
|
||||
goapSharedAction.Preconditions.Add((GoapKeys.HasAmmo, true));
|
||||
goapSharedAction.Effects.Add(((int)GoapKeys.Attacks, true));
|
||||
}
|
||||
|
||||
protected override void OnProcess(
|
||||
ref RangeAttackPlayerGoapAction action,
|
||||
ref GoapSharedAction goapSharedAction,
|
||||
GoapAction goapAction,
|
||||
GoapActionActor actor,
|
||||
ref GoapActiveAction active)
|
||||
{
|
||||
if (!Validate(actor.Actor))
|
||||
{
|
||||
active.Fail = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var weaponEntity = EntityManager.GetComponentData<ActorWeaponReferenceData>(actor.Actor).Weapon;
|
||||
var weaponData = EntityManager.GetComponentData<WeaponData>(weaponEntity);
|
||||
var npc = EntityManager.GetComponentData<ActorNpcData>(actor.Actor);
|
||||
|
||||
if (npc.AttackCooldown <= 0)
|
||||
{
|
||||
if (weaponData.FireTimer <= 0)
|
||||
{
|
||||
var actorData = EntityManager.GetComponentData<ActorData>(actor.Actor);
|
||||
var layerMask = EntityManager.HasComponent<ActorWeaponData>(actor.Actor)
|
||||
? (int)EntityManager.GetComponentData<ActorWeaponData>(actor.Actor).ProjectileMask
|
||||
: LayerMask.GetMask("Ground");
|
||||
PostUpdateCommands.PostEntityEvent(EntityManager, weaponEntity, new FireWeaponEvent { LayerMask = layerMask });
|
||||
if (EntityManager.TryGetComponentData<ActorAnimationData>(actor.Actor, out var animation))
|
||||
{
|
||||
animation.Triggers |= AnimationTriggerType.Attack;
|
||||
EntityManager.SetComponentData(actor.Actor, animation);
|
||||
}
|
||||
|
||||
active.Done = true;
|
||||
|
||||
EntityManager.SetComponentData(actor.Actor, actorData);
|
||||
EntityManager.SetComponentData(weaponEntity, weaponData);
|
||||
}
|
||||
else
|
||||
{
|
||||
active.Fail = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool OnValidate(
|
||||
ref RangeAttackPlayerGoapAction action,
|
||||
ref GoapSharedAction goapSharedAction,
|
||||
ref GoapAction goapAction,
|
||||
GoapActionActor actor)
|
||||
{
|
||||
if (!Validate(actor.Actor))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!EntityManager.Exists(EntityManager.GetComponentData<ActorWeaponReferenceData>(actor.Actor).Weapon) ||
|
||||
!EntityManager.HasComponent<WeaponData>(EntityManager.GetComponentData<ActorWeaponReferenceData>(actor.Actor).Weapon))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var WeaponData = GetComponentDataFromEntity<WeaponData>();
|
||||
var weaponData = WeaponData[actor.Actor];
|
||||
if (weaponData.FireTimer > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
goapSharedAction.Cost = 10f;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool Validate(Entity actor)
|
||||
{
|
||||
return EntityManager.HasComponents<ActorWeaponPropertiesData, ActorWeaponReferenceData, Rigidbody2D, ActorData, ActorNpcData>(actor);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/RangeAttackPlayerGoapAction.cs.meta
Normal file
3
Assets/Scripts/AI/RangeAttackPlayerGoapAction.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2095ab841e3b43068f58ac4db39ddd91
|
||||
timeCreated: 1533238406
|
||||
70
Assets/Scripts/AI/ReloadGoapAction.cs
Normal file
70
Assets/Scripts/AI/ReloadGoapAction.cs
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
using DefaultNamespace;
|
||||
using Events;
|
||||
using System;
|
||||
using Unity.Entities;
|
||||
using Zenject;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
public struct ReloadGoapAction : IComponentData
|
||||
{
|
||||
}
|
||||
|
||||
public class ReloadGoapActionSystem : GoapActionSystem<ReloadGoapAction>
|
||||
{
|
||||
[Serializable]
|
||||
public class Settings
|
||||
{
|
||||
public float ReloadAttackCooldown;
|
||||
}
|
||||
|
||||
[Inject] private readonly Settings settings;
|
||||
|
||||
protected override void OnInitialize(ref ReloadGoapAction action, ref GoapSharedAction goapSharedAction)
|
||||
{
|
||||
goapSharedAction.Effects.Add((GoapKeys.HasAmmo, true));
|
||||
goapSharedAction.Cost = 10;
|
||||
}
|
||||
|
||||
protected override void OnProcess(
|
||||
ref ReloadGoapAction action,
|
||||
ref GoapSharedAction goapSharedAction,
|
||||
GoapAction goapAction,
|
||||
GoapActionActor actor,
|
||||
ref GoapActiveAction active)
|
||||
{
|
||||
var weaponEntity = EntityManager.GetComponentData<ActorWeaponReferenceData>(actor.Actor).Weapon;
|
||||
if (!EntityManager.HasComponent<ReloadEvent>(weaponEntity))
|
||||
{
|
||||
active.MarkDone();
|
||||
}
|
||||
else
|
||||
{
|
||||
PostUpdateCommands.AddComponent(actor.Actor, new ReloadEvent());
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool OnValidate(
|
||||
ref ReloadGoapAction action,
|
||||
ref GoapSharedAction goapSharedAction,
|
||||
ref GoapAction goapAction,
|
||||
GoapActionActor actor)
|
||||
{
|
||||
if (!EntityManager.HasComponents<ActorWeaponPropertiesData, ActorWeaponReferenceData, ActorNpcData>(actor.Actor))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var weaponEntity = EntityManager.GetComponentData<ActorWeaponReferenceData>(actor.Actor).Weapon;
|
||||
if (!EntityManager.Exists(weaponEntity) || !EntityManager.HasComponent<WeaponData>(weaponEntity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var weaponData = EntityManager.GetComponentData<WeaponData>(weaponEntity);
|
||||
if (weaponData.Ammo <= 0 && weaponData.ReloadTimer <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/ReloadGoapAction.cs.meta
Normal file
3
Assets/Scripts/AI/ReloadGoapAction.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cb4d32816af9488c87f08debc843f58c
|
||||
timeCreated: 1533377513
|
||||
119
Assets/Scripts/AI/SearchTargetGoapAction.cs
Normal file
119
Assets/Scripts/AI/SearchTargetGoapAction.cs
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
using DefaultNamespace;
|
||||
using DefaultNamespace.Navigation;
|
||||
using System;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
using Zenject;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
public struct SearchTargetGoapAction : IComponentData
|
||||
{
|
||||
}
|
||||
|
||||
[UpdateAfter(typeof(ActorGroundCheckSystem))]
|
||||
public class SearchTargetGoapActionSystem : GoapActionInjectableSystem<SearchTargetGoapAction>
|
||||
{
|
||||
[Serializable]
|
||||
public class Settings
|
||||
{
|
||||
public float AttackCooldown;
|
||||
public float RepathCooldown;
|
||||
}
|
||||
|
||||
[Inject] private Settings settings;
|
||||
|
||||
protected override void OnInitialize(ref SearchTargetGoapAction action, ref GoapSharedAction goapSharedAction)
|
||||
{
|
||||
goapSharedAction.Cost = 10;
|
||||
goapSharedAction.Effects.Add((GoapKeys.SeesTarget, true));
|
||||
goapSharedAction.Preconditions.Add((GoapKeys.HasTarget, true));
|
||||
}
|
||||
|
||||
protected override void OnProcess(
|
||||
ref SearchTargetGoapAction action,
|
||||
ref GoapSharedAction goapSharedAction,
|
||||
GoapAction goapAction,
|
||||
GoapActionActor actor,
|
||||
ref GoapActiveAction active)
|
||||
{
|
||||
var actorTarget = EntityManager.GetComponentData<ActorTargetData>(actor.Actor);
|
||||
if (!EntityManager.Exists(actorTarget.Target) || !EntityManager.HasComponent<Rigidbody2D>(actorTarget.Target))
|
||||
{
|
||||
active.Fail = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (EntityManager.HasComponent<ActorData>(actor.Actor))
|
||||
{
|
||||
var actorData = EntityManager.GetComponentData<ActorData>(actor.Actor);
|
||||
if (actorData.Grounded)
|
||||
{
|
||||
var target = EntityManager.GetComponentData<ActorTargetData>(actor.Actor);
|
||||
if (EntityManager.Exists(target.Target) &&
|
||||
EntityManager.TryGetComponentObject<Rigidbody2D>(target.Target, out var targetRigidBody))
|
||||
{
|
||||
var actorRigidBody = EntityManager.GetComponentObject<Rigidbody2D>(actor.Actor);
|
||||
|
||||
var actorCenter = actorRigidBody.position;
|
||||
var targetPosition = targetRigidBody.position;
|
||||
if (EntityManager.HasComponent<AimCenterData>(target.Target))
|
||||
{
|
||||
var aimCenter = EntityManager.GetComponentData<AimCenterData>(target.Target);
|
||||
actorCenter += aimCenter.Offset;
|
||||
targetPosition += aimCenter.Offset;
|
||||
}
|
||||
|
||||
var cast = Physics2D.Raycast(
|
||||
actorCenter,
|
||||
(targetPosition - actorCenter).normalized,
|
||||
float.MaxValue,
|
||||
LayerMask.GetMask("Player", "Ground"));
|
||||
var canSee = targetRigidBody == cast.rigidbody;
|
||||
|
||||
if (EntityManager.TryGetComponentData<NavigationAgentData>(actor.Actor, out var agent))
|
||||
{
|
||||
if (!canSee)
|
||||
{
|
||||
agent.destination = targetRigidBody.position;
|
||||
}
|
||||
else if (agent.Grounded)
|
||||
{
|
||||
agent.destination = null;
|
||||
}
|
||||
EntityManager.SetComponentData(actor.Actor, agent);
|
||||
}
|
||||
|
||||
if (targetRigidBody == cast.rigidbody)
|
||||
{
|
||||
//can see target
|
||||
var npc = EntityManager.GetComponentData<ActorNpcData>(actor.Actor);
|
||||
npc.AttackCooldown += settings.AttackCooldown;
|
||||
active.Done = true;
|
||||
actorData.Aim = cast.point;
|
||||
EntityManager.SetComponentData(actor.Actor, actorData);
|
||||
EntityManager.SetComponentData(actor.Actor, npc);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
active.Fail = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool OnValidate(
|
||||
ref SearchTargetGoapAction action,
|
||||
ref GoapSharedAction goapSharedAction,
|
||||
ref GoapAction goapAction,
|
||||
GoapActionActor actor)
|
||||
{
|
||||
if (!EntityManager.HasComponents<ActorTargetData, Rigidbody2D, ActorNpcData>(actor.Actor))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AI/SearchTargetGoapAction.cs.meta
Normal file
3
Assets/Scripts/AI/SearchTargetGoapAction.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: dbae26fdf33d47658f68d527d1912a7f
|
||||
timeCreated: 1533316096
|
||||
25
Assets/Scripts/ActorBodyParts.cs
Normal file
25
Assets/Scripts/ActorBodyParts.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
public class ActorBodyParts : MonoBehaviour
|
||||
{
|
||||
public Transform Head;
|
||||
public Transform Hip;
|
||||
public SpriteRenderer ItemRenderer;
|
||||
public Transform LeftHandBone;
|
||||
public Transform RightHandBone;
|
||||
public Transform WeaponContainer;
|
||||
public SpriteRenderer EmotionRenderer;
|
||||
|
||||
public float DefaultHeadAngle { get; private set; }
|
||||
|
||||
public float DefaultHipAngle { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
DefaultHeadAngle = Head.transform.localRotation.eulerAngles.z;
|
||||
DefaultHipAngle = Head.transform.localRotation.eulerAngles.z;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/ActorBodyParts.cs.meta
Normal file
3
Assets/Scripts/ActorBodyParts.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 02b776b3d9884275a1428dc649693b26
|
||||
timeCreated: 1531221334
|
||||
9
Assets/Scripts/ActorGrenadeComponent.cs
Normal file
9
Assets/Scripts/ActorGrenadeComponent.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
public class ActorGrenadeComponent : MonoBehaviour
|
||||
{
|
||||
public float Cooldown;
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/ActorGrenadeComponent.cs.meta
Normal file
3
Assets/Scripts/ActorGrenadeComponent.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a4c4dfab380140f88bcdce596b244404
|
||||
timeCreated: 1533644441
|
||||
9
Assets/Scripts/AmmoDropComponent.cs
Normal file
9
Assets/Scripts/AmmoDropComponent.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
public class AmmoDropComponent : MonoBehaviour
|
||||
{
|
||||
public AssetReferenceAmmoPrefab AmmoType;
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AmmoDropComponent.cs.meta
Normal file
3
Assets/Scripts/AmmoDropComponent.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 004a70c56d9844adbf8a3f7d99e1ccb3
|
||||
timeCreated: 1532013399
|
||||
4
Assets/Scripts/AnimationEventType.cs
Normal file
4
Assets/Scripts/AnimationEventType.cs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
namespace DefaultNamespace
|
||||
{
|
||||
public enum AnimationEventType { None, Attack, Pickup }
|
||||
}
|
||||
3
Assets/Scripts/AnimationEventType.cs.meta
Normal file
3
Assets/Scripts/AnimationEventType.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1f74df743ef14745bc1f7127d862d09a
|
||||
timeCreated: 1532182521
|
||||
14
Assets/Scripts/AnimationSoundProxy.cs
Normal file
14
Assets/Scripts/AnimationSoundProxy.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
public class AnimationSoundProxy : MonoBehaviour
|
||||
{
|
||||
public AudioSource AudioSource;
|
||||
|
||||
public void PlayWeaponSound(SoundLibrary library)
|
||||
{
|
||||
library.PlayRandomOneShot(AudioSource);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/AnimationSoundProxy.cs.meta
Normal file
3
Assets/Scripts/AnimationSoundProxy.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8d3aa511d26646efae1ae834a3b5fa15
|
||||
timeCreated: 1531585641
|
||||
10
Assets/Scripts/AnimationTriggerType.cs
Normal file
10
Assets/Scripts/AnimationTriggerType.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
[Serializable, Flags]
|
||||
public enum AnimationTriggerType
|
||||
{
|
||||
None = 0, Attack = 1 << 0, Pickup = 1 << 1, Jump = 1 << 2, Melee = 1 << 3, ItemUse = 1 << 4, JumpObsticle = 1 << 5
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/AnimationTriggerType.cs.meta
Normal file
11
Assets/Scripts/AnimationTriggerType.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9f524cd2ac6658749906dbd5217d85f1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
3
Assets/Scripts/Attributes.meta
Normal file
3
Assets/Scripts/Attributes.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d831d6acd90745908c88508b031cf79e
|
||||
timeCreated: 1532263723
|
||||
9
Assets/Scripts/Attributes/OptionalComponentAttribute.cs
Normal file
9
Assets/Scripts/Attributes/OptionalComponentAttribute.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
using System;
|
||||
|
||||
namespace Attributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class OptionalComponentAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Attributes/OptionalComponentAttribute.cs.meta
Normal file
11
Assets/Scripts/Attributes/OptionalComponentAttribute.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d4d21a459884f8b498fe4f076adf8272
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/Scripts/Attributes/RootComponentAttribute.cs
Normal file
9
Assets/Scripts/Attributes/RootComponentAttribute.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
using System;
|
||||
|
||||
namespace Attributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class RootComponentAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Attributes/RootComponentAttribute.cs.meta
Normal file
3
Assets/Scripts/Attributes/RootComponentAttribute.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 54b4e0a88227402e8f096e61cc8f1243
|
||||
timeCreated: 1532263734
|
||||
4
Assets/Scripts/ColliderType.cs
Normal file
4
Assets/Scripts/ColliderType.cs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
namespace DefaultNamespace
|
||||
{
|
||||
public enum ColliderType { Box, Circle, Polygon }
|
||||
}
|
||||
3
Assets/Scripts/ColliderType.cs.meta
Normal file
3
Assets/Scripts/ColliderType.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b745848b708540ca9c8a6bb897048ca3
|
||||
timeCreated: 1532260833
|
||||
8
Assets/Scripts/Data.meta
Normal file
8
Assets/Scripts/Data.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a0e8b20b435e62a4088d9df363ee5ca5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Data/Actor.meta
Normal file
8
Assets/Scripts/Data/Actor.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2c5bbf590de27894db496494e020e89d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
55
Assets/Scripts/Data/Actor/ActorAnimationDataComponent.cs
Normal file
55
Assets/Scripts/Data/Actor/ActorAnimationDataComponent.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
public struct ActorAnimationData : IComponentData
|
||||
{
|
||||
public float WalkDir;
|
||||
public float WalkMultiply;
|
||||
public float StepTimer;
|
||||
public float LastStepSign;
|
||||
public float AttackSpeed;
|
||||
public float LastRotation;
|
||||
public float LastGunRotation;
|
||||
public float LastHeadRotation;
|
||||
public bool1 Landed;
|
||||
public AnimationTriggerType Triggers;
|
||||
public ItemUseType UseType;
|
||||
public bool1 ItemUseAdditive;
|
||||
public EmotionType Emotion;
|
||||
public float EmotionTimer;
|
||||
public float LookWeight;
|
||||
public float HeadLookWeight;
|
||||
}
|
||||
|
||||
public class ActorAnimationDataComponent : MonoBehaviour, IConvertGameObjectToEntity
|
||||
{
|
||||
[SerializeField, Range(0, 1)] private float HeadLookWeight = 1;
|
||||
|
||||
[SerializeField, Range(0, 1)] private float LookWeight = 1;
|
||||
private Entity m_entity;
|
||||
|
||||
private EntityManager m_entityManager;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (m_entityManager != null && m_entityManager.Exists(m_entity) && m_entityManager.HasComponent<ActorAnimationData>(m_entity))
|
||||
{
|
||||
var val = m_entityManager.GetComponentData<ActorAnimationData>(m_entity);
|
||||
|
||||
val.LookWeight = LookWeight;
|
||||
val.HeadLookWeight = HeadLookWeight;
|
||||
|
||||
m_entityManager.SetComponentData(m_entity, val);
|
||||
}
|
||||
}
|
||||
|
||||
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
|
||||
{
|
||||
m_entity = entity;
|
||||
m_entityManager = dstManager;
|
||||
dstManager.AddComponentData(entity, new ActorAnimationData { Landed = true });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1c72c6bf622d4206a4da5465adbcc92c
|
||||
timeCreated: 1531333408
|
||||
61
Assets/Scripts/Data/Actor/ActorAnimationEventComponent.cs
Normal file
61
Assets/Scripts/Data/Actor/ActorAnimationEventComponent.cs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
public struct ActorAnimationEventData : IComponentData
|
||||
{
|
||||
public bool1 Attacked;
|
||||
public bool1 PickedUp;
|
||||
public bool1 PickedCanceled;
|
||||
public bool1 Melee;
|
||||
public bool1 ItemUsed;
|
||||
public bool1 ItemUsedCancled;
|
||||
}
|
||||
|
||||
public class ActorAnimationEventComponent : MonoBehaviour, IConvertGameObjectToEntity
|
||||
{
|
||||
[SerializeField] private Entity m_entity;
|
||||
|
||||
private EntityManager m_entityManager;
|
||||
|
||||
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
|
||||
{
|
||||
m_entity = entity;
|
||||
dstManager.AddComponent<ActorAnimationEventData>(entity);
|
||||
m_entityManager = dstManager;
|
||||
}
|
||||
|
||||
//animator callback
|
||||
public void Attack()
|
||||
{
|
||||
PostEvent((ref ActorAnimationEventData d) => d.Attacked = true);
|
||||
}
|
||||
|
||||
//animator callback
|
||||
public void Pickup()
|
||||
{
|
||||
PostEvent((ref ActorAnimationEventData d) => d.PickedUp = true);
|
||||
}
|
||||
|
||||
//animator callback
|
||||
public void Melee()
|
||||
{
|
||||
PostEvent((ref ActorAnimationEventData d) => d.Melee = true);
|
||||
}
|
||||
|
||||
//animator callback
|
||||
public void UseItem()
|
||||
{
|
||||
PostEvent((ref ActorAnimationEventData d) => d.ItemUsed = true);
|
||||
}
|
||||
|
||||
private void PostEvent(EntityCommandBufferExtensions.ModifyData<ActorAnimationEventData> eAction)
|
||||
{
|
||||
if (m_entityManager != null && m_entityManager.Exists(m_entity))
|
||||
{
|
||||
m_entityManager.PostEntityEvent(m_entity, eAction);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ebc072dcce7d48a88505b0e354107676
|
||||
timeCreated: 1532182486
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
[Serializable]
|
||||
public struct ActorAnimationPropertiesData : ISharedComponentData
|
||||
{
|
||||
public Vector2 HipAngleRange;
|
||||
public Vector2 WeaponAngleRange;
|
||||
public Vector2 HeadAngleRange;
|
||||
public float HeadRotationOffset;
|
||||
public Vector2 HeadForward;
|
||||
}
|
||||
|
||||
public class ActorAnimationPropertiesDataComponent : MonoBehaviour, IConvertGameObjectToEntity
|
||||
{
|
||||
[SerializeField] private ActorAnimationPropertiesData m_SerializedData;
|
||||
|
||||
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
|
||||
{
|
||||
dstManager.AddSharedComponentData(entity, m_SerializedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 18b11bf53e5240169675470279b0508f
|
||||
timeCreated: 1531221505
|
||||
12
Assets/Scripts/Data/Actor/ActorBoundsData.cs
Normal file
12
Assets/Scripts/Data/Actor/ActorBoundsData.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
[GenerateAuthoringComponent]
|
||||
public struct ActorBoundsData : IComponentData
|
||||
{
|
||||
[NonSerialized] public Rect Rect;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Data/Actor/ActorBoundsData.cs.meta
Normal file
11
Assets/Scripts/Data/Actor/ActorBoundsData.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 16af98b6babd4a548bb86d67de63e106
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
23
Assets/Scripts/Data/Actor/ActorComponent.cs
Normal file
23
Assets/Scripts/Data/Actor/ActorComponent.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using DefaultNamespace;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
public struct ActorData : IComponentData
|
||||
{
|
||||
public Vector2 Aim;
|
||||
public Vector2 GroundUp;
|
||||
public bool1 Grounded;
|
||||
public float GroundDinstance;
|
||||
public Vector2 Look;
|
||||
public float Health;
|
||||
}
|
||||
|
||||
public class ActorComponent : ComponentDataProxy<ActorData>
|
||||
{
|
||||
private void Awake()
|
||||
{
|
||||
var val = Value;
|
||||
val.Grounded = true;
|
||||
Value = val;
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Data/Actor/ActorComponent.cs.meta
Normal file
3
Assets/Scripts/Data/Actor/ActorComponent.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a462e4757eef4e0d8b328486876b6d78
|
||||
timeCreated: 1531167500
|
||||
17
Assets/Scripts/Data/Actor/ActorDeathAnimationData.cs
Normal file
17
Assets/Scripts/Data/Actor/ActorDeathAnimationData.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
using Unity.Entities;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to keep GO for some time to do fancy animations.
|
||||
/// If this component is not present the GO is destroyed instantly.
|
||||
/// </summary>
|
||||
[GenerateAuthoringComponent]
|
||||
public struct ActorDeathAnimationData : IComponentData
|
||||
{
|
||||
/// <summary>
|
||||
/// The amount of time in seconds the GO should remain.
|
||||
/// </summary>
|
||||
public float Time;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e28fcfc7c8964385b6fc2284f4101356
|
||||
timeCreated: 1533839522
|
||||
11
Assets/Scripts/Data/Actor/ActorDeathData.cs
Normal file
11
Assets/Scripts/Data/Actor/ActorDeathData.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
public struct ActorDeathData : IComponentData
|
||||
{
|
||||
public Vector2 Direction;
|
||||
public float Force;
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Data/Actor/ActorDeathData.cs.meta
Normal file
3
Assets/Scripts/Data/Actor/ActorDeathData.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ec67e24d4cca4530b3a94d83d355ff0a
|
||||
timeCreated: 1533842958
|
||||
9
Assets/Scripts/Data/Actor/ActorGrenadeData.cs
Normal file
9
Assets/Scripts/Data/Actor/ActorGrenadeData.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
using Unity.Entities;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
public struct ActorGrenadeData : IComponentData
|
||||
{
|
||||
public float GrenadeTimer;
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Data/Actor/ActorGrenadeData.cs.meta
Normal file
3
Assets/Scripts/Data/Actor/ActorGrenadeData.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d446da21ec3c4cc19f22c291c7327a76
|
||||
timeCreated: 1534253886
|
||||
11
Assets/Scripts/Data/Actor/ActorMeleeData.cs
Normal file
11
Assets/Scripts/Data/Actor/ActorMeleeData.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using System;
|
||||
using Unity.Entities;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
[GenerateAuthoringComponent]
|
||||
public struct ActorMeleeData : IComponentData
|
||||
{
|
||||
[NonSerialized] public float MeleeTimer;
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Data/Actor/ActorMeleeData.cs.meta
Normal file
3
Assets/Scripts/Data/Actor/ActorMeleeData.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 143d3ba90a2544039d3013a621f2ed0c
|
||||
timeCreated: 1533242315
|
||||
37
Assets/Scripts/Data/Actor/ActorMeleeSharedDataComponent.cs
Normal file
37
Assets/Scripts/Data/Actor/ActorMeleeSharedDataComponent.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
[Serializable]
|
||||
public struct ActorMeleeSharedData : ISharedComponentData
|
||||
{
|
||||
public LayerMask MeleeMask;
|
||||
public float Range;
|
||||
public float Angle;
|
||||
public float Damage;
|
||||
public float Knockback;
|
||||
public float Cooldown;
|
||||
}
|
||||
|
||||
public class ActorMeleeSharedDataComponent : MonoBehaviour, IConvertGameObjectToEntity
|
||||
{
|
||||
[SerializeField] private ActorMeleeSharedData m_SerializedData;
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
Gizmos.DrawLine(
|
||||
transform.position,
|
||||
transform.position - Quaternion.Euler(0, 0, m_SerializedData.Angle * 0.5f) * transform.right * m_SerializedData.Range);
|
||||
Gizmos.DrawLine(
|
||||
transform.position,
|
||||
transform.position - Quaternion.Euler(0, 0, -m_SerializedData.Angle * 0.5f) * transform.right * m_SerializedData.Range);
|
||||
}
|
||||
|
||||
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
|
||||
{
|
||||
dstManager.AddSharedComponentData(entity, m_SerializedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1510ecf2e3864138bc4f83f56694bbbd
|
||||
timeCreated: 1532636662
|
||||
14
Assets/Scripts/Data/Actor/ActorNpcData.cs
Normal file
14
Assets/Scripts/Data/Actor/ActorNpcData.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using Trive.Core;
|
||||
using Unity.Entities;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
[GenerateAuthoringComponent]
|
||||
public struct ActorNpcData : IComponentData
|
||||
{
|
||||
public float AttackCooldown;
|
||||
public float ActionCooldown;
|
||||
public float JumpingTimer;
|
||||
public PIDFloat XPid;
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Data/Actor/ActorNpcData.cs.meta
Normal file
3
Assets/Scripts/Data/Actor/ActorNpcData.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 98d1febc8f35485292eca066f16b1db4
|
||||
timeCreated: 1533384927
|
||||
10
Assets/Scripts/Data/Actor/ActorTargetDataComponent.cs
Normal file
10
Assets/Scripts/Data/Actor/ActorTargetDataComponent.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using Unity.Entities;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
[GenerateAuthoringComponent]
|
||||
public struct ActorTargetData : IComponentData
|
||||
{
|
||||
public Entity Target;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f69ba83d17d14a50b51bd53c42b19c24
|
||||
timeCreated: 1533316695
|
||||
12
Assets/Scripts/Data/Actor/ActorWeaponAccuracyData.cs
Normal file
12
Assets/Scripts/Data/Actor/ActorWeaponAccuracyData.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using Unity.Entities;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
public struct ActorWeaponAccuracyData : IComponentData
|
||||
{
|
||||
public float Accuracy;
|
||||
public float AccuracyMultiply;
|
||||
public float AccuracyAttackTime;
|
||||
public float AccuracyRegainSpeed;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Data/Actor/ActorWeaponAccuracyData.cs.meta
Normal file
11
Assets/Scripts/Data/Actor/ActorWeaponAccuracyData.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6c4b4f69b8f01a44f969e2f466da97e6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Assets/Scripts/Data/Actor/ActorWeaponData.cs
Normal file
14
Assets/Scripts/Data/Actor/ActorWeaponData.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
/// <summary>
|
||||
/// Controls what other entities can it shoot
|
||||
/// </summary>
|
||||
[GenerateAuthoringComponent]
|
||||
public struct ActorWeaponData : IComponentData
|
||||
{
|
||||
public LayerMask ProjectileMask;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Data/Actor/ActorWeaponData.cs.meta
Normal file
11
Assets/Scripts/Data/Actor/ActorWeaponData.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f72ae9c9024a9a24f8f4ac1861c46bfa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
using Items;
|
||||
using System;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
using Hash128 = Unity.Entities.Hash128;
|
||||
|
||||
[Serializable]
|
||||
public struct ActorWeaponPropertiesData : ISharedComponentData, IEquatable<ActorWeaponPropertiesData>
|
||||
{
|
||||
public RangedWeaponItem Weapon;
|
||||
|
||||
public Hash128 Id { get; set; }
|
||||
|
||||
public bool Equals(ActorWeaponPropertiesData other)
|
||||
{
|
||||
return Equals(Weapon, other.Weapon) && Id.Equals(other.Id);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is ActorWeaponPropertiesData other && Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return ((Weapon != null ? Weapon.GetHashCode() : 0) * 397) ^ Id.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ActorWeaponPropertiesDataComponent : MonoBehaviour, IConvertGameObjectToEntity
|
||||
{
|
||||
[SerializeField] private ActorWeaponPropertiesData m_SerializedData;
|
||||
|
||||
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
|
||||
{
|
||||
dstManager.AddSharedComponentData(entity, m_SerializedData);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue