Пример #1
0
        void OnEnable()
        {
            Handler = (DialogHandler)target;

            Handler.FileList = FileManager.LoadFiles().Clone <string>();

            DialogHandler[] handlerList = FindObjectsOfType <DialogHandler>();

            foreach (var _handler in handlerList)
            {
                if (_handler.gameObject.GetInstanceID() != ((DialogHandler)target).gameObject.GetInstanceID() && _handler.LoadedDialogue == true)
                {
                    int fileIndex = _handler.FileList.FindIndex(a => a == _handler.SelectedFile);
                    if (fileIndex != -1)
                    {
                        Handler.FileList.RemoveAt(fileIndex);
                    }
                }
            }


            LoadedDialogue      = serializedObject.FindProperty("LoadedDialogue");
            SelectedDialogIndex = serializedObject.FindProperty("SelectedDialogIndex");
            SelectedFile        = serializedObject.FindProperty("SelectedFile");
        }
Пример #2
0
        public override void OnGUI(int WindowID)
        {
            GUILayout.BeginVertical();
            GUILayout.Label("Insert the Dialog file name without extension.");
            FileDialogName = GUILayout.TextArea(FileDialogName);

            List <string> fileList = FileManager.LoadFiles();

            if (GUILayout.Button("Save"))
            {
                if (FileDialogName.Trim() == "")
                {
                    EditorUtility.DisplayDialog("Empty filename", "The filename must not be empty.", "Ok");
                }
                else if (fileList.FindIndex(a => a == FileDialogName) != -1)
                {
                    EditorUtility.DisplayDialog("Filename already exists", "The filename already exists in the dialog list.", "Ok");
                }
                else
                {
                    db.New(FileDialogName);
                }
            }
            GUILayout.EndVertical();
            GUI.DragWindow();
        }
Пример #3
0
        public void Load(string FileName)
        {
            BinaryFormatter bf = new BinaryFormatter();

            // 1. Construct a SurrogateSelector object
            SurrogateSelector ss = new SurrogateSelector();

            RectSerializatoinSurrogate v3ss = new RectSerializatoinSurrogate();

            ss.AddSurrogate(typeof(Rect),
                            new StreamingContext(StreamingContextStates.All),
                            v3ss);

            // 2. Have the formatter use our surrogate selector
            bf.SurrogateSelector = ss;

            string fileLocation = FileManager.LoadFile(FileName);

            Stream stream = new FileStream(fileLocation, FileMode.Open);

            List <AbstractNode> _preNodeList = new List <AbstractNode>();

            _preNodeList = (List <AbstractNode>)bf.Deserialize(stream);

            foreach (AbstractNode _node in _preNodeList)
            {
                _node.SetDb(this);
            }

            stream.Close();

            Init();
            LoadNodeTypes();

            // Add Node to lists and dictionaries
            foreach (AbstractNode newNode in _preNodeList)
            {
                AddNodeToLists(newNode);
            }

            // Add connections
            foreach (AbstractNode node in NodeList)
            {
                Dictionary <int, string> activeConnections = node.GetActiveConnections();

                foreach (int key in activeConnections.Keys)
                {
                    AddConnection(node.UniqueID, key, activeConnections[key]);
                }
            }

            PropertiesNode propertiesNode = (PropertiesNode)GetNodeByType(typeof(PropertiesNode));

            propertiesNode.SelectedDialogIndex = FileManager.LoadFiles().FindIndex(a => a == FileName);

            propertiesNode.HasLoadedDialog = true;
            propertiesNode.LoadedFile      = FileName;
        }
Пример #4
0
        public override void OnGUI(int WindowID)
        {
            GUILayout.BeginVertical();

            List <string> fileList = FileManager.LoadFiles();

            string selectedFile = "";

            GUILayout.Label("Dialogs Menu:");

            SelectedDialogIndex = EditorGUILayout.Popup("Select dialog: ", SelectedDialogIndex, fileList.ToArray());

            if (fileList.Count != 0)
            {
                selectedFile = fileList[SelectedDialogIndex];
            }

            GUILayout.BeginHorizontal();

            if (GUILayout.Button("New"))
            {
                db.AddNode(db.GetLoadedNodeKey(typeof(NewDialog)));
            }

            if (String.IsNullOrEmpty(firstNode) || HasLoadedDialog == false)
            {
                GUI.enabled = false;
            }

            if (GUILayout.Button("Save"))
            {
                db.Save(selectedFile);
            }

            GUI.enabled = true;

            if (String.IsNullOrEmpty(selectedFile))
            {
                GUI.enabled = false;
            }

            if (GUILayout.Button("Load"))
            {
                db.Load(selectedFile);
            }

            GUI.enabled = true;

            if (selectedFile == "")
            {
                GUI.enabled = false;
            }

            if (GUILayout.Button("Delete"))
            {
                bool unloadDialog = false;

                if (selectedFile == this.LoadedFile)
                {
                    unloadDialog = true;
                }

                db.Delete(selectedFile, unloadDialog);
            }

            GUI.enabled = true;

            GUILayout.EndHorizontal();

            if (HasLoadedDialog == false)
            {
                EditorGUILayout.HelpBox("There's no loaded dialog to be saved. Create a new one or load a dialog.", MessageType.Error);
            }
            else if (String.IsNullOrEmpty(firstNode))
            {
                EditorGUILayout.HelpBox("You must declare an initial node before saving the dialog.", MessageType.Error);
            }

            GUILayout.Label("Add new nodes:");

            Dictionary <int, string> publicNodeList = db.GetPublicNodeList();

            int[] publicNodeKeyList = publicNodeList.Keys.ToArray();

            SelectedNodeType = EditorGUILayout.IntPopup("Select node type: ", SelectedNodeType, publicNodeList.Values.ToArray(), publicNodeKeyList);

            if (GUILayout.Button("Add Node"))
            {
                newNode(SelectedNodeType);
            }

            GUILayout.EndVertical();

            GUI.DragWindow();
        }