Example #1
0
        private void OnGUI()
        {
            var count = GrpcEnvironment.GetCurrentChannels(connectionInfos);

            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
            {
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("gRPC Channels(" + count + ")", EditorStyles.boldLabel);

                for (int i = 0; i < count; i++)
                {
                    var channel = connectionInfos[i];

                    using (new EditorGUILayout.HorizontalScope())
                    {
                        EditorGUILayout.LabelField(channel.Target);
                        if (GUILayout.Button("Shutdown"))
                        {
                            channel.ShutdownAsync().Subscribe();
                        }
                    }

                    EditorGUI.indentLevel += 1;
                    {
                        using (new EditorGUILayout.HorizontalScope())
                        {
                            EditorGUILayout.PrefixLabel("State");
                            EditorGUILayout.LabelField(ChannelStateToString(channel.State));
                        }
                    }

                    lock (subscriptions)
                    {
                        foreach (var item in subscriptions)
                        {
                            var c = item.Value.Key.Target;
                            if (channel == c)
                            {
                                EditorGUILayout.LabelField(item.Value.Value);
                            }
                        }
                    }

                    EditorGUI.indentLevel -= 1;
                }

                lock (subscriptions)
                {
                    foreach (var item in subscriptions)
                    {
                        var c = item.Value.Key.Target;
                        if (c != null)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var channel = connectionInfos[i];
                                //channel
                                if (c == channel)
                                {
                                    goto next;
                                }
                            }

                            unregistredSubscriptions.Add(item.Value.Value);
                            continue;
                        }

next:
                        continue;
                    }
                }

                if (unregistredSubscriptions.Count != 0)
                {
                    EditorGUILayout.Space();
                    EditorGUILayout.LabelField("Unfinished Subscriptions", EditorStyles.boldLabel);

                    for (int i = 0; i < unregistredSubscriptions.Count; i++)
                    {
                        var m = unregistredSubscriptions[i];
                        EditorGUILayout.LabelField(m);
                    }

                    unregistredSubscriptions.Clear();
                }
            }
            EditorGUILayout.EndScrollView();

            for (int i = 0; i < connectionInfos.Count; i++)
            {
                connectionInfos[i] = null; // null clear
            }
        }