Skip to content

Commit

Permalink
refactor: Changed Team property to a method.
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Users may want the entity's team to be exposed in the inspector, and they may also want it to be defined by a enum. This makes sure that case is covered.
  • Loading branch information
christides11 committed Aug 17, 2020
1 parent bd4d3a5 commit a22502b
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 7 deletions.
3 changes: 1 addition & 2 deletions Assets/CAF/Combat/Interfaces/IHurtable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ namespace CAF.Combat
{
public interface IHurtable
{
int Team { get; }

int GetTeam();
HitReaction Hurt(Vector3 center, Vector3 forward, Vector3 right, HitInfoBase hitInfo);
void Heal(HealInfoBase healInfo);
}
Expand Down
7 changes: 6 additions & 1 deletion Assets/CAF/Entities/Managers/EntityCombatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class EntityCombatManager : MonoBehaviour, IHurtable
public event ChargeLevelChangedAction OnChargeLevelChanged;
public event ChargeLevelChargeChangedAction OnChargeLevelChargeChanged;

public int Team { get; set; } = 0;
public int HitStun { get; protected set; } = 0;
public int HitStop { get; protected set; } = 0;
public int CurrentChargeLevel { get; protected set; } = 0;
Expand Down Expand Up @@ -323,6 +322,7 @@ public virtual void IncrementChargeLevelCharge()

public virtual HitReaction Hurt(Vector3 center, Vector3 forward, Vector3 right, HitInfoBase hitInfo)
{
Debug.Log("Hit.");
HitReaction hr = new HitReaction();
hr.reactionType = HitReactionType.Hit;
OnHit?.Invoke(null, controller, hitInfo);
Expand All @@ -333,5 +333,10 @@ public virtual void Heal(HealInfoBase healInfo)
{
OnHealed?.Invoke(null, controller, null);
}

public virtual int GetTeam()
{
return 0;
}
}
}
84 changes: 83 additions & 1 deletion Assets/CAF/Samples/TDAction/Characters/Boxer/Boxer.prefab
Original file line number Diff line number Diff line change
@@ -1,5 +1,86 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2277263397679295086
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1086198402494878418}
- component: {fileID: 8947666900839994706}
m_Layer: 0
m_Name: Visual (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1086198402494878418
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2277263397679295086}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0.25, y: 0.6, z: 0}
m_LocalScale: {x: 0.05, y: 0.5, z: 1}
m_Children: []
m_Father: {fileID: 3889041244988254788}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &8947666900839994706
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2277263397679295086}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: 3c2c380759997064582dae8282adffda, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 2}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!1 &6667267786158460212
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -268,7 +349,8 @@ Transform:
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_Children: []
m_Children:
- {fileID: 1086198402494878418}
m_Father: {fileID: 6667267786158460213}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ MonoBehaviour:
hitGroupType: 0
boxes:
- shape: 0
offset: {x: 0, y: 0, z: 0}
offset: {x: 1, y: 0, z: 0}
size: {x: 4, y: 4, z: 0}
rotation: {x: 0, y: 0, z: 0}
radius: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ public override void OnUpdate()

c.PhysicsManager.forceMovement = currentSpeed;

c.SetFaceDirection((int)Mathf.Sign(movementAxis.x));
if (movementAxis.x != 0)
{
c.SetFaceDirection((int)Mathf.Sign(movementAxis.x));
}

CheckInterrupt();
}
Expand Down
7 changes: 6 additions & 1 deletion Assets/CAF/Samples/TDAction/Scenes/PlayScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,11 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1011028484438550925, guid: 566a2b9082a19f54d9a11fabf7eb2be8,
type: 3}
propertyPath: m_FlipX
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6667267786158460212, guid: 566a2b9082a19f54d9a11fabf7eb2be8,
type: 3}
propertyPath: m_Name
Expand Down Expand Up @@ -2300,7 +2305,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 927051212}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c88f5cead0c0b2a4eb05b5900433f8d1, type: 3}
m_Name:
Expand Down
13 changes: 13 additions & 0 deletions Assets/CAF/Samples/TDAction/Scripts/Combat/TeamTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace TDAction.Combat
{
public enum TeamTypes
{
FFA = 0,
Team1 = 1,
Team2 = 2
}
}
11 changes: 11 additions & 0 deletions Assets/CAF/Samples/TDAction/Scripts/Combat/TeamTypes.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Assets/CAF/Samples/TDAction/Scripts/Entities/EntityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ protected virtual void SetupStates()
public void SetFaceDirection(int faceDirection)
{
this.faceDirection = faceDirection;
Vector3 visualScale = visual.transform.localScale;
visualScale.x = 1 * faceDirection;
visual.transform.localScale = visualScale;
}

public virtual bool TryAttack()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
using CAF.Combat;
using System.Collections;
using System.Collections.Generic;
using TDAction.Combat;
using UnityEngine;

namespace TDAction.Entities
{
public class EntityCombatManager : CAF.Entities.EntityCombatManager
{
public TeamTypes team = TeamTypes.FFA;

protected override void Awake()
{
hitboxManager = new EntityHitboxManager(this, (EntityManager)controller);
}

public override int GetTeam()
{
return (int)team;
}

public override HitReaction Hurt(Vector3 center, Vector3 forward, Vector3 right, HitInfoBase hitInfo)
{
return base.Hurt(center, forward, right, hitInfo);
Expand Down
1 change: 1 addition & 0 deletions TDAction_CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<Compile Include="Assets\CAF\Samples\TDAction\Scripts\Combat\Attack\AttackDefinition.cs" />
<Compile Include="Assets\CAF\Samples\TDAction\Scripts\Combat\Hitbox.cs" />
<Compile Include="Assets\CAF\Samples\TDAction\Scripts\Combat\Moveset\MovesetDefinition.cs" />
<Compile Include="Assets\CAF\Samples\TDAction\Scripts\Combat\TeamTypes.cs" />
<Compile Include="Assets\CAF\Samples\TDAction\Scripts\Entities\CharacterController2D.cs" />
<Compile Include="Assets\CAF\Samples\TDAction\Scripts\Entities\EntityDefinition.cs" />
<Compile Include="Assets\CAF\Samples\TDAction\Scripts\Entities\EntityManager.cs" />
Expand Down

0 comments on commit a22502b

Please sign in to comment.