public void OnGUI()
        {
            CanvasGUI.Position = position;

            if (DateTime.Now - lastCheck >= ResourceManager.CheckRate)
            {
                if (!EditorCache.ValidateCanvas(cache))
                {
                    Debug.LogWarning("Loading last opened session.");
                    InitCanvas();
                    cache = EditorCache.LoadCache();
                }
                else
                {
                    cache.Init();
                }
                lastCheck = DateTime.Now;
            }

            InputSystem.EarlyInputEvents(cache.States);
            DialogueEditorGUI.OnGUI(cache.States);
            ToolBar();
            InputSystem.LateInputEvents(cache.States);
            cache.States.UpdateEvents();

            if (openDebug = CanvasGUI.Toggle(new Rect(5, 5, 130, 20), new GUIContent("Debug Window"), openDebug))
            {
                DebuggerWindow();
            }
        }
Пример #2
0
        public static EditorCache SaveCanvas(string filePath, bool createCopy, EditorCache cache)
        {
            if (!ValidPath(ref filePath))
            {
                Debug.LogError("the file path: " + filePath + ", does not exist");
                return(cache);
            }
            Reset();

            if (createCopy)
            {
                CopyRefs(cache);
                cache = ReplaceSO(cache) as EditorCache;
                ReplaceRefs(cache);
            }
            SaveAsset(cache, filePath);

            foreach (ScriptableObject objRef in cache.GetAllReferences(true))
            {
                if (!objRef)
                {
                    throw new UnityException("' " + objRef.GetType() + "' Database is missing reference. Cannot save the dialogue canvas.");
                }
                SaveRefs(objRef, cache, false);
            }
            DialogueEditorGUI.Save();
            return(cache);
        }
        void ToolBar()
        {
            CanvasGUI.BeginGroup(CanvasGUI.ToolBarRect, GUI.skin.box, cache.States.curSpace == EventSpace.Toolbar);

            GUI.Label(new Rect(5, 5, CanvasGUI.ToolBarRect.width - 10, 20), new GUIContent(cache.CanvasName + (cache.AutoLoaded ? " (Last Session)" : "")));

            if (CanvasGUI.Button(new Rect(5, 30, CanvasGUI.ToolBarRect.width - 10, 20), "Save"))
            {
                cache = (cache.IsFileSaved && !cache.AutoLoaded) ? EditorCache.SaveCache(cache.SavePath ?? AssetDatabase.GetAssetPath(cache), cache) : SaveCanvas();
            }

            if (CanvasGUI.Button(new Rect(5, 55, CanvasGUI.ToolBarRect.width - 10, 20), "Save As"))
            {
                SaveCanvas();
            }

            if (CanvasGUI.Button(new Rect(5, 80, CanvasGUI.ToolBarRect.width - 10, 20), "Load"))
            {
                LoadCanvas();
            }

            if (CanvasGUI.Button(new Rect(5, 105, CanvasGUI.ToolBarRect.width - 10, 20), "New Canvas"))
            {
                cache = EditorCache.NewCache();
            }

            if (CanvasGUI.Button(new Rect(5, 130, CanvasGUI.ToolBarRect.width - 10, 20), "Settings"))
            {
                Setting();
            }

            CanvasGUI.EndGroup();
        }
Пример #4
0
 public EditorStates(EditorCache cache)
 {
     EditorName = cache.CanvasName;
     Nodes      = cache.Nodes;
     Actors     = cache.Actors;
     Conditions = cache.Conditions;
     Init();
 }
Пример #5
0
        public static EditorCache LoadCache(string filePath)
        {
            EditorCache cache = SaveManager.LoadCanvas(filePath);

            if (!cache.AutoLoaded)
            {
                SaveManager.SaveCanvas(ResourceManager.TEMPFILEPATH, cache.IsFileSaved, cache);
            }
            return(cache);
        }
 private static bool AutoOpenCanvas(int instanceID, int line)
 {
     if (EditorUtility.InstanceIDToObject(instanceID) is EditorCache)
     {
         OpenWindow();
         curWindow.cache     = EditorCache.LoadCache(AssetDatabase.GetAssetPath(instanceID));
         curWindow.lastCheck = DateTime.Now;
         return(true);
     }
     return(false);
 }
Пример #7
0
 public static EditorCache SaveCache(string filePath, EditorCache cache)
 {
     if (filePath == ResourceManager.TEMPFILEPATH)
     {
         Debug.LogWarning("Dont be saving stuff here dawg. plox file somewhere else to saving.");
         return(cache);
     }
     cache          = SaveManager.SaveCanvas(filePath, cache.IsFileSaved, cache);
     cache.SavePath = filePath;
     cache.Init();
     return(cache);
 }
        EditorCache LoadnSaveAs(bool load)
        {
            string filePath = (load) ? EditorUtility.OpenFilePanel("Load Dialogue Canvas", ResourceManager.SAVEPATH, "asset") :
                              EditorUtility.SaveFilePanelInProject("Save Dialogue Canvas", cache.CanvasName, "asset", "Select path to save Dialogue Canvas.", ResourceManager.SAVEPATH);

            if (string.IsNullOrEmpty(filePath))
            {
                ShowNotification(new GUIContent("No " + (load ? "load" : "save") + " path chosen."));
                return(cache);
            }
            return((load) ? EditorCache.LoadCache(filePath) : EditorCache.SaveCache(filePath, cache));
        }
Пример #9
0
        public static EditorCache LoadCache(EditorCache loadedCache)
        {
            EditorCache cache = CreateInstance <EditorCache> ();

            cache.Nodes      = loadedCache.Nodes;
            cache.Actors     = loadedCache.Actors;
            cache.Conditions = loadedCache.Conditions;
            cache.States     = loadedCache.States;

            SaveManager.SaveCanvas(ResourceManager.TEMPFILEPATH, true, cache);
            cache.Init();
            return(cache);
        }
Пример #10
0
        public static EditorCache NewCache()
        {
            EditorCache cache = CreateInstance <EditorCache> ();

            cache.CanvasName = "New Canvas";
            cache.Actors     = ActorDatabase.CreateNew <ActorDatabase> (cache.CanvasName);
            cache.Conditions = ConditionDatabase.CreateNew <ConditionDatabase> (cache.CanvasName);
            cache.Nodes      = NodeDatabase.CreateNew <NodeDatabase> (cache.CanvasName);
            cache.States     = new EditorStates(cache);

            cache.Init();
            SaveManager.SaveCanvas(ResourceManager.TEMPFILEPATH, false, cache);
            return(cache);
        }
Пример #11
0
        public override void OnGUI()
        {
            base.OnGUI();

            CanvasGUI.BeginGroup(Position, GUI.skin.box, actor.Tint, HasControl);

            if (Locked)
            {
                GUI.Label(new Rect(5, 5, 240, 20), name);
                GUI.Label(new Rect(5, 30, 240, 20), actor.name);
            }
            else
            {
                EditorCache cache    = DialogueEditorGUI.Cache;
                string      nodeName = name;

                if (CanvasGUI.TextField(new Rect(5, 5, 240, 20), ref nodeName))
                {
                    name = cache.Nodes.ItemNames[cache.Nodes.ItemNames.IndexOf(name)] = nodeName;
                }

                ActorDatabase actors = cache.Actors;
                actor = actors.Get(CanvasGUI.DropDownMenu(new Rect(5, 30, 240, 20),
                                                          position, actors.GetIndex(actor), actors.ItemNames.ToArray()));
            }

            if (CanvasGUI.Button(new Rect(Position.size.x - 50, 5, 20, 20), new GUIContent("L"), GUI.skin.button))
            {
                Locked = !Locked;
            }

            if (CanvasGUI.Button(new Rect(Position.size.x - 25, 5, 20, 20), new GUIContent("X"), GUI.skin.button))
            {
                Delete();
            }
            textArea = CanvasGUI.TextArea(new Rect(5, 55, 290, 115), textArea);

            if (CanvasGUI.Button(new Rect(5, 175, 290, 20), new GUIContent("Add Dialogue Option"), GUI.skin.button))
            {
                options.Add(OptionNode.Create(options.NextItemName("Option"), this));
            }

            CanvasGUI.EndGroup();

            options.OnGUI();
        }
Пример #12
0
        public override void Delete()
        {
            EditorCache cache = DialogueEditorGUI.Cache;

            foreach (BaseNode node in cache.Nodes)
            {
                foreach (OutputNodule nodule in node.Nodules.OfType <OutputNodule> ())
                {
                    if (nodule.Condition == this)
                    {
                        nodule.Condition = null;
                    }
                }
            }
            cache.Conditions.Remove(this);
            cache.Conditions.ItemNames.Remove(name);
            DestroyImmediate(this, true);
        }
Пример #13
0
        public static bool ValidateCanvas(EditorCache cache)
        {
            if (!cache)
            {
                Debug.LogError("Validation failed. No fking cache mate");
                return(false);
            }

            if (string.IsNullOrEmpty(cache.CanvasName))
            {
                Debug.LogError("Validation failed. This Cache does not have a name.");
                return(false);
            }

            if (cache.States == null)
            {
                cache.states = new EditorStates(cache);
                //Debug.LogError ("Validation failed. This Cache does not have a EditorStates reference");
                //return false;
            }

            foreach (ScriptableObject obj in cache.GetAllReferences(true))
            {
                if (!obj)
                {
                    Debug.LogError("Validation failed. The reference object '" + obj.GetType().Name + "' is missing reference.");
                    return(false);
                }

                if (!obj.name.Contains(cache.CanvasName))
                {
                    Debug.LogError("Validation failed. The reference object '" + obj.GetType().Name + "' does not match the cache.");
                    return(false);
                }
                //if (!cache.ValidateObject (obj))
                //    return false;
            }
            return(true);
        }
Пример #14
0
        public static EditorCache LoadCache()
        {
            EditorCache cache = SaveManager.LoadCanvas(ResourceManager.TEMPFILEPATH) ?? NewCache();

            return(cache);
        }
Пример #15
0
        static void AddCallBack(object callBackObj)
        {
            EditorStates states = callBackObj as EditorStates;

            if (states == null)
            {
                throw new UnityException();
            }
            EditorState state = states.curState;

            if (states.info.Contains("Node"))
            {
                switch (states.curSpace)
                {
                case EventSpace.Node:
                    if (states.info == "OptionNode")
                    {
                        if (state.selectedObject is MainNode)
                        {
                            MainNode main = state.selectedObject as MainNode;
                            main.Options.Add(OptionNode.Create(main.Options.NextItemName("Option"), main));
                        }
                        else
                        {
                            goto default;
                        }
                    }
                    else if (states.info == "MainNode")
                    {
                        goto default;
                    }
                    else
                    {
                        Debug.LogError("Cannot recognise name of 'Node'. Add More Error here");
                        return;
                    }
                    break;

                default:
                    EditorCache cache = DialogueEditorGUI.Cache;
                    cache.Nodes.Add(DialogueNode.Create(states.info,
                                                        cache.Nodes.NextItemName(states.info),
                                                        CanvasGUI.CanvasToScreenPosition(state, states.mousePos),
                                                        cache.Actors.DefaultActor));
                    break;
                }
            }
            else if (states.info.Contains("Nodule"))
            {
                BaseNode node = (states.curSpace == EventSpace.Node) ? state.selectedObject as BaseNode :
                                (states.curSpace == EventSpace.Nodule) ? (state.selectedObject as BaseNodule).MainNode :
                                null;

                if (node)
                {
                    node.Nodules.Add(BaseNodule.Create(states.info, node.Nodules.NextItemName(states.info), node));
                }
            }
            else
            {
                throw new UnityException();
            }
        }
 public static void UpdateEnvironment(EditorCache cache)
 {
     Cache  = cache;
     States = cache.States;
 }