示例#1
0
            private void ShowContextMenuOfType(ChangerPlate parent, ConditionTypeValuePair typeValuePair)
            {
                var conditionType = typeValuePair.conditionType;
                var menu          = new GenericMenu();

                // update parent:ChangerPlate's conditions to latest.
                ChangerPlate.Emit(new OnChangerEvent(OnChangerEvent.EventType.EVENT_REFRESHCONDITIONS, parent.changerId));

                var menuItems = parent.conditions
                                .Select(conditonData => conditonData.conditionType)
                                .Where(type => type != conditionType)
                                .ToList();

                // current.
                menu.AddDisabledItem(
                    new GUIContent(conditionType)
                    );

                menu.AddSeparator(string.Empty);

                // new.
                menu.AddItem(
                    new GUIContent("Add New Type"),
                    false,
                    () =>
                {
                    ChangerPlate.Emit(new OnChangerEvent(OnChangerEvent.EventType.EVENT_ADDNEWTYPE, parent.changerId));
                }
                    );

                menu.AddSeparator(string.Empty);

                // other.
                foreach (var conditonData in menuItems.Select((val, index) => new { index, val }))
                {
                    var currentType = conditonData.val;

                    menu.AddItem(
                        new GUIContent(currentType),
                        false,
                        () =>
                    {
                        parent.EmitUndo("Change Combination Type");
                        typeValuePair.conditionType = currentType;
                        parent.EmitSave();
                    }
                        );
                }

                menu.ShowAsContext();
            }
示例#2
0
            private void ShowContextMenuOfValue(ChangerPlate parent, ConditionTypeValuePair typeValuePair)
            {
                var conditionType  = typeValuePair.conditionType;
                var conditionValue = typeValuePair.conditionValue;

                var menu = new GenericMenu();

                // update parent:ChangerPlate's conditions to latest.
                ChangerPlate.Emit(new OnChangerEvent(OnChangerEvent.EventType.EVENT_REFRESHCONDITIONS, parent.changerId));

                var menuItems = parent.conditions
                                .Where(data => data.conditionType == conditionType)
                                .FirstOrDefault();

                // current.
                if (!string.IsNullOrEmpty(conditionValue))
                {
                    menu.AddDisabledItem(
                        new GUIContent(conditionValue)
                        );
                    menu.AddSeparator(string.Empty);
                }

                // new.
                if (string.IsNullOrEmpty(conditionType))
                {
                    menu.AddItem(
                        new GUIContent("Add New Type & Value"),
                        false,
                        () =>
                    {
                        ChangerPlate.Emit(new OnChangerEvent(OnChangerEvent.EventType.EVENT_ADDNEWTYPEVALUE, parent.changerId));
                    }
                        );
                }
                else
                {
                    menu.AddItem(
                        new GUIContent("Add New Value"),
                        false,
                        () =>
                    {
                        ChangerPlate.Emit(new OnChangerEvent(OnChangerEvent.EventType.EVENT_ADDNEWVALUE, parent.changerId));
                    }
                        );
                }


                // show other conditionValues.
                if (menuItems != null)
                {
                    // remove current.
                    menuItems.conditionValues.Remove(conditionValue);

                    menu.AddSeparator(string.Empty);

                    // other.
                    foreach (var currentConditionValue in menuItems.conditionValues.Select((val, index) => new { index, val }))
                    {
                        // var currentType = conditionType;

                        var currentValue = currentConditionValue.val;
                        var currentIndex = currentConditionValue.index;

                        menu.AddItem(
                            new GUIContent(currentValue),
                            false,
                            () =>
                        {
                            parent.EmitUndo("Change Combination Value");
                            typeValuePair.conditionValue = menuItems.conditionValues[currentIndex];
                            parent.EmitSave();
                        }
                            );
                    }
                }

                menu.ShowAsContext();
            }