// Render item element "active by default" toggle
        private void RenderListItemActiveByDefault(List <UiLayoutPreset> list, UiLayoutPreset item, ItemType type)
        {
            if (type != ItemType.Popup)
            {
                // Active by default
                EditorGUI.BeginChangeCheck();
                item.ActiveByDefault = EditorGUILayout.Toggle("Active by default", item.ActiveByDefault);
                if (EditorGUI.EndChangeCheck())
                {
                    InternalUtilities.SetDirty(target);

                    if (type == ItemType.Screen)
                    {
                        OnItemSetActiveByDefault(list, item, item.ActiveByDefault);
                    }
                }

                // Skip animation
                if (item.ActiveByDefault)
                {
                    EditorGUI.BeginChangeCheck();
                    item.ActiveByDefaultImmediately = EditorGUILayout.Toggle("Skip animation", item.ActiveByDefaultImmediately);
                    if (EditorGUI.EndChangeCheck())
                    {
                        InternalUtilities.SetDirty(target);
                    }
                }
            }
        }
Example #2
0
        public void SetSelectedSignals(string[] input)
        {
            bool foundUnusedSignals = false;

            List <UiLayoutSettings.Signal> signals = InternalUtilities.GetSignals();

            _selectedSignals = new List <string>();

            if (input != null)
            {
                for (int i = 0; i < input.Length; i++)
                {
                    if (signals.Find(x => x.Id == input[i]) != null)
                    {
                        _selectedSignals.Add(input[i]);
                    }
                    else
                    {
                        foundUnusedSignals = true;
                    }
                }
            }

            if (foundUnusedSignals)
            {
                Callback();
            }
        }
Example #3
0
        public static void ButtonSignals(string caption, string description, string[] signals, Action <string[]> callback, float offsetLeft = 0)
        {
            string title = "";

            if (signals == null || signals.Length == 0)
            {
                title = "None";
            }
            else if (signals.Length == 1)
            {
                title = InternalUtilities.GetSignalName(signals[0]);
            }
            else
            {
                title = InternalUtilities.GetSignalName(signals[0]) + ", ...";
            }

            var rect = EditorGUILayout.GetControlRect(false, 16f);

            rect        = EditorGUI.PrefixLabel(rect, new GUIContent(caption));
            rect.x     -= offsetLeft;
            rect.width += offsetLeft;
            EditorGUI.BeginChangeCheck();
            GUI.Button(rect, new GUIContent(title));
            if (EditorGUI.EndChangeCheck())
            {
                InternalSignalsList.ShowWindow
                (
                    description,
                    signals,
                    callback
                );
            }
        }
 // Render item element container field
 private void RenderListItemContainer(List <UiLayoutPreset> list, UiLayoutPreset item, ItemType type)
 {
     EditorGUI.BeginChangeCheck();
     item.Container = (RectTransform)EditorGUILayout.ObjectField("Container", item.Container, typeof(RectTransform), allowSceneObjects: true);
     if (EditorGUI.EndChangeCheck())
     {
         InternalUtilities.SetDirty(target);
     }
 }
        // Render item element prefab field
        private void RenderListItemPrefab(List <UiLayoutPreset> list, UiLayoutPreset item, ItemType type)
        {
            GameObject      prefabOriginal = Resources.Load <GameObject>(item.PrefabPath);
            UiLayoutElement prefab         = prefabOriginal != null?prefabOriginal.GetComponent <UiLayoutElement>() : null;

            // Screen property
            EditorGUI.BeginChangeCheck();
            switch (type)
            {
            case ItemType.Popup:
                prefab = (UiLayoutElementPopup)EditorGUILayout.ObjectField("Prefab", prefab, typeof(UiLayoutElementPopup), allowSceneObjects: false);
                break;

            case ItemType.Panel:
                prefab = (UiLayoutElementPanel)EditorGUILayout.ObjectField("Prefab", prefab, typeof(UiLayoutElementPanel), allowSceneObjects: false);
                break;

            case ItemType.Screen:
                prefab = (UiLayoutElementScreen)EditorGUILayout.ObjectField("Prefab", prefab, typeof(UiLayoutElementScreen), allowSceneObjects: false);
                break;
            }

            if (EditorGUI.EndChangeCheck())
            {
                InternalUtilities.SetDirty(target);

                if (prefab != null)
                {
                    Match match = Regex.Match
                                  (
                        AssetDatabase.GetAssetPath(prefab.gameObject),
                        @"Resources/([A-Za-z0-9\-\/.]*).prefab",
                        RegexOptions.IgnoreCase
                                  );

                    item.PrefabPath = match.Success ? match.Groups[1].Value : string.Empty;

                    UiLayoutSettings.Signal signalShow = InternalUtilities.AddSignal("Ui." + GetItemPrefabName(item) + ".Show");
                    UiLayoutSettings.Signal signalHide = InternalUtilities.AddSignal("Ui." + GetItemPrefabName(item) + ".Hide");

                    item.SignalsShow = item.SignalsShow.Push(signalShow.Id);
                    item.SignalsHide = item.SignalsHide.Push(signalHide.Id);
                }
                else
                {
                    item.PrefabPath = string.Empty;
                    //item.SignalShow = string.Empty;
                    //item.SignalHide = string.Empty;
                }
            }
        }
        // Render item element foldout
        private UiLayoutPreset RenderListItemFoldOut(UiLayoutPreset item, UiLayoutPreset listItemSelected, ItemType type)
        {
            bool foldout = item == listItemSelected;

            string name = "Undefined";

            if (string.IsNullOrEmpty(item.PrefabPath))
            {
                switch (type)
                {
                case ItemType.Popup:
                    name = "Undefined popup preset";
                    break;

                case ItemType.Screen:
                    name = "Undefined screen preset";
                    break;

                case ItemType.Panel:
                    name = "Undefined panel preset";
                    break;
                }
            }
            else
            {
                switch (type)
                {
                case ItemType.Popup:
                    name = GetItemPrefabName(item);
                    break;

                case ItemType.Screen:
                case ItemType.Panel:
                    name = GetItemPrefabName(item) + (item.ActiveByDefault ? " (active by default)" : string.Empty);
                    break;
                }
            }

            EditorGUI.BeginChangeCheck();

            foldout = EditorGUILayout.Foldout(foldout, name, true);

            if (EditorGUI.EndChangeCheck())
            {
                InternalUtilities.SetDirty(target);

                listItemSelected = foldout ? item : null;
            }

            return(listItemSelected);
        }
Example #7
0
        private void Callback()
        {
            string[] output = new string[_selectedSignals.Count];
            List <UiLayoutSettings.Signal> signals = InternalUtilities.GetSignals();

            int n = 0;

            for (int i = 0; i < signals.Count; i++)
            {
                if (_selectedSignals.Contains(signals[i].Id))
                {
                    output[n] = signals[i].Id;
                    n++;
                }
            }

            OnChange.InvokeIfNotNull(output);
        }
Example #8
0
        private void OnEnable()
        {
            List <UiLayoutSettings.Signal> signals = InternalUtilities.GetSignals();

            _reorderableList = new ReorderableList(signals, typeof(UiLayoutSettings.Signal), true, false, true, true);

            _reorderableList.onReorderCallback = (ReorderableList target) =>
            {
                signals = target.list as List <UiLayoutSettings.Signal>;
            };

            _reorderableList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                rect.y += 2;

                signals[index].Name = EditorGUI.TextField
                                      (
                    new Rect(rect.x + 20, rect.y, rect.width - 30, EditorGUIUtility.singleLineHeight),
                    signals[index].Name
                                      );

                bool isCheckedOld = _selectedSignals.Contains(signals[index].Id);
                bool isCheckedNew = EditorGUI.Toggle
                                    (
                    new Rect(rect.x, rect.y, 20, EditorGUIUtility.singleLineHeight),
                    isCheckedOld
                                    );

                if (isCheckedOld != isCheckedNew)
                {
                    if (isCheckedNew)
                    {
                        SignalAdd(signals[index].Id);
                    }
                    else
                    {
                        SignalRemove(signals[index].Id);
                    }
                }
            };

            _reorderableList.onAddCallback = (ReorderableList list) =>
            {
                InternalUtilities.AddSignal();
            };

            _reorderableList.onRemoveCallback = (ReorderableList list) =>
            {
                if (signals[list.index].Locked)
                {
                    EditorUtility.DisplayDialog
                    (
                        "Warning!",
                        "You can not delete this signal because it is Locked.",
                        "Ok"
                    );

                    return;
                }

                if
                (
                    EditorUtility.DisplayDialog
                    (
                        "Warning!",
                        "Are you sure you want to delete signal \"" + signals[list.index].Name + "\"?", "Yes", "No"
                    )
                )
                {
                    ReorderableList.defaultBehaviours.DoRemoveButton(list);
                }
            };
        }
        private UiLayoutPreset RenderList(List <UiLayoutPreset> list, UiLayoutPreset listItemSelected, ItemType type)
        {
            UiLayoutSettings layoutSettings = target as UiLayoutSettings;

            GUILayout.BeginVertical(new GUIStyle(GUI.skin.GetStyle("HelpBox")));

            if (list.Count == 0)
            {
                switch (type)
                {
                case ItemType.Screen:
                    EditorGUILayout.HelpBox("\nScreens is a basic layout elements like Main Menu, Choosing of level, Settings, etc. Only one slide can be active at the same time so if new slide shown then the old one will be automatically hidden. \n", MessageType.Info);
                    break;

                case ItemType.Panel:
                    EditorGUILayout.HelpBox("\nPanels is an additional layout elements like header, footer, etc. Panels can be shown and hided separatelly at any time. \n", MessageType.Info);
                    break;

                case ItemType.Popup:
                    EditorGUILayout.HelpBox("\nPopups is a overlaing layout elements like alerts, confirms and etc. Unlimited amount of same popups can be shown at the same time. After popup is hidden it's instance will be destroyed. \n", MessageType.Info);
                    break;
                }
            }

            // Items
            for (int i = 0; i < list.Count; i++)
            {
                listItemSelected = RenderListItem(list, list[i], i, listItemSelected, type);
            }

            // Buttons
            GUIStyle buttonsStyle = new GUIStyle();

            buttonsStyle.margin.left = -5;

            GUIStyle buttonStyle = new GUIStyle(GUI.skin.GetStyle("HelpBox"));

            buttonStyle.alignment    = TextAnchor.MiddleCenter;
            buttonStyle.stretchWidth = false;
            buttonStyle.fixedWidth   = 100;
            buttonStyle.fixedHeight  = 26;

            GUILayout.BeginHorizontal(buttonsStyle);

            EditorGUI.BeginChangeCheck();
            GUILayout.Button("ADD", buttonStyle);

            if (EditorGUI.EndChangeCheck())
            {
                InternalUtilities.SetDirty(target);

                UiLayoutPreset itemNew = new UiLayoutPreset();

                itemNew.Container = layoutSettings.DefaultContainer;

                list.Add(itemNew);
                listItemSelected = itemNew;
            }

            if (listItemSelected != null)
            {
                EditorGUI.BeginChangeCheck();
                GUILayout.Button("REMOVE", buttonStyle);
                if (EditorGUI.EndChangeCheck())
                {
                    InternalUtilities.SetDirty(target);

                    list.Remove(listItemSelected);
                    listItemSelected = null;
                }
            }

            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            return(listItemSelected);
        }