Exemplo n.º 1
0
    private IEnumerator UpdateThreader()
    {
        Threader.Stack += this.Callback;

        Threader.Stack += () =>
        {
            Debug.Log("Added directly to the stack.");
        };

        Threader.Add(this.Callback);

        Threader.Add(() =>
        {
            Debug.Log("Added with Add method.");
        }
                     );

        yield return(new WaitForSeconds(2f));

        StartCoroutine(this.UpdateThreader());

        // either syntax will work
        Threader.Stack -= this.Callback;
        // Threader.Remove( this.Callback );
        Debug.Log("Removed a function from the stack.");
    }
Exemplo n.º 2
0
 //Set the menu.
 public static void SetMenu(GenericMenu newMenu)
 {
     if (newMenu == null)
     {
         return;
     }
     boundMenu = newMenu;
     if (generationThread != null)
     {
         generationThread.Abort();
     }
     generationThread = Threader.StartAction(GenerateTree, () => { generationThread = null; current.editorWindow.Repaint(); });
 }
Exemplo n.º 3
0
        public Logger(ELogDestination logDestination)
        {
            this.logDestination = logDestination;

            if (logDestination == ELogDestination.File || logDestination == ELogDestination.All)
            {
                string date = GetLocalDateString();
                path = Directory.GetCurrentDirectory() + $"/logs/{date}.log";
                Directory.CreateDirectory(new FileInfo(path).Directory.FullName);
            }

            logThreader = new Threader(LogThread);
        }
Exemplo n.º 4
0
        ///Set another menu after it's open
        public void SetMenu(GenericMenu newMenu)
        {
            if (newMenu == null)
            {
                return;
            }

            willRepaint          = true;
            boundMenu            = newMenu;
            treeGenerationThread = Threader.StartAction(treeGenerationThread, current.GenerateTree, () =>
            {
                treeGenerationThread = null;
                willRepaint          = true;
            });
        }
Exemplo n.º 5
0
 public void OnDestroy()
 {
     Instance = null;
     PathfindingManager.Stop();
     Pathfinding.Clean();
 }
Exemplo n.º 6
0
 public void Awake()
 {
     Instance = this;
     PathfindingManager.Start();
 }
Exemplo n.º 7
0
        //THE TREE
        void DoTree(Rect treeRect, Event e)
        {
            if (treeGenerationThread != null)
            {
                return;
            }

            if (search != lastSearch)
            {
                lastSearch    = search;
                hoveringIndex = -1;
                if (!string.IsNullOrEmpty(search))
                {
                    //provide null reference thread (thus no aborting) so that results update all the time
                    searchGenerationThread = Threader.StartFunction(null, GenerateSearchResults, (resultNode) =>
                    {
                        currentNode            = resultNode;
                        searchGenerationThread = null;
                        if (current != null)
                        {
                            willRepaint = true;
                        }
                    });
                }
                else
                {
                    currentNode = rootNode;
                }
            }


            GUILayout.BeginArea(treeRect);
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos, false, false);
            GUILayout.BeginVertical();

            ///----------------------------------------------------------------------------------------------

            var    i                  = 0;
            var    itemAdded          = false;
            string lastSearchCategory = null;
            var    isSearch           = !string.IsNullOrEmpty(search);

            foreach (var childPair in currentNode.children)
            {
                if (isSearch && i >= 200)
                {
                    EditorGUILayout.HelpBox("There are more than 200 results. Please try refine your search input.", MessageType.Info);
                    break;
                }

                var node       = childPair.Value;
                var memberInfo = node.isLeaf ? node.item.userData as MemberInfo : null;
                var isDisabled = node.isLeaf && node.item.func == null && node.item.func2 == null;
                var icon       = node.isLeaf ? node.item.content.image : Icons.folderIcon;
                if (icon == null && memberInfo != null)
                {
                    icon = TypePrefs.GetTypeIcon(memberInfo);
                }

                //when within search, show category on top
                if (isSearch)
                {
                    var searchCategory = lastSearchCategory;
                    if (memberInfo == null || memberInfo is System.Type)
                    {
                        searchCategory = node.parent.fullPath != null?node.parent.fullPath.Split(new char[] { '/' }, System.StringSplitOptions.RemoveEmptyEntries).FirstOrDefault() : null;
                    }
                    else
                    {
                        searchCategory = memberInfo.ReflectedType.FriendlyName();
                    }

                    if (searchCategory != lastSearchCategory)
                    {
                        lastSearchCategory = searchCategory;
                        GUI.color          = EditorGUIUtility.isProSkin ? Color.black : Color.white;
                        GUILayout.BeginHorizontal("box");
                        GUI.color = Color.white;
                        GUILayout.Label(searchCategory, Styles.leftLabel, GUILayout.Height(16));
                        GUILayout.EndHorizontal();
                    }
                }
                //


                if (filterFavorites && !node.isFavorite && !node.HasAnyFavoriteChild())
                {
                    continue;
                }

                if (node.isLeaf && node.item.separator)
                {
                    if (itemAdded)
                    {
                        EditorUtils.Separator();
                    }
                    continue;
                }

                itemAdded = true;

                GUI.color = Color.clear;
                GUILayout.BeginHorizontal("box");
                GUI.color = Color.white;

                //Prefix icon
                GUILayout.Label(icon, GUILayout.Width(22), GUILayout.Height(16));
                GUI.enabled = !isDisabled;

                //Favorite
                if (currentKeyType != null)
                {
                    GUI.color = node.isFavorite ? Color.white : (node.HasAnyFavoriteChild() ? new Color(1, 1, 1, 0.2f) : new Color(0f, 0f, 0f, 0.4f));
                    if (GUILayout.Button(Icons.favoriteIcon, GUIStyle.none, GUILayout.Width(16), GUILayout.Height(16)))
                    {
                        node.ToggleFavorite();
                    }
                    GUI.color = Color.white;
                }

                //Content
                var label    = node.name;
                var hexColor = EditorGUIUtility.isProSkin ? "#B8B8B8" : "#262626";
                hexColor = isDisabled ? "#666666" : hexColor;
                var text = string.Format("<color={0}><size=11>{1}</size></color>", hexColor, (!node.isLeaf ? string.Format("<b>{0}</b>", label) : label));
                GUILayout.Label(text, Styles.leftLabel, GUILayout.Width(0), GUILayout.ExpandWidth(true));
                GUILayout.Label(node.isLeaf ? "●" : "►", Styles.leftLabel, GUILayout.Width(20));
                GUILayout.EndHorizontal();

                var elementRect = GUILayoutUtility.GetLastRect();
                if (e.type == EventType.MouseDown && e.button == 0 && elementRect.Contains(e.mousePosition))
                {
                    e.Use();
                    if (node.isLeaf)
                    {
                        ExecuteItemFunc(node.item);
                        break;
                    }
                    else
                    {
                        currentNode   = node;
                        hoveringIndex = 0;
                        break;
                    }
                }

                if (e.type == EventType.MouseMove && elementRect.Contains(e.mousePosition))
                {
                    hoveringIndex = i;
                }

                if (hoveringIndex == i)
                {
                    GUI.color = hoverColor;
                    GUI.DrawTexture(elementRect, EditorGUIUtility.whiteTexture);
                    GUI.color = Color.white;
                }

                i++;
                GUI.enabled = true;
            }

            if (hoveringIndex != lastHoveringIndex)
            {
                willRepaint       = true;
                lastHoveringIndex = hoveringIndex;
            }

            if (!itemAdded)
            {
                GUILayout.Label("No results to display with current search and filter combination");
            }

            GUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
            GUILayout.EndArea();
        }
Exemplo n.º 8
0
        public override void DrawUI()
        {
            //Move windows using title bar only
            ImGui.GetIO().ConfigWindowsMoveFromTitleBarOnly = true;

            if (ImGui.IsMouseDragging(ImGuiMouseButton.Right))
            {
                Setup.Camera.Move(-Input.MouseDelta(), ImGui.GetIO().DeltaTime * 60 / Setup.Camera.Zoom);
            }

            if (ImGui.GetIO().KeyCtrl&& Input.GetKeyDown(Microsoft.Xna.Framework.Input.Keys.S))  //Save scene
            {
                SceneManager.SerializeScene(SceneManager.ActiveScene.Name);
            }

            if (ImGui.GetIO().KeyCtrl&& Input.GetKeyDown(Microsoft.Xna.Framework.Input.Keys.G))  //Show Gizmos
            {
                GizmosVisualizer.ShowGizmos = !GizmosVisualizer.ShowGizmos;
            }

            if (ImGui.GetIO().KeyCtrl&& Input.GetKeyDown(Microsoft.Xna.Framework.Input.Keys.L))  //Launch game
            {
                SceneManager.SerializeScene(SceneManager.ActiveScene.Name);
                Threader.Invoke(FN_Project.VisualizeEngineStartup.RunExecutable, 0);
            }

            if (ImGui.GetIO().KeyCtrl&& Input.GetKeyDown(Microsoft.Xna.Framework.Input.Keys.P))  //Play In Editor
            {
                SceneManager.SerializeScene(SceneManager.ActiveScene.Name);

                SceneManager.ShouldUpdate = !SceneManager.ShouldUpdate;
                if (SceneManager.ShouldUpdate)
                {
                    SceneManager.ActiveScene.Start();
                }
                else
                {
                    SceneManager.LoadScene_Serialization(SceneManager.LastLoadPath);
                }
            }

            bool OpenHelp = false;

            if (ImGui.BeginMainMenuBar())
            {
                //ImGui.SetNextItemOpen(true);

                if (ImGui.BeginMenu("File"))
                {
                    if (ImGui.BeginMenu("New Scene"))
                    {
                        ImGui.InputText("Name", ref sceneName, 50);

                        ImGui.PushStyleColor(ImGuiCol.Button, new Vector4(1, 1, 1, 0.1f));

                        if (ImGui.SmallButton("Create"))
                        {
                            //Validate Name Here with the files in the directory
                            string[] Scenes = Directory.GetFiles(Environment.CurrentDirectory).Where(Item => Item.EndsWith(".scene")).ToArray();
                            sceneName = Utility.UniqueName(sceneName, Scenes);

                            //Create Scene
                            SceneManager.SerializeScene(SceneManager.ActiveScene.Name);
                            CreateScene(sceneName);
                        }

                        ImGui.PopStyleColor();
                        //var GEO = SceneManager.ActiveScene.FindGameObjectWithName("EditorGameObject");
                        //Scene NewScene = new Scene("NOice Scene");
                        //NewScene.AddGameObject_Recursive(GEO);
                        //SceneManager.SerializeScene(NewScene.Name);
                        //SceneManager.LoadScene_Serialization(NewScene.Name);
                        ImGui.EndMenu();
                    }

                    if (ImGui.MenuItem("Save", "CTRL + S"))
                    {
                        SceneManager.SerializeScene(SceneManager.ActiveScene.Name);
                    }

                    if (ImGui.BeginMenu("Save As.."))
                    {
                        ImGui.InputText("Name", ref sceneName, 50);

                        ImGui.PushStyleColor(ImGuiCol.Button, new Vector4(1, 1, 1, 0.1f));

                        if (ImGui.SmallButton("Save"))
                        {
                            //Validate Name Here with the files in the directory
                            string[] Scenes      = Directory.GetFiles(Environment.CurrentDirectory).Where(Item => Item.EndsWith(".scene")).ToArray();
                            bool     SceneExists = Scenes.Any(Item => Item.Equals(Environment.CurrentDirectory + "\\" + sceneName + ".scene"));

                            if (SceneExists)
                            {
                                ImGui.OpenPopup("Overwrite File?");
                                PopUpOpen = true;
                            }
                            else
                            {
                                string OldSceneName = SceneManager.ActiveScene.Name;
                                SceneManager.ActiveScene.Name = sceneName;
                                SceneManager.SerializeScene(sceneName);
                                SceneManager.ActiveScene.Name = OldSceneName;
                            }
                        }

                        if (ImGui.BeginPopupModal("Overwrite File?", ref PopUpOpen, ImGuiWindowFlags.AlwaysAutoResize))
                        {
                            if (ImGui.Button("Yes, overwrite file"))
                            {
                                string OldSceneName = SceneManager.ActiveScene.Name;
                                SceneManager.ActiveScene.Name = sceneName;
                                SceneManager.SerializeScene(sceneName);
                                SceneManager.ActiveScene.Name = OldSceneName;

                                ImGui.CloseCurrentPopup();
                            }

                            if (ImGui.Button("No") || ImGui.IsKeyPressed(ImGui.GetKeyIndex(ImGuiKey.Escape)))
                            {
                                ImGui.CloseCurrentPopup();
                            }

                            ImGui.EndPopup();
                        }

                        ImGui.PopStyleColor();

                        ImGui.EndMenu();
                    }

                    if (ImGui.MenuItem("Play", "CTRL + P"))
                    {
                        SceneManager.SerializeScene(SceneManager.ActiveScene.Name);

                        SceneManager.ShouldUpdate = !SceneManager.ShouldUpdate;
                        if (SceneManager.ShouldUpdate)
                        {
                            SceneManager.ActiveScene.Start();
                        }
                        else
                        {
                            SceneManager.LoadScene_Serialization(SceneManager.LastLoadPath);
                        }
                    }

                    if (ImGui.MenuItem("Launch Game", "CTRL + L"))
                    {
                        SceneManager.SerializeScene(SceneManager.ActiveScene.Name);
                        Threader.Invoke(FN_Project.VisualizeEngineStartup.RunExecutable, 0);
                    }

                    if (ImGui.MenuItem("Open Sln"))
                    {
                        Utility.ExecuteCommand(new string[] { "start " + FN_Project.VisualizeEngineStartup.GamePath + "\\" + FN_Project.VisualizeEngineStartup.GamePath.Substring(FN_Project.VisualizeEngineStartup.GamePath.LastIndexOf("\\") + 1) + ".sln" }, FN_Project.VisualizeEngineStartup.GamePath);
                    }

                    ImGui.EndMenu();
                }

                if (ImGui.BeginMenu("Tools"))
                {
                    if (ImGui.MenuItem("Animation Editor"))
                    {
                        AnimationEditor.IsWindowOpen = true;
                    }

                    if (ImGui.MenuItem("TileMap Editor"))
                    {
                        TilemapEditor.IsWindowOpen = true;
                    }

                    ImGui.EndMenu();
                }

                if (ImGui.BeginMenu("Config"))
                {
                    ImGui.Checkbox("Show Gizmos (CTRL + G)", ref GizmosVisualizer.ShowGizmos);
                    ImGui.Checkbox("Auto Config Windows", ref AutoConfigureWindows);

                    ImGui.EndMenu();
                }

                if (ImGui.BeginMenu("Help"))
                {
                    if (ImGui.MenuItem("Shortcuts"))
                    {
                        OpenHelp = true;
                    }

                    ImGui.EndMenu();
                }

                //var CursPosX = ImGui.GetCursorPosX();

                //ImGui.SetCursorPosX(Setup.graphics.PreferredBackBufferWidth * 0.5f);
                //if (ImGui.Checkbox("Play", ref SceneManager.ShouldUpdate))
                //{
                //    if (SceneManager.ShouldUpdate)
                //        SceneManager.ActiveScene.Start();
                //    else
                //        SceneManager.LoadScene_Serialization(SceneManager.LastLoadPath);
                //}
                //ImGui.SetCursorPosX(CursPosX);

                ImGui.EndMainMenuBar();
            }

            if (OpenHelp)
            {
                ImGui.OpenPopup("Shortcuts Popup");
            }

            if (ImGui.BeginPopup("Shortcuts Popup"))
            {
                if (ImGui.TreeNode("General"))
                {
                    ImGui.BulletText("To save the scene in editor => Ctrl + S");
                    ImGui.BulletText("To reload the scene in editor => Ctrl + R");
                    ImGui.BulletText("To play the scene in editor => Ctrl + P");
                    ImGui.BulletText("To launch the game => Ctrl + L");
                    ImGui.BulletText("You can Undo/Redo most actions by pressing Ctrl + Z/Y");

                    ImGui.TreePop();
                }

                if (ImGui.TreeNode("Scene Window"))
                {
                    ImGui.BulletText("To multiselect gameObjects => hold Ctrl then click on a gameObject");
                    ImGui.BulletText("To multiselect a region => hold Shift then click on a gameObject");
                    ImGui.BulletText("To copy a gameObject => Select then Ctrl + C");
                    ImGui.BulletText("To cut a gameObject => Select then Ctrl + X");
                    ImGui.BulletText("To duplicate a gameObject => Select then Ctrl + D");
                    ImGui.BulletText("To delete a gameObject => Select then press \"Delete\" button on the keyboard");
                    ImGui.BulletText("You can drag a gameObject");
                    ImGui.BulletText("You can parent/unparent a gameobject using drag/drop");
                    ImGui.BulletText("Right click on an empty space to open gamObject template creation menu");

                    ImGui.TreePop();
                }

                if (ImGui.TreeNode("Inspector Window"))
                {
                    ImGui.BulletText("To ensure that your action is registered in the undo \nbuffer, simply press enter after editing a writable widget");
                    ImGui.BulletText("Drag/Drop is supported for dragging a component from its \"Header\"\nthat contains its name");
                    ImGui.BulletText("To fine tune or edit a widget value, simply press Ctrl + Mouse click on it!\nN.B: Be careful, this allows you to exceed any constraints on the input!");

                    ImGui.TreePop();
                }

                if (ImGui.TreeNode("Content Window"))
                {
                    ImGui.BulletText("Drag/Drop is supported for dragging a Texture/Audio/Shader and dropping\nit on the appropriate field");
                    ImGui.BulletText("You can Import assets outside the engine by simply\ncopying them to the clipboad then press \"Paste Clipboard\" button");

                    ImGui.TreePop();
                }

                ImGui.EndPopup();
            }

            //Docking Part (Experimental
            //ImGui.GetIO().ConfigFlags |= ImGuiConfigFlags.DockingEnable;

            //GameObject ChosenGO = SceneManager.ActiveScene.GameObjects[0];
            //if (ImGui.IsMouseClicked(ImGuiMouseButton.Left) && GameObjects_Tab.WhoIsSelected == null)
            //{
            //    foreach (GameObject GO in SceneManager.ActiveScene.GameObjects)
            //    {
            //        SpriteRenderer SR = GO.GetComponent<SpriteRenderer>();
            //        if (SR != null && SR.Sprite != null)
            //        {
            //            if (SR.Sprite.DynamicScaledRect().Contains(Input.GetMousePosition()))
            //            {
            //                if(GO.Layer < ChosenGO.Layer)
            //                    ChosenGO = GO;
            //            }
            //        }
            //    }

            //    GameObjects_Tab.WhoIsSelected = ChosenGO;
            //}
        }