Commit d0256517 authored by 15박보승's avatar 15박보승

First version of DialogueSystem. Have some issues on DialogueSceneMaker's save problem.

parent 58943ad6
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class DialogueSceneMakerWindow : EditorWindow
{
[SerializeField]
public List<Dialogue> dialogues = new List<Dialogue>();
private string characterName;
private string dialogueText;
private int imageIndex;
Vector2 dialogueScroll;
private int loadFromDialoguesIndex = 0;
Rect dialogueAdderWindowRect = new Rect(0, 0, 400, 400);
Rect dialogueSceneMakerWindowRect = new Rect(400, 0, 400, 600);
DialogueScene dialogueScene = null;
string newFileName;
[MenuItem ("Tools/DialogueSceneMaker")]
static void Init()
{
DialogueSceneMakerWindow window = (DialogueSceneMakerWindow)EditorWindow.GetWindow(typeof(DialogueSceneMakerWindow));
window.minSize = new Vector2(800, 400);
window.Show();
}
private void OnGUI()
{
BeginWindows();
dialogueAdderWindowRect = GUILayout.Window(1, dialogueAdderWindowRect, DialogueAdderWindow, "Dialogue Adder");
dialogueSceneMakerWindowRect = GUILayout.Window(2, dialogueSceneMakerWindowRect, DialogueSceneWindow, "Dialogue Scene Maker");
EndWindows();
}
void DialogueAdderWindow(int id)
{
characterName = EditorGUILayout.TextField("Character Name", characterName, GUILayout.MaxWidth(position.width / 2));
imageIndex = EditorGUILayout.IntField("Character Image Index", imageIndex, GUILayout.MaxWidth(position.width / 2));
GUILayout.Label("Dialogue");
dialogueText = EditorGUILayout.TextArea(dialogueText, GUILayout.Height(200), GUILayout.MaxWidth(position.width / 2));
if (GUILayout.Button("Add new Dialogue", GUILayout.MaxWidth(position.width / 2)))
{
dialogues.Add(new Dialogue(characterName, imageIndex, dialogueText));
characterName = "";
imageIndex = 0;
dialogueText = "";
}
EditorGUILayout.BeginHorizontal();
loadFromDialoguesIndex = EditorGUILayout.IntField(loadFromDialoguesIndex, GUILayout.MaxWidth(position.width / 4));
if (GUILayout.Button("Add new Dialogue at", GUILayout.MaxWidth(position.width / 4)))
{
dialogues.Add(new Dialogue(characterName, imageIndex, dialogueText));
characterName = "";
imageIndex = 0;
dialogueText = "";
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
loadFromDialoguesIndex = EditorGUILayout.IntField(loadFromDialoguesIndex, GUILayout.MaxWidth(position.width / 4));
if (GUILayout.Button("Edit Dialogue at", GUILayout.MaxWidth(position.width / 4)))
{
dialogues.Add(new Dialogue(characterName, imageIndex, dialogueText));
characterName = "";
imageIndex = 0;
dialogueText = "";
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
loadFromDialoguesIndex = EditorGUILayout.IntField(loadFromDialoguesIndex, GUILayout.MaxWidth(position.width / 4));
if (GUILayout.Button("Load from current Dialogues", GUILayout.MaxWidth(position.width / 4)))
{
Dialogue dialogue = dialogues[loadFromDialoguesIndex];
characterName = dialogue.characterName;
imageIndex = dialogue.imageIndex;
dialogueText = dialogue.dialogue;
}
EditorGUILayout.EndHorizontal();
GUI.DragWindow();
}
void DialogueSceneWindow(int id)
{
GUILayout.Label("Current dialogue list", EditorStyles.boldLabel);
/*
GUILayout.BeginHorizontal();
dialogueScene = EditorGUILayout.ObjectField(dialogueScene, typeof(DialogueScene), false) as DialogueScene;
if (GUILayout.Button("Save", GUILayout.Width(100)))
{
}
if (GUILayout.Button("Load", GUILayout.Width(100)))
{
}
GUILayout.EndHorizontal();
/*
GUILayout.BeginHorizontal();
if (GUILayout.Button("Save", GUILayout.Width(100)))
{
}
if (GUILayout.Button("Load", GUILayout.Width(100)))
{
}
GUILayout.EndHorizontal();
*/
dialogueScroll = GUILayout.BeginScrollView(dialogueScroll);
var serializedObject = new SerializedObject(this);
var list = serializedObject.FindProperty("dialogues");
for (int i = 0; i < dialogues.Count; i++)
{
if (EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i),new GUIContent("Dialogue " + i.ToString()), true))
{
Debug.Log("ASDF");
var element = list.GetArrayElementAtIndex(i);
Dialogue dialogue = new Dialogue(
element.FindPropertyRelative("characterName").stringValue,
element.FindPropertyRelative("imageIndex").intValue,
element.FindPropertyRelative("dialogue").stringValue);
dialogues[i] = dialogue;
}
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (i > 0 && GUILayout.Button("↑", GUILayout.Width(20)))
{
Dialogue tmp = dialogues[i];
dialogues[i] = dialogues[i - 1];
dialogues[i - 1] = tmp;
break;
}
if (i < dialogues.Count - 1 && GUILayout.Button("↓", GUILayout.Width(20)))
{
Dialogue tmp = dialogues[i];
dialogues[i] = dialogues[i + 1];
dialogues[i + 1] = tmp;
break;
}
if (GUILayout.Button("+", GUILayout.Width(20)))
{
Dialogue tmp = new Dialogue(dialogues[i]);
dialogues.Insert(i + 1, tmp);
break;
}
if (GUILayout.Button("-", GUILayout.Width(20)))
{
dialogues.RemoveAt(i);
break;
}
GUILayout.EndHorizontal();
}
//EditorGUILayout.PropertyField(serializedObject.FindProperty("dialogues"), true, GUILayout.MaxWidth(position.width / 2));
GUILayout.EndScrollView();
GUI.DragWindow();
}
private void DialogueToEditorLayout(Dialogue dialogue)
{
}
}
fileFormatVersion: 2
guid: 2b8c933142c00294a800218e560e47dc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 7d44666a110d44a45bd7549e672ff0cc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 0e6c274425cdaa74f9c4b259333a3272
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
%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: eb3c5962ff7102843bc0a9c7df365f14, type: 3}
m_Name: Ezest
m_EditorClassIdentifier:
characterID: 0
characterName: Ezest
characterImageList:
- {fileID: 21300000, guid: 7a06fe9ad429ede4b8ae38144a30904d, type: 3}
- {fileID: 21300000, guid: 83ffe2f668b9cb24eaed3dd2229a1a18, type: 3}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 21300000, guid: 4c85b737d44119f4f828910c3bd26659, type: 3}
fileFormatVersion: 2
guid: 3138cc75370306745819c692135feee9
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:
%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: eb3c5962ff7102843bc0a9c7df365f14, type: 3}
m_Name: Ezist
m_EditorClassIdentifier:
characterID: 1
characterName: Ezist
characterImageList:
- {fileID: 21300000, guid: 7a06fe9ad429ede4b8ae38144a30904d, type: 3}
- {fileID: 21300000, guid: 4c85b737d44119f4f828910c3bd26659, type: 3}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 21300000, guid: 83ffe2f668b9cb24eaed3dd2229a1a18, type: 3}
fileFormatVersion: 2
guid: 4d16dbf81c2a92d488f6c3b8e23f94ed
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: a82113107d03ae644bb964177074714b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
%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: dae6c022c564874489089cfdac8364b2, type: 3}
m_Name: First
m_EditorClassIdentifier:
dialogues:
- characterName: Ezest
dialogue: "\uB098\uB294 \uC544\uBB34 \uC0DD\uAC01\uC774 \uC5C6\uB2E4."
characterCount: 1
characterIDs: 00000000
expressions: 00000000
- characterName: Ezest
dialogue: "\uC65C\uB0D0\uD558\uBA74 \uC544\uBB34 \uC0DD\uAC01\uC774 \uC5C6\uAE30
\uB54C\uBB38\uC774\uB2E4."
characterCount: 1
characterIDs: 00000000
expressions: 00000000
- characterName: Ezest
dialogue: "(\uB300\uCDA9 \uBBF8\uC18C\uC9D3\uAE30)"
characterCount: 1
characterIDs: 0000000000000000
expressions: 0100000000000000
- characterName: Ezist
dialogue: "(\uB300\uCDA9 \uC695\uD558\uAE30)"
characterCount: 2
characterIDs: 0000000000000000
expressions: 0100000000000000
- characterName: Ezest
dialogue: "(\uB300\uCDA9 \uD654\uB0B4\uAE30)"
characterCount: 1
characterIDs: 00000000
expressions: 08000000
fileFormatVersion: 2
guid: 9827229ed9108954781b6f1f0aa51872
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 2cda990e2423bbf4892e6590ba056729
guid: 7bf2393a390c57e4a989e6392274443f
DefaultImporter:
externalObjects: {}
userData:
......
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 9
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 3
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 11
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_TemporalCoherenceThreshold: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 0
m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings:
serializedVersion: 10
m_Resolution: 2
m_BakeResolution: 40
m_AtlasSize: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 0
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 500
m_PVRBounces: 2
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVRFilteringMode: 1
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ShowResolutionOverlay: 1
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &519420028
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 519420032}
- component: {fileID: 519420031}
- component: {fileID: 519420029}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &519420029
AudioListener:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 519420028}
m_Enabled: 1
--- !u!20 &519420031
Camera:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 519420028}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 2
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 0
m_HDR: 1
m_AllowMSAA: 0
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 0
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!4 &519420032
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 519420028}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
fileFormatVersion: 2
guid: 316fb978b30c81c47a60b54e29d10440
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 025d88b35e61fa848ada98d7872dcfdb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
/// <summary>
/// Used for loading dialogue system's character sprite. You can custom this as you needed.
/// </summary>
public enum CharacterExpression
{
DEFAULT,
SMILE,
HAPPINESS,
SAD,
CRY,
DEPRESSION,
CONFUSED,
DISPLEASURE,
ANGRY
}
public class CharacterResource : ScriptableObject
{
public int characterID;
public string characterName;
public Sprite[] characterImageList = new Sprite[Enum.GetNames(typeof(CharacterExpression)).Length];
public Sprite GetCharacterImage(int index)
{
return characterImageList[index];
}
public Sprite GetCharacterImage(CharacterExpression expression)
{
return characterImageList[(int)expression];
}
}
fileFormatVersion: 2
guid: eb3c5962ff7102843bc0a9c7df365f14
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -6,12 +6,16 @@ using BS;
public class DialogueScene : ScriptableObject
{
[SerializeField]
private List<Dialogue> dialogues = new List<Dialogue>();
public List<Dialogue> dialogues = new List<Dialogue>();
private int dialogueIndex = 0;
public bool IsEnd { get { return dialogueIndex >= dialogues.Count; } }
public bool IsStart { get { return dialogueIndex == 0; } }
public bool IsStart { get { return dialogueIndex == 1; } }
public void Init()
{
dialogueIndex = 0;
}
public Dialogue GetNextDialogue()
{
......@@ -20,29 +24,35 @@ public class DialogueScene : ScriptableObject
public Dialogue GetPrevDialogue()
{
return dialogues[dialogueIndex--];
return dialogues[--dialogueIndex - 1];
}
}
[System.Serializable]
public struct Dialogue
{
public Dialogue(string characterName, int imageIndex, string dialogue)
public string characterName;
[TextArea]
public string dialogue;
public int characterCount;
public List<int> characterIDs;
public List<CharacterExpression> expressions;
public Dialogue(string characterName, string dialogue, int characterCount, List<int> characterIDs, List<CharacterExpression> expressions)
{
this.characterName = characterName;
this.imageIndex = imageIndex;
this.dialogue = dialogue;
}
this.characterCount = characterCount;
this.characterIDs = characterIDs;
this.expressions = expressions;
}
public Dialogue(Dialogue dialogue)
{
this.characterName = dialogue.characterName;
this.imageIndex = dialogue.imageIndex;
this.dialogue = dialogue.dialogue;
}
public string characterName;
[TextArea]
public string dialogue;
public int imageIndex;
this.characterCount = dialogue.characterCount;
this.characterIDs = dialogue.characterIDs;
this.expressions = dialogue.expressions;
}
}
\ No newline at end of file
......@@ -22,14 +22,32 @@ public class DialogueSystem : MonoBehaviour
public List<Image> characterImages = new List<Image>();
[SerializeField]
private DialogueScene dialogueScene;
public string nextButton, prevButton;
private void Update()
public Image testImage;
private Dictionary<int, CharacterResource> characterResources = new Dictionary<int, CharacterResource>();
private void Start()
{
foreach (var resource in Resources.LoadAll<CharacterResource>("BS_DialogueSystem/CharacterResources"))
{
characterResources.Add(resource.characterID, resource);
}
if (dialogueScene != null)
{
dialogueScene.Init();
NextDialogue();
}
}
private void Update()
{
/*
if (Input.GetButtonDown(nextButton))
{
NextDialogue();
......@@ -38,7 +56,16 @@ public class DialogueSystem : MonoBehaviour
{
PrevDialogue();
}
}
*/
if (Input.GetKeyDown(KeyCode.RightArrow))
{
NextDialogue();
}
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
PrevDialogue();
}
}
public void StartDialogueScene(DialogueScene dialogueScene)
{
......@@ -50,14 +77,22 @@ public class DialogueSystem : MonoBehaviour
{
if (dialogueScene.IsEnd)
{
return;
}
Dialogue dialogue = dialogueScene.GetNextDialogue();
nameText.text = dialogue.characterName;
StartCoroutine(TypingDialogue(dialogue.dialogue));
int i = 0;
for (; i < dialogue.characterIDs.Count; i++)
{
characterImages[i].enabled = true;
characterImages[i].sprite = characterResources[dialogue.characterIDs[i]].GetCharacterImage(dialogue.expressions[i]);
}
for (; i < characterImages.Count; i++)
{
characterImages[i].enabled = false;
}
StopAllCoroutines();
StartCoroutine(TypingDialogue(dialogue.dialogue));
}
public void PrevDialogue()
......@@ -67,7 +102,18 @@ public class DialogueSystem : MonoBehaviour
return;
}
Dialogue dialogue = dialogueScene.GetPrevDialogue();
nameText.text = dialogue.characterName;
nameText.text = dialogue.characterName;
int i = 0;
for (; i < dialogue.characterIDs.Count; i++)
{
characterImages[i].enabled = true;
characterImages[i].sprite = characterResources[dialogue.characterIDs[i]].GetCharacterImage(dialogue.expressions[i]);
}
for (; i < characterImages.Count; i++)
{
characterImages[i].enabled = false;
}
StopAllCoroutines();
StartCoroutine(TypingDialogue(dialogue.dialogue));
}
......@@ -79,10 +125,12 @@ public class DialogueSystem : MonoBehaviour
typingTime /= dialogue.Length;
}
for (int i = 0; i < dialogue.Length; i++)
dialogueText.text = "";
for (int i = 0; i < dialogue.Length; i++)
{
dialogueText.text += dialogue[i];
yield return new WaitForSeconds(dialogueTypingSpeed);
yield return new WaitForSeconds(typingTime);
}
}
......
fileFormatVersion: 2
guid: 960b43286e99c8a4a85493d810859a59
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
using System.Linq;
using System.IO;
public class CharacterResourceEditorWindow : EditorWindow
{
public static Dictionary<int, CharacterResource> characters = new Dictionary<int, CharacterResource>();
private int characterIndex = 0;
Rect characterEditWindowRect = new Rect(0, 0, 400, 600);
Rect characterAdderWindowRect = new Rect(400, 0, 400, 600);
private int newCharacterID = 0;
private string newCharacterName = "";
private Sprite[] newCharacterImageList = new Sprite[Enum.GetNames(typeof(CharacterExpression)).Length];
private Vector2 newCharacterScroll;
private Vector2 characterEditScroll;
[MenuItem("Tools/Dialogue Character Resource Editor")]
static void Init()
{
CharacterResourceEditorWindow window = (CharacterResourceEditorWindow)GetWindow(typeof(CharacterResourceEditorWindow));
foreach (var character in Resources.LoadAll<CharacterResource>("BS_DialogueSystem/CharacterResources"))
{
try
{
characters.Add(character.characterID, character);
}
catch
{
Debug.LogError("Character ID is not unique! Check " +
characters[character.characterID].characterName +" and " +
character.characterName + "!");
throw;
}
}
window.Show();
}
private void OnGUI()
{
BeginWindows();
characterEditWindowRect = GUILayout.Window(0, characterEditWindowRect, CharacterEditWindow, "Character Editor");
characterAdderWindowRect = GUILayout.Window(1, characterAdderWindowRect, CharacterAdderWindow, "Character Adder");
EndWindows();
}
private void CharacterEditWindow(int id)
{
string[] names = new string[characters.Count];
int i = 0;
foreach (var key in characters.Keys)
{
names[i++] = characters[key].characterName;
}
characterIndex = EditorGUILayout.IntPopup("Character List", characterIndex, names, characters.Keys.ToArray());
CharacterResource character = characters[characterIndex];
characterEditScroll = EditorGUILayout.BeginScrollView(characterEditScroll);
/*
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Character ID");
EditorGUILayout.LabelField(character.characterID.ToString());
//character.characterID = EditorGUILayout.IntField("Character ID", character.characterID);
EditorGUILayout.EndHorizontal();
character.characterName = EditorGUILayout.TextField("Character Name", character.characterName);
*/
EditorGUILayout.LabelField("Character Images", EditorStyles.boldLabel);
string[] expressionNames = Enum.GetNames(typeof(CharacterExpression));
for (i = 0; i < newCharacterImageList.Length; i++)
{
character.characterImageList[i] = EditorGUILayout.ObjectField(expressionNames[i].ToLower(), character.characterImageList[i], typeof(Sprite), false) as Sprite;
}
EditorGUILayout.EndScrollView();
characters[characterIndex] = character;
GUI.DragWindow();
}
private void CharacterAdderWindow(int id)
{
SaveAsNewGUI();
newCharacterScroll = EditorGUILayout.BeginScrollView(newCharacterScroll);
newCharacterID = EditorGUILayout.IntField("Character ID", newCharacterID);
newCharacterName = EditorGUILayout.TextField("Character Name", newCharacterName);
EditorGUILayout.LabelField("Character Images", EditorStyles.boldLabel);
string[] expressionNames = Enum.GetNames(typeof(CharacterExpression));
for (int i = 0; i < newCharacterImageList.Length; i++)
{
newCharacterImageList[i] = EditorGUILayout.ObjectField(expressionNames[i].ToLower(),newCharacterImageList[i], typeof(Sprite), false) as Sprite;
}
EditorGUILayout.EndScrollView();
GUI.DragWindow();
}
private void SaveAsNewGUI()
{
GUILayout.BeginHorizontal();
bool hasSameID = false;
foreach (var character in Resources.LoadAll<CharacterResource>("BS_DialogueSystem/CharacterResources"))
{
hasSameID = character.characterID == newCharacterID;
if (hasSameID)
break;
}
GUI.enabled = newCharacterName.Length > 0 &&
Resources.Load<CharacterResource>("BS_DialougeSystem/CharacterResources" + newCharacterName) == null &&
!hasSameID;
if (GUILayout.Button("Save as new", GUILayout.Width(100)))
{
SaveAsNew();
}
GUILayout.EndHorizontal();
if (!GUI.enabled)
{
GUIStyle style = new GUIStyle();
style.normal.textColor = Color.red;
if (newCharacterName.Length <= 0)
{
EditorGUILayout.LabelField("Name must be longer than 0!", style);
}
else if (hasSameID)
{
EditorGUILayout.LabelField("ID is already used!", style);
}
else
{
EditorGUILayout.LabelField("The same named character already exists!", style);
}
}
GUI.enabled = true;
}
private void SaveAsNew()
{
CharacterResource resource = CreateInstance<CharacterResource>();
resource.characterID = newCharacterID;
resource.characterName = newCharacterName;
resource.characterImageList = newCharacterImageList;
string dir = Application.dataPath;
if (!Directory.Exists(dir + "/Resources/BS_DialogueSystem/CharacterResources"))
{
Debug.Log("Creating directory for CharacterResource assets...");
try
{
Directory.CreateDirectory(dir + "/Resources/BS_DialogueSystem/CharacterResources");
}
catch
{
Debug.LogError("Creating directory Failed!");
throw;
}
Debug.Log("Creating directory Success!");
}
try
{
AssetDatabase.CreateAsset(resource, "Assets/Resources/BS_DialogueSystem/CharacterResources/" + newCharacterName + ".asset");
}
catch
{
Debug.LogError("Creating" + newCharacterName + ".asset Failed!");
throw;
}
Debug.Log("Creating " + newCharacterName + ".asset Success!");
characters.Add(resource.characterID, resource);
newCharacterID = 0;
newCharacterName = "";
newCharacterImageList = new Sprite[Enum.GetNames(typeof(CharacterExpression)).Length];
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: b1da36e951418ba46836c97872d83fa2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System;
using System.Linq;
public class DialogueSceneMakerWindow : EditorWindow
{
[SerializeField]
public List<Dialogue> dialogues = new List<Dialogue>();
private string characterName;
private string dialogueText;
private CharacterExpression expression = CharacterExpression.DEFAULT;
Vector2 dialoguesScroll;
private int loadFromDialoguesIndex = 0;
Rect dialogueAdderWindowRect = new Rect(0, 0, 400, 400);
Rect dialogueSceneMakerWindowRect = new Rect(400, 0, 400, 600);
DialogueScene dialogueScene = null;
string newDialogueSceneName = "";
List<bool> dialogueFoldouts = new List<bool>();
[MenuItem ("Tools/DialogueSceneMaker")]
static void Init()
{
DialogueSceneMakerWindow window = (DialogueSceneMakerWindow)EditorWindow.GetWindow(typeof(DialogueSceneMakerWindow));
window.minSize = new Vector2(800, 400);
foreach (var character in Resources.LoadAll<CharacterResource>("BS_DialogueSystem/CharacterResources"))
{
try
{
CharacterResourceEditorWindow.characters.Add(character.characterID, character);
}
catch
{
Debug.LogError("Character ID is not unique! Check " +
CharacterResourceEditorWindow.characters[character.characterID].characterName + " and " +
character.characterName + "!");
throw;
}
}
window.Show();
}
private void OnGUI()
{
BeginWindows();
dialogueAdderWindowRect = GUILayout.Window(1, dialogueAdderWindowRect, DialogueAdderWindow, "Dialogue Adder");
dialogueSceneMakerWindowRect = GUILayout.Window(2, dialogueSceneMakerWindowRect, DialogueSceneWindow, "Dialogue Scene Maker");
EndWindows();
}
void DialogueAdderWindow(int id)
{
/*
characterName = EditorGUILayout.TextField("Character Name", characterName, GUILayout.MaxWidth(position.width / 2));
expression = (CharacterExpression)EditorGUILayout.EnumPopup(expression);
GUILayout.Label("Dialogue");
dialogueText = EditorGUILayout.TextArea(dialogueText, GUILayout.Height(200), GUILayout.MaxWidth(position.width / 2));
if (GUILayout.Button("Add new Dialogue", GUILayout.MaxWidth(position.width / 2)))
{
AddNewDialogue(new Dialogue(characterName, dialogueText, expression));
characterName = "";
dialogueText = "";
expression = CharacterExpression.DEFAULT;
}
EditorGUILayout.BeginHorizontal();
loadFromDialoguesIndex = EditorGUILayout.IntField(loadFromDialoguesIndex, GUILayout.MaxWidth(position.width / 4));
if (GUILayout.Button("Add new Dialogue at", GUILayout.MaxWidth(position.width / 4)))
{
AddNewDialogue(new Dialogue(characterName, dialogueText, expression));
characterName = "";
dialogueText = "";
expression = CharacterExpression.DEFAULT;
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
loadFromDialoguesIndex = EditorGUILayout.IntField(loadFromDialoguesIndex, GUILayout.MaxWidth(position.width / 4));
if (GUILayout.Button("Edit Dialogue at", GUILayout.MaxWidth(position.width / 4)))
{
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
loadFromDialoguesIndex = EditorGUILayout.IntField(loadFromDialoguesIndex, GUILayout.MaxWidth(position.width / 4));
if (GUILayout.Button("Load from current Dialogues", GUILayout.MaxWidth(position.width / 4)))
{
}
EditorGUILayout.EndHorizontal();
*/
GUI.DragWindow();
}
void DialogueSceneWindow(int id)
{
GUILayout.Label("Current dialogue list", EditorStyles.boldLabel);
SaveLoadGUI();
SaveAsNewGUI();
DialoguesGUI();
GUI.DragWindow();
}
#region DialogueSceneWindow Utilities
private void SaveLoadGUI()
{
GUILayout.BeginHorizontal();
dialogueScene = EditorGUILayout.ObjectField(dialogueScene, typeof(DialogueScene), false) as DialogueScene;
/*
GUI.enabled = dialogueScene != null;
if (GUILayout.Button("Save", GUILayout.Width(100)))
{
Save();
}
if (GUILayout.Button("Load", GUILayout.Width(100)))
{
Load();
}
GUI.enabled = true;
*/
if (dialogueScene != null)
Load();
GUILayout.EndHorizontal();
}
private void Save()
{
dialogueScene.dialogues = dialogues;
}
private void Load()
{
dialogues = new List<Dialogue>(dialogueScene.dialogues);
dialogueFoldouts = new List<bool>();
for (int i = 0; i < dialogues.Count; i++)
{
dialogueFoldouts.Add(true);
}
}
private void SaveAsNewGUI()
{
GUILayout.BeginHorizontal();
newDialogueSceneName = EditorGUILayout.TextField(newDialogueSceneName);
GUI.enabled = newDialogueSceneName.Length > 0 && Resources.Load<DialogueScene>("BS_DialogueSystem/DialogueScene" + newDialogueSceneName) == null;
if (GUILayout.Button("Save as new", GUILayout.Width(100)))
{
SaveAsNew();
}
GUILayout.EndHorizontal();
if (!GUI.enabled)
{
GUIStyle style = new GUIStyle();
style.normal.textColor = Color.red;
if (newDialogueSceneName.Length <= 0)
{
EditorGUILayout.LabelField("Name must be longer than 0!", style);
}
else
{
EditorGUILayout.LabelField("The same named file already exists!", style);
}
}
GUI.enabled = true;
}
private void SaveAsNew()
{
DialogueScene newDialogueScene = ScriptableObject.CreateInstance<DialogueScene>();
newDialogueScene.dialogues = dialogues;
string dir = Application.dataPath;
if (!Directory.Exists(dir + "/Resources/BS_DialogueSystem/DialogueScene"))
{
Debug.Log("Creating directory for DialogueScene assets...");
try
{
Directory.CreateDirectory(dir + "/Resources/BS_DialogueSystem/DialogueScene");
}
catch
{
Debug.LogError("Creating directory Failed!");
throw;
}
Debug.Log("Creating directory Success!");
}
try
{
AssetDatabase.CreateAsset(newDialogueScene, "Assets/Resources/BS_DialogueSystem/DialogueScene/" + newDialogueSceneName + ".asset");
}
catch
{
Debug.LogError("Creating" + newDialogueSceneName + ".asset Failed!");
throw;
}
Debug.Log("Creating " + newDialogueSceneName + ".asset Success!");
dialogueScene = newDialogueScene;
}
private void DialoguesGUI()
{
dialoguesScroll = GUILayout.BeginScrollView(dialoguesScroll);
for (int i = 0; i < dialogues.Count; i++)
{
GUILayout.BeginHorizontal();
dialogueFoldouts[i] = EditorGUILayout.Foldout(dialogueFoldouts[i], "Dialogue " + i.ToString());
Dialogue dialogue = new Dialogue(dialogues[i]);
EditorGUILayout.LabelField(dialogue.characterName + ": " +
dialogue.dialogue.Substring(0, Math.Min(20, dialogue.dialogue.Length)));
GUILayout.EndHorizontal();
EditorGUI.indentLevel++;
if (dialogueFoldouts[i])
{
dialogue.characterName = EditorGUILayout.TextField("Character name", dialogue.characterName);
dialogue.characterCount = EditorGUILayout.IntField("Character count", dialogue.characterCount);
while (dialogue.characterIDs.Count < dialogue.characterCount)
{
dialogue.characterIDs.Add(0);
}
while (dialogue.expressions.Count < dialogue.characterCount)
{
dialogue.expressions.Add(CharacterExpression.DEFAULT);
}
while (dialogue.characterIDs.Count > dialogue.characterCount)
{
dialogue.characterIDs.RemoveAt(dialogue.characterIDs.Count - 1);
}
while (dialogue.expressions.Count > dialogue.characterCount)
{
dialogue.expressions.RemoveAt(dialogue.expressions.Count - 1);
}
string[] names = new string[CharacterResourceEditorWindow.characters.Count];
int k = 0;
foreach (var key in CharacterResourceEditorWindow.characters.Keys)
{
names[k++] = CharacterResourceEditorWindow.characters[key].characterName;
}
EditorGUI.indentLevel++;
for (int j = 0; j < dialogue.characterCount; j++)
{
GUILayout.FlexibleSpace();
dialogue.characterIDs[j] = EditorGUILayout.IntPopup("Character " + j.ToString(), dialogue.characterIDs[j], names, CharacterResourceEditorWindow.characters.Keys.ToArray());
dialogue.expressions[j] = (CharacterExpression)EditorGUILayout.EnumPopup("Expression " + j.ToString(), dialogue.expressions[j]);
}
EditorGUI.indentLevel--;
EditorGUILayout.LabelField("Dialogue");
dialogue.dialogue = EditorGUILayout.TextArea(dialogue.dialogue,GUILayout.Height(75));
}
dialogues[i] = dialogue;
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (i > 0 && GUILayout.Button("↑", GUILayout.Width(20)))
{
dialogues[i] = dialogues[i - 1];
dialogues[i - 1] = dialogue;
break;
}
if (i < dialogues.Count - 1 && GUILayout.Button("↓", GUILayout.Width(20)))
{
dialogues[i] = dialogues[i + 1];
dialogues[i + 1] = dialogue;
break;
}
if (GUILayout.Button("+", GUILayout.Width(20)))
{
Dialogue newDialogue = new Dialogue(dialogue);
dialogues.Insert(i + 1, newDialogue);
dialogueFoldouts.Add(true);
break;
}
if (GUILayout.Button("-", GUILayout.Width(20)))
{
dialogues.RemoveAt(i);
dialogueFoldouts.RemoveAt(i);
break;
}
EditorGUILayout.EndHorizontal();
EditorGUI.indentLevel--;
Save();
}
GUILayout.EndScrollView();
}
#endregion
private void AddNewDialogue(Dialogue dialogue)
{
dialogues.Add(dialogue);
dialogueFoldouts.Add(true);
}
private void DialogueToEditorLayout(Dialogue dialogue)
{
}
}
fileFormatVersion: 2
guid: 312ca34db98326746902b63f2a99a72d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 4c85b737d44119f4f828910c3bd26659
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 10
mipmaps:
mipMapMode: 0
enableMipMap: 0
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
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: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
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: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 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: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 7a06fe9ad429ede4b8ae38144a30904d
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 10
mipmaps:
mipMapMode: 0
enableMipMap: 0
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
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: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
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: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 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: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 83ffe2f668b9cb24eaed3dd2229a1a18
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 10
mipmaps:
mipMapMode: 0
enableMipMap: 0
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
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: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
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: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 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: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment