using hedCommon.extension.editor; using hedCommon.extension.runtime; using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEngine; using static UnityEditor.EditorGUILayout; namespace extUnityComponents { public static class ExtComponentAddition { public static void AddComponentsExtension(string nameExtension, GameObject[] locationExtension) where T : Component { for (int i = 0; i < locationExtension.Length; i++) { AddComponentsExtension(nameExtension, locationExtension[i], out bool justCreated, out bool justDestroyed); } } /// /// return true if the component is present /// /// /// /// /// true if component is present public static bool AddComponentsExtension(string nameExtension, GameObject locationExtension, out bool justCreated, out bool justDestroyed) where T : Component { T current = locationExtension.GetComponent(); justCreated = false; justDestroyed = false; bool canActiveInternalPropertie = current != null; using (HorizontalScope horizontalScope = new HorizontalScope()) { GUI.changed = false; bool toggle = GUILayout.Toggle(canActiveInternalPropertie, nameExtension, EditorStyles.miniButton); if (canActiveInternalPropertie) { if (ExtGUIButtons.ButtonAskBefore("x", Color.white, "Warning", "Remove this components ?", EditorStyles.miniButton, GUILayout.Width(20))) { GameObject.DestroyImmediate(current); justDestroyed = true; return (true); } } else if (GUI.changed) { current = locationExtension.GetOrAddComponent(); canActiveInternalPropertie = current != null; justCreated = canActiveInternalPropertie; } } return (canActiveInternalPropertie); } } }