Ejemplo n.º 1
0
    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')");
        });
    }