public void Start() { try { isRicoEnabled = IsRicoEnabled(); GameObject gameObject = GameObject.Find("FindItMainButton"); if (gameObject != null) { return; } list = AssetTagList.instance; UITabstrip tabstrip = ToolsModifierControl.mainToolbar.component as UITabstrip; // TODO: temporary /*tabstrip.eventComponentAdded += (c, p) => * { * foreach (UIComponent tab in tabstrip.tabPages.components) * { * DebugUtils.Log(tab.name); * * if(tab.name == "LandscapingPanel") * { * tab.components[0].relativePosition = new Vector3(0, -134); * tab.components[1].relativePosition = new Vector3(0, -109); * tab.components[1].height = 218; * foreach(UIScrollablePanel panel in tab.components[1].GetComponentsInChildren<UIScrollablePanel>()) * { * panel.autoLayoutStart = LayoutStart.TopLeft; * panel.scrollWheelDirection = UIOrientation.Vertical; * panel.scrollWheelAmount = 104; * panel.wrapLayout = true; * panel.width = 764; * } * } * } * };*/ m_defaultXPos = tabstrip.relativePosition.x; UpdateMainToolbar(); GameObject asGameObject = UITemplateManager.GetAsGameObject("MainToolbarButtonTemplate"); GameObject asGameObject2 = UITemplateManager.GetAsGameObject("ScrollableSubPanelTemplate"); mainButton = tabstrip.AddTab("FindItMainButton", asGameObject, asGameObject2, new Type[] { typeof(UIGroupPanel) }) as UIButton; mainButton.atlas = atlas; Locale locale = (Locale)typeof(LocaleManager).GetField("m_Locale", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(LocaleManager.instance); Locale.Key key = new Locale.Key { m_Identifier = "TUTORIAL_ADVISER_TITLE", m_Key = mainButton.name }; if (!locale.Exists(key)) { locale.AddLocalizedString(key, "Find It! " + ModInfo.version); } key = new Locale.Key { m_Identifier = "TUTORIAL_ADVISER", m_Key = mainButton.name }; if (!locale.Exists(key)) { locale.AddLocalizedString(key, "Thanks for subscribing to Find It!\n\nStart typing some keywords into the input field to find the desired asset.\n\nIf you like the mod please consider leaving a rating on the steam workshop."); } FieldInfo m_ObjectIndex = typeof(MainToolbar).GetField("m_ObjectIndex", BindingFlags.Instance | BindingFlags.NonPublic); m_ObjectIndex.SetValue(ToolsModifierControl.mainToolbar, (int)m_ObjectIndex.GetValue(ToolsModifierControl.mainToolbar) + 1); mainButton.gameObject.GetComponent <TutorialUITag>().tutorialTag = name; m_groupPanel = tabstrip.GetComponentInContainer(mainButton, typeof(UIGroupPanel)) as UIGroupPanel; if (m_groupPanel != null) { m_groupPanel.name = "FindItGroupPanel"; m_groupPanel.enabled = true; m_groupPanel.component.isInteractive = true; m_groupPanel.m_OptionsBar = ToolsModifierControl.mainToolbar.m_OptionsBar; m_groupPanel.m_DefaultInfoTooltipAtlas = ToolsModifierControl.mainToolbar.m_DefaultInfoTooltipAtlas; if (ToolsModifierControl.mainToolbar.enabled) { m_groupPanel.RefreshPanel(); } scrollPanel = UIScrollPanel.Create(m_groupPanel.GetComponentInChildren <UIScrollablePanel>()); scrollPanel.eventClicked += OnButtonClicked; scrollPanel.eventVisibilityChanged += (c, p) => { HideAllOptionPanels(); if (p && scrollPanel.selectedItem != null) { // Simulate item click UIScrollPanelItem.ItemData item = scrollPanel.selectedItem; UIScrollPanelItem panelItem = scrollPanel.GetItem(0); panelItem.Display(scrollPanel.selectedItem, 0); panelItem.component.SimulateClick(); scrollPanel.selectedItem = item; scrollPanel.Refresh(); } }; scrollPanel.eventTooltipEnter += (c, p) => { UIScrollPanelItem.RefreshTooltipAltas(p.source); }; searchBox = scrollPanel.parent.AddUIComponent <UISearchBox>(); searchBox.scrollPanel = scrollPanel; searchBox.relativePosition = new Vector3(0, 0); searchBox.Search(); } else { DebugUtils.Warning("GroupPanel not found"); } mainButton.normalBgSprite = "ToolbarIconGroup6Normal"; mainButton.focusedBgSprite = "ToolbarIconGroup6Focused"; mainButton.hoveredBgSprite = "ToolbarIconGroup6Hovered"; mainButton.pressedBgSprite = "ToolbarIconGroup6ressed"; mainButton.disabledBgSprite = "ToolbarIconGroup6Disabled"; mainButton.normalFgSprite = "FindIt"; mainButton.focusedFgSprite = "FindItFocused"; mainButton.hoveredFgSprite = "FindItHovered"; mainButton.pressedFgSprite = "FindItPressed"; mainButton.disabledFgSprite = "FindItDisabled"; mainButton.tooltip = "Find It! " + ModInfo.version; m_beautificationPanel = FindObjectOfType <BeautificationPanel>(); DebugUtils.Log("Initialized"); } catch (Exception e) { DebugUtils.Log("Start failed"); DebugUtils.LogException(e); enabled = false; } }
public void Start() { try { GameObject gameObject = GameObject.Find("FindItMainButton"); if (gameObject != null) { return; } isRicoEnabled = IsRicoEnabled(); isPOEnabled = IsPOEnabled(); isTVPPatchEnabled = IsTVPPatchEnabled(); if (isPOEnabled) { POTool = new ProceduralObjectsTool(); } list = AssetTagList.instance; UITabstrip tabstrip = ToolsModifierControl.mainToolbar.component as UITabstrip; m_defaultXPos = tabstrip.relativePosition.x; UpdateMainToolbar(); GameObject asGameObject = UITemplateManager.GetAsGameObject("MainToolbarButtonTemplate"); GameObject asGameObject2 = UITemplateManager.GetAsGameObject("ScrollableSubPanelTemplate"); mainButton = tabstrip.AddTab("FindItMainButton", asGameObject, asGameObject2, new Type[] { typeof(UIGroupPanel) }) as UIButton; mainButton.atlas = atlas; mainButton.normalBgSprite = "ToolbarIconGroup6Normal"; mainButton.focusedBgSprite = "ToolbarIconGroup6Focused"; mainButton.hoveredBgSprite = "ToolbarIconGroup6Hovered"; mainButton.pressedBgSprite = "ToolbarIconGroup6ressed"; mainButton.disabledBgSprite = "ToolbarIconGroup6Disabled"; mainButton.normalFgSprite = "FindIt"; mainButton.focusedFgSprite = "FindItFocused"; mainButton.hoveredFgSprite = "FindItHovered"; mainButton.pressedFgSprite = "FindItPressed"; mainButton.disabledFgSprite = "FindItDisabled"; mainButton.tooltip = "Find It! " + (ModInfo.isBeta ? "[BETA] " : "") + ModInfo.version; Locale locale = (Locale)typeof(LocaleManager).GetField("m_Locale", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(LocaleManager.instance); Locale.Key key = new Locale.Key { m_Identifier = "TUTORIAL_ADVISER_TITLE", m_Key = mainButton.name }; if (!locale.Exists(key)) { locale.AddLocalizedString(key, "Find It! " + ModInfo.version); } key = new Locale.Key { m_Identifier = "TUTORIAL_ADVISER", m_Key = mainButton.name }; if (!locale.Exists(key)) { locale.AddLocalizedString(key, "Thanks for subscribing to Find It! 2.\n\nStart typing some keywords into the input field to find the desired asset.\n\nCheck the workshop page occasionally for new features or bug reports."); } FieldInfo m_ObjectIndex = typeof(MainToolbar).GetField("m_ObjectIndex", BindingFlags.Instance | BindingFlags.NonPublic); m_ObjectIndex.SetValue(ToolsModifierControl.mainToolbar, (int)m_ObjectIndex.GetValue(ToolsModifierControl.mainToolbar) + 1); mainButton.gameObject.GetComponent <TutorialUITag>().tutorialTag = name; m_groupPanel = tabstrip.GetComponentInContainer(mainButton, typeof(UIGroupPanel)) as UIGroupPanel; if (m_groupPanel != null) { m_groupPanel.name = "FindItGroupPanel"; m_groupPanel.enabled = true; m_groupPanel.component.isInteractive = true; m_groupPanel.m_OptionsBar = ToolsModifierControl.mainToolbar.m_OptionsBar; m_groupPanel.m_DefaultInfoTooltipAtlas = ToolsModifierControl.mainToolbar.m_DefaultInfoTooltipAtlas; if (ToolsModifierControl.mainToolbar.enabled) { m_groupPanel.RefreshPanel(); } scrollPanel = UIScrollPanel.Create(m_groupPanel.GetComponentInChildren <UIScrollablePanel>()); scrollPanel.eventClicked += OnButtonClicked; scrollPanel.eventVisibilityChanged += (c, p) => { HideAllOptionPanels(); if (p && scrollPanel.selectedItem != null) { // Simulate item click UIScrollPanelItem.ItemData item = scrollPanel.selectedItem; UIScrollPanelItem panelItem = scrollPanel.GetItem(0); panelItem.Display(scrollPanel.selectedItem, 0); panelItem.component.SimulateClick(); scrollPanel.selectedItem = item; scrollPanel.Refresh(); } }; scrollPanel.eventTooltipEnter += (c, p) => { UIScrollPanelItem.RefreshTooltipAltas(p.source); }; searchBox = scrollPanel.parent.AddUIComponent <UISearchBox>(); searchBox.scrollPanel = scrollPanel; searchBox.relativePosition = new Vector3(0, 0); searchBox.Search(); } else { Debugging.Message("GroupPanel not found"); } m_roadsPanel = FindObjectOfType <RoadsPanel>(); m_beautificationPanel = FindObjectOfType <BeautificationPanel>(); defaultPanel = GameObject.Find("FindItDefaultPanel").GetComponent <UIPanel>(); defaultPanelAtlas = defaultPanel.atlas; defaultPanelBackgroundSprite = defaultPanel.backgroundSprite; UpdateDefaultPanelBackground(); Debugging.Message("Initialized"); } catch (Exception e) { Debugging.Message("Start failed"); Debugging.LogException(e); enabled = false; } }
void Start() { mMaxCityRank = 1; mSun = new Sun(); LoadCities(); LoadEarth("Earth-1"); EnableCities(); // Get the Canvas the script is attached to UIElement canvas = new UIElement(gameObject); canvas.AddVerticalLayoutGroup(expandWidth: false, expandHeight: true); // Create a main panel which will include all UI elements UIElement mainPanel = new UIPanel(canvas, "Main Panel"); mainPanel.AddVerticalLayoutGroup(expandWidth: true, padding: new RectOffset(0, 0, 5, 0)); // left, right, top, bottom mainPanel.AddLayoutElement(preferredWidth: 210); // Create a header panel at the top with the title text UIElement titlePanel = new UIEmptyPanel(mainPanel, "Title Panel"); titlePanel.AddVerticalLayoutGroup(expandWidth: true, padding: new RectOffset(5, 5, 0, 0)); // left, right, top, bottom titlePanel.AddLayoutElement(minHeight: 40); new UIText(titlePanel, "UltimaEarth 2.0", fontSize: 18); new UIText(titlePanel, "for uGUI (4.6+)", fontSize: 14); // create a panel for all content below the header panel UIElement contentPanel = new UIPanel(mainPanel, "Content Panel"); contentPanel.AddVerticalLayoutGroup(padding: new RectOffset(5, 5, 5, 0)); // left, right, top, bottom //contentPanel.AddLayoutElement(preferredHeight: 1000); // A group panel is used as a toggle group UIGroupPanel radioGroup = new UIGroupPanel(contentPanel, "Earth Representation"); // The radio buttons will be arranged vertically radioGroup.AddVerticalLayoutGroup(spacing: 0, padding: new RectOffset(5, 0, 0, 5)); // left, right, top, bottom radioGroup.AddLayoutElement(preferredWidth: 210); UIText header1 = new UIText(radioGroup, "Earth Representation", fontSize: 14); header1.AddLayoutElement(preferredWidth: 200, preferredHeight: 30); header1.SetAlignment(TextAnchor.MiddleCenter); UIToggleButton radio1 = new UIToggleButton(radioGroup, "Natural, Ocean Floor", fontSize: controlFontSize); radio1.AddLayoutElement(preferredWidth: 200); // When a toggle button is attached to the group panel it is turns into a radio group // Sets the intial state of this toggle button to 'on' radio1.SetState(isOn: true); radioGroup.AddToggleButton(radio1); radio1.OnValueChanged((v) => { if (v) { LoadEarth("Earth-1"); } }); UIToggleButton radio2 = new UIToggleButton(radioGroup, "Natural, Ocean Floor, Ice", fontSize: controlFontSize); radio2.AddLayoutElement(preferredWidth: 200); // add the second toggle button to the radio group radioGroup.AddToggleButton(radio2); radio2.OnValueChanged((v) => { if (v) { LoadEarth("Earth-1 Polar Ice"); } }); UIToggleButton radio3 = new UIToggleButton(radioGroup, "Natural", fontSize: controlFontSize); radio3.AddLayoutElement(preferredWidth: 200); radioGroup.AddToggleButton(radio3); radio3.OnValueChanged((v) => { if (v) { LoadEarth("Earth-2"); } }); UIToggleButton radio4 = new UIToggleButton(radioGroup, "Natural, Ice", fontSize: controlFontSize); radio4.AddLayoutElement(preferredWidth: 200); radioGroup.AddToggleButton(radio4); radio4.OnValueChanged((v) => { if (v) { LoadEarth("Earth-2 Polar Ice"); } }); UIToggleButton radio5 = new UIToggleButton(radioGroup, "Hypsometric", fontSize: controlFontSize); radio5.AddLayoutElement(preferredWidth: 200); radioGroup.AddToggleButton(radio5); radio5.OnValueChanged((v) => { if (v) { LoadEarth("Earth-3"); } }); UIToggleButton radio6 = new UIToggleButton(radioGroup, "Hypsometric, Ice", fontSize: controlFontSize); radio6.AddLayoutElement(preferredWidth: 200); radioGroup.AddToggleButton(radio6); radio6.OnValueChanged((v) => { if (v) { LoadEarth("Earth-3 Polar Ice"); } }); //------------------------------------------------------------------- // Parameter Panel UIPanel parmPanel = new UIPanel(contentPanel, "Parameter Panel"); parmPanel.AddVerticalLayoutGroup(spacing: 0, padding: new RectOffset(5, 0, 5, 5)); // left, right, top, bottom parmPanel.AddLayoutElement(preferredWidth: 200); UIText header2 = new UIText(parmPanel, "Parameters", fontSize: 14); header2.AddLayoutElement(preferredWidth: 200, preferredHeight: 30); header2.SetAlignment(TextAnchor.MiddleCenter); UIHorizontalSlider slider1 = new UIHorizontalSlider(parmPanel); slider1.SetText("Earth Speed", controlFontSize); slider1.SetValue(mEarth.rotationSpeed); slider1.OnValueChanged((v) => { mEarth.rotationSpeed = v; }); UIHorizontalSlider slider2 = new UIHorizontalSlider(parmPanel); slider2.SetText("Sun Speed", controlFontSize); slider2.SetValue(mSun.rotationSpeed); slider2.OnValueChanged((v) => { mSun.rotationSpeed = v; }); UIHorizontalSlider slider3 = new UIHorizontalSlider(parmPanel); slider3.SetText("Cloud Intensity", controlFontSize); slider3.SetValue(mEarth.cloudIntensity); slider3.OnValueChanged((v) => { mEarth.cloudIntensity = v; }); UIHorizontalSlider slider4 = new UIHorizontalSlider(parmPanel); slider4.SetText("Cloud Speed", controlFontSize); slider4.SetValue(mEarth.cloudSpeed); slider4.OnValueChanged((v) => { mEarth.cloudSpeed = v; }); UIHorizontalSlider slider5 = new UIHorizontalSlider(parmPanel); slider5.SetText("Earth Tilt", controlFontSize); slider5.SetValue(mEarth.tilt); slider5.OnValueChanged((v) => { mEarth.tilt = v; }); UIHorizontalSlider citySlider = new UIHorizontalSlider(parmPanel); citySlider.SetText("Cities", controlFontSize); citySlider.SetMinMaxValue(-1, 8); // -1 means no cities citySlider.SetValue(mMaxCityRank); citySlider.OnValueChanged((v) => { mMaxCityRank = v; EnableCities(); }); //------------------------------------------------------------------- // Info Panel UIPanel infoPanel = new UIPanel(contentPanel, "Info Panel"); infoPanel.AddVerticalLayoutGroup(spacing: 0, padding: new RectOffset(2, 5, 5, 5)); // left, right, top, bottom infoPanel.AddLayoutElement(preferredWidth: 210); UIText infoText1 = new UIText(infoPanel, "There are many more parameters!", fontSize: 12); infoText1.AddLayoutElement(preferredWidth: 200, preferredHeight: 20); infoText1.SetAlignment(TextAnchor.MiddleCenter); UIText infoText2 = new UIText(infoPanel, "Please refer to the PDF manual.", fontSize: 12); infoText2.AddLayoutElement(preferredWidth: 200, preferredHeight: 20); infoText2.SetAlignment(TextAnchor.MiddleCenter); //------------------------------------------------------------------- // Asset Store Panel UIPanel storePanel = new UIPanel(contentPanel, "Store Panel"); storePanel.AddVerticalLayoutGroup(spacing: 0, padding: new RectOffset(2, 5, 5, 5)); // left, right, top, bottom storePanel.AddLayoutElement(preferredWidth: 210); UIText storeText = new UIText(storePanel, "Available from the Unity Asset Store:", fontSize: 12); storeText.AddLayoutElement(preferredWidth: 200, preferredHeight: 40); storeText.SetAlignment(TextAnchor.MiddleCenter); UIButton storeButton = new UIButton(storePanel, "http://www.assetstore.unity3d.com", fontSize: 11); storeButton.AddLayoutElement(preferredWidth: 200, preferredHeight: 40); storeButton.OnValueChanged(() => { Application.ExternalEval("window.open('https://www.assetstore.unity3d.com', '_blank')"); }); //------------------------------------------------------------------- // Website Panel UIPanel sitePanel = new UIPanel(contentPanel, "Website Panel"); sitePanel.AddVerticalLayoutGroup(spacing: 0, padding: new RectOffset(2, 5, 5, 5)); // left, right, top, bottom sitePanel.AddLayoutElement(preferredWidth: 210); UIButton siteButton = new UIButton(sitePanel, "(C) Michael Schmeling\nhttp://www.aridocean.com", fontSize: 11); siteButton.AddLayoutElement(preferredWidth: 200, preferredHeight: 55); siteButton.OnValueChanged(() => { Application.ExternalEval("window.open('http://www.aridocean.com', '_blank')"); }); }