Add files via upload

This commit is contained in:
Geri 2021-01-08 16:05:34 +01:00 committed by GitHub
parent 82aab308f0
commit 310f5c8838
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
54 changed files with 2357 additions and 0 deletions

View file

@ -0,0 +1,12 @@
using UnityEngine;
[CreateAssetMenu(fileName = "New Character", menuName = "Tools/Character", order = 0)]
public class Dialogue : ScriptableObject{
public bool displayName;
public string characterName;
[Space]
public Sprite characterImage;
[TextArea] public string[] sentences;
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bd553cd05b84d614b998afe62e37c17c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 4dfc626116fd10c4f972c17720d957ac, type: 3}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View file

@ -0,0 +1,96 @@
fileFormatVersion: 2
guid: 4dfc626116fd10c4f972c17720d957ac
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,72 @@
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class DialogueSystem : MonoBehaviour{
public static DialogueSystem instance;
public GameObject nameField = default;
public TextMeshProUGUI nameText = default;
public TMP_Animated dialogue = default;
public Image faceImage = default;
Queue<string> sentences;
bool talking;
Animator anim;
void Awake(){
instance = this;
sentences = new Queue<string>();
anim = GetComponent<Animator>();
}
public bool Dialogue(Dialogue dialogue){
if(!talking){
if (dialogue.displayName){
nameText.text = dialogue.characterName;
nameField.SetActive(true);
nameText.gameObject.SetActive(true);
}else{
nameField.SetActive(false);
nameText.gameObject.SetActive(false);
}
if (dialogue.characterImage)
faceImage.sprite = dialogue.characterImage;
else
faceImage.sprite = null;
sentences.Clear();
if(dialogue.sentences.Length != 0){
foreach (string sentence in dialogue.sentences){
sentences.Enqueue(sentence);
}
}else{
sentences.Enqueue("I am error. No text has been added");
}
talking = true;
if(sentences.Count == 0){
talking = false;
return false;
}
string sentenceToShow = sentences.Dequeue();
this.dialogue.ReadText(sentenceToShow);
anim.SetBool("Talking", true);
return true;
}else{
if (sentences.Count == 0){
talking = false;
anim.SetBool("Talking", false);
return false;
}
string sentenceToShow = sentences.Dequeue();
this.dialogue.ReadText(sentenceToShow);
return true;
}
}
}

View file

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

View file

@ -0,0 +1,71 @@
using System.Collections;
using UnityEngine;
using UnityEngine.Events;
namespace TMPro{
[System.Serializable] public class TextRevealEvent : UnityEvent<char> { }
[System.Serializable] public class DialogueEvent : UnityEvent { }
public class TMP_Animated : TextMeshProUGUI{
float speed;
public TextRevealEvent onTextReveal;
public DialogueEvent onDialogueFinish;
public void ReadText(string newText){
text = string.Empty;
string[] subTexts = newText.Split('<', '>');
string displayText = "";
for (int i = 0; i < subTexts.Length; i++){
if (i % 2 == 0)
displayText += subTexts[i];
else if (!isCustomTag(subTexts[i].Replace(" ", "")))
displayText += $"<{subTexts[i]}>";
}
bool isCustomTag(string tag){
return tag.StartsWith("speed=") || tag.StartsWith("pause=");
}
text = displayText;
maxVisibleCharacters = 0;
StartCoroutine(Read());
IEnumerator Read(){
int subCounter = 0;
int visibleCounter = 0;
while(subCounter < subTexts.Length){
if(subCounter % 2 == 1){
yield return EvaluateTag(subTexts[subCounter].Replace(" ", ""));
}else{
while(visibleCounter < subTexts[subCounter].Length){
onTextReveal.Invoke(subTexts[subCounter][visibleCounter]);
visibleCounter++;
maxVisibleCharacters++;
yield return new WaitForSeconds(1f / speed);
}
visibleCounter = 0;
}
subCounter++;
}
yield return null;
WaitForSeconds EvaluateTag(string tag){
if (tag.Length > 0){
if (tag.StartsWith("speed=")){
speed = float.Parse(tag.Split('=')[1]);
}else if (tag.StartsWith("pause=")){
return new WaitForSeconds(float.Parse(tag.Split('=')[1]));
}
}
return null;
}
onDialogueFinish.Invoke();
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f713d84a3ae882945800780459e26170
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 2fd6421f253b4ef1a19526541f9ffc0c, type: 3}
userData:
assetBundleName:
assetBundleVariant: