private void AddActiveInstaller(ZenjectServiceInstaller installer)
        {
            this.installersProperty.arraySize += 1;
            var serviceInstallerElementProperty = this.installersProperty.GetArrayElementAtIndex(this.installersProperty.arraySize - 1);

            serviceInstallerElementProperty.objectReferenceValue = installer;
        }
        private void DestroyServiceInstaller(ZenjectServiceInstaller installer)
        {
            Undo.SetCurrentGroupName("Remove Installer");
            this.RemoveActiveInstaller(installer);
            this.serializedObject.ApplyModifiedProperties();
            Undo.DestroyObjectImmediate(installer);

            this.Refresh();
        }
 private void RemoveActiveInstaller(ZenjectServiceInstaller installer)
 {
     for (int i = 0; i < this.installersProperty.arraySize; ++i)
     {
         var element = this.installersProperty.GetArrayElementAtIndex(i);
         if (element.objectReferenceValue == null || element.objectReferenceValue == installer)
         {
             this.installersProperty.DeleteArrayElementAtIndex(i);
             --i;
         }
     }
 }
        private ServiceEntry CreateServiceEntry(IServiceDescriptor service)
        {
            var entry = new ServiceEntry();

            entry.Title      = service.Title;
            entry.Descriptor = service;
            entry.AvailableInstallerTypes = ZenjectServiceInstaller.DiscoverInstallerTypes(service);

            entry.InheritedInstallers = this.targetConfigurationObject.InheritedInstallers
                                        .Where(x => x.TargetService == service)
                                        .ToArray();

            this.targetInstallerComponents.TryGetValue(service, out entry.Installer);
            entry.InstallerActive           = entry.Installer != null && this.targetActiveInstallers.Contains(entry.Installer);
            entry.ClosestInheritedInstaller = this.targetConfigurationObject.FindClosestInheritedInstallerForService(service);

            entry.TargetInstaller = (entry.ClosestInheritedInstaller != null && !entry.InstallerActive)
                ? entry.ClosestInheritedInstaller
                : entry.Installer;

            if (entry.TargetInstaller != null)
            {
                entry.TargetInstallerTitle = NicifyNamespaceQualifiedInstallerTitle(entry.TargetInstaller.GetType());
            }

            entry.DominantInstaller = this.targetConfigurationObject.FindDominantInstallerForService(service);

            if (entry.TargetInstaller != null)
            {
                string targetInstallerHint = NicifyInstallerTitle(entry.TargetInstaller.GetType());
                if (targetInstallerHint.StartsWith(entry.Title))
                {
                    targetInstallerHint = targetInstallerHint.Substring(entry.Title.Length).TrimStart(' ', '-');
                }
                if (!string.IsNullOrEmpty(targetInstallerHint))
                {
                    if (EditorGUIUtility.isProSkin)
                    {
                        entry.Title += " <color=white>(" + targetInstallerHint + ")</color>";
                    }
                    else
                    {
                        entry.Title += " <color=grey>(" + targetInstallerHint + ")</color>";
                    }
                }
            }

            return(entry);
        }
        private void ShowServiceInstallerContextMenu(ZenjectServiceInstaller installer, bool active)
        {
            var menu = new EditorMenu();

            menu.AddCommand("Reset to Default Values")
            .Enabled(active)
            .Action(() => {
                var serviceInstallerType = installer.GetType();

                Undo.RecordObject(installer, "Reset to Default Values");
                var clone       = ScriptableObject.CreateInstance(serviceInstallerType);
                clone.hideFlags = HideFlags.HideAndDontSave;
                EditorUtility.CopySerialized(clone, installer);
                DestroyImmediate(clone);
            });

            menu.AddSeparator();

            menu.AddCommand("Copy Values")
            .Action(() => {
                s_ClipboardReference = installer;
            });
            menu.AddCommand("Paste Values")
            .Enabled(active && s_ClipboardReference != null && s_ClipboardReference != installer && s_ClipboardReference.GetType().IsAssignableFrom(installer.GetType()))
            .Action(() => {
                Undo.RecordObject(installer, "Paste Values");
                EditorUtility.CopySerialized(s_ClipboardReference, installer);
            });

            menu.AddSeparator();

            menu.AddCommand("Edit Script")
            .Action(() => {
                var script    = MonoScript.FromScriptableObject(installer);
                var assetPath = AssetDatabase.GetAssetPath(script);
                if (!string.IsNullOrEmpty(assetPath))
                {
                    var filePath = Path.Combine(Directory.GetCurrentDirectory(), assetPath);
                    InternalEditorUtility.OpenFileAtLineExternal(filePath, 0);
                }
            });

            menu.ShowAsContext();
        }