Wizard - first action

This commit is contained in:
kabix09 2022-12-20 04:37:00 +01:00
parent c006e4a8ee
commit 00f210e83c
17 changed files with 603 additions and 92 deletions

View File

@ -27,6 +27,7 @@ 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_ConstrainProportionsScale: 0
m_Children:
- {fileID: 8200704089772688228}
m_Father: {fileID: 0}
@ -72,6 +73,7 @@ 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_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 3486965691320864245}
m_RootOrder: 0
@ -5205,6 +5207,16 @@ Tilemap:
m_TileObjectToInstantiateIndex: 65535
dummyAlignment: 0
m_AllTileFlags: 1073741825
- first: {x: 12, y: -11, z: 0}
second:
serializedVersion: 2
m_TileIndex: 750
m_TileSpriteIndex: 5
m_TileMatrixIndex: 0
m_TileColorIndex: 0
m_TileObjectToInstantiateIndex: 65535
dummyAlignment: 0
m_AllTileFlags: 1073741825
- first: {x: 14, y: -11, z: 0}
second:
serializedVersion: 2
@ -9087,6 +9099,8 @@ Tilemap:
m_Data: {fileID: 11400000, guid: d90c4377fe799d24a907e16c49d733cc, type: 2}
- m_RefCount: 1
m_Data: {fileID: 11400000, guid: c0ff3f7c040bfc041a2a0e4aa11c36a1, type: 2}
- m_RefCount: 1
m_Data: {fileID: 11400000, guid: 5c6bb9f647437dd4abf63fe1280c5512, type: 2}
m_TileSpriteArray:
- m_RefCount: 1
m_Data: {fileID: 3105379272556981734, guid: e7698f36d680635418599dd2745a3e61, type: 3}
@ -9098,7 +9112,7 @@ Tilemap:
m_Data: {fileID: 6696878938533527509, guid: e7698f36d680635418599dd2745a3e61, type: 3}
- m_RefCount: 1
m_Data: {fileID: -3159373967292191595, guid: e7698f36d680635418599dd2745a3e61, type: 3}
- m_RefCount: 1
- m_RefCount: 2
m_Data: {fileID: 6995023442814134182, guid: e7698f36d680635418599dd2745a3e61, type: 3}
- m_RefCount: 1
m_Data: {fileID: 5081585780740693538, guid: e7698f36d680635418599dd2745a3e61, type: 3}
@ -10589,7 +10603,7 @@ Tilemap:
- m_RefCount: 1
m_Data: {fileID: -179191534720846178, guid: e7698f36d680635418599dd2745a3e61, type: 3}
m_TileMatrixArray:
- m_RefCount: 750
- m_RefCount: 751
m_Data:
e00: 1
e01: 0
@ -10608,7 +10622,7 @@ Tilemap:
e32: 0
e33: 1
m_TileColorArray:
- m_RefCount: 750
- m_RefCount: 751
m_Data: {r: 1, g: 1, b: 1, a: 1}
m_TileObjectToInstantiateArray: []
m_AnimationFrameRate: 1
@ -10645,6 +10659,7 @@ TilemapRenderer:
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 0
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 0
m_ReflectionProbeUsage: 0
@ -10682,7 +10697,7 @@ TilemapRenderer:
m_Mode: 0
m_DetectChunkCullingBounds: 0
m_MaskInteraction: 0
--- !u!114 &2835299736381380299
--- !u!114 &4797349935403030433
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}

View File

@ -103,4 +103,16 @@ MonoBehaviour:
Buttons: []
EndOfDialogueStepAction:
m_PersistentCalls:
m_Calls: []
m_Calls:
- m_Target: {fileID: 4759712171538235750, guid: 417d111e604a8124cb960805d809e513, type: 3}
m_TargetAssemblyTypeName: NpcDialogueManager, Assembly-CSharp
m_MethodName: StepEndAction
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2

View File

@ -12,6 +12,7 @@ GameObject:
- component: {fileID: 4759712171538235752}
- component: {fileID: 4759712171538235748}
- component: {fileID: 4759712171538235749}
- component: {fileID: 1190203389089447339}
- component: {fileID: -8463239967595622325}
- component: {fileID: 4759712171538235750}
- component: {fileID: 7232042190984337245}
@ -33,6 +34,7 @@ Transform:
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -1.9412931, y: -2.068871, z: 133.20683}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
@ -48,6 +50,7 @@ SpriteRenderer:
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
@ -125,6 +128,26 @@ CircleCollider2D:
m_Offset: {x: 0, y: 0}
serializedVersion: 2
m_Radius: 1.5
--- !u!95 &1190203389089447339
Animator:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4759712171538235754}
m_Enabled: 1
m_Avatar: {fileID: 0}
m_Controller: {fileID: 9100000, guid: 4e408ead2b862ca4685d5ace7011f083, type: 2}
m_CullingMode: 0
m_UpdateMode: 0
m_ApplyRootMotion: 0
m_LinearVelocityBlending: 0
m_StabilizeFeet: 0
m_WarningMessage:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorControllerStateOnDisable: 0
--- !u!114 &-8463239967595622325
MonoBehaviour:
m_ObjectHideFlags: 0
@ -138,6 +161,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
Name: Wizard
State: 1
--- !u!114 &4759712171538235750
MonoBehaviour:
m_ObjectHideFlags: 0
@ -193,7 +217,7 @@ MonoBehaviour:
isAfterAction: 0
isDuringConversation: 0
actionRadius: 1
state: 1
state: 5
--- !u!114 &-7576677615092044163
MonoBehaviour:
m_ObjectHideFlags: 0
@ -213,4 +237,5 @@ MonoBehaviour:
walkable: 0
worldPosition: {x: 0, y: 0, z: 0}
gridPosition: {x: 0, y: 0}
isChasing: 0
path: []

View File

@ -0,0 +1,36 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 13312, guid: 0000000000000000e000000000000000, type: 0}
m_Name: inside_5 1
m_EditorClassIdentifier:
m_Sprite: {fileID: 6995023442814134182, guid: e7698f36d680635418599dd2745a3e61, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Transform:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
m_InstancedGameObject: {fileID: 0}
m_Flags: 1
m_ColliderType: 1

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5c6bb9f647437dd4abf63fe1280c5512
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -2,39 +2,38 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(NPC))]
public class NPCFollowing : MonoBehaviour
{
private Rigidbody2D myRigidbody;
public Animator anim;
public Transform homePosition;
public Vector3 homePosition;
public Transform targetPosition;
public AStarPathfindingAgent agent;
public GameObject player;
//public GameObject player;
public bool approaching = false;
public bool isAfterAction = false;
public bool isDuringConversation = false;
public float actionRadius = 1.0f;
public NPCStateEnum state = NPCStateEnum.Pending;
public float actionRadius = 1.5f;
void Awake()
{
//agent = GetComponent<AStarPathfindingAgent>();
agent = GetComponent<AStarPathfindingAgent>();
}
// Start is called before the first frame update
void Start()
{
isAfterAction = System.Convert.ToBoolean(PlayerPrefs.GetInt(gameObject.GetComponent<NPC>().name + ".FirstDialogue"));
state = NPCStateEnum.Walking;
gameObject.GetComponent<NPC>().State = NPCStateEnum.Walking;
myRigidbody = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
homePosition = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z);
targetPosition = GameObject.FindWithTag("Player").transform;
}
@ -47,63 +46,53 @@ public class NPCFollowing : MonoBehaviour
public void CheckDistance()
{
StopAllCoroutines();
if (isAfterAction == false)
{
if (approaching && Vector2.Distance(targetPosition.position, transform.position) >= actionRadius)
{
agent.FindPath();
//transform.position = Vector2.MoveTowards(transform.position, target.position, moveSpeed * Time.deltaTime);
StartCoroutine(agent.FollowPath());
}
/* else if (Vector2.Distance(target.position, transform.position) > chaseRadius)
{
//Debug.Log(Vector2.Distance(transform.position, path[currentPoint].position));
if (Vector2.Distance(transform.position, path[currentPoint].position) > roundingDistance)
{
StopAllCoroutines();
transform.position = Vector2.MoveTowards(transform.position, path[currentPoint].position, 2 * Time.deltaTime);
}
else
{
changeGoal();
}
}*/
else if (approaching)
{
//start dialogue here we want uga bunga
state = NPCStateEnum.Talking;
gameObject.GetComponent<NPC>().State = NPCStateEnum.Talking;
}
}
else if (!approaching && isAfterAction)
{
if (Vector2.Distance(transform.position, homePosition.position) > 1)
if (Vector2.Distance(transform.position, homePosition) > 0.05)
{
transform.position = Vector2.MoveTowards(transform.position, homePosition.position, 2 * Time.deltaTime);
transform.position = Vector2.MoveTowards(transform.position, homePosition, 2 * Time.deltaTime);
}
else
{
state = NPCStateEnum.Pending;
gameObject.GetComponent<NPC>().State = NPCStateEnum.Pending;
}
}
}
public void OnTriggerExit2D(Collider2D other)
{
// don't listen when component is disabled
if (!gameObject.GetComponent<NPCFollowing>().enabled)
return;
if (approaching && !isAfterAction)
{
gameObject.GetComponent<NpcDialogueManager>().Dialogue.BreakDialogueStep();
isDuringConversation = false;
state = NPCStateEnum.Walking;
gameObject.GetComponent<NPC>().State = NPCStateEnum.Walking;
}
}
public void HandleState()
{
switch (state)
switch (gameObject.GetComponent<NPC>().State)
{
case NPCStateEnum.Walking:
{
@ -140,13 +129,8 @@ public class NPCFollowing : MonoBehaviour
{
approaching = false;
isAfterAction = true;
isDuringConversation = false;
PlayerPrefs.SetInt(gameObject.name + ".FirstDialogue", System.Convert.ToInt32(isAfterAction));
state = NPCStateEnum.Walking;
gameObject.GetComponent<NPC>().State = NPCStateEnum.Walking;
}
public void SaveCheckpoint()
{
//PlayerPrefs.SetInt(enemyName + "-S", isKilled);
}
}

View File

@ -83,7 +83,6 @@ public class AStarPathfindingAgent : MonoBehaviour
myAnim.SetBool("Left", false);
}
transform.position = Vector3.MoveTowards(current, target, speed * Time.deltaTime);
Debug.Log(current + "target:" + target);
yield return null;
}
}

View File

@ -0,0 +1,19 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9890013e3eb0ea54b90ab8d093688ac6, type: 3}
m_Name: Ground - Wizard House
m_EditorClassIdentifier:
Tiles:
- {fileID: 11400000, guid: 8c3ddee63bc5db14db29c992ee3723b7, type: 2}
- {fileID: 11400000, guid: 0ee6194169e25d549b4d73f743602734, type: 2}
- {fileID: 11400000, guid: 329a66bde198f1940b719c63b8a3a0e6, type: 2}
walkable: 1

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 968830a9b677b6e46bbc887a37627ac6
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -6,14 +6,13 @@ using UnityEngine;
using UnityEngine.Events;
[RequireComponent(typeof(NPC))]
[Serializable]
public class NpcDialogueManager : MonoBehaviour
{
[SerializeField]
public string SpeakerName;
[SerializeField]
public MultiDialogue DialogueTemplate;
public LanguageDetector<MultiDialogue> languageDetector;
/* We user object CLONED TO PREVENT overwritting changes in main object inassets */
[SerializeField]
@ -24,8 +23,10 @@ public class NpcDialogueManager : MonoBehaviour
public void Start()
{
Dialogue = Instantiate(DialogueTemplate);
Dialogue = Instantiate(languageDetector.DetectInstanceBasedOnLanguage());
Dialogue.SetSpeakerName(SpeakerName);
Dialogue.Dialogues.ForEach(dial => dial.Value.SetActionAfterDialogueStep(dial.Key, dial.Value.ResetDialogue)); // reset dial
}
public void Update() { }

View File

@ -6,10 +6,10 @@ using UnityEngine;
using UnityEngine.SceneManagement;
[RequireComponent(typeof(NPC))]
class NpcShopManager : MonoBehaviour
public class NpcShopManager : MonoBehaviour
{
[SerializeField]
public List<IndexValuePair<SystemLanguageEnum, Dialogue>> DialogueTemplate;
public LanguageDetector<Dialogue> languageDetector;
/* We user object CLONED TO PREVENT overwritting changes in main object inassets */
public Dialogue Dialogue;
@ -97,7 +97,7 @@ class NpcShopManager : MonoBehaviour
public void CreateInstanceBasedOnLanguage()
{
Dialogue = Instantiate(DetectInstanceBasedOnLanguage());
Dialogue = Instantiate(languageDetector.DetectInstanceBasedOnLanguage());
Dialogue.SetSpeakerName(gameObject.GetComponent<NPC>().name);
Dialogue.SetActionAfterDialogueStep(0, Dialogue.ResetDialogue);
Dialogue.SetActionAfterDialogueStep(0, OpenShop);
@ -138,27 +138,5 @@ class NpcShopManager : MonoBehaviour
ShopUIManager.Instance.ClosePanel();
}
public Dialogue DetectInstanceBasedOnLanguage()
{
/*if (!PlayerPrefs.HasKey("language"))
throw new Exception("Language not setted !!!");*/
switch(PlayerPrefs.GetString("language"))
{
case "English":
{
return DialogueTemplate.Where(template => template.Key == SystemLanguageEnum.English).First().Value;
}
case "Polish":
{
return DialogueTemplate.Where(template => template.Key == SystemLanguageEnum.Polish).First().Value;
}
default:
{
return DialogueTemplate.Where(template => template.Key == SystemLanguageEnum.Polish).First().Value;
}
}
}
}

View File

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

View File

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
[Serializable]
public class LanguageDetector<T>
{
[SerializeField]
public List<IndexValuePair<SystemLanguageEnum, T>> InstanceTemplates;
public T DetectInstanceBasedOnLanguage()
{
/*if (!PlayerPrefs.HasKey("language"))
throw new Exception("Language not setted !!!");*/
switch (PlayerPrefs.GetString("language"))
{
case "English":
{
return InstanceTemplates.Where(template => template.Key == SystemLanguageEnum.English).First().Value;
}
case "Polish":
{
return InstanceTemplates.Where(template => template.Key == SystemLanguageEnum.Polish).First().Value;
}
default:
{
return InstanceTemplates.Where(template => template.Key == SystemLanguageEnum.Polish).First().Value;
}
}
}
}

View File

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

View File

@ -0,0 +1,5 @@
public enum SystemLanguageEnum
{
Polish,
English
}

View File

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