public void InitGame() { // Get Cube and instatiate IEnumerable <Toggle> activeToggles = previewToggles.ActiveToggles(); foreach (Toggle cubeToggle in activeToggles) { if (cubeToggle.isOn) { CubeSelector selector = cubeToggle.GetComponent <CubeSelector>(); if (selector) { GameObject cubeGameObject = Instantiate(selector.cubePrefab, cubePlaceholder.position, cubePlaceholder.rotation); cube = cubeGameObject.GetComponent <RubiksCube>(); break; } } } // set Timer countDown = timerToggle.isOn; timer = countDown ? float.Parse(timerInput.text) : 0f; // set Scrambles cube.StartScrambling(int.Parse(scrambleInput.text)); }
private void Setup(Color inputColor) { var satvalGO = GO("SaturationValue"); var satvalKnob = GO("SaturationValue/Knob"); var hueGO = GO("Hue"); var hueKnob = GO("Hue/Knob"); var result = GO("Result"); var hueColors = new Color [] { Color.red, Color.yellow, Color.green, Color.cyan, Color.blue, Color.magenta, }; var satvalColors = new Color [] { new Color(0, 0, 0), new Color(0, 0, 0), new Color(1, 1, 1), hueColors[0], }; var hueTex = new Texture2D(1, 7); for (int i = 0; i < 7; i++) { hueTex.SetPixel(0, i, hueColors[i % 6]); } hueTex.Apply(); hueGO.GetComponent <Image>().sprite = Sprite.Create(hueTex, new Rect(0, 0.5f, 1, 6), new Vector2(0.5f, 0.5f)); var hueSz = GetWidgetSize(hueGO); var satvalTex = new Texture2D(2, 2); satvalGO.GetComponent <Image>().sprite = Sprite.Create(satvalTex, new Rect(0.5f, 0.5f, 1, 1), new Vector2(0.5f, 0.5f)); Action resetSatValTexture = () => { for (int j = 0; j < 2; j++) { for (int i = 0; i < 2; i++) { satvalTex.SetPixel(i, j, satvalColors[i + j * 2]); } } satvalTex.Apply(); }; var satvalSz = GetWidgetSize(satvalGO); float Hue, Saturation, Value; RGBToHSV(inputColor, out Hue, out Saturation, out Value); Action applyHue = () => { var i0 = Mathf.Clamp(( int )Hue, 0, 5); var i1 = (i0 + 1) % 6; var resultColor = Color.Lerp(hueColors[i0], hueColors[i1], Hue - i0); satvalColors[3] = resultColor; resetSatValTexture(); }; Action applySaturationValue = () => { var sv = new Vector2(Saturation, Value); var isv = new Vector2(1 - sv.x, 1 - sv.y); var c0 = isv.x * isv.y * satvalColors[0]; var c1 = sv.x * isv.y * satvalColors[1]; var c2 = isv.x * sv.y * satvalColors[2]; var c3 = sv.x * sv.y * satvalColors[3]; var resultColor = c0 + c1 + c2 + c3; var resImg = result.GetComponent <Image>(); resImg.color = resultColor; if (_color != resultColor) { if (_onValueChange != null) { _onValueChange(resultColor); } _color = resultColor; } }; applyHue(); applySaturationValue(); satvalKnob.transform.localPosition = new Vector2(Saturation * satvalSz.x, Value * satvalSz.y); hueKnob.transform.localPosition = new Vector2(hueKnob.transform.localPosition.x, Hue / 6 * satvalSz.y); CubeSelector.AssignColorToCube(); Action dragH = null; Action dragSV = null; Action idle = () => { if (Input.GetMouseButtonDown(0)) { Vector2 mp; if (GetLocalMouse(hueGO, out mp)) { _update = dragH; } else if (GetLocalMouse(satvalGO, out mp)) { _update = dragSV; } } }; dragH = () => { Vector2 mp; GetLocalMouse(hueGO, out mp); Hue = mp.y / hueSz.y * 6; applyHue(); applySaturationValue(); hueKnob.transform.localPosition = new Vector2(hueKnob.transform.localPosition.x, mp.y); if (Input.GetMouseButtonUp(0)) { _update = idle; } }; dragSV = () => { Vector2 mp; GetLocalMouse(satvalGO, out mp); Saturation = mp.x / satvalSz.x; Value = mp.y / satvalSz.y; applySaturationValue(); satvalKnob.transform.localPosition = mp; if (Input.GetMouseButtonUp(0)) { _update = idle; } }; _update = idle; }
private void Awake() { originalColor = GetComponent <MeshRenderer>().material.color; // stores original color cubeSelector = FindObjectOfType <CubeSelector>(); // finds the 1st Cube Selector (should only be 1 per scene) speed = cubeSelector.cubeSpeed; // gets the speed from the cube spawner }
void Awake() { instance = this; }