Esempio n. 1
0
            public override void Initialize(LayoutElementsContainer layout)
            {
                _proxy = (PropertiesProxy)Values[0];
                if (_proxy?.DefaultValues == null)
                {
                    layout.Label("Loading...", TextAlignment.Center);
                    return;
                }

                var isPlayModeActive = _proxy.Window.Editor.StateMachine.IsPlayMode;

                if (isPlayModeActive)
                {
                    layout.Label("Play mode is active. Editing runtime values.", TextAlignment.Center);
                    layout.Space(10);

                    foreach (var e in _proxy.DefaultValues)
                    {
                        var name           = e.Key;
                        var value          = _proxy.Asset.GetValue(name);
                        var valueContainer = new VariableValueContainer(_proxy, name, value, false);
                        var propertyLabel  = new PropertyNameLabel(name)
                        {
                            Tag = name,
                        };
                        string tooltip = null;
                        if (_proxy.DefaultValues.TryGetValue(name, out var defaultValue))
                        {
                            tooltip = "Default value: " + defaultValue;
                        }
                        layout.Object(propertyLabel, valueContainer, null, tooltip);
                    }
                }
                else
                {
                    foreach (var e in _proxy.DefaultValues)
                    {
                        var name           = e.Key;
                        var value          = e.Value;
                        var valueContainer = new VariableValueContainer(_proxy, name, value, true);
                        var propertyLabel  = new ClickablePropertyNameLabel(name)
                        {
                            Tag = name,
                        };
                        propertyLabel.MouseLeftDoubleClick += (label, location) => StartParameterRenaming(name, label);
                        propertyLabel.SetupContextMenu     += OnPropertyLabelSetupContextMenu;
                        layout.Object(propertyLabel, valueContainer, null, "Type: " + CustomEditorsUtil.GetTypeNameUI(value.GetType()));
                    }

                    // TODO: improve the UI
                    layout.Space(40);
                    var addParamType = layout.ComboBox().ComboBox;
                    addParamType.Items         = AllowedTypes.Select(CustomEditorsUtil.GetTypeNameUI).ToList();
                    addParamType.SelectedIndex = 0;
                    _addParamType = addParamType;
                    var addParamButton = layout.Button("Add").Button;
                    addParamButton.Clicked += OnAddParamButtonClicked;
                }
            }
Esempio n. 2
0
                /// <inheritdoc />
                public override void Initialize(LayoutElementsContainer layout)
                {
                    var materialWin = Values[0] as MaterialWindow;
                    var material    = materialWin?.Asset;

                    if (material == null)
                    {
                        _parametersHash = -1;
                        layout.Label("No parameters");
                        return;
                    }
                    if (!material.IsLoaded)
                    {
                        _parametersHash = -2;
                        layout.Label("Loading...");
                        return;
                    }
                    _parametersHash = material._parametersHash;
                    var parameters = material.Parameters;

                    for (int i = 0; i < parameters.Length; i++)
                    {
                        var p = parameters[i];
                        if (!p.IsPublic)
                        {
                            continue;
                        }

                        var  pIndex    = i;
                        var  pValue    = p.Value;
                        var  pGuidType = false;
                        Type pType;
                        switch (p.Type)
                        {
                        case MaterialParameterType.CubeTexture:
                            pType     = typeof(CubeTexture);
                            pGuidType = true;
                            break;

                        case MaterialParameterType.Texture:
                        case MaterialParameterType.NormalMap:
                            pType     = typeof(Texture);
                            pGuidType = true;
                            break;

                        case MaterialParameterType.RenderTarget:
                            pType     = typeof(RenderTarget);
                            pGuidType = true;
                            break;

                        default:
                            pType = p.Value.GetType();
                            break;
                        }

                        var propertyValue = new CustomValueContainer(
                            pType,
                            pValue,
                            (instance, index) =>
                        {
                            // Get material parameter
                            var win = (MaterialWindow)instance;
                            return(win.Asset.Parameters[pIndex].Value);
                        },
                            (instance, index, value) =>
                        {
                            // Set material parameter and surface parameter
                            var win = (MaterialWindow)instance;

                            // Visject surface paramaters are only value type objects so convert value if need to (eg. instead of texture ref write texture id)
                            var surfaceParam = value;
                            if (pGuidType)
                            {
                                surfaceParam = (value as FlaxEngine.Object)?.ID ?? Guid.Empty;
                            }

                            win.Asset.Parameters[pIndex].Value   = value;
                            win.Surface.Parameters[pIndex].Value = surfaceParam;
                            win._paramValueChange = true;
                        }
                            );

                        var propertyLabel = new ClickablePropertyNameLabel(p.Name);
                        propertyLabel.MouseRightClick += (label, location) => ShowParameterMenu(pIndex, label, ref location);
                        var property = layout.AddPropertyItem(propertyLabel);
                        property.Object(propertyValue);
                    }

                    if (parameters.Length > 0)
                    {
                        layout.Space(10);
                    }

                    // Parameters creating
                    var paramType = layout.Enum(typeof(NewParameterType));

                    paramType.Value = (int)NewParameterType.Float;
                    var newParam = layout.Button("Add parameter");

                    newParam.Button.Clicked += () => AddParameter((ParameterType)paramType.Value);
                }