Exemplo n.º 1
0
        async Task RefreshVenueSelector(GroupID groupIdToSelect = null, VenueID venueIdToSelect = null)
        {
            selector.Clear();
            selector.Add(new IMGUIContainer(() => EditorGUILayout.HelpBox("会場情報を取得しています...", MessageType.None)));

            VisualElement venuePicker = null;

            void RecreateVenuePicker(GroupID groupId)
            {
                if (venuePicker != null)
                {
                    selector.Remove(venuePicker);
                }

                venuePicker = CreateVenuePicker(groupId, allVenues[groupId], venueIdToSelect);
                selector.Add(venuePicker);
            }

            try
            {
                var groups = await APIServiceClient.GetGroups.Call(Empty.Value, userInfo.VerifiedToken, 3);

                foreach (var group in groups.List)
                {
                    allVenues[group.Id] = await APIServiceClient.GetGroupVenues.Call(group.Id, userInfo.VerifiedToken, 3);
                }

                selector.Clear();
                if (groups.List.Count == 0)
                {
                    selector.Add(new IMGUIContainer(() => EditorGUILayout.HelpBox("clusterにてチーム登録をお願いいたします", MessageType.Warning)));
                }
                else
                {
                    var teamMenu = new PopupField <Group>("所属チーム", groups.List, 0, group => group.Name, group => group.Name);
                    teamMenu.RegisterValueChangedCallback(ev => RecreateVenuePicker(ev.newValue.Id));
                    selector.Add(teamMenu);

                    var groupToSelect = groups.List.Find(group => group.Id == groupIdToSelect) ?? groups.List[0];
                    teamMenu.SetValueWithoutNotify(groupToSelect);

                    RecreateVenuePicker(groupToSelect.Id);
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                selector.Clear();
                selector.Add(new IMGUIContainer(() => EditorGUILayout.HelpBox($"会場情報の取得に失敗しました {e.Message}", MessageType.Error)));
            }
        }
Exemplo n.º 2
0
        private void BuildMenuSelection(UIController controller)
        {
            VRCExpressionsMenu menu = controller.ExpressionInfo.AvatarDescriptor.expressionsMenu;

            if (menu == null)
            {
                ErrorValidate();
                return;
            }

            string PrettifyName(VRCExpressionsMenu arg)
            {
                if (arg == null)
                {
                    return("None");
                }
                return(arg.name);
            }

            var menus = menu.GetMenusRecursively().ToList();

            menus.Add(null);
            var menuSelector = new PopupField <VRCExpressionsMenu>(menus, menu, PrettifyName, PrettifyName)
            {
                label = "Expression menu",
            };

            controller.ContentFrame.Replace(_menuSelectionPlaceholder, menuSelector);

            menuSelector.RegisterValueChangedCallback(e => SetMenu(e.newValue));
            SetMenu(controller.ExpressionInfo.Menu);

            void SetMenu(VRCExpressionsMenu obj)
            {
                menuSelector.SetValueWithoutNotify(obj);
                if (controller.ExpressionInfo.Menu != obj)
                {
                    controller.ExpressionInfo.Menu = obj;
                }
                ErrorValidate();
            }
        }
Exemplo n.º 3
0
    // fill listElements with all resources for the type in fileType
    void InitializeList()
    {
        listElements.Clear();
        bool classFilterNeedsReset   = false;
        DummyResourceManager manager = new DummyResourceManager(resourceType);

        if (manager.GetResourceList().Count == 0)
        {
            manager.LoadResourceList();
        }
        List <ResourceProfile> namesList = new List <ResourceProfile>();

        classNames.Clear();
        if (editedProperty == null)
        {
            classNames.Add(typeof(ResourceProfile));
        }
        else if (typeFilter.value == typeof(ResourceProfile))
        {
            classFilterNeedsReset = true;
        }
        foreach (ResourceProfile item in manager.GetResourceList())
        {
            if (!classNames.Contains(item.GetType()))
            {
                classNames.Add(item.GetType());
            }
            if (MatchesFilter(item))
            {
                namesList.Add(item);
            }
        }
        namesList.Sort((a, b) => a.ResourceName.CompareTo(b.ResourceName));
        listElements.AddRange(namesList);
        if (classFilterNeedsReset && classNames.Contains(resourceType))
        {
            typeFilter.SetValueWithoutNotify(resourceType);
        }
    }
        private void SetupMaterialSlotPicker(UIController controller)
        {
            var holder = controller.ContentFrame.Q("material-slot");

            holder.Clear();

            if (_renderer == null)
            {
                return;
            }

            var materials = _renderer.sharedMaterials.ToList();
            var slots     = new List <int>();

            for (var i = 0; i < materials.Count; i++)
            {
                slots.Add(i);
            }

            string PrettifyName(int arg) => $"{arg} ({materials[arg].name})";

            var selector = new PopupField <int>(slots, 0, PrettifyName, PrettifyName)
            {
                label = "Material slot",
            };

            selector.RegisterValueChangedCallback(e => SetMaterial(e.newValue));

            void SetMaterial(int obj)
            {
                selector.SetValueWithoutNotify(obj);
                _materialSlot = obj;
                ErrorValidate();
            }

            SetMaterial(_materialSlot);
            holder.Add(selector);
        }
Exemplo n.º 5
0
        VisualElement CreateVenuePicker(GroupID groupId, Venues venues, VenueID venueIdToSelect = null)
        {
            var container = new VisualElement()
            {
                style = { flexDirection = FlexDirection.Row }
            };

            if (venues.List.Count != 0)
            {
                var dupedVenueNames = new HashSet <string>(
                    venues.List.GroupBy(venue => venue.Name, venue => venue.VenueId, (name, ids) => ids.Count() >= 2 ? name : "").Where(name => name != ""));
                string GetUniqueVenueName(Core.Editor.Venue.Json.Venue venue)
                {
                    return(dupedVenueNames.Contains(venue.Name) ? $"{venue.Name} ({venue.VenueId.Value})" : venue.Name);
                }

                var venueMenu = new PopupField <Core.Editor.Venue.Json.Venue>("会場一覧", venues.List, 0, GetUniqueVenueName, GetUniqueVenueName);
                venueMenu.style.flexGrow = 1f;
                venueMenu.RegisterValueChangedCallback(ev => { reactiveCurrentVenue.Val = ev.newValue; });
                container.Add(venueMenu);

                var venueToSelect = venues.List.Find(venue => venue.VenueId == venueIdToSelect) ?? venues.List[0];
                venueMenu.SetValueWithoutNotify(venueToSelect);

                reactiveCurrentVenue.Val = venueToSelect;
            }
            else
            {
                reactiveCurrentVenue.Val = null;
            }

            container.Add(new Button(() => CreateNewVenue(groupId))
            {
                text = "新規会場追加"
            });
            return(container);
        }
Exemplo n.º 6
0
 static void SetCoppaFieldValue(COPPACompliance coppaCompliance, PopupField <String> coppaField)
 {
     coppaField.SetValueWithoutNotify(GetFieldValueForCompliancy(coppaCompliance));
 }
Exemplo n.º 7
0
 public void Update(InspectorContext <BuildTarget> proxy)
 {
     m_TargetPopup.SetValueWithoutNotify(proxy.Data);
 }
Exemplo n.º 8
0
 protected virtual void RefreshChildFields()
 {
     m_TextField.SetValueWithoutNotify(GetTextFromValue());
     m_OptionsPopup.SetValueWithoutNotify(GetOptionFromValue());
 }
Exemplo n.º 9
0
        /// <summary>
        /// To attach a project an existing project, we must collect all orgs the current user is a member of.
        /// In addition the current user may be a guest of a specific project, in which case we must also look at
        /// all projects to find organizations.
        /// </summary>
        /// <param name="organizationField"></param>
        /// <param name="projectIdField"></param>
        void LoadReuseOrganizationField(PopupField <string> organizationField, PopupField <string> projectIdField = null)
        {
            ServicesConfiguration.instance.RequestCurrentUserApiUrl(currentUserApiUrl =>
            {
                var getOrganizationsRequest = new UnityWebRequest(currentUserApiUrl + "?include=orgs,projects",
                                                                  UnityWebRequest.kHttpVerbGET)
                {
                    downloadHandler = new DownloadHandlerBuffer()
                };
                getOrganizationsRequest.suppressErrorsToConsole = true;
                getOrganizationsRequest.SetRequestHeader("AUTHORIZATION", $"Bearer {UnityConnect.instance.GetUserInfo().accessToken}");
                var operation        = getOrganizationsRequest.SendWebRequest();
                operation.completed += op =>
                {
                    try
                    {
                        if (ServicesUtils.IsUnityWebRequestReadyForJsonExtract(getOrganizationsRequest))
                        {
                            var jsonParser = new JSONParser(getOrganizationsRequest.downloadHandler.text);
                            var json       = jsonParser.Parse();
                            try
                            {
                                m_OrgIdByName.Clear();
                                var sortedOrganizationNames = new List <string>();
                                foreach (var rawOrg in json.AsDict()[k_JsonOrgsNodeName].AsList())
                                {
                                    var org = rawOrg.AsDict();
                                    if (k_AnyRoleFilter.Contains(org[k_JsonRoleNodeName].AsString()))
                                    {
                                        sortedOrganizationNames.Add(org[k_JsonNameNodeName].AsString());
                                        m_OrgIdByName.Add(org[k_JsonNameNodeName].AsString(), org[k_JsonIdNodeName].AsString());
                                    }
                                }

                                foreach (var rawProject in json.AsDict()[k_JsonProjectsNodeName].AsList())
                                {
                                    var project = rawProject.AsDict();
                                    if (!project[k_JsonArchivedNodeName].AsBool() &&
                                        !sortedOrganizationNames.Contains(project[k_JsonOrgNameNodeName].AsString()))
                                    {
                                        sortedOrganizationNames.Add(project[k_JsonOrgNameNodeName].AsString());
                                        m_OrgIdByName.Add(project[k_JsonOrgNameNodeName].AsString(), project[k_JsonOrgIdNodeName].AsString());
                                    }
                                }

                                sortedOrganizationNames.Sort();
                                var popUpChoices = new List <string> {
                                    L10n.Tr(k_SelectOrganizationText)
                                };
                                organizationField.SetEnabled(true);
                                popUpChoices.AddRange(sortedOrganizationNames);
                                organizationField.choices = popUpChoices;
                                organizationField.SetValueWithoutNotify(organizationField.choices[0]);
                                if (projectIdField != null)
                                {
                                    projectIdField.choices = new List <string> {
                                        L10n.Tr(k_SelectProjectText)
                                    };
                                    projectIdField.SetValueWithoutNotify(L10n.Tr(k_SelectProjectText));
                                    projectIdField.SetEnabled(false);
                                }
                            }
                            catch (Exception ex)
                            {
                                if (exceptionCallback != null)
                                {
                                    exceptionCallback.Invoke(ex);
                                }
                                else
                                {
                                    //If there is no exception callback, we have to at least log it
                                    Debug.LogException(ex);
                                }
                            }
                        }
                        else
                        {
                            var ex = new UnityConnectWebRequestException(L10n.Tr(k_CouldNotObtainOrganizationsMessage))
                            {
                                error           = getOrganizationsRequest.error,
                                method          = getOrganizationsRequest.method,
                                timeout         = getOrganizationsRequest.timeout,
                                url             = getOrganizationsRequest.url,
                                responseHeaders = getOrganizationsRequest.GetResponseHeaders(),
                                responseCode    = getOrganizationsRequest.responseCode,
                                isHttpError     = (getOrganizationsRequest.result == UnityWebRequest.Result.ProtocolError),
                                isNetworkError  = (getOrganizationsRequest.result == UnityWebRequest.Result.ConnectionError),
                            };
                            if (exceptionCallback != null)
                            {
                                exceptionCallback.Invoke(ex);
                            }
                            else
                            {
                                //If there is no exception callback, we have to at least log it
                                Debug.LogException(ex);
                            }
                        }
                    }
                    finally
                    {
                        getOrganizationsRequest.Dispose();
                    }
                };
            });
        }
        static VisualElement CreateExpressionPropertyGUI(SerializedProperty property,
                                                         List <GimmickTarget> targetChoices,
                                                         Func <GimmickTarget, string> formatTarget,
                                                         int depth = 0)
        {
            Assert.AreEqual(property.type, nameof(Expression));
            var container = new VisualElement
            {
                style = { marginLeft = new StyleLength(5) }
            };

            var valueProperty = property.FindPropertyRelative("value");
            var valueField    = CreateValuePropertyGUI(valueProperty, targetChoices, formatTarget);

            container.Add(valueField);

            if (depth > 0)
            {
                return(container);
            }

            valueField.style.marginLeft = new StyleLength(5);

            var typeProperty = property.FindPropertyRelative("type");
            var currentType  = (ExpressionType)typeProperty.intValue;
            var operatorExpressionProperty = property.FindPropertyRelative("operatorExpression");
            var operatorProperty           = operatorExpressionProperty.FindPropertyRelative("operator");
            var currentOperator            = (Operator)operatorProperty.intValue;
            var operandsProperty           = operatorExpressionProperty.FindPropertyRelative("operands");

            var operandsContainer = new VisualElement();

            container.Add(operandsContainer);

            const int ExpressionTypeValue      = -1;
            var       typeOperatorChoices      = Enum.GetValues(typeof(Operator)).Cast <int>().Prepend(ExpressionTypeValue).ToList();
            var       typeOperatorDefaultIndex = typeOperatorChoices.IndexOf(currentType == ExpressionType.Value ? ExpressionTypeValue : (int)currentOperator);
            var       typeOperatorField        = new PopupField <int>(typeOperatorChoices, typeOperatorDefaultIndex, TypeOperatorFormat, TypeOperatorFormat);

            string TypeOperatorFormat(int value)
            {
                return(value == ExpressionTypeValue ? "=" : $"= {(Operator) value}");
            }

            typeOperatorField.RegisterValueChangedCallback(e =>
            {
                var type = e.newValue == ExpressionTypeValue ? ExpressionType.Value : ExpressionType.OperatorExpression;

                if (typeProperty.intValue != (int)type)
                {
                    typeProperty.intValue = (int)type;
                    typeProperty.serializedObject.ApplyModifiedProperties();

                    var operandsFirstProperty = operandsProperty.GetArrayElementAtIndex(0);
                    switch (type)
                    {
                    case ExpressionType.Value:
                        if (operandsFirstProperty != null)
                        {
                            CopyValueProperty(operandsFirstProperty.FindPropertyRelative("value"), valueProperty);
                        }
                        break;

                    case ExpressionType.OperatorExpression:
                        if (operandsFirstProperty == null)
                        {
                            operandsProperty.InsertArrayElementAtIndex(0);
                        }
                        CopyValueProperty(valueProperty, operandsFirstProperty.FindPropertyRelative("value"));
                        break;
                    }
#if !UNITY_2019_3_OR_NEWER
                    OnTypeChanged(type);
#endif
                }

                if (type == ExpressionType.OperatorExpression && operatorProperty.intValue != e.newValue)
                {
                    operatorProperty.intValue = e.newValue;
                    operatorProperty.serializedObject.ApplyModifiedProperties();
#if !UNITY_2019_3_OR_NEWER
                    OnOperatorChanged((Operator)e.newValue);
#endif
                }
            });
            container.Insert(0, typeOperatorField);

            var typeField = EnumField.CreateAsStringPopupField <ExpressionType>(typeProperty, newValue =>
            {
                typeOperatorField.SetValueWithoutNotify(newValue == ExpressionType.Value ? ExpressionTypeValue : operatorProperty.intValue);
                OnTypeChanged(newValue);
            });
            typeField.style.display = new StyleEnum <DisplayStyle>(DisplayStyle.None);
            container.Add(typeField);

            var operatorField = EnumField.CreateAsStringPopupField <Operator>(operatorProperty, newValue =>
            {
                typeOperatorField.SetValueWithoutNotify(typeProperty.intValue == (int)ExpressionType.Value ? ExpressionTypeValue : (int)newValue);
                OnOperatorChanged(newValue);
            });
            operatorField.style.display = new StyleEnum <DisplayStyle>(DisplayStyle.None);
            container.Add(operatorField);

            void OnOperatorChanged(Operator @operator)
            {
                operandsContainer.Unbind();
                operandsContainer.Clear();

                var requiredLength = @operator.GetRequiredLength();

                if (requiredLength != operandsProperty.arraySize)
                {
                    operandsProperty.arraySize = requiredLength;
                    operandsProperty.serializedObject.ApplyModifiedProperties();
                }

                var operandsField = CreateOperandsPropertyGUI(operandsProperty, targetChoices, formatTarget, depth);

                operandsContainer.Add(operandsField);
            }

            OnOperatorChanged(currentOperator);

            void OnTypeChanged(ExpressionType type)
            {
                valueField.SetVisibility(type == ExpressionType.Value);
                operandsContainer.SetVisibility(type == ExpressionType.OperatorExpression);
            }

            OnTypeChanged(currentType);

            return(container);
        }
Exemplo n.º 11
0
        private void SetupListItem(VisualElement listItem)
        {
            var objectField = listItem.Q <ObjectField>("target-object");

            objectField.RegisterValueChangedCallback(e =>
            {
                SetupListMaterialSlotPicker();
                ErrorValidate();
            });
            objectField.allowSceneObjects = true;
            var type = listItem.Q <EnumField>(_targetTypeName);

            var materialField = listItem.Q <ObjectField>(_targetMaterialName);

            materialField.objectType = typeof(Material);
            materialField.RegisterValueChangedCallback(e => ErrorValidate());

            type.RegisterValueChangedCallback(e =>
            {
                SetupListParameterField();
                ShowTypeFields(e.newValue);
            });

            ShowTypeFields(type.value);

            void SetupListParameterField()
            {
                var pickerHolder = listItem.Q("parameters-picker");
                var valueHolder  = listItem.Q("parameters-value");

                pickerHolder.Clear();

                VRCExpressionParameters.Parameter[] parameters = _controller.ExpressionInfo.AvatarDescriptor.expressionParameters.parameters;
                var slots = new List <VRCExpressionParameters.Parameter>();

                slots.AddRange(parameters);

                string PrettifyName(VRCExpressionParameters.Parameter arg) => $"{arg.name} ({arg.valueType})";

                var selector = new PopupField <VRCExpressionParameters.Parameter>(slots, 0, PrettifyName, PrettifyName)
                {
                    name  = _vrcParameterName,
                    label = "VRC Parameter"
                };

                selector.RegisterValueChangedCallback(e => SetValue(e.newValue));

                void SetValue(VRCExpressionParameters.Parameter obj)
                {
                    selector.SetValueWithoutNotify(obj);
                    valueHolder.Clear();

                    VisualElement valueElement;

                    switch (obj.valueType)
                    {
                    case VRCExpressionParameters.ValueType.Int:
                        valueElement = new IntegerField {
                            label = "Toggled value"
                        };
                        break;

                    case VRCExpressionParameters.ValueType.Float:
                        valueElement = new FloatField {
                            label = "Toggled value"
                        };
                        break;

                    case VRCExpressionParameters.ValueType.Bool:
                        valueElement = new Toggle {
                            label = "Toggled state"
                        };
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    valueElement.name = _parameterValueImplementationName;
                    valueHolder.Add(valueElement);
                    ErrorValidate();
                }

                SetValue(selector.value);
                pickerHolder.Add(selector);
            }

            void SetupListMaterialSlotPicker()
            {
                var holder = listItem.Q("material-slot");

                holder.Clear();

                if (!(objectField.value is Renderer renderer))
                {
                    return;
                }

                var materials = renderer.sharedMaterials.ToList();
                var slots     = new List <int>();

                for (var i = 0; i < materials.Count; i++)
                {
                    slots.Add(i);
                }

                string PrettifyName(int arg) => $"{arg} ({materials[arg].name})";

                var selector = new PopupField <int>(slots, 0, PrettifyName, PrettifyName)
                {
                    tooltip = "Material slot",
                };

                selector.RegisterValueChangedCallback(e => SetMaterial(e.newValue));

                void SetMaterial(int obj)
                {
                    selector.SetValueWithoutNotify(obj);
                    ErrorValidate();
                }

                SetMaterial(selector.value);
                holder.Add(selector);
            }

            void ShowTypeFields(Enum enumValue)
            {
                var value        = (AdvancedToggleObjectMode)enumValue;
                var activeToggle = listItem.Q(_targetActiveStateName);
                var parameter    = listItem.Q("parameters");

                activeToggle.Display(false);
                materialField.Display(false);
                objectField.Display(false);
                parameter.Display(false);

                switch (value)
                {
                case AdvancedToggleObjectMode.GameObject:
                    objectField.label = "Target Object";
                    activeToggle.Display(true);
                    objectField.Display(true);
                    objectField.objectType = typeof(Transform);
                    objectField.value      = null;
                    break;

                case AdvancedToggleObjectMode.Material:
                    objectField.label = "Target Renderer";
                    materialField.Display(true);
                    objectField.Display(true);
                    objectField.objectType = typeof(Renderer);
                    objectField.value      = null;
                    break;

                case AdvancedToggleObjectMode.Parameter:
                    parameter.Display(true);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                ErrorValidate();
            }
        }
        public static VisualElement Create <TEnum>(string label, SerializedProperty property, List <TEnum> choices, TEnum defaultValue, Func <TEnum, string> format, Action <TEnum> onValueChanged = null)
            where TEnum : struct, Enum
        {
            // Enum の SerializedProperty type が int になることがある(深さによって発生する)
            //Assert.AreEqual(property.propertyType, SerializedPropertyType.Enum);
            var container = new VisualElement
            {
                style = { flexGrow = new StyleFloat(1) }
            };

            void UpdateProperty(TEnum value)
            {
                var newValue = (int)(object)value;

                if (property.intValue == newValue)
                {
                    return;
                }
                property.intValue = newValue;
                property.serializedObject.ApplyModifiedProperties();
            }

            UpdateProperty(defaultValue);

            var popupField = new PopupField <TEnum>(label, choices, defaultValue, format, format)
            {
                style = { flexGrow = new StyleFloat(1) }
            };

            popupField.RegisterValueChangedCallback(e =>
            {
                UpdateProperty(e.newValue);
#if !UNITY_2019_3_OR_NEWER
                onValueChanged?.Invoke(e.newValue);
#endif
            });
            popupField.SetEnabled(choices.Count > 1);
            container.Add(popupField);

            VisualElement CreateFieldAsEnum()
            {
                Assert.AreEqual(property.propertyType, SerializedPropertyType.Enum);
                var enumField = CreateAsStringPopupField <TEnum>(property, newValue =>
                {
                    popupField.SetValueWithoutNotify(newValue);
                    onValueChanged?.Invoke(newValue);
                });

                return(enumField);
            }

            VisualElement CreateFieldAsInt()
            {
                Assert.AreEqual(property.propertyType, SerializedPropertyType.Integer);
                var intField = new IntegerField
                {
                    bindingPath = property.propertyPath
                };

                intField.Bind(property.serializedObject);
                intField.RegisterValueChangedCallback(e =>
                {
                    var newValue = (TEnum)(object)e.newValue;
                    popupField.SetValueWithoutNotify(newValue);
                    onValueChanged?.Invoke(newValue);
                });
                return(intField);
            }

            VisualElement CreateFieldByType()
            {
                switch (property.propertyType)
                {
                case SerializedPropertyType.Enum:
                {
                    return(CreateFieldAsEnum());
                }

                // HACK: Enum の SerializedProperty type が int になることがある(深さによって発生する)
                case SerializedPropertyType.Integer:
                {
                    return(CreateFieldAsInt());
                }

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            var field = CreateFieldByType();
            field.style.display = new StyleEnum <DisplayStyle>(DisplayStyle.None);
            container.Add(field);

            return(container);
        }
        public void SetTypePopupValueWithoutNotify(Type type)
        {
            var typeDisplayName = m_TypeOptions.FirstOrDefault(pair => pair.Value == type).Key;

            m_TypePopup.SetValueWithoutNotify(typeDisplayName);
        }
Exemplo n.º 14
0
        async Task RefreshVenueSelector(GroupID groupIdToSelect = null, VenueID venueIdToSelect = null)
        {
            selector.Clear();
            selector.Add(new Label()
            {
                text = "loading..."
            });

            var venuePickerHolder = new VisualElement()
            {
                style = { flexGrow = 1 }
            };

            void RecreateVenuePicker(GroupID groupId)
            {
                venuePickerHolder.Clear();
                venuePickerHolder.Add(CreateVenuePicker(groupId, allVenues[groupId], venueIdToSelect));
            }

            try
            {
                // Fetch all data
                var groups = await APIServiceClient.GetGroups.Call(Empty.Value, userInfo.VerifiedToken, 3);

                foreach (var group in groups.List)
                {
                    allVenues[group.Id] = await APIServiceClient.GetGroupVenues.Call(group.Id, userInfo.VerifiedToken, 3);
                }

                // Construct menu
                selector.Clear();
                selector.Add(new Label("所属チーム"));
                if (groups.List.Count == 0)
                {
                    selector.Add(new Label()
                    {
                        text = "読み込みに失敗しました"
                    });
                }
                else
                {
                    var teamMenu = new PopupField <Group>(groups.List, 0, group => group.Name, group => group.Name);
                    teamMenu.RegisterValueChangedCallback(ev => RecreateVenuePicker(ev.newValue.Id));
                    selector.Add(teamMenu);

                    var groupToSelect = groups.List.Find(group => group.Id == groupIdToSelect) ?? groups.List[0];
                    teamMenu.SetValueWithoutNotify(groupToSelect);

                    RecreateVenuePicker(groupToSelect.Id);
                }

                selector.Add(UiUtils.Separator());

                selector.Add(new Label()
                {
                    text = "ワールド"
                });
                selector.Add(venuePickerHolder);

                selector.Add(UiUtils.Separator());

                selector.Add(new Label("ユーザーID"));
                var userSelector = new VisualElement()
                {
                    style = { flexShrink = 0 }
                };
                userSelector.Add(new Label(userInfo.Username));
                userSelector.Add(new Button(() => reactiveForceLogout.Val = true)
                {
                    text = "アカウント切替"
                });
                selector.Add(userSelector);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                selector.Clear();
                selector.Add(new IMGUIContainer(() => EditorGUILayout.HelpBox($"会場情報の取得に失敗しました", MessageType.Error)));
            }
        }
Exemplo n.º 15
0
        private void CreateTaskReferenceUI(Type type, FieldInfo fInfo, object obj, VisualElement container)
        {
            var innerType = type.IsArray ? type.GetElementType() : type;

            var tasks = _inspectorObject?.View?.GetNodesOfType(innerType).ToList();

            if (tasks == null)
            {
                return;
            }

            if (type.IsArray)
            {
                var existing = fInfo.GetValue(obj) as Array;

                var size = new IntegerField("Size");
                if (existing != null)
                {
                    size.SetValueWithoutNotify(existing.Length);
                }

                container.Add(size);

                var listView = CreateTaskListView(tasks, existing);

                size.RegisterValueChangedCallback(ev =>
                {
                    var value = ev.newValue;
                    if (value < 0)
                    {
                        value = 0;
                        size.SetValueWithoutNotify(value);
                    }

                    existing  = fInfo.GetValue(obj) as Array;
                    var array = Array.CreateInstance(innerType, value);

                    if (existing != null)
                    {
                        Array.Copy(existing, array, Math.Min(existing.Length, array.Length));
                    }

                    fInfo.SetValue(obj, array);

                    listView.RemoveFromHierarchy();
                    listView = CreateTaskListView(tasks, array);
                    container.Add(listView);
                    container.MarkDirtyRepaint();

                    Repaint();
                });

                container.Add(listView);
            }
            else
            {
                var existing = fInfo.GetValue(obj);
                tasks.Insert(0, null);
                string Format(TaskNode node) => node == null ? "None" : $"{node.title} ({node.Data.ID})";

                var popup = new PopupField <TaskNode>("", tasks, 0, Format, Format);
                popup.RegisterValueChangedCallback(ev =>
                {
                    fInfo.SetValue(obj, ev.newValue?.Data);
                });

                var taskNode = tasks.FirstOrDefault(x => x?.Data == existing);
                popup.SetValueWithoutNotify(taskNode);

                container.Add(popup);
            }
        }