// 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;
                }
            }
        }
Ejemplo n.º 2
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);
                }
            };
        }