public void OnSaveCurrentGradientButtonClicked() { if (gradientList.CurrentIndex >= 0) { GlobalState.Settings.skies[gradientList.CurrentIndex] = GlobalState.Settings.sky; GradientItem currentItem = gradientList.GetItems()[gradientList.CurrentIndex].Content.GetComponent <GradientItem>(); currentItem.Colors = GlobalState.Settings.sky; } }
private void AddGradient(SkySettings sky) { GradientItem gradientItem = GradientItem.GenerateGradientItem(sky); gradientItem.AddListeners(OnDuplicateGradientItem, OnDeleteGradientItem); UIDynamicListItem dlItem = gradientList.AddItem(gradientItem.transform); dlItem.UseColliderForUI = false; // dont use the default global collider, sub-widget will catch UI events and propagate them. gradientItem.transform.localScale = Vector3.one; // Items are hidden (scale 0) while they are not added into a list, so activate the item here. gradientItem.SetListItem(dlItem); // link individual elements to their parent list in order to be able to send messages upwards. }
private void OnListItemClicked(object sender, IndexedGameObjectArgs args) { GameObject item = args.gobject; GradientItem gradientItem = item.GetComponent <GradientItem>(); SkySettings itemSky = gradientItem.Colors; SkySettings oldSky = new SkySettings { topColor = topButton.ImageColor, middleColor = middleButton.ImageColor, bottomColor = bottomButton.ImageColor }; SetSkyColors(oldSky, itemSky); }
public static GradientItem GenerateGradientItem(SkySettings sky) { GameObject root = new GameObject("GradientItem"); GradientItem gradientItem = root.AddComponent <GradientItem>(); root.layer = LayerMask.NameToLayer("CameraHidden"); // Set the item invisible in order to hide it while it is not added into // a list. We will activate it after it is added root.transform.localScale = Vector3.zero; // // Background Panel // UIPanel panel = UIPanel.Create(new UIPanel.CreatePanelParams { parent = root.transform, widgetName = "GradientPreviewBackgroundPanel", relativeLocation = new Vector3(0.01f, -0.01f, -UIPanel.default_element_thickness), width = 0.145f, height = 0.185f, margin = 0.005f }); panel.SetLightLayer(3); // // Gradient Button // UIGradientPreview gradientPreview = UIGradientPreview.Create(new UIGradientPreview.CreateParams { parent = panel.transform, widgetName = "GradientPreview", relativeLocation = new Vector3(0.0725f, -0.0725f, -UIGradientPreview.default_thickness), width = 0.12f, height = 0.12f, margin = 0.001f }); gradientPreview.SetLightLayer(3); gradientPreview.Colors = sky; gradientPreview.NeedsRebuild = true; // // Copy Button // UIButton copyButton = UIButton.Create(new UIButton.CreateButtonParams { parent = panel.transform, widgetName = "CopyButton", relativeLocation = new Vector3(0.075f, -0.15f, -UIButton.default_thickness), width = 0.03f, height = 0.03f, icon = UIUtils.LoadIcon("duplicate"), buttonContent = UIButton.ButtonContent.ImageOnly, margin = 0.001f, }); copyButton.SetLightLayer(3); // // Delete Button // UIButton deleteButton = UIButton.Create(new UIButton.CreateButtonParams { parent = panel.transform, widgetName = "DeleteButton", relativeLocation = new Vector3(0.11f, -0.15f, -UIButton.default_thickness), width = 0.03f, height = 0.03f, icon = UIUtils.LoadIcon("trash"), buttonContent = UIButton.ButtonContent.ImageOnly, margin = 0.001f, }); deleteButton.SetLightLayer(3); gradientItem.gradientPreview = gradientPreview; gradientItem.copyButton = copyButton; gradientItem.deleteButton = deleteButton; gradientItem.backgroundPanel = panel; return(gradientItem); }