Skip to content

Commit

Permalink
02 : 클래스 설계 (2)
Browse files Browse the repository at this point in the history
https://doublsb.tistory.com/81

- Emotion Class Serialize
- 변경된 클래스에 맞도록 DialogManager 수정
- Enum Emotion 삭제
  • Loading branch information
DoublSB committed Apr 8, 2020
1 parent 25abda3 commit f18dcab
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 50 deletions.
111 changes: 102 additions & 9 deletions Assets/DialogAsset/Demo/Demo.unity
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1888300536}
- {fileID: 1309522346}
m_Father: {fileID: 470720707}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Expand Down Expand Up @@ -722,6 +723,104 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1186725838}
m_CullTransparentMesh: 0
--- !u!1 &1309522345
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1309522346}
- component: {fileID: 1309522349}
- component: {fileID: 1309522348}
- component: {fileID: 1309522347}
m_Layer: 5
m_Name: Character
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1309522346
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1309522345}
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_Children: []
m_Father: {fileID: 743017251}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 1, y: 0.5}
--- !u!114 &1309522347
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1309522345}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2255e66b58bcfa24f9911b3ed2d2488f, type: 3}
m_Name:
m_EditorClassIdentifier:
Emotion:
_emotion:
- Happy
- Normal
- Sad
_sprite:
- {fileID: 21300000, guid: 77fa19401d8472a498f2164bce0d7a4b, type: 3}
- {fileID: 21300000, guid: 34f96a43c2ac0804b95b2e3ab9751332, type: 3}
- {fileID: 21300000, guid: 8f01fa9aca81c9142a73bb0c759a88de, type: 3}
SE:
- {fileID: 8300000, guid: 32d4b1811dda14a6cb9e059ee8ad17d2, type: 3}
--- !u!114 &1309522348
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1309522345}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 21300000, guid: 34f96a43c2ac0804b95b2e3ab9751332, type: 3}
m_Type: 0
m_PreserveAspect: 1
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
--- !u!222 &1309522349
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1309522345}
m_CullTransparentMesh: 0
--- !u!1 &1459828191
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -852,15 +951,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 2255e66b58bcfa24f9911b3ed2d2488f, type: 3}
m_Name:
m_EditorClassIdentifier:
Emotions:
- {fileID: 21300000, guid: 34f96a43c2ac0804b95b2e3ab9751332, type: 3}
- {fileID: 21300000, guid: 77fa19401d8472a498f2164bce0d7a4b, type: 3}
- {fileID: 21300000, guid: 8f01fa9aca81c9142a73bb0c759a88de, type: 3}
- {fileID: 0}
- {fileID: 21300000, guid: 8f01fa9aca81c9142a73bb0c759a88de, type: 3}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
Emotion:
_emotion: []
_sprite: []
SE:
- {fileID: 8300000, guid: 32d4b1811dda14a6cb9e059ee8ad17d2, type: 3}
--- !u!114 &1888300538
Expand Down
5 changes: 3 additions & 2 deletions Assets/DialogAsset/Script/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ namespace Doublsb.Dialog
[RequireComponent(typeof(Image))]
public class Character : MonoBehaviour
{
[HideInInspector]
public Sprite[] Emotions;
public Emotion Emotion;
public AudioClip[] SE;
}

/*
#if UNITY_EDITOR
[CustomEditor(typeof(Character))]
Expand Down Expand Up @@ -52,4 +52,5 @@ public override void OnInspectorGUI()
}
#endif
*/
}
14 changes: 0 additions & 14 deletions Assets/DialogAsset/Script/DialogBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@

namespace Doublsb.Dialog
{
//[Editable] You can freely change emotion list.
//It responds to character script either.
public enum Emotion
{
Normal,
Happy,
Sad,
Blushful,
Cynical,
Fearful,
Excited,
Surprised
}

public enum State
{
Show,
Expand Down
19 changes: 14 additions & 5 deletions Assets/DialogAsset/Script/DialogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ private int Get_CharIndexLength(string Text, char chr)

private void Show_Emotion(string Text, Character character)
{
Emotion emotion;
if (Enum.TryParse(Text, out emotion))
{
character.GetComponent<Image>().sprite = character.Emotions[(int)emotion];
}
character.GetComponent<Image>().sprite = character.Emotion.Data[Text];
}

#endregion
Expand All @@ -96,4 +92,17 @@ private void Play_SE(Character character)

#endregion
}

public class CharacterDatabase
{
public CharacterDatabase(string JsonData)
{
JsonUtility.FromJson<CharacterDatabase>(JsonData);
}

public void Add()
{

}
}
}
36 changes: 16 additions & 20 deletions Assets/DialogAsset/Script/Emotion.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,41 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

namespace Doublsb.Dialog
{
[SerializeField]
public class Emotion : MonoBehaviour
[Serializable]
public class Emotion
{
//================================================
//Public Variable
//================================================
public Dictionary<string, Sprite> Data;


//================================================
//Private Variable
//================================================
[SerializeField]
private string[] _emotion;

[SerializeField]
private Sprite[] _sprite;
private Dictionary<string, Sprite> _data;
public Dictionary<string, Sprite> Data
{
get
{
if (_data == null) _init_emotionList();
return _data;
}
}

public string[] _emotion;
public Sprite[] _sprite;

//================================================
//Private Method
//================================================
private void Awake()
{
_init_emotionList();
}

private void _init_emotionList()
{
Data = new Dictionary<string, Sprite>();
_data = new Dictionary<string, Sprite>();

if (_emotion.Length != _sprite.Length)
Debug.LogError("Emotion and Sprite have different lengths");

for (int i = 0; i < _emotion.Length; i++)
Data.Add(_emotion[i], _sprite[i]);
_data.Add(_emotion[i], _sprite[i]);
}
}
}

0 comments on commit f18dcab

Please sign in to comment.