text:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using DialogSystem.ScriptObject;
using ReadyGamerOne.Common;
using ReadyGamerOne.EditorExtension;
using ReadyGamerOne.Script;
using ReadyGamerOne.Utility;
using ReadyGamerOne.View;
using ReadyGamerOne.View.Effects;
using UnityEngine;
using UnityEngine.Events;
using Random = UnityEngine.Random;
#if UNITY_EDITOR

using UnityEditor;
using UnityEditorInternal;
#endif

namespace DialogSystem.Model
{
    public enum UnitType
    {
        Null = 0,
        Word = 10,
        Choose = 11,
        Narrator=12,
        ExWord=13,

        If=20,
        Else=21,
        EndIf=22,
        End=23,
        Skip=24,

        //闪烁
        Shining=30,
        Wait=31,
        FadeIn=32,
        FadeOut=33,
        Audio=34,

        Panel=40,//切换Panel
        Scene=41,//切换场景

        Message = 50,
        Event=51,

        SetVar=60,

        Jump=70,//跳转对话资源

        VarInfo=80,//显示变量信息
        Print=81,
        ProcessInfo=82,//显示当前进度信息

        Progress=90, //设置当前进度

        Camera=100 //相机移动

    }

    public enum ShowType
    {
        Dialog,
        Caption
    }

    public enum NarratorType
    {
        Color,
        Image,
        Object
    }

    public enum AudioType
    {
        BGM,
        Effect,
        StopBGM,
    }

    [Serializable]
    public class DialogUnitInfo
    {
#pragma warning disable 649

        #region Static

        private static Dictionary<string, List<string>> messageCache = new Dictionary<string, List<string>>();

        private static void SetAssetMessage(string message,string assetName)
        {
//            Debug.Log("DialogUnitInfo_AddAssetMessage:" + assetName);
            if (!messageCache.ContainsKey(message))
            {
                messageCache.Add(message,new List<string>());
            }

            if (!messageCache[message].Contains(assetName))
                messageCache[message].Add(assetName);
        }

        private static bool GetAssetMessage(string message, string assetName)
        {
            if (!messageCache.ContainsKey(message))
            {
                return false;
            }

            if (!messageCache[message].Contains(assetName))
                return false;

            messageCache[message].Remove(assetName);
            return true;
        }

        static DialogUnitInfo()
        {
            CEventCenter.AddListener<string>(Scripts.DialogSystem.EndThisDialogUnit,
                (assetName) =>
                {
                    SetAssetMessage(Scripts.DialogSystem.EndThisDialogUnit, assetName);
                });
        }

        #endregion

        #region Editor

#if UNITY_EDITOR
        private ReorderableList skipChoiceList;
        public ReorderableList GetReorderableList(SerializedProperty property)
        {
                    skipChoiceList = new ReorderableList(property.serializedObject,property, true, true, true, true)
                    {
                        elementHeight = 4 * EditorGUIUtility.singleLineHeight
                    };

                    skipChoiceList.drawHeaderCallback = (rect) => { EditorGUI.LabelField(rect, "选项"); };

                    //绘制单个元素
                    skipChoiceList.drawElementCallback =
                        (rect, index, isActive, isFocused) =>
                        {
                            var choiceProp = property.GetArrayElementAtIndex(index);
                            var enableProp=choiceProp.FindPropertyRelative("enable");
                            var assetProp = enableProp.FindPropertyRelative("abstractAbstractDialogInfoAsset");
                            if (assetProp.objectReferenceValue == null)
                            {
                                assetProp.objectReferenceValue = abstractAbstractDialogInfoAsset;
                                enableProp.FindPropertyRelative("valueType").enumValueIndex = 0;
                                enableProp.FindPropertyRelative("argType").enumValueIndex = 3;
                                var argChooserProp=enableProp.FindPropertyRelative("ArgChooser");
                                argChooserProp.FindPropertyRelative("argType").enumValueIndex = 3;
                                argChooserProp.FindPropertyRelative("BoolArg").boolValue = true;
                            }
                            EditorGUI.PropertyField(rect,choiceProp);
                        };
                    return skipChoiceList;
        }
        public void onDrawMoreInfo(SerializedProperty property,Rect position)
        {
            #region Shit

            var index = 0;
            var dialogSystem = abstractAbstractDialogInfoAsset;

            GUIStyle style = new GUIStyle()
            {
                fontSize = 20,
                alignment = TextAnchor.MiddleCenter,
            };

            EditorGUI.LabelField(position.GetRectFromIndexWithHeight(ref index,20+5),"详细信息",style);

            EditorGUI.LabelField(position.GetRectAtIndex(index++),"类型",UnitType.ToString());
            EditorGUI.LabelField(position.GetRectAtIndex(index++), "ID", id.ToString());

            var characterProp = property.FindPropertyRelative("character");
            var msgProp=property.FindPropertyRelative("workMessageTrigger");
            var sceneNameChooserProp = property.FindPropertyRelative("sceneNameChooser");
            var panelNameChooserProp = property.FindPropertyRelative("panelChooser");
            var audioNameChooserProp = property.FindPropertyRelative("m_AudioName");

            if (abstractAbstractDialogInfoAsset.refreshStringChooser)
            {
                if(abstractAbstractDialogInfoAsset.MessageType!=null)
                    EditorUtil.InitSerializedStringArray(msgProp.FindPropertyRelative("messageToTick.values"),
                        abstractAbstractDialogInfoAsset.MessageType);
                if(abstractAbstractDialogInfoAsset.SceneType!=null)
                    EditorUtil.InitSerializedStringArray(sceneNameChooserProp.FindPropertyRelative("values"),
                        abstractAbstractDialogInfoAsset.SceneType);
                if(abstractAbstractDialogInfoAsset.PanelType!=null)
                    EditorUtil.InitSerializedStringArray(panelNameChooserProp.FindPropertyRelative("values"),
                        abstractAbstractDialogInfoAsset.PanelType);
                if(abstractAbstractDialogInfoAsset.AudioType!=null)
                    EditorUtil.InitSerializedStringArray(audioNameChooserProp.FindPropertyRelative("values"),
                        abstractAbstractDialogInfoAsset.AudioType);

            }

            #endregion

            switch ((int)UnitType)
            {
                case 10: //Model.UnitType.Word
                    #region Word

                    var showTypeProp = property.FindPropertyRelative("showType");
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++), showTypeProp);
                    var prefabIndexProp = property.FindPropertyRelative("wordPrefabIndex");
                    switch (showTypeProp.enumValueIndex)
                    {
                        case 0://Dialog
                            var fromNullProp = property.FindPropertyRelative("fromNull");
                            EditorGUI.BeginChangeCheck();
                            EditorGUI.PropertyField(position.GetRectAtIndex(index++),fromNullProp);

                            if (fromNullProp.boolValue)
                            {
                                if (EditorGUI.EndChangeCheck())
                                {
                                    prefabIndexProp.intValue = 2;
                                }
                            }
                            else
                            {
                                EditorGUI.PropertyField(position.GetRectAtIndex(index++), characterProp);
                            }

                            if(abstractAbstractDialogInfoAsset.DialogWordUiKeys==null)
                                EditorGUI.HelpBox(position.GetRectAtIndex(index++),"未设置DialogWordUiPaths",MessageType.Error);
                            else
                                prefabIndexProp.intValue = EditorGUI.Popup(position.GetRectAtIndex(index++), "预制体",
                                    prefabIndexProp.intValue, abstractAbstractDialogInfoAsset.DialogWordUiKeys);
                            break;
                        case 1://Caption
                            if(abstractAbstractDialogInfoAsset.CaptionWordUiKeys==null)
                                EditorGUI.HelpBox(position.GetRectAtIndex(index++),"未设置CaptionWordUiPaths",MessageType.Error);
                            else
                                prefabIndexProp.intValue = EditorGUI.Popup(position.GetRectAtIndex(index++), "预制体",
                                    prefabIndexProp.intValue, abstractAbstractDialogInfoAsset.CaptionWordUiKeys);

                            EditorGUI.PropertyField(position.GetRectAtIndex(index++), characterProp);
                            break;
                    }

                    EditorGUI.PropertyField(position.GetRectAtIndex(index++), property.FindPropertyRelative("words"));
                    break;

                    #endregion
                case 11: //Model.UnitType.Choose
                    #region Choose

                    //InitSerializedStringArray(characterProp
                    //    .FindPropertyRelative("values"), abstractAbstractDialogInfoAsset.SpeakerType);

                    EditorGUI.PropertyField(position.GetRectAtIndex(index++), characterProp);
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++), property.FindPropertyRelative("title"));

                    var timeLimitProp = property.FindPropertyRelative("timeLimit");

                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),timeLimitProp);
                    if (timeLimitProp.boolValue)
                    {
                        EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                            property.FindPropertyRelative("limitTime"));
                        var defaultIndexProp = property.FindPropertyRelative("defaultIndex");

                        var strArr = new string[this.Choices.Count];
                        var intArr = new int[this.Choices.Count];
                        for (var i = 0; i < Choices.Count; i++)
                        {
                            strArr[i] = i.ToString();
                            intArr[i] = i;
                        }

                        defaultIndexProp.intValue = EditorGUI.IntPopup(position.GetRectAtIndex(index++), "默认选择的Index",
                            defaultIndexProp.intValue, strArr, intArr);
                    }

                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                        property.FindPropertyRelative("sendToExWord"));

                    var choicesProp = property.FindPropertyRelative("Choices");
                    if (GUILayout.Button("清空选项列表"))
                    {
                        choicesProp.arraySize = 0;
                    }
                    var list = GetReorderableList(choicesProp);
                    list.DoLayoutList();

                    break;

                    #endregion
                case 12: //Model.UnitType.Narrator
                    #region Narrator

                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                        property.FindPropertyRelative("wordToNarrator"));
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                        property.FindPropertyRelative("narratorSpeed"));

                    var narratorTypeProp = property.FindPropertyRelative("m_NarratorType");
                    var narratorColorProp = property.FindPropertyRelative("m_NarratorColor");
                    EditorGUI.BeginChangeCheck();
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),narratorTypeProp);
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (narratorTypeProp.enumValueIndex == 0)
                        {
                            narratorColorProp.colorValue=Color.black;
                        }
                        else
                        {
                            narratorColorProp.colorValue=Color.white;
                        }
                    }

                    switch (narratorTypeProp.enumValueIndex)
                    {
                        case 0:// Color
                            EditorGUI.PropertyField(position.GetRectAtIndex(index++), narratorColorProp);
                            break;
                        case 1:// Image
                            EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                                property.FindPropertyRelative("m_NarratorImage"));
                            EditorGUI.PropertyField(position.GetRectAtIndex(index++), narratorColorProp);
                            break;
                        case 2:// Object
                            EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                                property.FindPropertyRelative("m_NarratorObject"));
                            EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                                property.FindPropertyRelative("m_NarratorImage"));
                            EditorGUI.PropertyField(position.GetRectAtIndex(index++), narratorColorProp);
                            break;
                    }

                    var enableFadeOutPorp = property.FindPropertyRelative("enableFadeOut");
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),enableFadeOutPorp);
                    if (enableFadeOutPorp.boolValue)
                        EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                            property.FindPropertyRelative("narratorTextFadeOutTime"));

                    break;

                #endregion
                case 13: //Model.UnitType.ExWord
                    #region ExWord

                    //InitSerializedStringArray(characterProp
                    //    .FindPropertyRelative("values"), abstractAbstractDialogInfoAsset.SpeakerType);
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                        property.FindPropertyRelative("needInput"));
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++), characterProp);
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++), property.FindPropertyRelative("words"));
                    break;
                #endregion
                case 20:
                    #region IF

                    ValueChooser.argTypeWidth = 0.3f;
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++), property.FindPropertyRelative("vc1"));
                    var compareProp = property.FindPropertyRelative("compareType");
                    compareProp.intValue = EditorGUI.Popup(position.GetRectAtIndex(index++), compareProp.intValue,
                        new[] {"==", "!=", "<", ">", ">=", "<="});
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++), property.FindPropertyRelative("vc2"));

                    break;

                    #endregion
                case 24: //Model.UnitType.Skip
                    #region Skip

                    EditorGUI.PropertyField(position.GetRectAtIndex(index++), property.FindPropertyRelative("skipNum"));
                    break;

                    #endregion
                case 60:
                    #region RunSetVarUnit

                    if (dialogSystem.VarAsset.varInfos.Count == 0)
                    {
                        var rect = position.GetRectAtIndex(index++);
                        rect.height *= 4;
                        EditorGUI.HelpBox(rect,"现在 Assets/DialogSystemAssets/GlobalVar.asset 中没有变量",MessageType.Error);
                        break;
                    }

                    var varTypeR = position.GetRectAtIndex(index++);

                    var varInfos = dialogSystem.GetValueInfos();
                    var keyArray = varInfos.Keys.ToArray();

                    var varIndexProp = property.FindPropertyRelative("varIndex");
                    varIndexProp.intValue = EditorGUI.Popup(varTypeR.GetLeft(0.3f), varIndexProp.intValue,
                        keyArray);

                    var varToSetProp = property.FindPropertyRelative("varToSet");

                    ArgChooser.typeChangAble = false;
                    varToSetProp.FindPropertyRelative("argType").enumValueIndex =
                        (int) varInfos[keyArray[varIndexProp.intValue]].argType;
                    EditorGUI.PropertyField(varTypeR.GetRight(0.7f), varToSetProp);

                    break;
                    #endregion
                case 50: //Model.UnitType.Message
                    #region Message
                    ValueChooser.argTypeWidth = 0.235f;
                    EditorGUI.PropertyField(position.GetRectFromIndexWithHeight(ref index,EditorGUI.GetPropertyHeight(msgProp)), msgProp);
                    break;

                    #endregion
                case 51:
                    #region Event

                    var eventProp = property.FindPropertyRelative("myEvent");
                    EditorGUI.PropertyField(
                        position.GetRectFromIndexWithHeight(ref index, EditorGUI.GetPropertyHeight(eventProp)),
                        eventProp);
                    break;

                    #endregion
                case 52:
                    #region RunPrintUnit

                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                        property.FindPropertyRelative("wordToPrint"));
                    break;

                    #endregion
                case 30:
                    #region Shining

                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                        property.FindPropertyRelative("shiningObject"));
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++), property.FindPropertyRelative("times"));
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                        property.FindPropertyRelative("shiningDeltaTime"));
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                        property.FindPropertyRelative("lightTime"));
                    break;

                    #endregion
                case 31:
                    #region Wait

                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                        property.FindPropertyRelative("waitTime"));

                    break;

                    #endregion
                case 32: //Model.UnitType.FadeIn
                    #region FadeIn

                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                        property.FindPropertyRelative("fadeInTime"));
                    break;

                    #endregion
                case 33: //Model.UnitType.FadeOut
                    #region FadeOut

                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),property.FindPropertyRelative("fadeOutTime"));
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++), property.FindPropertyRelative("finalColor"));
                    break;

                    #endregion

                case 34: //Model.UnitType.Audio

                    var audioTypeProp = property.FindPropertyRelative("m_AudioType");
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++), audioTypeProp);
                    if (audioTypeProp.enumValueIndex != (int) AudioType.StopBGM)
                    {
                        EditorGUI.PropertyField(position.GetRectAtIndex(index++), audioNameChooserProp);
                    }

                    break;

                case 40:
                    #region Panel

                    var operateType = property.FindPropertyRelative("panelType");
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++), operateType);
                    switch (operateType.enumValueIndex)
                    {
                        case 0://Push
                            EditorGUI.PropertyField(position.GetRectAtIndex(index++),panelNameChooserProp);
                            var fadeProp = property.FindPropertyRelative("fade");
                            //fadeProp.boolValue = EditorGUI.Toggle(position.GetRectAtIndex(index++),"是否渐隐", fadeProp.boolValue);
                            EditorGUI.PropertyField(position.GetRectAtIndex(index++), fadeProp);
                            if (fadeProp.boolValue)
                            {
                                var fadeValue = property.FindPropertyRelative("floatValue");
                                fadeValue.floatValue =
                                    EditorGUI.Slider(position.GetRectAtIndex(index++), "渐隐时间",fadeValue.floatValue, 0, 5f);
                            }
                            break;
                        case 1://Pop
                            break;
                    }
                    break;

                    #endregion
                case 41:
                    #region Scene

                    var mgr = property.FindPropertyRelative("useSceneMgr");
                    var backProp = property.FindPropertyRelative("loadBack");
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),mgr);
                    if(mgr.boolValue)
                        EditorGUI.PropertyField(position.GetRectAtIndex(index++), backProp);
                    if(mgr.boolValue && !backProp.boolValue)
                        EditorGUI.PropertyField(position.GetRectAtIndex(index++),sceneNameChooserProp);
                    break;

                    #endregion
                case 70://Model.UnitType.Jump
                    #region Jump

                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                        property.FindPropertyRelative("targetAsset"));
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                        property.FindPropertyRelative("willBack"));

                    break;
                    #endregion
                case 80://Model.UnitType.VarInfo
                    #region VarInfo

                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                        property.FindPropertyRelative("varInfoHelpText"));
                    break;

                    #endregion
                case 81://Model.UnitType.Print
                    #region Print

                    EditorGUI.PropertyField(position.GetRectAtIndex(index),
                        property.FindPropertyRelative("wordToPrint"));

                    break;
                    #endregion
                case 90://Model.UnitType.Progress
                    #region Progress

                    var pos = position.GetRectAtIndex(index++);
                    EditorGUI.LabelField(pos.GetLeft(0.4f), "将要设定的全局进度值");
                    var value = ProgressPointChooser.ShowLabel;
                    ProgressPointChooser.ShowLabel = false;
                    EditorGUI.PropertyField(pos.GetRight(0.6f),
                        property.FindPropertyRelative("progressValueToSet"));
                    ProgressPointChooser.ShowLabel = value;
                    break;

                    #endregion
                case 100://Model.UnitType.Camera
                    #region Camera

                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                        property.FindPropertyRelative("positionOffset"));
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                        property.FindPropertyRelative("targetOrigSize"));
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                        property.FindPropertyRelative("cameraMoveTime"));
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                        property.FindPropertyRelative("cameraMachinePath"));
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++),
                        property.FindPropertyRelative("cameraWaitTime"));

                    break;
                    #endregion
                default:
                    break;
            }
        }

#endif

        #endregion

        #region Every

        /// <summary>
        /// 物体上的DialogSystem脚本
        /// </summary>
        public AbstractDialogInfoAsset abstractAbstractDialogInfoAsset;
        /// <summary>
        /// 单元类型
        /// </summary>
        public UnitType UnitType;

        /// <summary>
        /// ID
        /// </summary>
        public int id;

        #endregion

        public string SpeakerName => (character).CharacterName;

        #region Word

        public ShowType showType;

        public int wordPrefabIndex = 0;

        public bool fromNull = false;
        /// <summary>
        /// 讲述人
        /// </summary>
        public CharacterChooser character;
        /// <summary>
        /// 讲述人说的话
        /// </summary>
        public string words;

        public IEnumerator RunWordUnit()
        {
            abstractAbstractDialogInfoAsset.CreateWordUI(this);
            while (!GetAssetMessage(Scripts.DialogSystem.EndThisDialogUnit, abstractAbstractDialogInfoAsset.name))
            {
//                Debug.Log("woc");
                yield return null;
            }
        }

        #endregion

        #region ExWord

        public bool needInput = false;

        public IEnumerator RunExWordUnit()
        {
            //如果需要用户输入才能下一步，这里就循环
            if(needInput)
                while (!abstractAbstractDialogInfoAsset.CanGoToNext())
                    yield return null;

            CEventCenter.BroadMessage(Scripts.DialogSystem.ExternWord, this);

            while (!GetAssetMessage(Scripts.DialogSystem.EndThisDialogUnit, abstractAbstractDialogInfoAsset.name))
                yield return null;
        }

        #endregion

        #region Choose

        /// <summary>
        /// 选择的题目
        /// </summary>
        [SerializeField] internal string title;

        public List<SkipChoice> Choices;

        public bool timeLimit = false;
        public float limitTime = 1.0f;
        public int defaultIndex = 0;
        public bool sendToExWord = false;

        public IEnumerator RunChooseUnit()
        {
           abstractAbstractDialogInfoAsset.CreateChooseUi(this);

           while (!GetAssetMessage(Scripts.DialogSystem.EndThisDialogUnit, abstractAbstractDialogInfoAsset.name))
           {
               if (Scripts.DialogSystem.GetAssetMessage(Scripts.DialogSystem.ChooseNotBack,abstractAbstractDialogInfoAsset.name,false))
               {
                   yield break;
               }
               yield return null;
           }
        }

        #endregion

        #region Narrator

        public string wordToNarrator;
        public float narratorSpeed;
        public bool enableFadeOut = true;
        public float narratorTextFadeOutTime = 1.0f;

        public NarratorType m_NarratorType;
        public Color m_NarratorColor=Color.black;
        public Sprite m_NarratorImage;
        public GameObject m_NarratorObject;

        public IEnumerator RunNarratorUnit()
        {
            if(abstractAbstractDialogInfoAsset.CreateNarratorUI==null)
                throw new Exception("你没有重写CreateNarratorUI属性！");
            abstractAbstractDialogInfoAsset.CreateNarratorUI.Invoke(this);

            while (!GetAssetMessage(Scripts.DialogSystem.EndThisDialogUnit, abstractAbstractDialogInfoAsset.name))
                yield return null;
        }

        #endregion

        #region Jump

        public AbstractDialogInfoAsset targetAsset;
        public bool willBack = true;

        public IEnumerator RunJumpUnit()
        {
            if (willBack == false)
                CEventCenter.BroadMessage(Scripts.DialogSystem.ChooseNotBack, abstractAbstractDialogInfoAsset.name);
            yield return Scripts.DialogSystem.RunDialog(targetAsset);
        }

        #endregion

        #region Message

        /// <summary>
        /// 消息触发器
        /// </summary>
        [SerializeField] private MessageTrigger workMessageTrigger;

        public void RunMessageUnit()
        {
            this.workMessageTrigger.TickMessage();
        }

        #endregion

        #region VarInfo

        public string varInfoHelpText;

        public string GetVarInfo()
        {
            var text = "所在对话资源名:\t" + abstractAbstractDialogInfoAsset.name+"\n";
            text += "变量资源ID:\t\t" + abstractAbstractDialogInfoAsset.VarAsset.GetInstanceID() + "\n";
            text += "变量信息：\n";
            foreach (var VARIABLE in abstractAbstractDialogInfoAsset.VarAsset.varInfos)
            {
                text += VARIABLE.ArgChooser.argType + "\t" +VARIABLE.ArgChooser.GetValueString() + ":\t"
                         + VARIABLE.VarName+ "\n";
            }

            return text;
        }

        public void ShowVarInfo()
        {
            var text = "《变量信息";
            if (!string.IsNullOrEmpty(varInfoHelpText))
                text += "——"+varInfoHelpText+"》\n";
            else
            {
                text += "》\n";
            }
            text += GetVarInfo() + "\n";

            Debug.Log(text);
        }

        #endregion

        #region SetVar

        [SerializeField] private int varIndex;

        [SerializeField] private ArgChooser varToSet;

        public void RunSetVarUnit()
        {
            abstractAbstractDialogInfoAsset.VarAsset.varInfos[varIndex].ArgChooser.SetValue(varToSet);
        }

        #endregion

        #region IF

        [SerializeField] private ValueChooser vc1;
        [SerializeField] private ValueChooser vc2;
        /// <summary>
        /// 0  ==
        /// 1  !=
        /// 2  <
        /// 3  >
        /// 4  >=
        /// 5  <=
        /// </summary>
        [SerializeField] private int compareType;

        public bool Complare()
        {
            switch (compareType)
            {
                case 0:
                    return vc1 == vc2;
                case 1:
                    return vc1 != vc2;
                case 2:
                    return vc1 < vc2;
                case 3:
                    return vc1 > vc2;
                case 4:
                    return vc1 >= vc2;
                case 5:
                    return vc1 <= vc2;
            }

            throw new Exception("比较异常");
        }

        #endregion

        #region Skip

        public int skipNum = 1;

        #endregion

        #region Action

        [SerializeField] private UnityEvent myEvent;

        public void RunEventUnit()
        {
            myEvent.Invoke();
        }

        #endregion

        #region Print

        [SerializeField] private string wordToPrint;

        public void RunPrintUnit()
        {
            Debug.Log(wordToPrint);
        }

        #endregion

        #region Shining

        [SerializeField] private GameObject shiningObject;
        [SerializeField] private int times;
        [SerializeField] private float shiningDeltaTime;
        [SerializeField] private float lightTime;

        public IEnumerator Shining()
        {
            if(shiningObject==null)
                yield break;
            if(shiningObject.activeSelf)
                shiningObject.SetActive(false);
            for (var i = 0; i < times; i++)
            {
                shiningObject.SetActive(true);
                yield return new WaitForSeconds(lightTime);
                shiningObject.SetActive(false);
                yield return new WaitForSeconds(Random.Range(0,shiningDeltaTime));
            }

        }

        #endregion

        #region Audio

        public AudioType m_AudioType;
        public StringChooser m_AudioName;

        public void RunAudio()
        {
            switch (m_AudioType)
            {
                case AudioType.Effect:
                    AudioMgr.Instance.PlayEffect(m_AudioName.StringValue);
                    break;
                case AudioType.BGM:
                    AudioMgr.Instance.PlayBgm(m_AudioName.StringValue);
                    break;
                default:
                    throw new NotImplementedException($"还没做:{m_AudioType}");
            }
        }

        #endregion

        #region FadeIn

        public float fadeInTime=1.0f;

        public IEnumerator FadeIn()
        {
            yield return PanelMgr.FadeIn(fadeInTime);
        }

        #endregion

        #region FadeOut

        public float fadeOutTime=1.5f;
        public Color finalColor=Color.black;

        public IEnumerator FadeOut()
        {
            yield return PanelMgr.FadeOut(fadeOutTime, finalColor);
        }

        #endregion

        #region Wait

        public float waitTime;

        public IEnumerator WaitForTime()
        {
            if (abstractAbstractDialogInfoAsset.affectedByTimeScale)
                yield return new WaitForSeconds(waitTime);
            else
            {
                for (var i = 0; i < waitTime / 0.02f; i++)
                    yield return null;
            }

        }

        #endregion

        #region Panel

        public enum PanelOperateType
        {
            Push,
            Pop
        }

        public PanelOperateType panelType;
        public bool fade;
        public float floatValue;
        public StringChooser panelChooser;

        public void RunPanelUnit()
        {
            switch (panelType)
            {
                case DialogUnitInfo.PanelOperateType.Pop:
                    PanelMgr.PopPanel();
                    break;
                case DialogUnitInfo.PanelOperateType.Push:
                    Debug.Log("DialogUnitInfo_RunPanelUnit_Switch_PushPanel");
                    if(fade)
                        PanelMgr.PushPanel(panelChooser.StringValue,new FadeInOut(floatValue));
                    else
                    {
                        PanelMgr.PushPanel(panelChooser.StringValue);
                    }
                    break;
            }
        }

        #endregion

        #region Scene

        [SerializeField] private bool useSceneMgr = true;
        [SerializeField] private bool loadBack = false;
        [SerializeField] private StringChooser sceneNameChooser;

        public IEnumerator RunSceneUnit()
        {
//            Debug.Log("DialogUnitInfo_RunSceneUnit_Before");
            // if (useSceneMgr)
            // {
            //     if(loadBack)
            //         yield return SceneMgr.LoadBack();
            //     else
            //         yield return SceneMgr.LoadSceneCoroutine(sceneNameChooser.StringValue);
            // }
            //
//            Debug.Log("DialogUnitInfo_RunSceneUnit_End");

            throw new NotImplementedException("you must useSceneMgr");
        }

        #endregion

        #region Progress

        public ProgressPointChooser progressValueToSet;

        public void RunProgressUnit()
        {
            //保证就算走原来情节，进度不会倒退
            if (progressValueToSet.Value > DialogProgressAsset.Instance.CurrentProgress)
            {
                Debug.Log("设置游戏进度："+progressValueToSet.Value);
                DialogProgressAsset.Instance.CurrentProgress = progressValueToSet.Value+0.01f;
            }
        }

        #endregion

        #region ProgressInfo

        public void RunProgressInfoUnit()
        {
            var min = float.MinValue;
            var max = float.MaxValue;
            int minIndex=-1, maxIndex=-1;
            foreach (var VARIABLE in DialogProgressAsset.Instance.DialogProgressPoints)
            {
                if (VARIABLE.value > min && VARIABLE.value < DialogProgressAsset.Instance.CurrentProgress)
                {
                    min = VARIABLE.value;
                    minIndex = VARIABLE.index;
                }

                if (VARIABLE.value > DialogProgressAsset.Instance.CurrentProgress && VARIABLE.value < max)
                {
                    max = VARIABLE.value;
                    maxIndex = VARIABLE.index;
                }
            }

            var ans = "";
            ans += "《游戏进度信息》\n";
            if(minIndex!=-1)
                ans += DialogProgressAsset.Instance.DialogProgressPoints[minIndex].name +
                       $"【{DialogProgressAsset.Instance.DialogProgressPoints[minIndex].value}】\n";

            ans += "当前进度：" + DialogProgressAsset.Instance.CurrentProgress + "\n";

            if(maxIndex!=-1)
                 ans+=DialogProgressAsset.Instance.DialogProgressPoints[maxIndex].name +
                     $"【{DialogProgressAsset.Instance.DialogProgressPoints[maxIndex].value}】\n";

            Debug.Log(ans);
        }

        #endregion

        #region Camera

        public Vector3 positionOffset;
        public float targetOrigSize=1;
        public float cameraMoveTime;
        public string cameraMachinePath = "CM vcam1";
        public float cameraWaitTime = 0.5f;
        public IEnumerator RunCameraUnit()
        {
            var cameraMachine= Camera.main.transform.Find(cameraMachinePath).gameObject;
            cameraMachine.SetActive(false);
            var goTime = cameraMoveTime /2f;
            var backTime = cameraMoveTime - goTime;
            var startSize = Camera.main.orthographicSize;
            var startPos = Camera.main.transform.position;
            for (var timer = 0f; timer < goTime; timer += Time.deltaTime)
            {
                Camera.main.transform.position = Vector3.Lerp(startPos, startPos + positionOffset, timer / goTime);
                Camera.main.orthographicSize = Mathf.Lerp(startSize, targetOrigSize, timer / goTime);
                yield return null;
            }

            yield return new WaitForSeconds(cameraWaitTime);

            for (var timer = 0f; timer < backTime; timer += Time.deltaTime)
            {
                Camera.main.transform.position = Vector3.Lerp(startPos + positionOffset, startPos, timer / backTime);
                Camera.main.orthographicSize = Mathf.Lerp(targetOrigSize, startSize, timer / backTime);
                yield return null;
            }

            Camera.main.transform.position = startPos;
            Camera.main.orthographicSize = startSize;
            cameraMachine.SetActive(true);
        }

        #endregion

#pragma warning restore 649
    }
}


text:
fileFormatVersion: 2
guid: 1f134e871ae2c6141945af72d834321f
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:

mime_type: text/plain


text:
fileFormatVersion: 2
guid: 896370c8791b7a44292b280dfa9a7044
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: 6026c44d0b276454bb4ebcdf21e0c7c2
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
using System;
using DialogSystem.ScriptObject;

namespace DialogSystem.Model
{
    [Serializable]
    public class SkipChoice
    {
        public ValueChooser enable;
        public string text;
        public AbstractDialogInfoAsset targetDialogInfoAsset;
        public bool willBack=true;
    }
}


text:
fileFormatVersion: 2
guid: 44411b6c957ffec44b3311d019666231
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: d4970a6923514c6db7a9da13c761a12d
timeCreated: 1563806485


text:
using System;
using UnityEngine;

namespace DialogSystem.Model
{
    [Serializable]
    public class ProgressPointRange
    {
#pragma warning disable 649
        [SerializeField] private ProgressPointChooser min;
        [SerializeField] private ProgressPointChooser max;

        public float Min => Mathf.Min(min.Value, max.Value);
        public float Max => Mathf.Max(min.Value, max.Value);
#pragma warning restore 649
    }
}


text:
using System;
using ReadyGamerOne.Common;
using ReadyGamerOne.EditorExtension;
using UnityEngine;

namespace DialogSystem.Model
{
    [Serializable]
    public class MessageTrigger
    {
#pragma warning disable 649
        public int argCount;

        [SerializeField] private ValueChooser arg1;
        [SerializeField] private ValueChooser arg2;

        public StringChooser messageToTick;

        public void TickMessage()
        {
            switch (argCount)
            {
                case 0:
                    CEventCenter.BroadMessage(messageToTick.StringValue);
                    break;
                case 1:
                    switch (arg1.ArgType)
                    {
                        case ArgType.Float:
                            CEventCenter.BroadMessage(messageToTick.StringValue,arg1.FloatValue);
                            break;
                        case ArgType.Int:
                            CEventCenter.BroadMessage(messageToTick.StringValue,arg1.IntValue);
                            break;
                        case ArgType.String:
                            CEventCenter.BroadMessage(messageToTick.StringValue,arg1.StrValue);
                            break;
                        case ArgType.Bool:
                            CEventCenter.BroadMessage(messageToTick.StringValue,arg1.BoolValue);
                            break;
                        case ArgType.Vector3:
                            CEventCenter.BroadMessage(messageToTick.StringValue, arg1.Vector3Value);
                            break;
                    }
                    break;
                case 2:
                    switch (arg1.ArgType)
                    {
                        case ArgType.Float:
                            switch (arg2.ArgType)
                            {
                                case ArgType.Float:
                                    CEventCenter.BroadMessage(messageToTick.StringValue,arg1.FloatValue, arg2.FloatValue);
                                    break;
                                case ArgType.Int:
                                    CEventCenter.BroadMessage(messageToTick.StringValue,arg1.FloatValue,arg2.IntValue);
                                    break;
                                case ArgType.String:
                                    CEventCenter.BroadMessage(messageToTick.StringValue,arg1.FloatValue,arg2.StrValue);
                                    break;
                                case ArgType.Bool:
                                    CEventCenter.BroadMessage(messageToTick.StringValue,arg1.FloatValue,arg2.BoolValue);
                                    break;

                                case ArgType.Vector3:
                                    CEventCenter.BroadMessage(messageToTick.StringValue, arg1.FloatValue,arg2.Vector3Value);
                                    break;
                            }
                            break;
                        case ArgType.Int:
                            switch (arg2.ArgType)
                            {
                                case ArgType.Float:
                                    CEventCenter.BroadMessage(messageToTick.StringValue,arg1.IntValue, arg2.FloatValue);
                                    break;
                                case ArgType.Int:
                                    CEventCenter.BroadMessage(messageToTick.StringValue,arg1.IntValue,arg2.IntValue);
                                    break;
                                case ArgType.String:
                                    CEventCenter.BroadMessage(messageToTick.StringValue,arg1.IntValue,arg2.StrValue);
                                    break;
                                case ArgType.Bool:
                                    CEventCenter.BroadMessage(messageToTick.StringValue,arg1.IntValue,arg2.BoolValue);
                                    break;
                                case ArgType.Vector3:
                                    CEventCenter.BroadMessage(messageToTick.StringValue, arg1.IntValue,arg2.Vector3Value);
                                    break;
                            }
                            break;
                        case ArgType.String:
                            switch (arg2.ArgType)
                            {
                                case ArgType.Float:
                                    CEventCenter.BroadMessage(messageToTick.StringValue,arg1.StrValue, arg2.FloatValue);
                                    break;
                                case ArgType.Int:
                                    CEventCenter.BroadMessage(messageToTick.StringValue,arg1.StrValue,arg2.IntValue);
                                    break;
                                case ArgType.String:
                                    CEventCenter.BroadMessage(messageToTick.StringValue,arg1.StrValue,arg2.StrValue);
                                    break;
                                case ArgType.Bool:
                                    CEventCenter.BroadMessage(messageToTick.StringValue,arg1.StrValue,arg2.BoolValue);
                                    break;
                                case ArgType.Vector3:
                                    CEventCenter.BroadMessage(messageToTick.StringValue, arg1.StrValue,arg2.Vector3Value);
                                    break;
                            }
                            break;
                        case ArgType.Bool :
                            switch (arg2.ArgType)
                            {
                                case ArgType.Float:
                                    CEventCenter.BroadMessage(messageToTick.StringValue,arg1.BoolValue, arg2.FloatValue);
                                    break;
                                case ArgType.Int:
                                    CEventCenter.BroadMessage(messageToTick.StringValue,arg1.BoolValue,arg2.IntValue);
                                    break;
                                case ArgType.String:
                                    CEventCenter.BroadMessage(messageToTick.StringValue,arg1.BoolValue,arg2.StrValue);
                                    break;
                                case ArgType.Bool:
                                    CEventCenter.BroadMessage(messageToTick.StringValue,arg1.BoolValue,arg2.BoolValue);
                                    break;
                                case ArgType.Vector3:
                                    CEventCenter.BroadMessage(messageToTick.StringValue, arg1.BoolValue,arg2.Vector3Value);
                                    break;
                            }
                            break;
                        case ArgType.Vector3:
                            switch (arg2.ArgType)
                            {
                                case ArgType.Float:
                                    CEventCenter.BroadMessage(messageToTick.StringValue,arg1.Vector3Value, arg2.FloatValue);
                                    break;
                                case ArgType.Int:
                                    CEventCenter.BroadMessage(messageToTick.StringValue,arg1.Vector3Value,arg2.IntValue);
                                    break;
                                case ArgType.String:
                                    CEventCenter.BroadMessage(messageToTick.StringValue,arg1.Vector3Value,arg2.StrValue);
                                    break;
                                case ArgType.Bool:
                                    CEventCenter.BroadMessage(messageToTick.StringValue,arg1.Vector3Value,arg2.BoolValue);
                                    break;

                                case ArgType.Vector3:
                                    CEventCenter.BroadMessage(messageToTick.StringValue, arg1.Vector3Value,arg2.Vector3Value);
                                    break;
                            }
                            break;
                    }
                    break;
            }
        }
#pragma warning restore 649
    }

}


text:
using System;

namespace DialogSystem.Model
{
    /// <summary>
    /// 对话进度点
    /// </summary>
    [Serializable]
    public class DialogProgressPoint
    {
        public int index;
        public string name;
        public float value;
    }
}


text:
fileFormatVersion: 2
guid: 17b6ec9b0fc643658698d6449b0f9ab4
timeCreated: 1564126999


text:
fileFormatVersion: 2
guid: 5f85c01d429633449ba8dd36dbb00665
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
using System;
using DialogSystem.ScriptObject;
#if UNITY_EDITOR

using UnityEditor;
#endif
using UnityEngine;

namespace DialogSystem.Model
{
    [Serializable]
    public class CharacterChooser
    {
        [SerializeField] private int selectedIndex=0;

        public string CharacterName
        {
            get
            {
                var arr = DialogCharacterAsset.Instance.characterNames;
                if (selectedIndex >= arr.Count)
                    throw new Exception("CharacterChooser selectedIndex 异常：" + selectedIndex);
                return arr[selectedIndex];
            }
        }

#if UNITY_EDITOR
        public static string GetShowTextFromSerializedProperty(SerializedProperty property)
        {
            var selectedIndex = property.FindPropertyRelative("selectedIndex").intValue;
            var arr = DialogCharacterAsset.Instance.characterNames;
            if (selectedIndex >= arr.Count)
            {
                if (selectedIndex == 0)
                    return null;
                throw new Exception("CharacterChooser selectedIndex 异常：" + selectedIndex+"  arr.Count:"+arr.Count);
            }
            return arr[selectedIndex];
        }
#endif

    }
}


text:
fileFormatVersion: 2
guid: 13a823cc443845c3b4f5a654b64acf8a
timeCreated: 1568113906


text:
fileFormatVersion: 2
guid: d5694c7e97c64503a6fff9671f28e49f
timeCreated: 1568817886


text:
using System.Collections.Generic;
using DialogSystem.ScriptObject;
using ReadyGamerOne.Utility;
using UnityEditor;
using UnityEngine;

namespace DialogSystem.Model.Editor
{
    [CustomPropertyDrawer(typeof(ProgressPointChooser))]
    public class ProgressPointChooserDrawer:PropertyDrawer
    {
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var indexProp = property.FindPropertyRelative("selectedIndex");
            var valueTypeProp = property.FindPropertyRelative("valueType");
            var valueProp = property.FindPropertyRelative("value");
            var list = new List<string>();

            var left = 0.3f;
            valueTypeProp.enumValueIndex = EditorGUI.Popup(position.GetLeft(left), valueTypeProp.enumValueIndex,
                valueTypeProp.enumNames);
            position = position.GetRight(1 - left);
            var index = 0;
            if (valueTypeProp.enumValueIndex == 1)//使用DialogProgressAsset中的值
            {
                foreach (var VARIABLE in DialogProgressAsset.Instance.DialogProgressPoints)
                {
                    if (string.IsNullOrEmpty(VARIABLE.name))
                    {
                        Debug.LogError("DialogProgressAsset中关键点名不能为空");
                        continue;
                    }
                    list.Add(VARIABLE.name+$"【{VARIABLE.value}】");
                }

                if(ProgressPointChooser.ShowLabel)
                    indexProp.intValue = EditorGUI.Popup(position.GetRectAtIndex(index++), "剧情关键点", indexProp.intValue, list.ToArray());
                else
                {
                    indexProp.intValue = EditorGUI.Popup(position.GetRectAtIndex(index++), indexProp.intValue, list.ToArray());
                }
            }
            else//使用常量
            {
                if (ProgressPointChooser.ShowLabel)
                    valueProp.floatValue =
                        EditorGUI.FloatField(position.GetRectAtIndex(index++), "剧情关键点", valueProp.floatValue);
                else
                {
                    valueProp.floatValue =
                        EditorGUI.FloatField(position.GetRectAtIndex(index++),  valueProp.floatValue);
                }
            }

        }
    }
}


text:
fileFormatVersion: 2
guid: 2b3073be0c1f458e92e550c83701f1f3
timeCreated: 1564127014


text:
using DialogSystem.ScriptObject;
using UnityEditor;
using UnityEngine;

namespace DialogSystem.Model.Editor
{
    [CustomPropertyDrawer(typeof(CharacterChooser))]
    public class CharacterChooserDrawer:PropertyDrawer
    {
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var selectedIndexProp = property.FindPropertyRelative("selectedIndex");
            selectedIndexProp.intValue = EditorGUI.Popup(position,"说话人", selectedIndexProp.intValue,
                DialogCharacterAsset.Instance.characterNames.ToArray());
        }
    }
}


text:
using System.Linq;
using DialogSystem.ScriptObject;
using ReadyGamerOne.EditorExtension;
using ReadyGamerOne.Utility;
using UnityEditor;
using UnityEngine;

namespace DialogSystem.Model.Editor
{
    [CustomPropertyDrawer(typeof(DialogUnitInfo))]
    public class DialogUnitDrawer : PropertyDrawer
    {
        private string[] compare = new[] {"==", "!=", "<", ">", ">=", "<="};

        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            var sp = property.FindPropertyRelative("UnitType");
            var choicesProp = property.FindPropertyRelative("Choices");
            switch (EnumUtil.GetEnumValue<UnitType>(sp.enumValueIndex))
            {
               // case 11://Choos
               //     return 6*EditorGUIUtility.singleLineHeight;
               case 12:// Narrator
                   return 11 * EditorGUIUtility.singleLineHeight;
               default:
                    return 10 * EditorGUIUtility.singleLineHeight;
            }
        }

        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {

            var index = 0;
            var dialogSystem = property.FindPropertyRelative("abstractAbstractDialogInfoAsset").objectReferenceValue as AbstractDialogInfoAsset;

            #region LeftPart

            var sp = property.FindPropertyRelative("UnitType");
            GUIStyle titleStyle = new GUIStyle()
            {
                fontSize = 18,
                alignment = TextAnchor.UpperLeft
            };

            var leftPart = position.GetLeft(0.15f);

            // UnitType类型
            EditorGUI.LabelField(leftPart.GetUp(0.6f),sp.enumNames[sp.enumValueIndex],titleStyle);
            // ID
            EditorGUI.LabelField(leftPart.GetBottom(.5f),"ID:   "+property.FindPropertyRelative("id").intValue.ToString());

            #endregion

            position = position.GetRight(.85f);

            var text = "";
            bool error = false;

            var name = CharacterChooser.GetShowTextFromSerializedProperty(property.FindPropertyRelative("character"));

            name = name ?? "未设置名字 ";

            //EditorGUI.ObjectField(position.GetRectAtIndex(index++), property.FindPropertyRelative("character"));

            switch (EnumUtil.GetEnumValue<UnitType>(sp.enumValueIndex))
            {
                case 10: //Model.UnitType.Word

                    #region Word

                    text =name+ ":\"" +
                           property.FindPropertyRelative("words").stringValue+"\"";

                    break;
                    #endregion
                case 11: //Model.UnitType.Choose
                    #region Choose
                    text =name+ ":\"" +
                          property.FindPropertyRelative("title").stringValue+"\"";
                    break;

                    #endregion
                case 12: //Model.UnitType.Narrator
                    #region Narrator

                    text = $"【{((NarratorType) property.FindPropertyRelative("m_NarratorType").enumValueIndex).ToString()}】";
                    text += property.FindPropertyRelative("wordToNarrator").stringValue;

                    break;

                #endregion
                case 13: //Model.UnitType.ExWord
                    #region ExWord
                    text =name+ ":\"" +
                          property.FindPropertyRelative("words").stringValue+"\"";
                    break;
                #endregion
                case 20:
                    #region IF

                    var vc1Prop = property.FindPropertyRelative("vc1");
                    var vc2Prop = property.FindPropertyRelative("vc2");
                    var ans= dialogSystem.GetValueStrings((ArgType)ValueChooser.GetArgTypeFromSerializedProperty(vc1Prop));

                    var vc1Type = vc1Prop.FindPropertyRelative("valueType");
                    var vc2Type = vc2Prop.FindPropertyRelative("valueType");
                    if ((vc1Type.enumValueIndex==1||vc2Type.enumValueIndex==1)&& ans.Count == 0 || (ValueChooser.GetArgTypeFromSerializedProperty(vc1Prop)!=ValueChooser.GetArgTypeFromSerializedProperty(vc2Prop)))
                    {
                        error = true;
                        text = "注意！！！  条件设置异常！！！";
//                        text += ValueChooser.GetArgTypeFromSerializedProperty(vc1Prop);
//                        text += "  ";
//                        text += ValueChooser.GetArgTypeFromSerializedProperty(vc2Prop);
                        break;
                    }

                    text += ValueChooser.GetShowTextFromSerializedProperty(vc1Prop);
                    text += compare[property.FindPropertyRelative("compareType").intValue];
                    text += ValueChooser.GetShowTextFromSerializedProperty(vc2Prop);

                    break;

                    #endregion
                case 24: //Model.UnitType.Skip
                    text = "SkipNum=" + property.FindPropertyRelative("skipNum").intValue;
                    break;
                case 60:
                    #region RunSetVarUnit

                    if (dialogSystem.VarAsset.varInfos.Count == 0)
                    {
                        var rect = position.GetRectAtIndex(index++);
                        EditorGUI.HelpBox(rect,"现在 Assets/DialogSystemAssets/GlobalVar.asset 中没有变量",MessageType.Error);
                        break;
                    }

                    var varTypeR = position.GetRectAtIndex(index++);

                    var varInfos = dialogSystem.GetValueInfos();
                    var keyArray = varInfos.Keys.ToArray();

                    var varIndexProp = property.FindPropertyRelative("varIndex");

                    var varToSetProp = property.FindPropertyRelative("varToSet");

                    text = keyArray[varIndexProp.intValue] + " = " +
                           ArgChooser.GetShowTextFromSerializedProperty(varToSetProp);

                    break;
                    #endregion
                case 50: //Model.UnitType.Message
                    #region Message

                    var strchooser=property.FindPropertyRelative("workMessageTrigger").FindPropertyRelative("messageToTick");
                    text = "Tick Message : " + StringChooser.GetShowTextFromSerializedProperty(strchooser);
                    break;

                    #endregion
                case 31:
                    #region Wait

                    text = "等待 " + property.FindPropertyRelative("waitTime").floatValue + " s";

                    break;

                    #endregion
                case 32: //Model.UnitType.FadeIn
                    #region FadeIn

                    text = "画面逐渐正常";

                    break;

                    #endregion
                case 33: //Model.UnitType.FadeOut
                    #region FadeOut

                    text = "画面逐渐变色";
                    break;

                    #endregion
                case 40:
                    #region Panel

                    var operateType = property.FindPropertyRelative("panelType");
                    switch (operateType.enumValueIndex)
                    {
                        case 0://Push
                            text = "Push " + StringChooser.GetShowTextFromSerializedProperty(
                                       property.FindPropertyRelative("panelChooser"));
                            break;
                        case 1://Pop
                            text = "Pop Panel";
                            break;
                    }
                    break;

                    #endregion
                case 41:
                    #region Scene

                    if (property.FindPropertyRelative("useSceneMgr").boolValue &&
                        property.FindPropertyRelative("loadBack").boolValue)
                        text = "LoadBack";
                    else
                        text = "LoadScene: " +
                           StringChooser.GetShowTextFromSerializedProperty(
                               property.FindPropertyRelative("sceneNameChooser"));

                    break;

                    #endregion

                case 70:

                    #region Jump

                    var targetAssetProp = property.FindPropertyRelative("targetAsset");
                    if (targetAssetProp.objectReferenceValue)
                        text = "跳转：" + (targetAssetProp.objectReferenceValue as AbstractDialogInfoAsset).name;
                    else
                    {
                        error = true;
                        text = "跳转对象未设置";
                    }
                    break;
                #endregion
                case 90://Model.UnitType.Progress

                    text += ProgressPointChooser.GetShowTextFromSerializedProperty(
                        property.FindPropertyRelative("progressValueToSet"));
                    break;

                case 80://Model.UnitType.VarInfo
                    text = "运行时打印变量信息";
                    break;
                case 81://Model.UnitType.Print
                    text = "Print:" + property.FindPropertyRelative("wordToPrint").stringValue;
                    break;
                case 82://Model.UnitType.ProcessInfo
                    text = "运行时打印进度信息";
                    break;
                default:
                    break;
            }

            if(error)
                EditorGUI.HelpBox(position,text,MessageType.Error);
            else
                EditorGUI.LabelField(position,text);
        }
    }
}


text:
fileFormatVersion: 2
guid: 69ec5a1c843e4b2780ade40b9cc92f21
timeCreated: 1567217332


text:
using ReadyGamerOne.EditorExtension;
using ReadyGamerOne.Utility;
using UnityEditor;
using UnityEngine;

namespace DialogSystem.Model.Editor
{
    [CustomPropertyDrawer(typeof(SkipChoice))]
    public class SkipChoiceDrawer:PropertyDrawer
    {
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            return 4 * EditorGUIUtility.singleLineHeight;
        }

        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var index = 0;
            var r = position.GetRectAtIndex(index++);
            EditorGUI.LabelField(r.GetLeft(.4f),"enable");
            var enableProp = property.FindPropertyRelative("enable");
            EditorGUI.PropertyField(r.GetRight(0.6f), enableProp);
            if(ValueChooser.GetArgType(property.FindPropertyRelative("enable"))!=ArgType.Bool)
                EditorGUILayout.HelpBox("这里必须为Bool类型",MessageType.Error);

            var text = property.FindPropertyRelative("text");
            var targetDialogInfoAssetProp = property.FindPropertyRelative("targetDialogInfoAsset");
            EditorGUI.PropertyField(position.GetRectAtIndex(index++), text);
            EditorGUI.PropertyField(position.GetRectAtIndex(index++), targetDialogInfoAssetProp);
            EditorGUI.PropertyField(position.GetRectAtIndex(index++), property.FindPropertyRelative("willBack"));
        }
    }
}


text:
using System.Collections.Generic;
using DialogSystem.ScriptObject;
using ReadyGamerOne.EditorExtension;
using UnityEditor;
using UnityEngine;

namespace DialogSystem.Model.Editor
{
    [CustomPropertyDrawer(typeof(BoolVarChooser))]
    public class BoolVarChooserDrawer:PropertyDrawer
    {
        private List<string> names=new List<string>();
        private List<int> indexs=new List<int>();
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            names.Clear();
            indexs.Clear();

            var index = 0;
            foreach (var VARIABLE in DialogVarAsset.Instance.varInfos)
            {
                if (VARIABLE.ArgType == ArgType.Bool)
                {
                    indexs.Add(index);
                    names.Add(VARIABLE.VarName);
                }
                index++;
            }

            var indexProp = property.FindPropertyRelative("selectedIndex");
            indexProp.intValue = EditorGUI.Popup(position, property.displayName, indexProp.intValue, names.ToArray());

        }
    }
}


text:
fileFormatVersion: 2
guid: 50ab659a6a534a1295b369fe1172a3d1
timeCreated: 1568114066


text:
fileFormatVersion: 2
guid: 2d6009c76f1f4e14ac14e58244da26d4
timeCreated: 1564539653


text:
fileFormatVersion: 2
guid: 4400f9e72031462296a2c149b3263a02
timeCreated: 1564473285


text:
fileFormatVersion: 2
guid: 31535ef70dba4de99fcb5c3639aa6590
timeCreated: 1564459321


text:
fileFormatVersion: 2
guid: 106f87ae21d344bc915cf37564192b84
timeCreated: 1568819311


text:
using ReadyGamerOne.EditorExtension;
using ReadyGamerOne.Utility;
using UnityEditor;
using UnityEngine;

namespace DialogSystem.Model.Editor
{
    [CustomPropertyDrawer(typeof(VarUnitInfo))]
    public class VarUnitInfoDrawer:PropertyDrawer
    {
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            return EditorGUIUtility.singleLineHeight * 2;
        }

        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var index = 0;
            EditorGUI.PropertyField(position.GetRectAtIndex(index++), property.FindPropertyRelative("VarName"));
            ArgChooser.typeChangAble = false;
            EditorGUI.PropertyField(position.GetRectAtIndex(index++), property.FindPropertyRelative("ArgChooser"));

        }
    }
}


text:
using ReadyGamerOne.Utility;
using UnityEditor;
using UnityEngine;

namespace DialogSystem.Model.Editor
{
    [CustomPropertyDrawer(typeof(DialogProgressPoint))]
    public class DialogProgressPointDrawer:UnityEditor.PropertyDrawer
    {
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            return EditorGUIUtility.singleLineHeight * 2;
        }

        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var index = 0;
            var left = 0.1f;
            var s=new GUIStyle()
            {
                fontSize = 20
            };
            EditorGUI.LabelField(position.GetLeft(left), property.FindPropertyRelative("index").intValue.ToString(),s);

            position = position.GetRight(1 - left);

            EditorGUI.PropertyField(position.GetRectAtIndex(index++), property.FindPropertyRelative("name"));
            EditorGUI.PropertyField(position.GetRectAtIndex(index++), property.FindPropertyRelative("value"));
        }
    }
}


text:
using ReadyGamerOne.EditorExtension;
using ReadyGamerOne.Utility;
using UnityEditor;
using UnityEngine;

namespace DialogSystem.Model.Editor
{
    [CustomPropertyDrawer(typeof(MessageTrigger))]
    public class MessageTriggerDrawer:PropertyDrawer
    {
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {

            var height = 0;
            height+=2;
            var argCount = property.FindPropertyRelative("argCount").intValue;

            height += argCount;

            return height * EditorGUIUtility.singleLineHeight;

        }

        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var index = 0;
            var argCount = property.FindPropertyRelative("argCount").intValue;

            EditorGUI.PropertyField(position.GetRectAtIndex(index++), property.FindPropertyRelative("messageToTick"));

            argCount = EditorGUI.Popup(position.GetRectAtIndex(index++), "argCount",argCount,
                new[] {"0", "1", "2"});

            ArgChooser.typeChangAble = true;

            switch (argCount)
            {
                case 1:
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++).GetRight(.9f),
                        property.FindPropertyRelative("arg1"));
                    break;
                case 2:
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++).GetRight(.9f),
                        property.FindPropertyRelative("arg1"));
                    EditorGUI.PropertyField(position.GetRectAtIndex(index++).GetRight(.9f),
                        property.FindPropertyRelative("arg2"));
                    break;
            }

            property.FindPropertyRelative("argCount").intValue = argCount;

        }
    }
}


text:
using ReadyGamerOne.Utility;
using UnityEditor;
using UnityEngine;

namespace DialogSystem.Model.Editor
{
    [CustomPropertyDrawer(typeof(ProgressPointRange))]
    public class ProgressPointRangeDrawer:PropertyDrawer
    {
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            return 2 * EditorGUIUtility.singleLineHeight;
        }

        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var value = ProgressPointChooser.ShowLabel;
            ProgressPointChooser.ShowLabel = false;
            var left = 0.4f;
            EditorGUI.LabelField(position.GetLeft(left), "剧情关键点范围");

            var index = 0;
            position = position.GetRight(1 - left);
            EditorGUI.PropertyField(position.GetRectAtIndex(index++), property.FindPropertyRelative("min"));
            EditorGUI.PropertyField(position.GetRectAtIndex(index++), property.FindPropertyRelative("max"));
            ProgressPointChooser.ShowLabel = value;
        }
    }
}


text:
using System;
using System.Collections.Generic;
using System.Linq;
using DialogSystem.ScriptObject;
using ReadyGamerOne.EditorExtension;
using ReadyGamerOne.Utility;
using UnityEditor;
using UnityEngine;

namespace DialogSystem.Model.Editor
{
    [CustomPropertyDrawer(typeof(ValueChooser))]
    public class ValueChooserEditor : PropertyDrawer
    {

        private static float ArgValueWidth => 1 - ValueChooser.valueTypeWidth - ValueChooser.argTypeWidth;

        private AbstractDialogInfoAsset _abstractDialogSystem;
        private SerializedProperty indexProp;

        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            _abstractDialogSystem = property.FindPropertyRelative("abstractAbstractDialogInfoAsset").objectReferenceValue as AbstractDialogInfoAsset;

            if (_abstractDialogSystem == null)
                throw new Exception("abstractAbstractDialogInfoAsset is null");

            indexProp = property.FindPropertyRelative("selectedIndex");

            var valueTypeProp = property.FindPropertyRelative("valueType");
            valueTypeProp.enumValueIndex = EditorGUI.Popup(position.GetLeft(ValueChooser.valueTypeWidth),
                valueTypeProp.enumValueIndex, valueTypeProp.enumNames);

            if (valueTypeProp.enumValueIndex == 0) // Value
            {
                ArgChooser.argTypeWidth = ValueChooser.argTypeWidth / (1 -ValueChooser. valueTypeWidth);
                ArgChooser.typeChangAble = true;

                EditorGUI.PropertyField(position.GetRight(1 - ValueChooser.valueTypeWidth),
                    property.FindPropertyRelative("ArgChooser"));
            }
            else // Var
            {
                var argType = property.FindPropertyRelative("argType");

                argType.enumValueIndex =
                    EditorGUI.Popup(position.GetLeft(ValueChooser.valueTypeWidth + ValueChooser.argTypeWidth, ValueChooser.valueTypeWidth),
                        argType.enumValueIndex, argType.enumNames);

                Dictionary<string, string> ans = null;
                switch (argType.enumValueIndex)
                {
                    case 0: // Int
                        ans = _abstractDialogSystem.GetValueStrings(ArgType.Int);

                        if (ans.Count == 0)
                        {
                            break;
                        }
                        indexProp.intValue = EditorGUI.Popup(position.GetRight(ArgValueWidth), indexProp.intValue,
                            ans.Keys.ToArray());
                        break;
                    case 1: // Float
                        ans = _abstractDialogSystem.GetValueStrings(ArgType.Float);
                        if (ans.Count == 0)
                        {
                            break;
                        }
                        indexProp.intValue = EditorGUI.Popup(position.GetRight(ArgValueWidth), indexProp.intValue,
                            ans.Keys.ToArray());
                        break;
                    case 2: // String
                        ans =_abstractDialogSystem.GetValueStrings(ArgType.String);
                        if (ans.Count == 0)
                        {
                            //property.FindPropertyRelative("StrArg").stringValue = "";
                            break;
                        }
                        indexProp.intValue = EditorGUI.Popup(position.GetRight(ArgValueWidth), indexProp.intValue,
                            ans.Keys.ToArray());
                        break;
                    case 3: // bool
                        ans = _abstractDialogSystem.GetValueStrings(ArgType.Bool);
                        if (ans.Count == 0)
                        {
                            break;
                        }
                        indexProp.intValue = EditorGUI.Popup(position.GetRight(ArgValueWidth), indexProp.intValue,
                            ans.Keys.ToArray());
                        break;
                }
            }
        }

    }
}


text:
fileFormatVersion: 2
guid: 8d26ae54e2764cfcb42a18523633f81b
timeCreated: 1568812554


text:
fileFormatVersion: 2
guid: 727591b16b384f12a55c8e8acf6432f4
timeCreated: 1569204196


text:
fileFormatVersion: 2
guid: 9dee4a7f7b4f44cd8f2ed7700659af4c
timeCreated: 1564559539


text:
using System;
using System.Collections;
using DialogSystem.Model;
using DialogSystem.Scripts;
using ReadyGamerOne.Common;
using ReadyGamerOne.MemorySystem;
using ReadyGamerOne.Script;
using UnityEngine;
using UnityEngine.UI;

namespace DialogSystem.View
{
    public abstract class AbstractChooseDialogUI:DialogUnitUI
    {
        protected abstract string SpeakerTextPath { get; }
        protected abstract string TitleTextPath { get; }
        protected abstract Func<Transform> onGetChoiceParent { get; }
        protected abstract string choiceObjPath { get; }
        protected abstract string textPathOnChoice { get; }

        /// <summary>
        /// 有时间限制的时候随着时间流逝会调用这个委托
        /// <float>已经经过的时间</float>
        /// <float>最大时间限制</float>
        /// <GameObject>默认选项物体</GameObject>
        /// </summary>
        protected virtual Action<float, float, GameObject> onTimeLeave => null;
        private Transform choiceParent;

        public Transform ChoiceParent
        {
            get
            {
                if (choiceParent == null)
                    choiceParent = onGetChoiceParent();
                if (!choiceParent)
                    throw new Exception("获取 ChoiceParent 失败");
                return choiceParent;
            }
        }

        protected bool clicked = false;

        public AbstractChooseDialogUI(DialogUnitInfo dialogUnitInfo):base(dialogUnitInfo)
        {
            Create(dialogUnitInfo.abstractAbstractDialogInfoAsset.ChooseUiKeys);

            m_TransFrom.Find(SpeakerTextPath).GetComponent<Text>().text = dialogUnitInfo.SpeakerName;
            var speaker = m_TransFrom.Find(SpeakerTextPath).GetComponent<Text>();
            speaker.text = dialogUnitInfo.SpeakerName;
            var title= m_TransFrom.Find(TitleTextPath).GetComponent<Text>();
            title.text = dialogUnitInfo.title;

            Show();

            //打字机效果
            var titleEffect = title.gameObject.AddComponent<TypeWriterEffect>();
            titleEffect.StartWriter(
                dialogUnitInfo.abstractAbstractDialogInfoAsset.wordFinishTime,
                () => { MainLoop.Instance.StartCoroutine(ShowChoices(dialogUnitInfo)); },
                ()=>canGoNext,
                dialogUnitInfo.abstractAbstractDialogInfoAsset.affectedByTimeScale);
        }

        private IEnumerator ShowChoices(DialogUnitInfo dialogUnitInfo)
        {
            GameObject defaultObj = null;
            var index = 0;
            //显示选项
            foreach (var choice in dialogUnitInfo.Choices)
            {
                if(choice.enable.BoolValue==false)
                                 continue;

                var obj = ResourceMgr.InstantiateGameObject(choiceObjPath, ChoiceParent);

                if (index++ == dialogUnitInfo.defaultIndex)
                    defaultObj = obj;

                var text = obj.transform.Find(textPathOnChoice).GetComponent<Text>();
                text.text = choice.text;

                //添加回调
                text.gameObject.AddComponent<UIInputer>().eventOnPointerClick += (dat) =>
                {
                    clicked = true;

                    Hide();
                    if (choice.targetDialogInfoAsset == null)
                    {
                        CEventCenter.BroadMessage(Scripts.DialogSystem.ChooseNotBack,dialogUnitInfo.abstractAbstractDialogInfoAsset.name);
                        DestroyThis();
                    }
                    else
                    {
//                        Debug.Log("选项："+choice.text+"  willBack:"+choice.willBack);
                        if (!choice.willBack)
                        {
//                            Debug.Log($"广播消息：{Scripts.DialogSystem.ChooseNotBack},名字：{dialogUnitInfo.abstractAbstractDialogInfoAsset.name}");
                            CEventCenter.BroadMessage(Scripts.DialogSystem.ChooseNotBack,dialogUnitInfo.abstractAbstractDialogInfoAsset.name);
//                            Debug.Log("开始选项协程："+choice.targetDialogInfoAsset.name);
                            MainLoop.Instance.StartCoroutine(
                                Scripts.DialogSystem.RunDialogAwait(choice.targetDialogInfoAsset, () =>
                                {
                                    if (dialogUnitInfo.sendToExWord)
                                    {
                                        dialogUnitInfo.words = choice.text;
                                        CEventCenter.BroadMessage(Scripts.DialogSystem.ExternWord, dialogUnitInfo);
                                    }
                                    DestroyThis();
                                }));
                        }
                        else
                        {
//                            Debug.Log("Else???");
                            MainLoop.Instance.StartCoroutine(
                                Scripts.DialogSystem.RunDialog(choice.targetDialogInfoAsset, () =>
                                {
                                    if (dialogUnitInfo.sendToExWord)
                                    {
                                        dialogUnitInfo.words = choice.text;
                                        CEventCenter.BroadMessage(Scripts.DialogSystem.ExternWord, dialogUnitInfo);
                                    }
                                    DestroyThis();
                                }));
                        }

                    }

                };
                yield return new WaitForSeconds(.4f);
            }

            //如果有时间限制
            if (dialogUnitInfo.timeLimit)
            {
                var timer = 0f;
                MainLoop.Instance.UpdateForSeconds(() =>
                {
                    if (!m_TransFrom)
                        return;
                    onTimeLeave?.Invoke(timer, dialogUnitInfo.limitTime,defaultObj);
                    timer += Time.deltaTime;
                }, dialogUnitInfo.limitTime, () =>
                {
                    if (!m_TransFrom)
                        return;
                    //如果到现在没有点击下去
                    if (!clicked)
                    {
                        Hide();
                        MainLoop.Instance.StartCoroutine(
                            Scripts.DialogSystem.RunDialog(
                                dialogUnitInfo.Choices[dialogUnitInfo.defaultIndex].targetDialogInfoAsset,
                                () =>
                                {
                                    if (dialogUnitInfo.sendToExWord)
                                    {
                                        dialogUnitInfo.words = dialogUnitInfo.Choices[dialogUnitInfo.defaultIndex].text;
                                        CEventCenter.BroadMessage(Scripts.DialogSystem.ExternWord, dialogUnitInfo);
                                    }
                                    if (!dialogUnitInfo.Choices[dialogUnitInfo.defaultIndex].willBack)
                                        CEventCenter.BroadMessage(Scripts.DialogSystem.ChooseNotBack);
                                    DestroyThis();
                                }));
                    }
                });
            }

        }

    }
}


text:
fileFormatVersion: 2
guid: 30cc2c25a3d54559bb91cad6d8c9be7e
timeCreated: 1564558162


text:
using DialogSystem.Model;
using ReadyGamerOne.Common;
using ReadyGamerOne.View;
using UnityEngine.EventSystems;

namespace DialogSystem.View
{
    public class DialogUnitUI:AbstractUI
    {
        protected DialogUnitInfo m_dialogUnitInfo;
        public DialogUnitUI(DialogUnitInfo info)
        {
            m_dialogUnitInfo = info;
        }

        public override void DestroyThis(PointerEventData eventData = null)
        {
            base.DestroyThis(eventData);
            CEventCenter.BroadMessage(Scripts.DialogSystem.EndThisDialogUnit,m_dialogUnitInfo.abstractAbstractDialogInfoAsset.name);
//            Debug.Log("DialogUnitUI_DestoryThis_CEventCenter_BroadMessage:"+m_dialogUnitInfo.abstractAbstractDialogInfoAsset.name);
        }

        protected bool canGoNext = false;
        private void SetCanGoNext() => this.canGoNext = true;

        protected override void OnAddListener()
        {
            base.OnAddListener();
            CEventCenter.AddListener(Scripts.DialogSystem.CanGoNext, SetCanGoNext);
        }

        protected override void OnRemoveListener()
        {
            base.OnRemoveListener();
            CEventCenter.RemoveListener(Scripts.DialogSystem.CanGoNext, SetCanGoNext);
        }
    }
}


text:
fileFormatVersion: 2
guid: 4a624db0baf34c7b89d231fe09a25b88
timeCreated: 1566012842


text:
using DialogSystem.Model;
using DialogSystem.Scripts;
using ReadyGamerOne.Script;
using UnityEngine.UI;

namespace DialogSystem.View
{
    public abstract class AbstractWordDialogUI:DialogUnitUI
    {
        private bool enableGoNext = false;
        protected abstract string SpeakerTextPath { get; }
        protected virtual string DialogWordTextPath => null;
        protected virtual string CaptionWordTextPath => null;

        private DialogData _data;
        public AbstractWordDialogUI(DialogUnitInfo unitInfo):base(unitInfo)
        {
            Text words = null;

            //判断显示类型，是字幕式，还是对话框
            switch (unitInfo.showType)
            {
                case ShowType.Caption:
                    Create(unitInfo.abstractAbstractDialogInfoAsset.CaptionWordUiKeys[unitInfo.wordPrefabIndex]);

                    m_TransFrom.Find(SpeakerTextPath).GetComponent<Text>().text = unitInfo.SpeakerName;
                    words = m_TransFrom.Find(CaptionWordTextPath).GetComponent<Text>();

                    break;
                case ShowType.Dialog:
                    Create(unitInfo.abstractAbstractDialogInfoAsset.DialogWordUiKeys[unitInfo.wordPrefabIndex]);

                    _data = m_TransFrom.GetComponent<DialogData>();

                    m_TransFrom.position = unitInfo.fromNull
                        ? _data.GetSuitPos()
                        : _data.GetSuitPos(Scripts.DialogSystem.GetCharacterObj(unitInfo.SpeakerName).transform);

                    words = m_TransFrom.Find(DialogWordTextPath).GetComponent<Text>();
                    break;
            }

            words.text = unitInfo.words;

            Show();

            words.gameObject.AddComponent<TypeWriterEffect>().StartWriter(
                unitInfo.abstractAbstractDialogInfoAsset.wordFinishTime,
                ()=>enableGoNext=true,
                ()=>canGoNext,
                unitInfo.abstractAbstractDialogInfoAsset.affectedByTimeScale);
        }

        protected override void Update()
        {
            base.Update();

            if (m_dialogUnitInfo.showType == ShowType.Dialog && !m_dialogUnitInfo.fromNull)
            {
                m_TransFrom.position = m_dialogUnitInfo.fromNull
                    ? _data.GetSuitPos()
                    : _data.GetSuitPos(Scripts.DialogSystem.GetCharacterObj(m_dialogUnitInfo.SpeakerName).transform);
            }

            if (enableGoNext && canGoNext)
                DestroyThis();
        }
    }
}


text:
using System;
using System.Collections;
using DialogSystem.Model;
using DialogSystem.Scripts;
using ReadyGamerOne.Script;
using UnityEngine;
using UnityEngine.UI;
using Object = UnityEngine.Object;

namespace DialogSystem.View
{
    public abstract class AbstractNarratorDialogUI:DialogUnitUI
    {
        protected bool enbaleGoNext = false;
        protected abstract string TextPath { get; }
        protected abstract string ImagePath { get; }

        protected Text text;
        protected Image image;

        protected AbstractNarratorDialogUI(DialogUnitInfo info):base(info)
        {
            Create(info.abstractAbstractDialogInfoAsset.NarratorUiKeys);

            text = m_TransFrom.Find(TextPath).GetComponent<Text>();
            text.text = info.wordToNarrator;

            image = m_TransFrom.Find(ImagePath).GetComponent<Image>();

            switch (info.m_NarratorType)
            {
                case NarratorType.Color:
                    image.sprite = null;
                    image.color = info.m_NarratorColor;
                    break;
                case NarratorType.Image:
                    image.sprite = info.m_NarratorImage;
                    image.color = info.m_NarratorColor;
                    break;
                case NarratorType.Object:
                    var obj = Object.Instantiate(info.m_NarratorObject, m_TransFrom.parent);
                    obj.transform.SetAsFirstSibling();
                    image.sprite = info.m_NarratorImage;
                    image.color = info.m_NarratorColor;
                    break;
            }

            Show();

            if (info.enableFadeOut)
            {
                text.gameObject.AddComponent<TypeWriterEffect>().StartWriter(
                    info.wordToNarrator.Length/info.narratorSpeed,
                    ()=> MainLoop.Instance.StartCoroutine(FadeOutText(text,info.fadeOutTime,()=>DestroyThis())),
                    ()=>canGoNext,
                    info.abstractAbstractDialogInfoAsset.affectedByTimeScale);
            }
            else
            {
                text.gameObject.AddComponent<TypeWriterEffect>().StartWriter(
                    info.wordToNarrator.Length/info.narratorSpeed,
                    ()=>enbaleGoNext=true,
                    ()=>canGoNext,
                    info.abstractAbstractDialogInfoAsset.affectedByTimeScale);
            }

        }

        protected override void Update()
        {
            base.Update();
            if(enbaleGoNext && canGoNext)
                DestroyThis();
        }

        private IEnumerator FadeOutText(Text text, float fadeOutTime,Action endCall)
        {
            var color = text.color;
            for (var i = 0f; i < fadeOutTime; i += Time.deltaTime)
            {
                var alpha = 1 - i / fadeOutTime;
                text.color = new Color(color.r, color.g, color.b, alpha);
                yield return null;
            }
            endCall?.Invoke();
        }
    }
}


text:
fileFormatVersion: 2
guid: dbb006ccea167e34dbad0776caaa4664
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: 33b3095a3727f544dbe47311776edb53


text:
fileFormatVersion: 2
guid: 519776d3d02747548a264d7d32320ab1
folderAsset: yes
timeCreated: 1536092918
licenseType: Store
DefaultImporter:
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: 3aa7d582439bc2f4da8254d1364e0f41


text:
fileFormatVersion: 2
guid: 94693c6931cea70439c26417a1fc0d33
MonoImporter:
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}


text:
fileFormatVersion: 2
guid: 9fda1b74d4b0f014290027837e4813c3
PluginImporter:
  externalObjects: {}
  serializedVersion: 2
  iconMap: {}
  executionOrder: {}
  isPreloaded: 0
  isOverridable: 0
  platformData:
  - first:
      Any:
    second:
      enabled: 0
      settings: {}
  - first:
      Editor: Editor
    second:
      enabled: 1
      settings:
        DefaultValueInitialized: true
  - first:
      Windows Store Apps: WindowsStoreApps
    second:
      enabled: 0
      settings:
        CPU: AnyCPU
  userData:
  assetBundleName:
  assetBundleVariant:


text:
Shader "Hidden/Behavior Designer/Grid" {
    SubShader {
        Pass {
            CGPROGRAM
            #pragma vertex vert_img
            #pragma fragment frag
            #include "UnityCG.cginc"
            fixed4 frag(v2f_img i) : Color {
                return fixed4(0.21, 0.21, 0.21, 1);
            }
            ENDCG
        }
		Pass {
            CGPROGRAM
            #pragma vertex vert_img
            #pragma fragment frag
            #include "UnityCG.cginc"
            fixed4 frag(v2f_img i) : Color {
                return fixed4(0.33, 0.33, 0.33, 1);
            }
            ENDCG
        }
		Pass {
            CGPROGRAM
            #pragma vertex vert_img
            #pragma fragment frag
            #include "UnityCG.cginc"
            fixed4 frag(v2f_img i) : Color {
                return fixed4(0.26, 0.26, 0.26, 1);
            }
            ENDCG
        }
		Pass {
            CGPROGRAM
            #pragma vertex vert_img
            #pragma fragment frag
            #include "UnityCG.cginc"
            fixed4 frag(v2f_img i) : Color {
                return fixed4(0.27, 0.27, 0.27, 1);
            }
            ENDCG
        }
    }
}


text:
fileFormatVersion: 2
guid: 1f0cb79f53e760c4d950b8c6ade6a242
MonoImporter:
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:


text:
fileFormatVersion: 2
guid: 956347559c803f7489f75873ef2715e5
folderAsset: yes
DefaultImporter:
  userData:


text:
using UnityEditor;
using BehaviorDesigner.Runtime;

namespace BehaviorDesigner.Editor
{
    [CustomEditor(typeof(ExternalBehaviorTree))]
    public class ExternalBehaviorTreeInspector : ExternalBehaviorInspector
    {
        // intentionally left blank
    }
}


text:
fileFormatVersion: 2
guid: afbd9f0fb1c22d1409403fdef158479f
ShaderImporter:
  defaultTextures: []
  userData:


text:
using UnityEditor;
using BehaviorDesigner.Runtime;

namespace BehaviorDesigner.Editor
{
    [CustomEditor(typeof(BehaviorTree))]
    public class BehaviorTreeInspector : BehaviorInspector
    {
        // intentionally left blank
    }
}


text:
using UnityEngine;
using UnityEditor;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.ObjectDrawers;

namespace BehaviorDesigner.Editor.ObjectDrawers
{
    [CustomObjectDrawer(typeof(FloatSliderAttribute))]
    public class FloatSliderDrawer : ObjectDrawer
    {
        public override void OnGUI(GUIContent label)
        {
            var floatSliderAttribute = (FloatSliderAttribute)attribute;
            if (value is SharedFloat) {
                var sharedFloat = value as SharedFloat;
                sharedFloat.Value = EditorGUILayout.Slider(label, sharedFloat.Value, floatSliderAttribute.min, floatSliderAttribute.max);
            } else {
                value = EditorGUILayout.Slider(label, (float)value, floatSliderAttribute.min, floatSliderAttribute.max);
            }
        }
    }
}


text:
using UnityEngine;
using UnityEditor;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.ObjectDrawers;

namespace BehaviorDesigner.Editor.ObjectDrawers
{
    [CustomObjectDrawer(typeof(IntSliderAttribute))]
    public class IntSliderDrawer : ObjectDrawer
    {
        public override void OnGUI(GUIContent label)
        {
            var intSliderAttribute = (IntSliderAttribute)attribute;
            if (value is SharedInt) {
                var sharedFloat = value as SharedInt;
                sharedFloat.Value = EditorGUILayout.IntSlider(label, sharedFloat.Value, intSliderAttribute.min, intSliderAttribute.max);
            } else {
                value = EditorGUILayout.IntSlider(label, (int)value, intSliderAttribute.min, intSliderAttribute.max);
            }
        }
    }
}


text:
fileFormatVersion: 2
guid: ed5dac524fa5f61468bb6ca49a556b3b
MonoImporter:
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:


text:
fileFormatVersion: 2
guid: 5f0987c6ff37141458ff776277e2b65a
MonoImporter:
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:


text:
fileFormatVersion: 2
guid: a43abd9ecc0166043973a4ba6da07bf1
DefaultImporter:
  userData:


text:
fileFormatVersion: 2
guid: a52d5a185c5a1614f875fcb1828d78d8
DefaultImporter:
  userData:


text:
fileFormatVersion: 2
guid: 29d0d8866b4fa984bbc7dbf5d988ebcc
folderAsset: yes
DefaultImporter:
  userData:


text:
namespace BehaviorDesigner.Runtime
{
    [System.Serializable]
    public class ExternalBehaviorTree : ExternalBehavior
    {
        // intentionally left blank
    }
}


text:
fileFormatVersion: 2
guid: b23f08d2ae4cba14087c1ed36193d82b
MonoImporter:
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {fileID: 2800000, guid: 5b5f458971c6fd5459c51a7b8079bc3b, type: 3}
  userData:


text:
using UnityEngine;

namespace BehaviorDesigner.Runtime
{
    // Wrapper for the Behavior class
    [AddComponentMenu("Behavior Designer/Behavior Tree")]
    public class BehaviorTree : Behavior
    {
        // intentionally left blank
    }
}


text:
fileFormatVersion: 2
guid: 136279939989e9b4ea53bd2aa06b82e2
PluginImporter:
  externalObjects: {}
  serializedVersion: 2
  iconMap: {}
  executionOrder: {}
  isPreloaded: 0
  isOverridable: 0
  platformData:
  - first:
      Any:
    second:
      enabled: 1
      settings: {}
  - first:
      Editor: Editor
    second:
      enabled: 0
      settings:
        DefaultValueInitialized: true
  - first:
      Windows Store Apps: WindowsStoreApps
    second:
      enabled: 0
      settings:
        CPU: AnyCPU
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: 29f9234d5be47744daf373fb6fd54184
folderAsset: yes
DefaultImporter:
  externalObjects: {}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: 8d7b55c7ecdb49a4a89fa5e6f9022861
MonoImporter:
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {fileID: 2800000, guid: 5b5f458971c6fd5459c51a7b8079bc3b, type: 3}


text:
fileFormatVersion: 2
guid: 143ae0c3fc255864893a532a2571f3d9
MonoImporter:
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}


text:
namespace BehaviorDesigner.Runtime.Tasks
{
    // The entry task is a task that is used for display purposes within Behavior Designer to indicate the root of the tree. It is not a real task and
    // cannot be used within the behavior tree.
    [TaskIcon("{SkinColor}EntryIcon.png")]
    public class EntryTask : ParentTask
    {
        public override int MaxChildren()
        {
            return 1;
        }
    }
}


text:
fileFormatVersion: 2
guid: 02c91ef526a3f8a41b5df4402d7c783f
folderAsset: yes
DefaultImporter:
  externalObjects: {}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: c3a63466abc2809449aec6088f9153e6
folderAsset: yes
DefaultImporter:
  externalObjects: {}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: dd959be462adfbc4a8878260547827cb
folderAsset: yes
DefaultImporter:
  externalObjects: {}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: de0476b4548c1d4408860e4ee2dd9471
DefaultImporter:
  userData:


text:
fileFormatVersion: 2
guid: 91c6a439cec3003498369e01301ee57a
folderAsset: yes
DefaultImporter:
  externalObjects: {}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: 4952cbfc1e77be24b99e34c9acffc2a0
MonoImporter:
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}


text:
fileFormatVersion: 2
guid: 15b5d0aafd7d4f04f8332d33705ebd63
MonoImporter:
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData: