Ejemplo n.º 1
0
    public DialogueAsset Copy()
    {
        DialogueAsset asset = ScriptableObject.CreateInstance <DialogueAsset>();

        UnityEditor.EditorUtility.CopySerialized(this, asset);
        return(asset);
    }
        /// <summary>
        /// Tests 01 setup.
        /// </summary>
        private static void Test_01_Setup()
        {
            AssetManager.Instance.Bridge = bridge2;

            //! Add assets and automatically create the Asset Manager.
            //
            asset1 = new Asset();
            asset2 = new Asset();

            asset3 = new Logger();
            asset4 = new Logger();

            asset5 = new DialogueAsset();

            bridge2.Prefix = "private bridge: ";

            // For Unity3D we need a bridge as Console.WriteLine is not supported and we have to use Debug.log() instead!
            asset3.Bridge = bridge2;

            asset3.log("Asset1: " + asset1.Class + ", " + asset1.Id);
            asset3.log("Asset2: " + asset2.Class + ", " + asset2.Id);
            asset3.log("Asset3: " + asset3.Class + ", " + asset3.Id);
            asset3.log("Asset4: " + asset4.Class + ", " + asset4.Id);
            asset3.log("Asset5: " + asset5.Class + ", " + asset5.Id);
        }
Ejemplo n.º 3
0
    /// <summary>
    /// Starts dialogue and increments dialogueindex by 1.
    /// </summary>
    /// <param name="startIndex"></param>
    public void StartDialogue(int startIndex, DialogueAsset inAsset)
    {
        dialogueActive = true;

        if (!inAsset.containers[startIndex].playTriggerAtEndInstead)
        {
            for (int i = 0; i < inAsset.containers[startIndex].triggers.Length; i++)
            {
                GameObject g = Instantiate(inAsset.containers[startIndex].triggers[i]);
                g.GetComponent <ITrigger>().StartTrigger();
            }

            if (previewTriggers != null)
            {
                print("Previews");

                print(previewTriggers.Length);
                print(startIndex);

                if (previewTriggers.Length >= startIndex)
                {
                    print("Previews2");

                    for (int i = 0; i < previewTriggers[startIndex].triggers.Length; i++)
                    {
                        previewTriggers[startIndex].triggers[i].GetComponent <ITrigger>().StartTrigger();
                    }
                }
            }
        }

        Manager.GetPlayer.InDialogue = true;

        StartCoroutine(DelayedStartDialogue(inAsset.containers[startIndex].delay, startIndex, inAsset));
    }
Ejemplo n.º 4
0
 void DrawDialogueAsset(DialogueAsset asset)
 {
     if (asset == null)
     {
         return;
     }
     _talkScrollPos = EditorGUILayout.BeginScrollView(_talkScrollPos);
     DrawDialogueView(asset);
     EditorGUILayout.EndScrollView();
 }
Ejemplo n.º 5
0
    private void OnEnable()
    {
        _curDialogAsset   = null;
        _curDialogueAsset = null;

        _wordTextStyle                  = new GUIStyle();
        _wordTextStyle.fontSize         = 20;
        _wordTextStyle.fontStyle        = FontStyle.Bold;
        _wordTextStyle.normal.textColor = Color.white;
        _wordTextStyle.alignment        = TextAnchor.MiddleCenter;
    }
Ejemplo n.º 6
0
 public static bool OnOpenAsset(int instanceID, int line)
 {
     if (Selection.activeObject is DialogueAsset)
     {
         DialogueEditor window = CreateWindow <DialogueEditor>();
         DialogueAsset  asset  = Selection.activeObject as DialogueAsset;
         window.titleContent           = new GUIContent("Dialogue Editor");
         window.m_dialogueAssetBuilder = CreateInstance <DialogueAssetBuilder>();
         window.m_dialogueAssetBuilder.m_dialogueAsset = asset;
         window.m_dialogueAssetBuilder.LoadEditorSaveData();
         window.m_dialogueAssetBuilder.m_dialogueAsset = asset;
         return(true);
     }
     return(false);
 }
Ejemplo n.º 7
0
    public static void CreateAsset()
    {
        DialogueAsset dialogue_asset = CreateInstance <DialogueAsset>();
        string        asset_path     = AssetDatabase.GetAssetPath(Selection.activeObject);

        if (asset_path == "")
        {
            asset_path = "Assets/Dialogue";
        }

        asset_path = AssetDatabase.GenerateUniqueAssetPath(asset_path + "/New" + typeof(DialogueAsset).ToString() + ".asset");
        Debug.Log(asset_path);
        AssetDatabase.CreateAsset(dialogue_asset, asset_path);

        AssetDatabase.SaveAssets();
        Selection.activeObject = dialogue_asset;
    }
Ejemplo n.º 8
0
    IEnumerator DelayedStartDialogue(float time, int startIndex, DialogueAsset inAsset)
    {
        dialogueFinished = false;

        yield return(new WaitForSecondsRealtime(time));

        asset = inAsset;

        OpenDialogue();

        currentDialogueIndex = startIndex;
        content = asset.containers[startIndex].content;

        currentDialogueIndex++;

        StartCoroutine(Print());
    }
Ejemplo n.º 9
0
    private void DisplayAssetProperties(DialogueAssetBuilder asset_builder)
    {
        Label("Dialogue Asset", EditorStyles.boldLabel);
        Label("Used in Scene :" + asset_builder.m_dialogueAsset.SceneName, EditorStyles.boldLabel);
        DialogueAsset asset = asset_builder.m_dialogueAsset;

        asset.m_isActiveDialogue = Toggle(asset.m_isActiveDialogue, "Is Dialogue Active");

        ScriptableObject target = asset;
        SerializedObject so     = new SerializedObject(target);

        Label("");
        Label("Characeters Involved");
        BeginHorizontal();
        if (Button("Add character involved"))
        {
            asset.m_CharactersInvoled.Add(null);
        }
        if (Button("Remove character involved"))
        {
            int index = (asset.m_CharactersInvoled.Count - 1 <= 0) ? 0 : asset.m_CharactersInvoled.Count - 1;
            if (asset.m_CharactersInvoled.Count > 0)
            {
                asset.m_CharactersInvoled.RemoveAt(index);
            }
        }
        EndHorizontal();
        for (int i = 0; i < asset.m_CharactersInvoled.Count; ++i)
        {
            asset.m_CharactersInvoled[i] = EditorGUILayout.ObjectField(asset.m_CharactersInvoled[i], typeof(GameObject), true) as GameObject;
        }


        so.ApplyModifiedProperties();

        Label("");
        if (Button("Save Asset", Width(m_nodePropertiesRect.width - 20)))
        {
            // save asset
            asset_builder.SaveAsset(m_nodeGraphModel);
        }
    }
Ejemplo n.º 10
0
    void InitTalkAsset(DialogAsset asset)
    {
        _dialogueList = new ReorderableList(asset.DialogueAssetList, typeof(DialogueAsset));
        _dialogueList.headerHeight        = 0;
        _dialogueList.drawElementCallback = (rect, index, isActive, isFocused) =>
        {
            var talkAsset = asset.DialogueAssetList[index];

            if (talkAsset.LanguageDict.Count == 0)
            {
                talkAsset.LanguageDict.Add(E_LanguageType.CN, new ContentData());
                talkAsset.LanguageDict.Add(E_LanguageType.JP, new ContentData());
                talkAsset.LanguageDict.Add(E_LanguageType.EN, new ContentData());
            }

            var languageType = talkAsset.LanguageType;
            talkAsset.LanguageDict.TryGetValue(languageType, out ContentData data);

            GUI.Label(rect, (index + 1).ToString() + ":   " + data.Content);
            //GUI.Label(rect, asset.DialogueAssetList[index].DialogueId.ToString());
            if (isFocused)
            {
                _curDialogueAsset = talkAsset;
                InitTalkEventList(_curDialogueAsset);
            }
        };
        if (asset.DialogueAssetList != null && asset.DialogueAssetList.Count > 0)
        {
            _curDialogueAsset = asset.DialogueAssetList[0];
            if (_curDialogueAsset.LanguageDict.Count == 0)
            {
                _curDialogueAsset.LanguageDict.Add(E_LanguageType.CN, new ContentData());
                _curDialogueAsset.LanguageDict.Add(E_LanguageType.JP, new ContentData());
                _curDialogueAsset.LanguageDict.Add(E_LanguageType.EN, new ContentData());
            }
            InitTalkEventList(_curDialogueAsset);
        }
        _dialogueList.onAddCallback    = AddDialogueAsset;
        _dialogueList.onRemoveCallback = RemoveDialogueAsset;
    }
Ejemplo n.º 11
0
    void AddDialogueAsset(ReorderableList reorderable)
    {
        DialogueAsset dialogueAsset = ScriptableObject.CreateInstance <DialogueAsset>();

        if (reorderable.list.Count > 0)
        {
            var list  = reorderable.list as List <DialogueAsset>;
            var maxId = list.Max(i => i.DialogueId);
            var asset = list.Find(i => i.DialogueId == maxId);
            dialogueAsset            = asset.Copy();
            dialogueAsset.DialogueId = maxId + 1;
        }
        else
        {
            dialogueAsset.DialogueId = 1;
        }
        dialogueAsset.name = dialogueAsset.DialogueId.ToString();
        _curDialogAsset.DialogueAssetList.Add(dialogueAsset);

        AssetDatabase.AddObjectToAsset(dialogueAsset, _curDialogAsset);
        AssetDatabase.SaveAssets();
    }
Ejemplo n.º 12
0
 public void OnEnable()
 {
     m_dialogueAsset = CreateInstance <DialogueAsset>();
     m_dialogueAsset.m_dialogueData = new Dictionary <int, DialogueData>();
 }
Ejemplo n.º 13
0
    void DrawDialogueView(DialogueAsset asset)
    {
        EditorGUILayout.BeginHorizontal();
        EditorGUIUtility.labelWidth = 60;
        asset.DialogType            = (E_DialogType)EditorGUILayout.EnumPopup("对话框类型", asset.DialogType);
        if (asset.DialogType == E_DialogType.FullScreen)
        {
            EditorGUIUtility.labelWidth = 90;
            asset.IsNewTalk             = EditorGUILayout.Toggle("是否为新段落", asset.IsNewTalk);
            asset.IsNewPage             = EditorGUILayout.Toggle("是否为新的一页", asset.IsNewPage);
        }
        else
        {
            asset.TalkType = (E_TalkType)EditorGUILayout.EnumPopup("内容类型", asset.TalkType);
        }
        asset.MaskType = (E_MaskType)EditorGUILayout.EnumPopup("显示动画", asset.MaskType);
        GUILayout.Label("背景");
        asset.Background = (GameObject)EditorGUILayout.ObjectField(asset.Background, typeof(GameObject), false);
        asset.Bgm        = (AudioClip)EditorGUILayout.ObjectField("背景音乐", asset.Bgm, typeof(AudioClip), false);
        EditorGUILayout.EndHorizontal();


        if (asset.DialogType == E_DialogType.Normal)
        {
            EditorGUIUtility.labelWidth = 60;

            EditorGUILayout.BeginHorizontal();
            asset.LeftBody         = (GameObject)EditorGUILayout.ObjectField("立绘(左)", asset.LeftBody, typeof(GameObject), false);
            asset.LeftBodyShowType = (E_BodyShowType)EditorGUILayout.EnumPopup("显示类型", asset.LeftBodyShowType);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            asset.RightBody         = (GameObject)EditorGUILayout.ObjectField("立绘(右)", asset.RightBody, typeof(GameObject), false);
            asset.RightBodyShowType = (E_BodyShowType)EditorGUILayout.EnumPopup("显示类型", asset.RightBodyShowType);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            asset.CenterBody         = (GameObject)EditorGUILayout.ObjectField("立绘(中)", asset.CenterBody, typeof(GameObject), false);
            asset.CenterBodyShowType = (E_BodyShowType)EditorGUILayout.EnumPopup("显示类型", asset.CenterBodyShowType);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            asset.BottomBody         = (GameObject)EditorGUILayout.ObjectField("立绘(下)", asset.BottomBody, typeof(GameObject), false);
            asset.BottomBodyShowType = (E_BodyShowType)EditorGUILayout.EnumPopup("显示类型", asset.BottomBodyShowType);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUIUtility.labelWidth = 60;
            asset.NamePos    = (E_NamePos)EditorGUILayout.EnumPopup("名字位置", asset.NamePos);
            asset.TalkerName = EditorGUILayout.TextField("角色名", asset.TalkerName);

            EditorGUIUtility.labelWidth = 90;
            asset.DubDelay = EditorGUILayout.IntField("配音等待字数", asset.DubDelay);
            asset.Dub      = (AudioClip)EditorGUILayout.ObjectField("角色配音", asset.Dub, typeof(AudioClip), false);
            EditorGUILayout.EndHorizontal();
        }
        EditorGUILayout.BeginHorizontal();
        asset.LanguageType = (E_LanguageType)EditorGUILayout.EnumPopup("语言类型", asset.LanguageType);
        if (asset.LanguageType != _lastLanguageType)
        {
            _lastLanguageType = asset.LanguageType;
        }
        EditorGUILayout.EndHorizontal();

        GUILayout.Label("事件列表");
        _eventScrollPos = EditorGUILayout.BeginScrollView(_eventScrollPos, GUILayout.Height(90));
        _talkEventList?.DoLayoutList();
        EditorGUILayout.EndScrollView();


        GUILayout.Label("对话内容");
        EditorGUILayout.BeginHorizontal();
        asset.LanguageDict.TryGetValue(asset.LanguageType, out ContentData data);
        data.Content = EditorGUILayout.TextArea(data.Content, GUILayout.Height(80));
        if (GUILayout.Button("生成", GUILayout.Width(80), GUILayout.Height(80)))
        {
            data.WordList = new List <TyperRhythm>();


            for (int i = 0; i < data.Content.Length; i++)
            {
                bool   isDirective = false;
                string word        = null;
                if (data.Content[i] == '<')
                {
                    int count = 0;
                    for (int j = i; j < data.Content.Length; j++)
                    {
                        word += data.Content[j];
                        if (data.Content[j] == '>')
                        {
                            Regex reg = new Regex(@"<c=[0-9a-fA-F]{6}");
                            if (word.Equals("<b>") || word.Equals("</b>") || reg.IsMatch(word) || word.Equals("</c>"))
                            {
                                isDirective = true;
                            }
                            break;
                        }
                        count++;
                    }
                    if (isDirective)
                    {
                        i += count;
                    }
                    else
                    {
                        word = data.Content[i].ToString();
                    }
                }
                else
                {
                    word = data.Content[i].ToString();
                }
                TyperRhythm typerWord = new TyperRhythm(word, 0.1f, isDirective);
                data.WordList.Add(typerWord);
            }

            //SaveDialogAsset(_curDialogAsset, _curDialogAsset);
        }
        EditorGUILayout.EndHorizontal();
        if (data.WordList.Count > 0)
        {
            DrawTyperWordList(data.WordList);
        }
    }
Ejemplo n.º 14
0
    void InitTalkEventList(DialogueAsset dialogueAsset)
    {
        if (dialogueAsset == null)
        {
            return;
        }
        dialogueAsset.LanguageDict.TryGetValue(dialogueAsset.LanguageType, out ContentData data);
        _talkEventList = new ReorderableList(data.DelayEventList, typeof(DelayEvent));
        _talkEventList.headerHeight        = 0;
        _talkEventList.drawElementCallback = (rect, index, isActive, isFocused) =>
        {
            float posX   = rect.position.x;
            int   width  = 120;
            int   height = 20;
            EditorGUIUtility.labelWidth = 60;

            Rect tempRect = new Rect(posX, rect.position.y, width, height);
            data.DelayEventList[index].Delay = EditorGUI.IntField(tempRect, "等待字数", data.DelayEventList[index].Delay);
            posX    += width;
            tempRect = new Rect(posX, rect.position.y, width, height);
            data.DelayEventList[index].EventType = (E_EventType)EditorGUI.EnumPopup(tempRect, data.DelayEventList[index].EventType);

            switch (data.DelayEventList[index].EventType)
            {
            case E_EventType.PlayAudio:
                posX    += width;
                width    = 200;
                tempRect = new Rect(posX, rect.position.y, width, height);
                data.DelayEventList[index].AuidoType = (E_AudioType)EditorGUI.EnumPopup(tempRect, "声音类型", data.DelayEventList[index].AuidoType);
                posX    += width;
                width    = 200;
                tempRect = new Rect(posX, rect.position.y, width, height);
                data.DelayEventList[index].Audio = (AudioClip)EditorGUI.ObjectField(tempRect, "音效", data.DelayEventList[index].Audio, typeof(AudioClip), false);
                break;

            case E_EventType.ChangeBody:
                posX    += width;
                width    = 200;
                tempRect = new Rect(posX, rect.position.y, width, height);
                data.DelayEventList[index].BodyPos = (E_BodyPos)EditorGUI.EnumPopup(tempRect, "立绘位置", data.DelayEventList[index].BodyPos);

                posX    += width;
                width    = 200;
                tempRect = new Rect(posX, rect.position.y, width, height);
                data.DelayEventList[index].BodyShowType = (E_BodyShowType)EditorGUI.EnumPopup(tempRect, "显示类型", data.DelayEventList[index].BodyShowType);

                posX    += width;
                width    = 200;
                tempRect = new Rect(posX, rect.position.y, width, height);
                EditorGUIUtility.labelWidth     = 40;
                data.DelayEventList[index].Body = (GameObject)EditorGUI.ObjectField(tempRect, "立绘", data.DelayEventList[index].Body, typeof(GameObject), false);

                break;

            case E_EventType.Hint:
                posX    += width;
                width    = 200;
                tempRect = new Rect(posX, rect.position.y, width, height);
                data.DelayEventList[index].HintTime = EditorGUI.FloatField(tempRect, "显示时长", data.DelayEventList[index].HintTime);
                posX    += width;
                width    = 200;
                tempRect = new Rect(posX, rect.position.y, width, height);
                data.DelayEventList[index].StringValue = EditorGUI.TextField(tempRect, "提示文字", data.DelayEventList[index].StringValue);
                break;

            case E_EventType.Label:
                posX    += width;
                width    = 200;
                tempRect = new Rect(posX, rect.position.y, width, height);
                data.DelayEventList[index].StringValue = EditorGUI.TextField(tempRect, "文字", data.DelayEventList[index].StringValue);
                break;

            default:
                break;
            }
        };
    }
Ejemplo n.º 15
0
    public void StartDialogue(int startIndex, DialogueAsset inAsset, DialoguePreview[] preview)
    {
        previewTriggers = preview;

        StartDialogue(startIndex, inAsset);
    }