示例#1
0
        void DrawServiceElement(IHostingService svc, List <IHostingService> svcList)
        {
            bool   isDirty = false;
            string newName = EditorGUILayout.DelayedTextField("Service Name", svc.DescriptiveName);

            if (svcList.Find(s => s.DescriptiveName == newName) == default(IHostingService))
            {
                svc.DescriptiveName = newName;
                m_ServicesList.Reload();
                isDirty = true;
            }

            var typeAndId = string.Format("{0} ({1})", svc.GetType().Name, svc.InstanceId.ToString());

            EditorGUILayout.LabelField("Service Type (ID)", typeAndId, GUILayout.MinWidth(225f));

            // Allow service to provide additional GUI configuration elements
            svc.OnGUI();

            var newIsServiceEnabled = EditorGUILayout.Toggle("Enable", svc.IsHostingServiceRunning);

            if (newIsServiceEnabled != svc.IsHostingServiceRunning)
            {
                if (newIsServiceEnabled)
                {
                    svc.StartHostingService();
                }
                else
                {
                    svc.StopHostingService();
                }
                isDirty = true;
            }

            EditorGUILayout.Space();

            using (new EditorGUI.DisabledScope(!svc.IsHostingServiceRunning))
            {
                GUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Hosting Service Variables");

                var manager = m_Settings.HostingServicesManager;
                if (GUILayout.Button("Refresh", GUILayout.ExpandWidth(false)))
                {
                    manager.RefreshGlobalProfileVariables();
                }

                GUILayout.EndHorizontal();

                DrawProfileVarTable(svc);
            }

            if (isDirty && m_Settings != null)
            {
                m_Settings.SetDirty(AddressableAssetSettings.ModificationEvent.HostingServicesManagerModified, this, false, true);
            }
        }
        /// <summary>
        /// Stops the given <see cref="IHostingService"/>, unregisters callbacks, and removes it from management. This
        /// function does nothing if the service is not being managed by this <see cref="HostingServicesManager"/>
        /// </summary>
        /// <param name="svc"></param>
        public void RemoveHostingService(IHostingService svc)
        {
            if (!m_HostingServiceInfoMap.ContainsKey(svc))
            {
                return;
            }

            svc.StopHostingService();
            m_Settings.profileSettings.UnregisterProfileStringEvaluationFunc(svc.EvaluateProfileString);
            m_HostingServiceInfoMap.Remove(svc);
            m_Settings.SetDirty(AddressableAssetSettings.ModificationEvent.HostingServicesManagerModified, this, true, true);
        }
        void DrawServiceElement(IHostingService svc)
        {
            EditorGUILayout.BeginHorizontal();
            {
                svc.DescriptiveName = EditorGUILayout.DelayedTextField("Service EventName", svc.DescriptiveName);

                var newIsServiceEnabled = GUILayout.Toggle(svc.IsHostingServiceRunning, "Enable Service", "Button", GUILayout.MaxWidth(150f));

                if (GUILayout.Button("Remove...", GUILayout.MaxWidth(75f)))
                {
                    if (EditorUtility.DisplayDialog("Remove Service", "Are you sure?", "Ok", "Cancel"))
                    {
                        m_RemovalQueue.Add(svc);
                    }
                }
                else if (newIsServiceEnabled != svc.IsHostingServiceRunning)
                {
                    if (newIsServiceEnabled)
                    {
                        svc.StartHostingService();
                    }
                    else
                    {
                        svc.StopHostingService();
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            var typeAndId = string.Format("{0} ({1})", svc.GetType().Name, svc.InstanceId.ToString());

            EditorGUILayout.LabelField("Service Type (ID)", typeAndId, GUILayout.MinWidth(225f));

            EditorGUILayout.Space();

            using (new EditorGUI.DisabledGroupScope(!svc.IsHostingServiceRunning))
            {
                // Allow service to provide additional GUI configuration elements
                svc.OnGUI();

                EditorGUILayout.Space();

                DrawProfileVarTable(svc, svc.ProfileVariables);
            }
        }