Skip to content

Commit

Permalink
extract core keybound interaction logic to shared parent
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterSquishy committed May 24, 2018
1 parent 5894de3 commit b998e9b
Show file tree
Hide file tree
Showing 24 changed files with 645 additions and 197 deletions.
69 changes: 69 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
[Ll]ibrary/

[Tt]emp/

[Oo]bj/

[Bb]uild/

[Bb]uilds/

Assets/AssetStoreTools*



# Visual Studio cache directory

.vs/



# Autogenerated VS/MD/Consulo solution and project files

ExportedObj/

.consulo/

*.csproj

*.unityproj

*.sln

*.suo

*.tmp

*.user

*.userprefs

*.pidb

*.booproj

*.svd

*.pdb

*.opendb



# Unity3D generated meta files

*.pidb.meta

*.pdb.meta



# Unity3D Generated File On Crash Reports

sysinfo.txt

# Builds

*.apk

*.unitypackage
Original file line number Diff line number Diff line change
Expand Up @@ -4919,6 +4919,106 @@ Prefab:
Transform:
m_PrefabParentObject: {fileID: 477176, guid: bda711bd1947bee44ab35c84e70cc635, type: 2}
m_PrefabInternal: {fileID: 853436542}
--- !u!1001 &869622792
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 1867320607}
m_Modifications:
- target: {fileID: 224643287947181804, guid: 520d53a83a3e0ea42898cde0a5b5c357,
type: 2}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224643287947181804, guid: 520d53a83a3e0ea42898cde0a5b5c357,
type: 2}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224643287947181804, guid: 520d53a83a3e0ea42898cde0a5b5c357,
type: 2}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224643287947181804, guid: 520d53a83a3e0ea42898cde0a5b5c357,
type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224643287947181804, guid: 520d53a83a3e0ea42898cde0a5b5c357,
type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224643287947181804, guid: 520d53a83a3e0ea42898cde0a5b5c357,
type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224643287947181804, guid: 520d53a83a3e0ea42898cde0a5b5c357,
type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 224643287947181804, guid: 520d53a83a3e0ea42898cde0a5b5c357,
type: 2}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224643287947181804, guid: 520d53a83a3e0ea42898cde0a5b5c357,
type: 2}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224643287947181804, guid: 520d53a83a3e0ea42898cde0a5b5c357,
type: 2}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224643287947181804, guid: 520d53a83a3e0ea42898cde0a5b5c357,
type: 2}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224643287947181804, guid: 520d53a83a3e0ea42898cde0a5b5c357,
type: 2}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224643287947181804, guid: 520d53a83a3e0ea42898cde0a5b5c357,
type: 2}
propertyPath: m_AnchorMin.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224643287947181804, guid: 520d53a83a3e0ea42898cde0a5b5c357,
type: 2}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224643287947181804, guid: 520d53a83a3e0ea42898cde0a5b5c357,
type: 2}
propertyPath: m_AnchorMax.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224643287947181804, guid: 520d53a83a3e0ea42898cde0a5b5c357,
type: 2}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224643287947181804, guid: 520d53a83a3e0ea42898cde0a5b5c357,
type: 2}
propertyPath: m_Pivot.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 224643287947181804, guid: 520d53a83a3e0ea42898cde0a5b5c357,
type: 2}
propertyPath: m_Pivot.y
value: 0.5
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 520d53a83a3e0ea42898cde0a5b5c357, type: 2}
m_IsPrefabParent: 0
--- !u!1001 &871842616
Prefab:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -11574,6 +11674,11 @@ GameObject:
m_PrefabParentObject: {fileID: 1252688374852670, guid: 05ad65f220e15b449af7c9dc94414160,
type: 2}
m_PrefabInternal: {fileID: 1867320605}
--- !u!4 &1867320607 stripped
Transform:
m_PrefabParentObject: {fileID: 4103889916688558, guid: 05ad65f220e15b449af7c9dc94414160,
type: 2}
m_PrefabInternal: {fileID: 1867320605}
--- !u!1 &1877758297
GameObject:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2322,23 +2322,25 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 05ad53d65a4e3d941b0dcc671639f818, type: 3}
m_Name:
m_EditorClassIdentifier:
fadeTransition: 1
fadeTime: 1
fadeTransition: 0
fadeTime: 0.25
NameMusic:
- Name: Demo Start
BGMusic: {fileID: 0}
- Name: MainMenu
BGMusic: {fileID: 8300000, guid: d0b0000c821593a499762febe7cfd438, type: 3}
BGMusic: {fileID: 0}
- Name: MainWorld
BGMusic: {fileID: 8300000, guid: d0b0000c821593a499762febe7cfd438, type: 3}
BGMusic: {fileID: 0}
- Name: HouseMd
BGMusic: {fileID: 8300000, guid: d0b0000c821593a499762febe7cfd438, type: 3}
BGMusic: {fileID: 0}
- Name: HouseLrg
BGMusic: {fileID: 8300000, guid: d0b0000c821593a499762febe7cfd438, type: 3}
BGMusic: {fileID: 0}
- Name: HouseSml
BGMusic: {fileID: 8300000, guid: d0b0000c821593a499762febe7cfd438, type: 3}
BGMusic: {fileID: 0}
- Name: InnBasement
BGMusic: {fileID: 8300000, guid: d0b0000c821593a499762febe7cfd438, type: 3}
BGMusic: {fileID: 0}
- Name: Field
BGMusic: {fileID: 0}
--- !u!114 &827076141
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public class Player_Manager : Character, Can_Take_Damage, Can_Attack {
// Is the player engaged in an Action Key Dialogue.
public bool IsActionKeyDialogued = false;
// The Action Key Dialogue we are currently engaged in due to it being the closest.
public Action_Key_Dialogue ClosestAKD = null;
public Interaction_Area ClosestInteractionArea = null;
// The List of Area Dialogues currently inside.
public List<Area_Dialogue> ListOfAreaDialogues = new List<Area_Dialogue>();
// The List of Action Key Dialogues currently inside.
public List<Action_Key_Dialogue> ListOfActionKeyDialogues = new List<Action_Key_Dialogue>();
public List<Interaction_Area> ListOfInteractionAreas = new List<Interaction_Area>();

private Collider2D playerCollider;
private Equipment equipment;
Expand Down Expand Up @@ -76,7 +76,7 @@ void Update(){
// Make the player look at the NPC it is interacting with.
PlayerLookDirection();
if (Input.GetKeyDown (InteractionKey) && DialogueInteraction()) {
ClosestAKD.CreateDialogue ();
ClosestInteractionArea.Do_Interaction();
} else if (Input.GetKeyDown (AttackKey) && CharacterAnimator != null) {
Attack ("IsAttacking", AttackSound);
}
Expand All @@ -101,29 +101,29 @@ public void Attack(string animationNameValue, AudioClip clip){

private bool DialogueInteraction(){
// IF we are inside a Action Key Dialogue area.
if(ListOfActionKeyDialogues.Count > 0){
if(ListOfInteractionAreas.Count > 0){
// IF we are not already engaged in a dialogue.
if(!IsActionKeyDialogued){
// Grab the list of dialogue gameobjects that the player is currently inside.
List<Action_Key_Dialogue> akd = ListOfActionKeyDialogues;
List<Interaction_Area> interaction_areas = ListOfInteractionAreas;
// Preset a distance variable to detect the closest action key dialogue.
float _dist = -1f;
// Loop through all the Action Key Dialogues.
for(int i = 0; i < akd.Count; i++){
for(int i = 0; i < interaction_areas.Count; i++){
// See which one is the closest.
float dist = Vector2.Distance(characterEntity.transform.position, akd[i].gameObject.transform.position);
float dist = Vector2.Distance(characterEntity.transform.position, interaction_areas[i].gameObject.transform.position);
// IF this is the first time in here. Also this takes care of 1 Interactive NPC in the List.
// ELSE IF we have more interactive npcs and we need to compare distance to see which is closest.
if(_dist == -1f){
// Set the shortest distance.
_dist = dist;
// Set the closest action key dialogue.
ClosestAKD = akd[i];
ClosestInteractionArea = interaction_areas[i];
}else if(dist < _dist){
// Set the shortest distance.
_dist = dist;
// Set the closest action key dialogue.
ClosestAKD = akd[i];
ClosestInteractionArea = interaction_areas[i];
}
}
// We are now engaged in a dialogue.
Expand All @@ -141,9 +141,9 @@ private bool DialogueInteraction(){
/// lets make sure we are facing them (if you have the animations to do so, if not nothing bad will happen in terms of crashing or atleast it shouldnt :3).
/// </summary>
private void PlayerLookDirection(){
if(ClosestAKD != null){
if(ClosestInteractionArea != null){
// Store the focused objects Transform.
Transform focTransform = ClosestAKD.transform;
Transform focTransform = ClosestInteractionArea.transform;
// IF we have a Four Direction Animation for this gameobject,
// ELSE IF we have a Eight Direction Animation for this gameobject.
if(FourDirAnim){
Expand Down
Loading

0 comments on commit b998e9b

Please sign in to comment.