//
        public void DrawGUI()
        {
            Camera  cam    = Camera.main;
            Vector3 anchor = cam.WorldToScreenPoint(transform.position + new Vector3(0f, 0f, -3f));

            if (anchor.z < 0f)
            {
                return;
            }

            var style = UI.skin.button;

            var size = style.CalcSize(labelAddObject);

            size    = Vector2.Max(size, style.CalcSize(labelRemoveObject));
            size    = Vector2.Max(size, style.CalcSize(labelChangeMaterial));
            size    = Vector2.Max(size, style.CalcSize(labelChangeShader));
            size.x += 40f;

            size.y = 30f;

            Rect position = new Rect(anchor.x, anchor.y, size.x, size.y);

            // Center
            position.x -= 0.5f * size.x;
            position.y += 0.5f * (4f * size.y + 3f * UI.spacing.y);

            //
            position.y = Screen.height - position.y;

            if (UI.Button(position, labelAddObject))
            {
                AddObject();
            }

            position.y += size.y + UI.spacing.y;
            if (UI.Button(position, labelRemoveObject))
            {
                RemoveObject();
            }

            position.y += size.y + UI.spacing.y;
            if (UI.Button(position, labelChangeMaterial))
            {
                ChangeMaterial();
            }

            position.y += size.y + UI.spacing.y;
            if (UI.Button(position, labelChangeShader))
            {
                ChangeShader();
            }
        }
Example #2
0
        //
        public void DrawGUI()
        {
            GUI.skin = UI.skin;

            float dropdownWidth = 200f;
            float buttonWidth   = 30f;
            float commonHeight  = 30f;

            Rect    position  = new Rect(0f, 0f, dropdownWidth, commonHeight);
            Vector2 totalSize = new Vector2(dropdownWidth + 2f * (UI.spacing.x + buttonWidth), commonHeight);

            position.position = UI.Position(totalSize, anchor);

            // Dropdown
            int selected = UI.Dropdown(position, dropdownState);

            if (selected != dropdownState.selected)
            {
                OnValueChanged(selected);
            }

            bool cachedEnabled;

            // Previous
            cachedEnabled = GUI.enabled;
            GUI.enabled   = dropdownState.selected > 0;
            position      = new Rect(position.x + position.width + UI.spacing.x, position.y, buttonWidth, commonHeight);
            if (UI.Button(position, UI.labelArrowLeft))
            {
                OnPrevious();
            }
            GUI.enabled = cachedEnabled;

            // Next
            cachedEnabled = GUI.enabled;
            GUI.enabled   = dropdownState.selected < dropdownState.items.Count - 1;
            position      = new Rect(position.x + position.width + UI.spacing.x, position.y, buttonWidth, commonHeight);
            if (UI.Button(position, UI.labelArrowRight))
            {
                OnNext();
            }
            GUI.enabled = cachedEnabled;

            GUI.skin = null;
        }