Iteration 1

have some art, didn't really do much there
I did spend a lot more time on the code, it's more iteresting.
Player is in it's own file.
All Players use the same code.
Refactored how turns are processed.
Added a defend and counter ability, have code for "Blood Counter" that I
might revisit. Want to change defend to a "Holy Shield" and add a magic
ability that is countered by it. This is to stop the counter until you
win strategy.
This commit is contained in:
twig 2021-02-16 21:10:46 -06:00
parent c56a139556
commit b2eb3ca9a5
21 changed files with 3467 additions and 61 deletions

View File

@ -22,6 +22,7 @@
<Path>ProjectSettings</Path> <Path>ProjectSettings</Path>
</explicitIncludes> </explicitIncludes>
<explicitExcludes> <explicitExcludes>
<Path>.git</Path>
<Path>.idea</Path> <Path>.idea</Path>
<Path>Library</Path> <Path>Library</Path>
<Path>Logs</Path> <Path>Logs</Path>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -218,6 +218,9 @@ RectTransform:
- {fileID: 1700659786} - {fileID: 1700659786}
- {fileID: 2003127417} - {fileID: 2003127417}
- {fileID: 2122497092} - {fileID: 2122497092}
- {fileID: 137837623}
- {fileID: 829062269}
- {fileID: 251530422}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 1 m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -239,8 +242,435 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
attackButton: {fileID: 1700659787} attackButton: {fileID: 1700659787}
bloodCounterButton: {fileID: 829062266}
counterButton: {fileID: 251530419}
defendButton: {fileID: 137837620}
userHealth: {fileID: 2003127418} userHealth: {fileID: 2003127418}
enemyHealth: {fileID: 2122497093} enemyHealth: {fileID: 2122497093}
--- !u!1 &137837619
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 137837623}
- component: {fileID: 137837622}
- component: {fileID: 137837621}
- component: {fileID: 137837620}
m_Layer: 5
m_Name: Defend
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &137837620
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 137837619}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_WrapAround: 0
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 2
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 5437299029774813188, guid: 4880d72e2864aa54389378d2e1821522, type: 3}
m_SelectedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 137837621}
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 24251070}
m_TargetAssemblyTypeName:
m_MethodName:
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName:
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &137837621
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 137837619}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 8047949451544522013, guid: 4880d72e2864aa54389378d2e1821522, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &137837622
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 137837619}
m_CullTransparentMesh: 1
--- !u!224 &137837623
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 137837619}
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:
- {fileID: 816304657}
m_Father: {fileID: 24251074}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 125, y: 40}
m_SizeDelta: {x: 80, y: 60}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &228826172
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 228826173}
- component: {fileID: 228826175}
- component: {fileID: 228826174}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &228826173
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 228826172}
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_Father: {fileID: 251530422}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &228826174
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 228826172}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 18
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 1
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Counter
--- !u!222 &228826175
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 228826172}
m_CullTransparentMesh: 1
--- !u!1 &251530418
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 251530422}
- component: {fileID: 251530421}
- component: {fileID: 251530420}
- component: {fileID: 251530419}
m_Layer: 5
m_Name: Counter
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &251530419
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 251530418}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_WrapAround: 0
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 2
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 5437299029774813188, guid: 4880d72e2864aa54389378d2e1821522, type: 3}
m_SelectedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 251530420}
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 24251070}
m_TargetAssemblyTypeName:
m_MethodName:
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName:
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &251530420
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 251530418}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 8047949451544522013, guid: 4880d72e2864aa54389378d2e1821522, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &251530421
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 251530418}
m_CullTransparentMesh: 1
--- !u!224 &251530422
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 251530418}
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:
- {fileID: 228826173}
m_Father: {fileID: 24251074}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 210, y: 40}
m_SizeDelta: {x: 80, y: 60}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &393001464
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 393001465}
- component: {fileID: 393001467}
- component: {fileID: 393001466}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &393001465
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 393001464}
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_Father: {fileID: 829062269}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &393001466
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 393001464}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 18
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 1
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Blood Counter
--- !u!222 &393001467
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 393001464}
m_CullTransparentMesh: 1
--- !u!1 &519420028 --- !u!1 &519420028
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -324,6 +754,218 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &816304656
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 816304657}
- component: {fileID: 816304659}
- component: {fileID: 816304658}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &816304657
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 816304656}
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_Father: {fileID: 137837623}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &816304658
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 816304656}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 18
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 1
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Defend
--- !u!222 &816304659
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 816304656}
m_CullTransparentMesh: 1
--- !u!1 &829062265
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 829062269}
- component: {fileID: 829062268}
- component: {fileID: 829062267}
- component: {fileID: 829062266}
m_Layer: 5
m_Name: BloodCounter
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!114 &829062266
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 829062265}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_WrapAround: 0
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 2
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 5437299029774813188, guid: 4880d72e2864aa54389378d2e1821522, type: 3}
m_SelectedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 829062267}
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 24251070}
m_TargetAssemblyTypeName:
m_MethodName:
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName:
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &829062267
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 829062265}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 8047949451544522013, guid: 4880d72e2864aa54389378d2e1821522, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &829062268
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 829062265}
m_CullTransparentMesh: 1
--- !u!224 &829062269
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 829062265}
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:
- {fileID: 393001465}
m_Father: {fileID: 24251074}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 295, y: 40}
m_SizeDelta: {x: 80, y: 60}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &885956096 --- !u!1 &885956096
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -449,10 +1091,10 @@ MonoBehaviour:
m_Calls: [] m_Calls: []
m_FontData: m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14 m_FontSize: 18
m_FontStyle: 0 m_FontStyle: 0
m_BestFit: 0 m_BestFit: 0
m_MinSize: 10 m_MinSize: 1
m_MaxSize: 40 m_MaxSize: 40
m_Alignment: 4 m_Alignment: 4
m_AlignByGeometry: 0 m_AlignByGeometry: 0
@ -505,8 +1147,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 80, y: 60} m_AnchoredPosition: {x: 40, y: 40}
m_SizeDelta: {x: 160, y: 30} m_SizeDelta: {x: 80, y: 60}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1700659787 --- !u!114 &1700659787
MonoBehaviour: MonoBehaviour:
@ -527,7 +1169,7 @@ MonoBehaviour:
m_SelectOnDown: {fileID: 0} m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0} m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0} m_SelectOnRight: {fileID: 0}
m_Transition: 1 m_Transition: 2
m_Colors: m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1} m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
@ -538,7 +1180,7 @@ MonoBehaviour:
m_FadeDuration: 0.1 m_FadeDuration: 0.1
m_SpriteState: m_SpriteState:
m_HighlightedSprite: {fileID: 0} m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0} m_PressedSprite: {fileID: 5437299029774813188, guid: 4880d72e2864aa54389378d2e1821522, type: 3}
m_SelectedSprite: {fileID: 0} m_SelectedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0} m_DisabledSprite: {fileID: 0}
m_AnimationTriggers: m_AnimationTriggers:
@ -584,8 +1226,8 @@ MonoBehaviour:
m_OnCullStateChanged: m_OnCullStateChanged:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0} m_Sprite: {fileID: 8047949451544522013, guid: 4880d72e2864aa54389378d2e1821522, type: 3}
m_Type: 1 m_Type: 0
m_PreserveAspect: 0 m_PreserveAspect: 0
m_FillCenter: 1 m_FillCenter: 1
m_FillMethod: 4 m_FillMethod: 4

View File

@ -1,90 +1,143 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
public class BattleMenu : MonoBehaviour public class BattleMenu : MonoBehaviour
{ {
private class Player
{
public int Health;
public int Damage;
public Action UpdateHealth;
}
private Player _user;
private Player _enemy;
private EnemyAi _enemyLogic; private EnemyAi _enemyLogic;
private readonly List<Action> _turnOrder = new List<Action>(); private readonly List<Player> _players = new List<Player>();
private int _currentTurnIndex = 0; private int _currentPlayerIndex;
private Player CurrentPlayer => _players[_currentPlayerIndex];
public Button attackButton; public Button attackButton;
public Button bloodCounterButton;
public Button counterButton;
public Button defendButton;
public Text userHealth; public Text userHealth;
public Text enemyHealth; public Text enemyHealth;
private void Awake() private void Awake()
{ {
_user = new Player {Health = 10, Damage = 1, UpdateHealth = UpdateUserHealth}; _players.Add(new Player {health = 100, damage = 5, updateHealth = UpdateUserHealth, isHumanControlled = true});
_enemy = new Player {Health = 10, Damage = 1, UpdateHealth = UpdateEnemyHealth}; _players.Add(new Player {health = 100, damage = 5, updateHealth = UpdateEnemyHealth, isHumanControlled = false});
_enemyLogic = new EnemyAi(); _enemyLogic = new EnemyAi();
_enemyLogic.AttackCallback += EnemyAttack; _enemyLogic.attackCallback += Attack;
_enemyLogic.defendCallback += Defend;
_enemyLogic.counterCallback += Counter;
} }
private void Start() private void Start()
{ {
attackButton.onClick.AddListener(PlayerAttack); attackButton.onClick.AddListener(Attack);
bloodCounterButton.onClick.AddListener(BloodCounter);
defendButton.onClick.AddListener(Defend);
counterButton.onClick.AddListener(Counter);
foreach (var player in _players)
{
player.updateHealth(player.health);
}
_turnOrder.Add(UserTakeTurn); Debug.Log(CurrentPlayer.isHumanControlled ? "Start user turn" : "Start enemy turn");
_turnOrder.Add(_enemyLogic.TakeTurn); StartTurn();
_turnOrder[_currentTurnIndex]();
UpdateUserHealth();
UpdateEnemyHealth();
} }
private void UpdateUserHealth() private void UpdateUserHealth(int health)
{ {
userHealth.text = $"Health: {_user.Health}"; userHealth.text = $"Health: {health}";
} }
private void UpdateEnemyHealth() private void UpdateEnemyHealth(int health)
{ {
enemyHealth.text = $"Health: {_enemy.Health}"; enemyHealth.text = $"Health: {health}";
} }
private void FinishTurn() private void FinishTurn()
{ {
_currentTurnIndex = ++_currentTurnIndex % _turnOrder.Count;
_turnOrder[_currentTurnIndex]();
}
private void PlayerAttack()
{
Attack(_user, _enemy);
// TODO: disable hud // TODO: disable hud
attackButton.interactable = false; attackButton.interactable = !CurrentPlayer.isHumanControlled;
bloodCounterButton.interactable = !CurrentPlayer.isHumanControlled;
defendButton.interactable = !CurrentPlayer.isHumanControlled;
counterButton.interactable = !CurrentPlayer.isHumanControlled;
_currentPlayerIndex = ++_currentPlayerIndex % _players.Count;
StartTurn();
}
private void Attack()
{
// TODO: when target selection is a thing this will need to be changed.
var victimIndex = (_currentPlayerIndex + 1) % _players.Count;
Attack(CurrentPlayer, _players[victimIndex]);
FinishTurn(); FinishTurn();
} }
private void EnemyAttack() private void BloodCounter()
{ {
Attack(_enemy, _user); CurrentPlayer.isBloodCounter = true;
FinishTurn(); FinishTurn();
} }
private void UserTakeTurn() private void Defend()
{ {
CurrentPlayer.damageReduction = 0.4f;
CurrentPlayer.startTurnEffects = ResetDamageReduction;
FinishTurn();
}
private void Counter()
{
CurrentPlayer.isCounter = true;
FinishTurn();
}
private void StartTurn()
{
CurrentPlayer.isCounter = false;
if (CurrentPlayer.isStunned)
{
Debug.Log("stunned, skipping turn");
CurrentPlayer.isStunned = false;
FinishTurn();
return;
}
// TODO: enable hud. // TODO: enable hud.
attackButton.interactable = true; attackButton.interactable = CurrentPlayer.isHumanControlled;
bloodCounterButton.interactable = CurrentPlayer.isHumanControlled;
defendButton.interactable = CurrentPlayer.isHumanControlled;
counterButton.interactable = CurrentPlayer.isHumanControlled;
CurrentPlayer.startTurnEffects?.Invoke(CurrentPlayer);
CurrentPlayer.startTurnEffects = null;
// TODO: controller.
if (!CurrentPlayer.isHumanControlled)
{
_enemyLogic.TakeTurn();
}
}
private void ResetDamageReduction(Player p)
{
p.damageReduction = 1f;
} }
private void Attack(Player attacker, Player victim) private void Attack(Player attacker, Player victim)
{ {
victim.Health -= attacker.Damage; if (victim.isCounter)
victim.UpdateHealth(); {
if (victim.Health <= 0) attacker.isStunned = true;
Debug.Log("COUNTER");
return;
}
victim.TakeDamage((int)(attacker.damage * attacker.damageModification));
// damage mod is spent whenever they attack.
attacker.damageModification = 1;
attacker.isBloodCounter = false;
if (victim.health <= 0)
{ {
Debug.Log("The victim died!"); Debug.Log("The victim died!");
} }

View File

@ -1,11 +1,39 @@
using System; using System;
using UnityEngine;
using Random = System.Random;
public class EnemyAi public class EnemyAi
{ {
public Action AttackCallback; public Action attackCallback;
public Action defendCallback;
public Action counterCallback;
private Random rng;
public EnemyAi()
{
rng = new Random(1337);
}
// TODO: will need more information, not sure what info should be exposed.
public void TakeTurn() public void TakeTurn()
{ {
AttackCallback(); var number = rng.Next(1, 4);
Debug.Log($"enemy rolled {number}");
switch (number)
{
case 1:
attackCallback();
break;
case 2:
defendCallback();
break;
case 3:
counterCallback();
break;
default:
Debug.LogWarning($"Enemy rolled something that it can't do {number}");
break;
}
} }
} }

29
Assets/Scripts/Player.cs Normal file
View File

@ -0,0 +1,29 @@
using System;
public class Player
{
public int health;
public int damage;
public float damageReduction = 1.0f;
public float damageModification = 1.0f;
public bool isBloodCounter;
public bool isCounter;
public bool isStunned;
public bool isHumanControlled;
public Action<int> updateHealth;
public Action<Player> startTurnEffects;
public void TakeDamage(int incomingDamage)
{
var modifiedDamage = (int) (incomingDamage * damageReduction);
// Not sure if blood counter should negate damage or not...
if (isBloodCounter)
{
damageModification += (modifiedDamage * 0.15F);
}
health -= modifiedDamage;
updateHealth(health);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 374046a0afc221d459f369d95fc41b42
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
Assets/Spritesheets.meta Normal file
View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,89 @@
<TextureAtlas imagePath="sheet.png">
<SubTexture name="arrowBeige_left.png" x="303" y="486" width="22" height="21"/>
<SubTexture name="arrowBeige_right.png" x="171" y="486" width="22" height="21"/>
<SubTexture name="arrowBlue_left.png" x="193" y="486" width="22" height="21"/>
<SubTexture name="arrowBlue_right.png" x="215" y="486" width="22" height="21"/>
<SubTexture name="arrowBrown_left.png" x="237" y="486" width="22" height="21"/>
<SubTexture name="arrowBrown_right.png" x="325" y="486" width="22" height="21"/>
<SubTexture name="arrowSilver_left.png" x="281" y="486" width="22" height="21"/>
<SubTexture name="arrowSilver_right.png" x="259" y="486" width="22" height="21"/>
<SubTexture name="barBack_horizontalLeft.png" x="372" y="330" width="9" height="18"/>
<SubTexture name="barBack_horizontalMid.png" x="338" y="386" width="18" height="18"/>
<SubTexture name="barBack_horizontalRight.png" x="190" y="294" width="9" height="18"/>
<SubTexture name="barBack_verticalBottom.png" x="290" y="189" width="18" height="9"/>
<SubTexture name="barBack_verticalMid.png" x="338" y="404" width="18" height="18"/>
<SubTexture name="barBack_verticalTop.png" x="338" y="440" width="18" height="9"/>
<SubTexture name="barBlue_horizontalBlue.png" x="356" y="431" width="18" height="18"/>
<SubTexture name="barBlue_horizontalLeft.png" x="372" y="294" width="9" height="18"/>
<SubTexture name="barBlue_horizontalRight.png" x="372" y="312" width="9" height="18"/>
<SubTexture name="barBlue_verticalBottom.png" x="344" y="189" width="18" height="9"/>
<SubTexture name="barBlue_verticalMid.png" x="356" y="386" width="18" height="18"/>
<SubTexture name="barBlue_verticalTop.png" x="356" y="404" width="18" height="9"/>
<SubTexture name="barGreen_horizontalLeft.png" x="370" y="108" width="9" height="18"/>
<SubTexture name="barGreen_horizontalMid.png" x="338" y="368" width="18" height="18"/>
<SubTexture name="barGreen_horizontalRight.png" x="190" y="312" width="9" height="18"/>
<SubTexture name="barGreen_verticalBottom.png" x="338" y="467" width="18" height="9"/>
<SubTexture name="barGreen_verticalMid.png" x="356" y="413" width="18" height="18"/>
<SubTexture name="barGreen_verticalTop.png" x="171" y="476" width="18" height="9"/>
<SubTexture name="barRed_horizontalLeft.png" x="370" y="90" width="9" height="18"/>
<SubTexture name="barRed_horizontalMid.png" x="356" y="368" width="18" height="18"/>
<SubTexture name="barRed_horizontalRight.png" x="190" y="348" width="9" height="18"/>
<SubTexture name="barRed_verticalBottom.png" x="347" y="503" width="18" height="9"/>
<SubTexture name="barRed_verticalMid.png" x="347" y="485" width="18" height="18"/>
<SubTexture name="barRed_verticalTop.png" x="338" y="476" width="18" height="9"/>
<SubTexture name="barYellow_horizontalLeft.png" x="370" y="126" width="9" height="18"/>
<SubTexture name="barYellow_horizontalMid.png" x="338" y="449" width="18" height="18"/>
<SubTexture name="barYellow_horizontalRight.png" x="190" y="330" width="9" height="18"/>
<SubTexture name="barYellow_verticalBottom.png" x="326" y="189" width="18" height="9"/>
<SubTexture name="barYellow_verticalMid.png" x="338" y="422" width="18" height="18"/>
<SubTexture name="barYellow_verticalTop.png" x="308" y="189" width="18" height="9"/>
<SubTexture name="buttonLong_beige.png" x="0" y="282" width="190" height="49"/>
<SubTexture name="buttonLong_beige_pressed.png" x="0" y="237" width="190" height="45"/>
<SubTexture name="buttonLong_blue.png" x="0" y="188" width="190" height="49"/>
<SubTexture name="buttonLong_blue_pressed.png" x="0" y="143" width="190" height="45"/>
<SubTexture name="buttonLong_brown.png" x="0" y="49" width="190" height="49"/>
<SubTexture name="buttonLong_brown_pressed.png" x="0" y="98" width="190" height="45"/>
<SubTexture name="buttonLong_grey.png" x="0" y="0" width="190" height="49"/>
<SubTexture name="buttonLong_grey_pressed.png" x="0" y="331" width="190" height="45"/>
<SubTexture name="buttonRound_beige.png" x="335" y="76" width="35" height="38"/>
<SubTexture name="buttonRound_blue.png" x="335" y="38" width="35" height="38"/>
<SubTexture name="buttonRound_brown.png" x="335" y="114" width="35" height="38"/>
<SubTexture name="buttonRound_grey.png" x="335" y="0" width="35" height="38"/>
<SubTexture name="buttonSquare_beige.png" x="293" y="294" width="45" height="49"/>
<SubTexture name="buttonSquare_beige_pressed.png" x="290" y="94" width="45" height="45"/>
<SubTexture name="buttonSquare_blue.png" x="290" y="0" width="45" height="49"/>
<SubTexture name="buttonSquare_blue_pressed.png" x="290" y="139" width="45" height="45"/>
<SubTexture name="buttonSquare_brown.png" x="293" y="343" width="45" height="49"/>
<SubTexture name="buttonSquare_brown_pressed.png" x="293" y="392" width="45" height="45"/>
<SubTexture name="buttonSquare_grey.png" x="293" y="437" width="45" height="49"/>
<SubTexture name="buttonSquare_grey_pressed.png" x="290" y="49" width="45" height="45"/>
<SubTexture name="cursorGauntlet_blue.png" x="30" y="482" width="30" height="30"/>
<SubTexture name="cursorGauntlet_bronze.png" x="0" y="482" width="30" height="30"/>
<SubTexture name="cursorGauntlet_grey.png" x="60" y="482" width="30" height="30"/>
<SubTexture name="cursorHand_beige.png" x="90" y="482" width="27" height="28"/>
<SubTexture name="cursorHand_blue.png" x="117" y="482" width="27" height="28"/>
<SubTexture name="cursorHand_grey.png" x="144" y="482" width="27" height="28"/>
<SubTexture name="cursorSword_bronze.png" x="338" y="331" width="34" height="37"/>
<SubTexture name="cursorSword_gold.png" x="338" y="294" width="34" height="37"/>
<SubTexture name="cursorSword_silver.png" x="335" y="152" width="34" height="37"/>
<SubTexture name="iconCheck_beige.png" x="369" y="184" width="16" height="15"/>
<SubTexture name="iconCheck_blue.png" x="370" y="30" width="16" height="15"/>
<SubTexture name="iconCheck_bronze.png" x="370" y="45" width="16" height="15"/>
<SubTexture name="iconCheck_grey.png" x="370" y="75" width="16" height="15"/>
<SubTexture name="iconCircle_beige.png" x="356" y="466" width="17" height="17"/>
<SubTexture name="iconCircle_blue.png" x="365" y="483" width="17" height="17"/>
<SubTexture name="iconCircle_brown.png" x="369" y="152" width="17" height="17"/>
<SubTexture name="iconCircle_grey.png" x="356" y="449" width="17" height="17"/>
<SubTexture name="iconCross_beige.png" x="369" y="169" width="16" height="15"/>
<SubTexture name="iconCross_blue.png" x="370" y="15" width="16" height="15"/>
<SubTexture name="iconCross_brown.png" x="370" y="0" width="16" height="15"/>
<SubTexture name="iconCross_grey.png" x="370" y="60" width="16" height="15"/>
<SubTexture name="panelInset_beige.png" x="200" y="294" width="93" height="94"/>
<SubTexture name="panelInset_beigeLight.png" x="190" y="200" width="93" height="94"/>
<SubTexture name="panelInset_blue.png" x="200" y="388" width="93" height="94"/>
<SubTexture name="panelInset_brown.png" x="283" y="200" width="93" height="94"/>
<SubTexture name="panel_beige.png" x="190" y="100" width="100" height="100"/>
<SubTexture name="panel_beigeLight.png" x="100" y="376" width="100" height="100"/>
<SubTexture name="panel_blue.png" x="190" y="0" width="100" height="100"/>
<SubTexture name="panel_brown.png" x="0" y="376" width="100" height="100"/>
</TextureAtlas>

View File

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

View File

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

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 23aa647f2fb21bf46b850587506ba4a2
folderAsset: yes
timeCreated: 1430572177
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,281 @@
using System;
using System.IO;
using System.Linq;
using System.Xml;
using UnityEditor;
using UnityEngine;
public class TextureAtlasSlicer : EditorWindow {
[MenuItem("CONTEXT/TextureImporter/Slice Sprite Using XML")]
public static void SliceUsingXML(MenuCommand command) {
var textureImporter = command.context as TextureImporter;
var window = CreateInstance<TextureAtlasSlicer>();
window.importer = textureImporter;
window.ShowUtility();
}
[MenuItem("Assets/Slice Sprite Using XML")]
public static void TextureAtlasSlicerWindow() {
var window = CreateInstance<TextureAtlasSlicer>();
window.Show();
}
[MenuItem("CONTEXT/TextureImporter/Slice Sprite Using XML", true)]
public static bool ValidateSliceUsingXML(MenuCommand command) {
var textureImporter = command.context as TextureImporter;
//valid only if the texture type is 'sprite' or 'advanced'.
return textureImporter && textureImporter.textureType == TextureImporterType.Sprite ||
textureImporter.textureType == TextureImporterType.Default;
}
public TextureImporter importer;
public TextureAtlasSlicer() {
titleContent = new GUIContent("XML Slicer");
}
[SerializeField]
private TextAsset xmlAsset;
public SpriteAlignment spriteAlignment = SpriteAlignment.Center;
public Vector2 customOffset = new Vector2(0.5f, 0.5f);
public void OnSelectionChange() {
UseSelectedTexture();
}
private Texture2D selectedTexture;
private void UseSelectedTexture() {
if (Selection.objects.Length > 1) {
selectedTexture = null;
} else {
selectedTexture = Selection.activeObject as Texture2D;
}
if (selectedTexture != null) {
var assetPath = AssetDatabase.GetAssetPath(selectedTexture);
importer = AssetImporter.GetAtPath(assetPath) as TextureImporter;
if (importer) {
var extension = Path.GetExtension(assetPath);
var pathWithoutExtension = assetPath.Remove(assetPath.Length - extension.Length, extension.Length);
var xmlPath = pathWithoutExtension + ".xml";
var textAsset = AssetDatabase.LoadAssetAtPath(xmlPath, typeof (TextAsset));
if (textAsset != null) {
xmlAsset = textAsset as TextAsset;
} else {
xmlAsset = null;
subTextures = null;
}
ParseXML();
} else {
xmlAsset = null;
subTextures = null;
}
} else {
importer = null;
xmlAsset = null;
subTextures = null;
}
Repaint();
}
private SubTexture[] subTextures;
private int wantedWidth, wantedHeight;
private void ParseXML() {
try {
var document = new XmlDocument();
document.LoadXml(xmlAsset.text);
var root = document.DocumentElement;
if (root == null || root.Name != "TextureAtlas") {
return;
}
subTextures = root.ChildNodes
.Cast<XmlNode>()
.Where(childNode => childNode.Name == "SubTexture")
.Select(childNode => new SubTexture {
width = Convert.ToInt32(childNode.Attributes["width"].Value),
height = Convert.ToInt32(childNode.Attributes["height"].Value),
x = Convert.ToInt32(childNode.Attributes["x"].Value),
y = Convert.ToInt32(childNode.Attributes["y"].Value),
name = childNode.Attributes["name"].Value
}).ToArray();
wantedWidth = 0;
wantedHeight = 0;
foreach (var subTexture in subTextures) {
var right = subTexture.x + subTexture.width;
var bottom = subTexture.y + subTexture.height;
wantedWidth = Mathf.Max(wantedWidth, right);
wantedHeight = Mathf.Max(wantedHeight, bottom);
}
} catch (Exception) {
subTextures = null;
}
}
public void OnEnable() {
UseSelectedTexture();
}
public void OnGUI() {
if (importer == null) {
EditorGUILayout.LabelField("Please select a texture to slice.");
return;
}
EditorGUI.BeginDisabledGroup(focusedWindow != this);
{
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.ObjectField("Texture", Selection.activeObject, typeof (Texture), false);
EditorGUI.EndDisabledGroup();
if (importer.textureType != TextureImporterType.Sprite &&
importer.textureType != TextureImporterType.Default) {
EditorGUILayout.LabelField("The Texture Type needs to be Sprite or Advanced!");
}
EditorGUI.BeginDisabledGroup((importer.textureType != TextureImporterType.Sprite &&
importer.textureType != TextureImporterType.Default));
{
EditorGUI.BeginChangeCheck();
xmlAsset = EditorGUILayout.ObjectField("XML Source", xmlAsset, typeof (TextAsset), false) as TextAsset;
if (EditorGUI.EndChangeCheck()) {
ParseXML();
}
spriteAlignment = (SpriteAlignment) EditorGUILayout.EnumPopup("Pivot", spriteAlignment);
EditorGUI.BeginDisabledGroup(spriteAlignment != SpriteAlignment.Custom);
EditorGUILayout.Vector2Field("Custom Offset", customOffset);
EditorGUI.EndDisabledGroup();
var needsToResizeTexture = wantedWidth > selectedTexture.width || wantedHeight > selectedTexture.height;
if (xmlAsset != null && needsToResizeTexture) {
EditorGUILayout.LabelField(
string.Format("Texture size too small."
+ " It needs to be at least {0} by {1} pixels!",
wantedWidth,
wantedHeight));
EditorGUILayout.LabelField("Try changing the Max Size property in the importer.");
}
if (subTextures == null || subTextures.Length == 0) {
EditorGUILayout.LabelField("Could not find any SubTextures in XML.");
}
EditorGUI.BeginDisabledGroup(xmlAsset == null || needsToResizeTexture || subTextures == null ||
subTextures.Length == 0);
if (GUILayout.Button("Slice")) {
PerformSlice();
}
EditorGUI.EndDisabledGroup();
}
EditorGUI.EndDisabledGroup();
}
EditorGUI.EndDisabledGroup();
}
private struct SubTexture {
public int width;
public int height;
public int x;
public int y;
public string name;
}
private void PerformSlice() {
if (importer == null) {
return;
}
var textureHeight = selectedTexture.height;
var needsUpdate = false;
if (importer.spriteImportMode != SpriteImportMode.Multiple) {
needsUpdate = true;
importer.spriteImportMode = SpriteImportMode.Multiple;
}
var wantedSpriteSheet = (from subTexture in subTextures
let actualY = textureHeight - (subTexture.y + subTexture.height)
select new SpriteMetaData {
alignment = (int) spriteAlignment,
border = new Vector4(),
name = subTexture.name,
pivot = GetPivotValue(spriteAlignment, customOffset),
rect = new Rect(subTexture.x, actualY, subTexture.width, subTexture.height)
}).ToArray();
if (!needsUpdate && !importer.spritesheet.SequenceEqual(wantedSpriteSheet)) {
needsUpdate = true;
importer.spritesheet = wantedSpriteSheet;
}
if (needsUpdate) {
EditorUtility.SetDirty(importer);
try {
AssetDatabase.StartAssetEditing();
AssetDatabase.ImportAsset(importer.assetPath);
EditorUtility.DisplayDialog("Success!", "The sprite was sliced successfully.", "OK");
} catch (Exception exception) {
Debug.LogException(exception);
EditorUtility.DisplayDialog("Error", "There was an exception while trying to reimport the image." +
"\nPlease check the console log for details.", "OK");
} finally {
AssetDatabase.StopAssetEditing();
}
} else {
EditorUtility.DisplayDialog("Nope!", "The sprite is already sliced according to this XML file.", "OK");
}
}
//SpriteEditorUtility
public static Vector2 GetPivotValue(SpriteAlignment alignment, Vector2 customOffset) {
switch (alignment) {
case SpriteAlignment.Center:
return new Vector2(0.5f, 0.5f);
case SpriteAlignment.TopLeft:
return new Vector2(0.0f, 1f);
case SpriteAlignment.TopCenter:
return new Vector2(0.5f, 1f);
case SpriteAlignment.TopRight:
return new Vector2(1f, 1f);
case SpriteAlignment.LeftCenter:
return new Vector2(0.0f, 0.5f);
case SpriteAlignment.RightCenter:
return new Vector2(1f, 0.5f);
case SpriteAlignment.BottomLeft:
return new Vector2(0.0f, 0.0f);
case SpriteAlignment.BottomCenter:
return new Vector2(0.5f, 0.0f);
case SpriteAlignment.BottomRight:
return new Vector2(1f, 0.0f);
case SpriteAlignment.Custom:
return customOffset;
default:
return Vector2.zero;
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 2067bd0762faf2c48910fee768c92901
timeCreated: 1430572201
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,17 @@
# Unity3D-TextureAtlasSlicer
Simple and fast tool to import XML spritesheets (TextureAtlas) into Unity3D!
![Preview Image](https://i.imgur.com/LhmcMjX.png)
Works very well to import [Kenney's sprite assets](http://opengameart.org/users/kenney)!
## Usage
- Copy this folder to your project's assets directory, or just use the latest .unitypackage file from the [Github project's releases](https://github.com/toxicFork/Unity3D-TextureAtlasSlicer/releases), or the [Unity3D asset store](https://www.assetstore.unity3d.com/en/#!/content/36103)!
- You can now use the Assets/Slice Sprite Using XML button!
- This will open a window.
- Select any sprite asset in your Project window
- If it has a XML file with the same name next to it, that XML file will automatically be selected
- Otherwise, drag-drop the XML file reference onto the XML Source field in the Texture Atlas Slicer window
- Configure the pivot settings
- Hit Slice!
- Enjoy! :D

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 463e84607d141d645b70834aa062a0d1
timeCreated: 1430859603
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -145,7 +145,8 @@ PlayerSettings:
resolutionScalingMode: 0 resolutionScalingMode: 0
androidSupportedAspectRatio: 1 androidSupportedAspectRatio: 1
androidMaxAspectRatio: 2.1 androidMaxAspectRatio: 2.1
applicationIdentifier: {} applicationIdentifier:
Standalone: com.DefaultCompany.prototurnbasedrpg
buildNumber: buildNumber:
Standalone: 0 Standalone: 0
iPhone: 0 iPhone: 0

View File

@ -1,2 +1,2 @@
m_EditorVersion: 2020.2.3f1 m_EditorVersion: 2020.2.4f1
m_EditorVersionWithRevision: 2020.2.3f1 (8ff31bc5bf5b) m_EditorVersionWithRevision: 2020.2.4f1 (becced5a802b)

View File

@ -4,7 +4,7 @@
QualitySettings: QualitySettings:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
serializedVersion: 5 serializedVersion: 5
m_CurrentQuality: 5 m_CurrentQuality: 3
m_QualitySettings: m_QualitySettings:
- serializedVersion: 2 - serializedVersion: 2
name: Very Low name: Very Low
@ -165,7 +165,7 @@ QualitySettings:
skinWeights: 4 skinWeights: 4
textureQuality: 0 textureQuality: 0
anisotropicTextures: 2 anisotropicTextures: 2
antiAliasing: 2 antiAliasing: 0
softParticles: 1 softParticles: 1
softVegetation: 1 softVegetation: 1
realtimeReflectionProbes: 1 realtimeReflectionProbes: 1
@ -201,7 +201,7 @@ QualitySettings:
skinWeights: 255 skinWeights: 255
textureQuality: 0 textureQuality: 0
anisotropicTextures: 2 anisotropicTextures: 2
antiAliasing: 2 antiAliasing: 0
softParticles: 1 softParticles: 1
softVegetation: 1 softVegetation: 1
realtimeReflectionProbes: 1 realtimeReflectionProbes: 1