Wizard - first action - fix

Dialogue add base trigger
This commit is contained in:
kabix09 2022-12-20 15:23:09 +01:00
parent 9d97accd5b
commit e26bbce901
9 changed files with 167 additions and 89 deletions

View File

@ -28654,7 +28654,6 @@ Transform:
- {fileID: 1539180721} - {fileID: 1539180721}
- {fileID: 2042768023} - {fileID: 2042768023}
- {fileID: 543241739} - {fileID: 543241739}
- {fileID: 1839194624}
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}
@ -34004,8 +34003,6 @@ GameObject:
- component: {fileID: 1701466740} - component: {fileID: 1701466740}
- component: {fileID: 1701466739} - component: {fileID: 1701466739}
- component: {fileID: 1701466738} - component: {fileID: 1701466738}
- component: {fileID: 1701466744}
- component: {fileID: 1701466743}
m_Layer: 0 m_Layer: 0
m_Name: UiManager m_Name: UiManager
m_TagString: Untagged m_TagString: Untagged
@ -34104,37 +34101,6 @@ MonoBehaviour:
DynamicPanel: {fileID: 0} DynamicPanel: {fileID: 0}
keyToOpen: 113 keyToOpen: 113
Elements: [] Elements: []
--- !u!114 &1701466743
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1701466736}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 703bf6cf8b4d9d949a3bf7543e072e30, type: 3}
m_Name:
m_EditorClassIdentifier:
DynamicPanel: {fileID: 0}
keyToOpen: 0
Elements: []
--- !u!114 &1701466744
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1701466736}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4d0be1073753419b9be341d0f373ba56, type: 3}
m_Name:
m_EditorClassIdentifier:
DynamicPanel: {fileID: 0}
keyToOpen: 101
Elements: []
CurrentShopOwnerName:
--- !u!1 &1702764354 --- !u!1 &1702764354
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -36887,51 +36853,6 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1823960543} m_GameObject: {fileID: 1823960543}
m_CullTransparentMesh: 1 m_CullTransparentMesh: 1
--- !u!1 &1839194623
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1839194624}
- component: {fileID: 1839194625}
m_Layer: 0
m_Name: ShopManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1839194624
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1839194623}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1144548810}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1839194625
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1839194623}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 40e9faa037584ea2bfba8168125f3fde, type: 3}
m_Name:
m_EditorClassIdentifier:
UiManager: {fileID: 0}
--- !u!1 &1841894126 --- !u!1 &1841894126
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -11,6 +11,7 @@ public enum BossThugEnum
Attacking=2 Attacking=2
} }
[RequireComponent(typeof(NpcDialogueManager))]
public class BossThug : MonoBehaviour public class BossThug : MonoBehaviour
{ {
@ -27,6 +28,11 @@ public class BossThug : MonoBehaviour
public BossThugEnum state = BossThugEnum.Pending; public BossThugEnum state = BossThugEnum.Pending;
// Start is called before the first frame update // Start is called before the first frame update
public void Awake()
{
gameObject.GetComponent<NpcDialogueManager>().OpenInDefaultWay = false;
}
void Start() void Start()
{ {
rb = GetComponent<Rigidbody2D>(); rb = GetComponent<Rigidbody2D>();

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
[RequireComponent(typeof(NPC))] [RequireComponent(typeof(NPC))]
[RequireComponent(typeof(NpcDialogueManager))]
public class NPCFollowing : MonoBehaviour public class NPCFollowing : MonoBehaviour
{ {
private Rigidbody2D myRigidbody; private Rigidbody2D myRigidbody;
@ -28,13 +29,16 @@ public class NPCFollowing : MonoBehaviour
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
isAfterAction = System.Convert.ToBoolean(PlayerPrefs.GetInt(gameObject.GetComponent<NPC>().name + ".FirstDialogue")); //isAfterAction = System.Convert.ToBoolean(PlayerPrefs.GetInt(gameObject.GetComponent<NPC>().name + ".FirstDialogue"));
gameObject.GetComponent<NPC>().State = NPCStateEnum.Walking;
myRigidbody = GetComponent<Rigidbody2D>(); myRigidbody = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>(); anim = GetComponent<Animator>();
homePosition = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z); homePosition = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z);
targetPosition = GameObject.FindWithTag("Player").transform; targetPosition = GameObject.FindWithTag("Player").transform;
if(!isAfterAction)
StartCoroutine(WaitBeforStartingAction(5f));
} }
// Update is called once per frame // Update is called once per frame
@ -43,6 +47,26 @@ public class NPCFollowing : MonoBehaviour
HandleState(); HandleState();
} }
private IEnumerator WaitBeforStartingAction(float waitTime)
{
while (true)
{
yield return new WaitForSeconds(waitTime);
// Start story
approaching = true;
gameObject.GetComponent<NPC>().State = NPCStateEnum.Walking;
}
}
private IEnumerator Wait(float waitTime)
{
while (true)
{
yield return new WaitForSeconds(waitTime);
}
}
public void CheckDistance() public void CheckDistance()
{ {
StopAllCoroutines(); StopAllCoroutines();
@ -60,6 +84,8 @@ public class NPCFollowing : MonoBehaviour
//start dialogue here we want uga bunga //start dialogue here we want uga bunga
gameObject.GetComponent<NPC>().State = NPCStateEnum.Talking; gameObject.GetComponent<NPC>().State = NPCStateEnum.Talking;
gameObject.GetComponent<NpcDialogueManager>().CheckIfCanBeOpen();
} }
} }
@ -118,7 +144,7 @@ public class NPCFollowing : MonoBehaviour
public void DoAction() public void DoAction()
{ {
if (approaching == true && isDuringConversation == false) if (approaching == true && isDuringConversation == false && gameObject.GetComponent<NpcDialogueManager>().CanBeOpened)
{ {
isDuringConversation = true; isDuringConversation = true;
gameObject.GetComponent<NpcDialogueManager>().Dialogue.StartDialogue(); gameObject.GetComponent<NpcDialogueManager>().Dialogue.StartDialogue();

View File

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

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
class DialogueOpenCondition : MonoBehaviour
{
private void OnTriggerStay2D(Collider2D collision)
{
if (collision.tag == "Player")
{
ChestUIManager.Instance.CurrentChestName = gameObject.transform.parent.name;
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.tag == "Player")
{
ChestUIManager.Instance.CurrentChestName = null;
ChestUIManager.Instance.ClosePanel();
}
}
}

View File

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

View File

@ -11,7 +11,7 @@ public class MultiDialogue : ScriptableObject, IDialogue
public string SpeakerName; public string SpeakerName;
[SerializeField] [SerializeField]
int CurrentDialogue = 0; public int CurrentDialogue = 0;
[SerializeField] [SerializeField]
public List<IndexValuePair<int, Dialogue>> Dialogues; public List<IndexValuePair<int, Dialogue>> Dialogues;

View File

@ -21,6 +21,20 @@ public class NpcDialogueManager : MonoBehaviour
// List<Key<dialogue No, dialogue step No>, Value : UnityEvent> // List<Key<dialogue No, dialogue step No>, Value : UnityEvent>
public List<IndexValuePair<IndexValuePair<int, int>, UnityEvent>> EndactionEventList; public List<IndexValuePair<IndexValuePair<int, int>, UnityEvent>> EndactionEventList;
[SerializeField] public KeyCode keyToOpen = KeyCode.E;
public bool CanBeOpened = false;
/// <summary>
/// This flag tell that manager will open dialogue automatically after
/// - beeing in collision range
/// - when dialogue is closed
/// - when Player press KeyToOpen button
///
/// Change var status in other sctipt if you want to use other triggers to open dialogue
/// </summary>
public bool OpenInDefaultWay = true;
public void Start() public void Start()
{ {
Dialogue = Instantiate(languageDetector.DetectInstanceBasedOnLanguage()); Dialogue = Instantiate(languageDetector.DetectInstanceBasedOnLanguage());
@ -29,7 +43,65 @@ public class NpcDialogueManager : MonoBehaviour
Dialogue.Dialogues.ForEach(dial => dial.Value.SetActionAfterDialogueStep(dial.Key, dial.Value.ResetDialogue)); // reset dial Dialogue.Dialogues.ForEach(dial => dial.Value.SetActionAfterDialogueStep(dial.Key, dial.Value.ResetDialogue)); // reset dial
} }
public void Update() { } public void Update()
{
if(OpenInDefaultWay && CanBeOpened && !GetCurrentDialoguePanelStatus() && Input.GetKeyDown(keyToOpen))
gameObject.GetComponent<NpcDialogueManager>().Dialogue.StartDialogue();
}
public void OnTriggerEnter2D(Collider2D collision)
{
// don't listen when component is disabled
if (!gameObject.GetComponent<NpcDialogueManager>().enabled)
return;
if (collision.gameObject.tag == "Player")
CheckIfCanBeOpen();
}
public void OnTriggerExit2D(Collider2D collision)
{
// don't listen when component is disabled
if (!gameObject.GetComponent<NpcDialogueManager>().enabled)
return;
if (collision.gameObject.tag == "Player")
{
CanBeOpened = false;
}
}
/// <summary>
/// Opened = 1
/// Closed = 0
/// </summary>
/// <returns></returns>
public bool GetCurrentDialoguePanelStatus()
{
var multiDialStatius = Dialogue.DialogueStepStatus();
return Dialogue
.Dialogues
.Where(dialogue => dialogue.Key == multiDialStatius.Item1)
.First()
.Value
.DialogueSteps[multiDialStatius.Item2].DialogueController.CurrentPanel != null;
}
public void CheckIfCanBeOpen()
{
/*
* Conditions:
* - agent in collision must be player
* - npc bust me in Talking mode
* - panel assigned to next sentence in dialogue must be closed
*/
if(gameObject.GetComponent<NPC>().State == NPCStateEnum.Talking && !GetCurrentDialoguePanelStatus())
{
CanBeOpened = true;
}
}
/// <summary> /// <summary>
/// Function to invoke actions declared in manager on object from scene not onto asset /// Function to invoke actions declared in manager on object from scene not onto asset

View File

@ -6,6 +6,7 @@ using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
[RequireComponent(typeof(NPC))] [RequireComponent(typeof(NPC))]
[RequireComponent(typeof(NpcDialogueManager))]
public class NpcShopManager : MonoBehaviour public class NpcShopManager : MonoBehaviour
{ {
[SerializeField] [SerializeField]
@ -19,6 +20,11 @@ public class NpcShopManager : MonoBehaviour
bool CanShopBeOpened = false; bool CanShopBeOpened = false;
public void Awake()
{
gameObject.GetComponent<NpcDialogueManager>().OpenInDefaultWay = false;
}
public virtual void Start() public virtual void Start()
{ {
// 1. Set npc state to trading // 1. Set npc state to trading
@ -51,10 +57,12 @@ public class NpcShopManager : MonoBehaviour
* - dialogue panel must be closed * - dialogue panel must be closed
* - shop panel must be closed * - shop panel must be closed
*/ */
if (CanShopBeOpened && Input.GetKeyDown(ShopUIManager.Instance.keyToOpen) && Dialogue.DialogueSteps.First().DialogueController?.CurrentPanel == null && !ShopUIManager.Instance.GetPanelStatus()) if (gameObject.GetComponent<NpcDialogueManager>().CanBeOpened && Input.GetKeyDown(ShopUIManager.Instance.keyToOpen) && !ShopUIManager.Instance.GetPanelStatus())
{ {
// Open dialogue panel (Shop will be opened later) // Open dialogue panel (Shop will be opened later)
Dialogue.StartDialogue(); Dialogue.StartDialogue();
// TODO pass dialogue to npocDialManager and invoke from there
} }
} }
@ -73,7 +81,7 @@ public class NpcShopManager : MonoBehaviour
*/ */
if (collision.gameObject.tag == "Player" && gameObject.GetComponent<NPC>().State == NPCStateEnum.Trading && !ShopUIManager.Instance.GetPanelStatus()) if (collision.gameObject.tag == "Player" && gameObject.GetComponent<NPC>().State == NPCStateEnum.Trading && !ShopUIManager.Instance.GetPanelStatus())
{ {
CanShopBeOpened = true; gameObject.GetComponent<NpcDialogueManager>().CanBeOpened = true;
} }
} }
@ -85,8 +93,6 @@ public class NpcShopManager : MonoBehaviour
if (collision.gameObject.tag == "Player") if (collision.gameObject.tag == "Player")
{ {
CanShopBeOpened = false;
if (Dialogue.DialogueSteps.First().DialogueController?.CurrentPanel != null) if (Dialogue.DialogueSteps.First().DialogueController?.CurrentPanel != null)
Dialogue.BreakDialogueStep(); Dialogue.BreakDialogueStep();