public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);

        List<PopupOption<string>> options = new List<PopupOption<string>>();

        if (UnityObject.FindObjectOfType<Timekeeper>() != null)
        {
            Timekeeper timekeeper = Timekeeper.instance;

            foreach (GlobalClock globalClock in timekeeper
                .GetComponents<GlobalClock>()
                .Where(gc => !string.IsNullOrEmpty(gc.key)))
            {
                options.Add(new PopupOption<string>(globalClock.key));
            }
        }

        PopupOption<string> selectedOption;

        if (options.Any(o => o.value == property.stringValue))
        {
            selectedOption = new PopupOption<string>(property.stringValue);
        }
        else if (!string.IsNullOrEmpty(property.stringValue))
        {
            selectedOption = new PopupOption<string>(property.stringValue, property.stringValue + " (Missing)");
        }
        else
        {
            selectedOption = null;
        }

        PopupOption<string> noneOption = new PopupOption<string>(null, "None");

        var currentProperty = property;

        position = EditorGUI.PrefixLabel(position, label);

        PopupGUI<string>.Render
        (
            position,
            gc => ChangeValue(currentProperty, gc),
            options,
            selectedOption,
            noneOption,
            property.hasMultipleDifferentValues
        );

        EditorGUI.EndProperty();
    }
示例#2
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);

        Timekeeper timekeeper = Timekeeper.instance;

        List <PopupOption <string> > options = new List <PopupOption <string> >();

        foreach (GlobalClock globalClock in timekeeper
                 .GetComponents <GlobalClock>()
                 .Where(gc => !string.IsNullOrEmpty(gc.key)))
        {
            options.Add(new PopupOption <string>(globalClock.key));
        }

        PopupOption <string> selectedOption;

        if (options.Any(o => o.value == property.stringValue))
        {
            selectedOption = new PopupOption <string>(property.stringValue);
        }
        else if (!string.IsNullOrEmpty(property.stringValue))
        {
            selectedOption = new PopupOption <string>(property.stringValue, property.stringValue + " (Missing)");
        }
        else
        {
            selectedOption = null;
        }

        PopupOption <string> noneOption = new PopupOption <string>(null, "None");

        var currentProperty = property;

        position = EditorGUI.PrefixLabel(position, label);

        PopupGUI <string> .Render
        (
            position,
            gc => ChangeValue(currentProperty, gc),
            options,
            selectedOption,
            noneOption,
            property.hasMultipleDifferentValues
        );

        EditorGUI.EndProperty();
    }
示例#3
0
    public void Show(string text, PopupOption pop)
    {
        if (canvas.alpha <= 0)
        {
            popup = pop;

            Title.UpdateKey(text);

            canvas.alpha          = 1;
            canvas.blocksRaycasts = true;
            canvas.interactable   = true;
            CurrentSelect         = evenSys.currentSelectedGameObject;
            evenSys.SetSelectedGameObject(Title.gameObject);
            back.enabled = true;
        }
    }
示例#4
0
    public void Hide()
    {
        if (ControlMenu)
        {
            if (boxes != null)
            {
                for (int i = 0; i < boxes.Length; i++)
                {
                    boxes[i].enabled = false;
                }
            }

            Debug.Log("Trato de Salvar");

            /*/string saveFolder = PathUtility.GetInputSaveFolder(0);
             * if (!System.IO.Directory.Exists(saveFolder))
             *  System.IO.Directory.CreateDirectory(saveFolder);
             *
             *
             * InputSaverXML saver = new InputSaverXML(saveFolder + "/input_config.xml");
             * InputManager.Save(saver);/*/

            if (tutoriales != null)
            {
                for (int i = 0; i < tutoriales.Length; i++)
                {
                    tutoriales[i].UpdateInputKey();
                }
            }

            if (optionObject != null)
            {
                optionObject.SetActive(true);
            }
        }

        evenSys.SetSelectedGameObject(CurrentSelect);
        CurrentSelect = null;

        popup                 = null;
        canvas.alpha          = 0;
        canvas.blocksRaycasts = false;
        canvas.interactable   = false;
        back.enabled          = false;
    }
示例#5
0
 void OnValueChanged(string code, PopupOption joinOption)
 {
     joinOption.SetInteractable(!String.IsNullOrWhiteSpace(code));
 }
示例#6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="resultCode"></param>
 /// <param name="popup"></param>
 public ResultMessage(ResultCode resultCode = ResultCode.Ok, PopupOption popup = PopupOption.Default)
 {
     Title   = resultCode.GetDescription();
     Message = resultCode.GetDescription();
     Popup   = popup;
 }
示例#7
0
        /// <inheritdoc />
        protected override void RenderMemberControl(Rect position)
        {
            // Other Targets
            // Some Unity Objects, like Assets, are not supported by the drawer.
            // Just display an error message to let the user change their target.

            if (targetType == UnityObjectType.Other)
            {
                EditorGUI.HelpBox(position, "Unsupported Unity Object type.", MessageType.None);
                return;
            }

            // Display a list of all available reflected members in a popup.

            var options = new List <PopupOption <TMember> >();

            TMember value = GetValue();

            PopupOption <TMember> selectedOption = null;
            PopupOption <TMember> noneOption     = new PopupOption <TMember>(null, string.Format("No {0}", memberLabel));

            if (targetType == UnityObjectType.GameObject)
            {
                // Check if all targets have a GameObject (none are empty).
                // If they do, display all members of the GameObject type.

                if (HasSharedGameObject())
                {
                    var gameObjectOptions = GetMemberOptions(typeof(GameObject));

                    foreach (var gameObjectOption in gameObjectOptions)
                    {
                        // Prefix label by GameObject for popup clarity.

                        gameObjectOption.label = string.Format("GameObject/{0}", gameObjectOption.label);

                        options.Add(gameObjectOption);
                    }
                }

                // Find all shared component types across targets.
                // Display all members of each one found.

                foreach (Type componentType in GetSharedComponentTypes())
                {
                    var componentOptions = GetMemberOptions(componentType, componentType.Name);

                    foreach (var componentOption in componentOptions)
                    {
                        // Prefix label and option by component type for clear distinction.

                        componentOption.label = string.Format("{0}/{1}", componentType.Name, componentOption.label);

                        options.Add(componentOption);
                    }
                }

                // Determine which option is currently selected.

                if (value != null)
                {
                    string label;

                    if (value.component == null)
                    {
                        label = string.Format("GameObject.{0}", value.name);
                    }
                    else
                    {
                        label = string.Format("{0}.{1}", value.component, value.name);
                    }

                    UnityMethod method = value as UnityMethod;

                    if (method != null)
                    {
                        string parameterString = string.Join(", ", method.parameterTypes.Select(t => t.PrettyName()).ToArray());

                        label += string.Format(" ({0})", parameterString);
                    }

                    TMember valueInOptions = options.Select(option => option.value).FirstOrDefault(member => member.Corresponds(value));

                    if (valueInOptions != null)
                    {
                        selectedOption = new PopupOption <TMember>(valueInOptions, label);
                    }
                    else
                    {
                        selectedOption = new PopupOption <TMember>(value, label);
                    }
                }
            }
            else if (targetType == UnityObjectType.ScriptableObject)
            {
                // ScriptableObject Target
                // Make sure all targets share the same ScriptableObject Type.
                // If they do, display all members of that type.

                Type scriptableObjectType = GetSharedScriptableObjectType();

                if (scriptableObjectType != null)
                {
                    options.AddRange(GetMemberOptions(scriptableObjectType));

                    // Determine which option is currently selected.

                    if (value != null)
                    {
                        selectedOption = options.Find(o => o.value.Corresponds(value));

                        if (selectedOption == null)
                        {
                            selectedOption = new PopupOption <TMember>(value, value.name);
                        }
                    }
                }
            }

            // Make sure the callback uses the property of this drawer, not at its later value.
            var propertyNow = property;

            bool enabled = targetType != UnityObjectType.None;

            if (!enabled)
            {
                EditorGUI.BeginDisabledGroup(true);
            }

            PopupGUI <TMember> .Render
            (
                position,
                newValue =>
            {
                Update(propertyNow);
                SetValue(newValue);
                propertyNow.serializedObject.ApplyModifiedProperties();
            },
                options,
                selectedOption,
                noneOption,
                hasMultipleDifferentValues
            );

            if (!enabled)
            {
                EditorGUI.EndDisabledGroup();
            }
        }
示例#8
0
        private void CreateUI()
        {
            _Panel = new StackPanel()
            {
                Padding = new Skill.Framework.UI.Thickness(2, 4, 2, 0)
            };
            _TextureField = new Skill.Editor.UI.ObjectField <Texture2D>()
            {
                Object = _PaintColor.Texture, HorizontalAlignment = Skill.Framework.UI.HorizontalAlignment.Center, Width = 80, Height = 80, Margin = new Skill.Framework.UI.Thickness(2)
            };


            #region _TbChannels
            _TbChannels = new UI.TabHeader(4, true)
            {
                Margin = new Thickness(0, 2, 0, 10), HorizontalAlignment = HorizontalAlignment.Center, Width = 200, Height = 20
            };
            _TbChannels[0].text = "R";
            _TbChannels[1].text = "G";
            _TbChannels[2].text = "B";
            _TbChannels[3].text = "A";

            _TbChannels.SetTabSelected(0, _PaintColor.ChannelR);
            _TbChannels.SetTabSelected(1, _PaintColor.ChannelG);
            _TbChannels.SetTabSelected(2, _PaintColor.ChannelB);
            _TbChannels.SetTabSelected(3, _PaintColor.ChannelA);
            #endregion

            #region _LayersField and _PUV and _TbBrush

            Grid layersPanel = new Grid()
            {
                Height = 32, Padding = new Thickness(2, 6)
            };
            layersPanel.ColumnDefinitions.Add(90, GridUnitType.Pixel);
            layersPanel.ColumnDefinitions.Add(50, GridUnitType.Pixel);
            layersPanel.ColumnDefinitions.Add(10, GridUnitType.Pixel);
            layersPanel.ColumnDefinitions.Add(45, GridUnitType.Pixel);
            layersPanel.ColumnDefinitions.Add(1, GridUnitType.Star);


            _TbBrush = new UI.ToggleButton()
            {
                Column = 0, IsChecked = _PaintColor.Brush, Left = true
            };
            _TbBrush.Label.text = "Brush View";
            layersPanel.Controls.Add(_TbBrush);

            _PUV = new Popup()
            {
                Row = 0, Column = 1
            };
            PopupOption uv1 = new PopupOption(0)
            {
                Name = "UV1"
            }; uv1.Content.text = "UV 1";
            PopupOption uv2 = new PopupOption(1)
            {
                Name = "UV2"
            }; uv2.Content.text = "UV 2";
            _PUV.Options.Add(uv1);
            _PUV.Options.Add(uv2);
            _PUV.SelectedIndex = _PaintColor.UV2 ? 1 : 0;
            layersPanel.Controls.Add(_PUV);

            Label lbl = new Label()
            {
                Text = "Layers", Column = 3
            };
            layersPanel.Controls.Add(lbl);


            _LayersField = new LayerMaskField()
            {
                Row = 0, Column = 4
            };
            _LayersField.Layers     = _PaintColor.LayerMask;
            _LayersField.Label.text = string.Empty;
            layersPanel.Controls.Add(_LayersField);


            #endregion

            _PnlFavoriteColors = new Grid()
            {
                Height = 22, Margin = new Thickness(0, 2)
            };
            _FavoriteColors = new Color[] { new Color(1.0f, 0.0f, 0.0f, 0.0f),   // red
                                            new Color(0.0f, 1.0f, 0.0f, 0.0f),   // green
                                            new Color(0.0f, 0.0f, 1.0f, 0.0f),   // blue
                                            new Color(0.0f, 0.0f, 0.0f, 1.0f),   // Alpha
                                            new Color(1.0f, 1.0f, 1.0f, 1.0f),   // white
                                            new Color(0.0f, 0.0f, 0.0f, 0.0f) }; // black
            _PnlFavoriteColors.Controls.Add(new Box()
            {
                Row = 0, Column = 0, ColumnSpan = _FavoriteColors.Length
            });
            for (int i = 0; i < _FavoriteColors.Length; i++)
            {
                _PnlFavoriteColors.ColumnDefinitions.Add(1, GridUnitType.Star);
                Skill.Framework.UI.Button btn = new Skill.Framework.UI.Button()
                {
                    Tag = i.ToString(), Margin = new Thickness(4), Style = new GUIStyle(), Column = i
                };
                string    toolTip    = string.Empty;
                Texture2D background = null;
                if (i == 0)
                {
                    background = Skill.Editor.Resources.UITextures.Colors.Red; toolTip = "Red";
                }
                else if (i == 1)
                {
                    background = Skill.Editor.Resources.UITextures.Colors.Green; toolTip = "Green";
                }
                else if (i == 2)
                {
                    background = Skill.Editor.Resources.UITextures.Colors.Blue; toolTip = "Blue";
                }
                else if (i == 3)
                {
                    background = Skill.Editor.Resources.UITextures.Colors.Transparent; toolTip = "Alpha";
                }
                else if (i == 4)
                {
                    background = Skill.Editor.Resources.UITextures.Colors.White; toolTip = "White";
                }
                else if (i == 5)
                {
                    background = Skill.Editor.Resources.UITextures.Colors.Black; toolTip = "Black";
                }
                btn.Style.normal.background = btn.Style.focused.background = btn.Style.hover.background = btn.Style.active.background = background;
                btn.Content.tooltip         = toolTip;
                btn.Click += btn_Click;
                _PnlFavoriteColors.Controls.Add(btn);
            }


            _ColorField = new ColorField()
            {
                Color = _PaintColor.Color, Margin = new Thickness(2)
            };
            _SliRadius = new Skill.Editor.UI.Slider()
            {
                Value = _PaintColor.Radius, MinValue = 1, MaxValue = 40, Margin = new Thickness(2), Height = 16
            }; _SliRadius.Label.text = "Radius"; _SliRadius.Label.tooltip = "Shift + (A/D)";
            _SliStrength             = new Skill.Editor.UI.Slider()
            {
                Value = _PaintColor.Strength, MinValue = 1f, MaxValue = 100f, Margin = new Thickness(2), Height = 16
            }; _SliStrength.Label.text = "Strength";
            _SliFalloff = new Skill.Editor.UI.Slider()
            {
                Value = _PaintColor.Falloff, MinValue = 0.0f, MaxValue = 1.0f, Margin = new Thickness(2), Height = 16
            }; _SliFalloff.Label.text = "Falloff";
            _HelpBox = new HelpBox()
            {
                Height = 60, Message = "Hold CTRL and drag with Right Click to paint.\nTexture must be read/write enable\nValid texture format:\n    ARGB32, RGBA32, RGB24 and Alpha8"
            };

            _BtnSaveTexture = new Skill.Framework.UI.Button()
            {
                Margin = new Thickness(2), Height = 40
            }; _BtnSaveTexture.Content.text = "Save Texture";
            _TbShadowMode = new UI.ToggleButton()
            {
                Left = false, Margin = new Thickness(2), Height = 20
            }; _TbShadowMode.Label.text = "Shadow Mode";


            _Panel.Controls.Add(_TextureField);
            _Panel.Controls.Add(_TbChannels);
            _Panel.Controls.Add(_PnlFavoriteColors);
            _Panel.Controls.Add(_ColorField);
            _Panel.Controls.Add(layersPanel);
            _Panel.Controls.Add(_SliRadius);
            _Panel.Controls.Add(_SliStrength);
            _Panel.Controls.Add(_SliFalloff);
            _Panel.Controls.Add(_TbShadowMode);
            _Panel.Controls.Add(_HelpBox);
            _Panel.Controls.Add(_BtnSaveTexture);

            _Frame = new Frame("Frame");
            _Frame.Grid.Controls.Add(_Panel);

            _TextureField.ObjectChanged += _TextureField_ObjectChanged;
            _TbBrush.Changed            += _TbBrush_Changed;
            _TbShadowMode.Changed       += _TbShadowMode_Changed;

            _TbChannels.TabChanged += Channel_Changed;

            _LayersField.LayersChanged += _LayersField_LayersChanged;
            _PUV.OptionChanged         += _PUV_OptionChanged;
            _ColorField.ColorChanged   += _ColorField_ColorChanged;

            _SliRadius.ValueChanged   += _SliRadius_ValueChanged;
            _SliStrength.ValueChanged += _SliStrength_ValueChanged;
            _SliFalloff.ValueChanged  += _SliFalloff_ValueChanged;
            _BtnSaveTexture.Click     += _BtnSaveTexture_Click;
        }
示例#9
0
        /// <summary>
        /// Constructs a list of all possible method call chains that result in the given target type.
        /// Some limits set to keep the possible options under control:
        /// - Only look for methods from classes with [Receivable] attribute
        /// - Up to 8 chained method calls
        /// </summary>
        void GetGetterMethods(List <Type> types, List <string> path, Type targetType, List <PopupOption> list)
        {
            Type memberType = types[types.Count - 1];

            if (targetType.IsAssignableFrom(memberType))
            {
                var option = new PopupOption(types[0], path);
                if (!list.Contains(option))
                {
                    list.Add(option);
                }
            }

            if (memberType.GetCustomAttribute <Receivable>() == null)
            {
                return;
            }
            if (memberType.IsValueType)
            {
                Debug.LogWarning($"Struct {memberType.GetFriendlyName()} has been marked [{nameof(Receivable)}] but that is not supported");
                return;
            }

            foreach (var method in memberType.GetMethods())
            {
                if (method.DeclaringType == typeof(object))
                {
                    continue;
                }
                if (method.ReturnType == typeof(void))
                {
                    continue;
                }
                if (method.GetParameters().Length > 0)
                {
                    continue;
                }
                if (method.IsStatic)
                {
                    continue;
                }
                if (method.ContainsGenericParameters)
                {
                    continue;
                }

                Delegate accessor;
                try
                {
                    accessor = DataAccessorHelper.CreateGetter(method);
                }
                catch (Exception e)
                {
                    Debug.LogWarning($"Couldn't add {method.DeclaringType}:{method.Name}: " + e.Message + e.StackTrace);
                    continue;
                }

                var returnType = GetterChainCall.GetMethodReturnType(accessor.Method);

                if (returnType != typeof(void) && !types.Contains(returnType) && path.Count < 8)
                {
                    types.Add(returnType);
                    path.Add(method.Name);
                    GetGetterMethods(types, path, targetType, list);
                    path.RemoveAt(path.Count - 1);
                    types.RemoveAt(types.Count - 1);
                }
            }
        }
        /// <inheritdoc />
        protected override void RenderMemberControl(Rect position)
        {
            var options = GetNameOptions();

            PopupOption<AnimatorParameter> selectedOption = null;
            PopupOption<AnimatorParameter> noneOption = new PopupOption<AnimatorParameter>(null, "No Parameter");

            AnimatorParameter value = GetValue();

            if (value != null)
            {
                string label = value.name;

                AnimatorParameter valueInOptions = options.Select(option => option.value).FirstOrDefault(ap => ap.Corresponds(value));

                if (valueInOptions != null)
                {
                    selectedOption = new PopupOption<AnimatorParameter>(valueInOptions, label);
                }
                else
                {
                    selectedOption = new PopupOption<AnimatorParameter>(value, label);
                }

            }

            // Make sure the callback uses the property of this drawer, not at its later value.
            var propertyNow = property;

            bool enabled = targets.Any(target => target != null);

            if (!enabled) EditorGUI.BeginDisabledGroup(true);

            PopupGUI<AnimatorParameter>.Render
            (
                position,
                newValue =>
                {
                    Update(propertyNow);
                    SetValue(newValue);
                    propertyNow.serializedObject.ApplyModifiedProperties();
                },
                options,
                selectedOption,
                noneOption,
                nameProperty.hasMultipleDifferentValues
            );

            if (!enabled) EditorGUI.EndDisabledGroup();
        }