private static ColorSlider CreateSlider(ColorValueType type) { ColorPicker picker = GetColorPicker(); GameObject result; if (CreateGameObject(out result)) { SetRectTransformSize(result.transform as RectTransform, 160, 20); result.name = "Slider_" + type.ToString(); // Background CreateGradientBackground(type); // Handle slider area RectTransform handleArea = new GameObject("HandleArea").AddComponent<RectTransform>(); handleArea.SetParent(result.transform, false); SetRectTransformSize(handleArea, Vector2.zero, Vector2.one, new Vector2(2.5f, 2.5f)); // Handle RectTransform handleRect = new GameObject("Handle").AddComponent<RectTransform>(); handleRect.SetParent(handleArea, false); handleRect.offsetMin = Vector2.zero; handleRect.offsetMax = Vector2.zero; handleRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 6f); Image handle = handleRect.gameObject.AddComponent<Image>(); handle.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/Knob.psd"); // Slider Slider slider = result.AddComponent<Slider>(); slider.handleRect = handleRect; slider.targetGraphic = handle; // ColorSlider ColorSlider colorSlider = result.AddComponent<ColorSlider>(); colorSlider.Type = type; colorSlider.Picker = picker; Selection.activeGameObject = result.gameObject; return colorSlider; } return null; }
private static void CreateInput(ColorValueType type) { ColorPicker picker = GetColorPicker(); GameObject result; if (CreateGameObject(out result)) { SetRectTransformSize(result.transform as RectTransform, 50, 20); result.name = "Input_" + type.ToString(); InputField input = AddInput(result, 0, 0); input.textComponent.alignment = TextAnchor.MiddleCenter; input.characterValidation = InputField.CharacterValidation.Decimal; input.keyboardType = TouchScreenKeyboardType.NumbersAndPunctuation; ColorInput colorInput = result.AddComponent<ColorInput>(); colorInput.Type = type; colorInput.SetDefaultMinMax(); colorInput.Picker = picker; } }