Пример #1
0
 void OnDisable()
 {
     if (parentWindow != null)
     {
         parentWindow.CommonContext.APIManager.ResponseReceived -= OnResponseReceived;
         parentWindow = null;
     }
 }
Пример #2
0
        public static void OpenWindow()
        {
            SidekickInspectorWindow window = EditorWindow.GetWindow <SidekickInspectorWindow>();

            window.Show();
            window.titleContent = new GUIContent("Sidekick");
            window.UpdateTitleContent();
        }
Пример #3
0
        bool AcquireParentWindowIfPossible()
        {
            SidekickInspectorWindow[] windows = Resources.FindObjectsOfTypeAll <SidekickInspectorWindow>();
            if (windows.Length > 0)
            {
                parentWindow = windows[0];

                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #4
0
        bool AcquireParentWindowIfPossible()
        {
            SidekickInspectorWindow[] windows = Resources.FindObjectsOfTypeAll <SidekickInspectorWindow>();
            if (windows.Length > 0 && windows[0].CommonContext.Enabled)
            {
                parentWindow = windows[0];

                parentWindow.CommonContext.APIManager.ResponseReceived += OnResponseReceived;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #5
0
        void OnGUI()
        {
            GUIStyle centerMessageStyle = new GUIStyle(GUI.skin.label);

            centerMessageStyle.alignment = TextAnchor.MiddleCenter;
            centerMessageStyle.wordWrap  = true;

            if (parentWindow == null)
            {
                AcquireParentWindowIfPossible();
            }

            if (parentWindow == null || parentWindow.CommonContext.Enabled == false)
            {
                GUILayout.FlexibleSpace();
                GUILayout.Label("Sidekick Inspector window must be open to use remote hierarchy", centerMessageStyle);
                if (GUILayout.Button("Open Sidekick Inspector"))
                {
                    SidekickInspectorWindow.OpenWindow();
                    AcquireParentWindowIfPossible();
                }
                GUILayout.FlexibleSpace();


                return;
            }

            if (parentWindow.CommonContext.Settings.InspectionConnection == InspectionConnection.RemotePlayer)
            {
                GUILayout.Space(9);

                SidekickSettings settings = parentWindow.CommonContext.Settings;

                if (settings.InspectionConnection == InspectionConnection.RemotePlayer)
                {
                    int playerCount = EditorConnection.instance.ConnectedPlayers.Count;


                    StringBuilder builder = new StringBuilder();
                    builder.AppendLine(string.Format("{0} players connected.", playerCount));

                    bool validConnection = (playerCount > 0);

#if SIDEKICK_DEBUG
                    // If we're in Local Dev Mode also consider that a valid connection
                    validConnection |= settings.LocalDevMode;
#endif


                    if (validConnection == false)
                    {
#if UNITY_2017_1_OR_NEWER
                        EditorGUILayout.HelpBox("No player connected, selected a Connected Player in the Console window or attach the Profiler to a remote player", MessageType.Warning);
#else
                        EditorGUILayout.HelpBox("No player connected, attach the Profiler to a remote player", MessageType.Warning);
#endif
                    }
                    else
                    {
                        int count = 0;
                        foreach (ConnectedPlayer p in EditorConnection.instance.ConnectedPlayers)
                        {
#if UNITY_2017_3_OR_NEWER
                            // ConnectedPlayer interface changed in 2017.3
                            builder.AppendLine(string.Format("[{0}] - {1} {2}", count++, p.name, p.playerId));
#else
                            builder.AppendLine(string.Format("[{0}] - {1}", count++, p.PlayerId));
#endif
                        }

                        EditorGUILayout.HelpBox(builder.ToString(), MessageType.Info);
                    }
                    settings.AutoRefreshRemote = EditorGUILayout.Toggle("Auto Refresh Remote", settings.AutoRefreshRemote);

#if SIDEKICK_DEBUG
                    settings.LocalDevMode = EditorGUILayout.Toggle("Local Dev Mode", settings.LocalDevMode);
#endif
                    if (validConnection)
                    {
                        if (GUILayout.Button("Refresh Hierarchy"))
                        {
                            parentWindow.CommonContext.APIManager.SendToPlayers(new GetHierarchyRequest());
                        }

                        DoToolbar();
                        DoTreeView();
                    }
                }
            }
            else
            {
                treeView.SetDisplays(new List <TreeViewItem>());
                GUILayout.FlexibleSpace();
                GUILayout.Label("Remote hierarchy is only visible in remote mode", centerMessageStyle);
                if (GUILayout.Button("Set Remote Mode"))
                {
                    parentWindow.SetConnectionMode(InspectionConnection.RemotePlayer);
                }
                GUILayout.FlexibleSpace();
            }
        }
Пример #6
0
        void OnGUI()
        {
            GUIStyle centerMessageStyle = new GUIStyle(GUI.skin.label);

            centerMessageStyle.alignment = TextAnchor.MiddleCenter;
            centerMessageStyle.wordWrap  = true;

            if (parentWindow == null)
            {
                AcquireParentWindowIfPossible();
            }

            if (parentWindow == null)
            {
                GUILayout.FlexibleSpace();
                GUILayout.Label("Sidekick Inspector window must be open to use remote hierarchy", centerMessageStyle);
                if (GUILayout.Button("Open Sidekick Inspector"))
                {
                    SidekickInspectorWindow.OpenWindow();
                    AcquireParentWindowIfPossible();
                }
                GUILayout.FlexibleSpace();


                return;
            }

            if (Settings.InspectionConnection == InspectionConnection.RemotePlayer)
            {
                GUILayout.Space(9);

                if (Settings.InspectionConnection == InspectionConnection.RemotePlayer)
                {
                    bool validConnection = (EditorMessaging.KnownEndpoints.Count >= 1);

#if SIDEKICK_DEBUG
                    validConnection |= Settings.LocalDevMode;
#endif

                    if (validConnection == false)
                    {
                        EditorGUILayout.HelpBox("No player found, make sure both the editor and player are on the same network", MessageType.Warning);
                    }
                    else
                    {
                        List <string> displayNames   = new List <string>();
                        int           index          = 0;
                        int           selectionIndex = 0;
                        foreach (var pair in EditorMessaging.KnownEndpoints)
                        {
                            displayNames.Add(string.Format("{0} - {1}", pair.Key, pair.Value));
                            if (pair.Key == EditorMessaging.ConnectedIP)
                            {
                                selectionIndex = index;
                            }
                            index++;
                        }
                        EditorGUILayout.Popup(selectionIndex, displayNames.ToArray());
                    }
                    Settings.AutoRefreshRemote = EditorGUILayout.Toggle("Auto Refresh Remote", Settings.AutoRefreshRemote);

#if SIDEKICK_DEBUG
                    Settings.LocalDevMode = EditorGUILayout.Toggle("Local Dev Mode", Settings.LocalDevMode);
#endif
                    if (validConnection)
                    {
                        if (GUILayout.Button("Refresh Hierarchy"))
                        {
                            APIManager.SendToPlayers(new GetHierarchyRequest());
                        }

                        DoToolbar();
                        DoTreeView();
                    }
                }
            }
            else
            {
                treeView.ClearDisplays();
                GUILayout.FlexibleSpace();
                GUILayout.Label("Remote hierarchy is only visible in remote mode", centerMessageStyle);
                if (GUILayout.Button("Set Remote Mode"))
                {
                    parentWindow.SetConnectionMode(InspectionConnection.RemotePlayer);
                }
                GUILayout.FlexibleSpace();
            }
        }