Пример #1
0
    public override void OnInspectorGUI()
    {
        var state = target as MonoBehaviourState;

        K10EditorGUIUtils.Semaphore(state.IsAlive, "IsAlive");
        K10EditorGUIUtils.Semaphore(state.IsActive, "IsActive");
    }
Пример #2
0
    public static bool DrawSemaphoresOnGUI <T, K>(object obj, float sizePerElements = 100) where T : class where K : IValueStateObserver <bool>
    {
        var t     = obj as T;
        var props = typeof(T).GetProperties();

        bool initialLabel = false;

        int items       = 1;
        int itemsPerRow = (int)(EditorGUIUtility.currentViewWidth / sizePerElements);

        GUILayout.BeginHorizontal();
        for (int i = 0; i < props.Length; i++)
        {
            var prop = props[i];
            if (prop.PropertyType == typeof(K))
            {
                if (!initialLabel)
                {
                    initialLabel = true;
                    GUILayout.Label(typeof(K).Name + "(s)", K10GuiStyles.boldStyle);
                }
                var name = prop.Name;

                try
                {
                    var semaphore = (K)prop.GetValue(t, null);
                    K10EditorGUIUtils.Semaphore(semaphore, name);
                }
                catch (System.Exception ex)
                {
                    GUILayout.BeginHorizontal();
                    K10.EditorGUIExtention.IconButton.Layout("error", 18, 'X', "", Color.red);
                    GUILayout.Label($"{name}({ex.Message})", K10GuiStyles.smallStyle);
                    GUILayout.EndHorizontal();
                }
                items++;

                if (items >= itemsPerRow)
                {
                    items = 0;
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                }
            }
        }
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        return(initialLabel);
    }