void Start() { // Set up motion variables _moveID = -1; _moveStartPos = Vector2.zero; _moveMin = Screen.width / 32.0f; // TODO: MAKE SURE THIS VALUE NEVER BECOMES TOO LARGE _lastMovePos = Vector2.zero; float dpi = Screen.dpi; if (dpi <= 0) { Debug.LogWarning("Failed to find Screen DPI!"); dpi = 160; // Default value for Android mdpi devices } _distanceForMaxSpeed = InchesForMaxSpeed * dpi; // Set up action variables _actionID = -1; _actionStartPos = Vector2.zero; _actionMin = Screen.width / 32.0f; // TODO: MAKE SURE THIS VALUE NEVER BECOMES TOO LARGE _lastActionPos = Vector2.zero; _speedForInstantAction = _distanceForMaxSpeed * 100.0f; // TODO: DETERMINE A GOOD VALUE FOR THIS // Gonna store the input here _input = GameManager.Player.GetComponent <CharacterInput> (); // Left-hand side GUI _horizontalSlider = (Transform)Instantiate(SliderPrefab, SliderPrefab.position, Quaternion.identity); _verticalSlider = (Transform)Instantiate(SliderPrefab, SliderPrefab.position, Quaternion.Euler(Vector3.forward * 90)); _moveButton = (Transform)Instantiate(MoveButtonPrefab, MoveButtonPrefab.position, MoveButtonPrefab.rotation); _radioWaves = (Transform)Instantiate(RadioPrefab, RadioPrefab.position, RadioPrefab.rotation); // Organize it away _horizontalSlider.parent = transform; _verticalSlider.parent = transform; _moveButton.parent = transform; _radioWaves.parent = transform; // And hide them _horizontalSlider.GetComponent <Renderer>().enabled = false; _verticalSlider.GetComponent <Renderer>().enabled = false; _moveButton.GetComponent <Renderer>().enabled = false; _radioWaves.GetComponent <Renderer>().enabled = false; // Right-hand side GUI _blueCircle = (Transform)Instantiate(BlueCirclePrefab, BlueCirclePrefab.position, BlueCirclePrefab.rotation); Color blueAlpha = _blueCircle.GetComponent <Renderer>().material.color; blueAlpha.a = blueAlpha.a * 0.5f; _blueCircle.GetComponent <Renderer>().material.color = blueAlpha; _selections = (Transform)Instantiate(SelectionsPrefab, SelectionsPrefab.position, SelectionsPrefab.rotation); _jumpSign = (Transform)Instantiate(JumpSignPrefab, JumpSignPrefab.position, JumpSignPrefab.rotation); _attack1Sign = (Transform)Instantiate(AttackSignPrefab, AttackSignPrefab.position, AttackSignPrefab.rotation); _attack2Sign = (Transform)Instantiate(AttackSignPrefab, -AttackSignPrefab.position, AttackSignPrefab.rotation); _pickupSign = (Transform)Instantiate(ItemPickupSignPrefab, ItemPickupSignPrefab.position, ItemPickupSignPrefab.rotation); _glowOff = (Transform)Instantiate(GlowOffPrefab, GlowOffPrefab.position, GlowOffPrefab.rotation); Transform particles = (Transform)Instantiate(ParticlePrefab, ParticlePrefab.position, ParticlePrefab.rotation); _particles = particles.GetComponent <ParticleSystem> (); // Organize them away _blueCircle.parent = transform; _selections.parent = transform; _jumpSign.parent = transform; _attack1Sign.parent = transform; _attack2Sign.parent = transform; _pickupSign.parent = transform; _glowOff.parent = transform; // And hide them _blueCircle.GetComponent <Renderer>().enabled = false; _selections.GetComponent <Renderer>().enabled = false; _jumpSign.GetComponent <Renderer>().enabled = false; _attack1Sign.GetComponent <Renderer>().enabled = false; _attack2Sign.GetComponent <Renderer>().enabled = false; _pickupSign.GetComponent <Renderer>().enabled = false; _glowOff.GetComponent <Renderer>().enabled = false; // The dots indicating the action to the player _uiDots = new List <Transform> (9); for (int i = 0; i < 9; i++) { Transform dot = (Transform)Instantiate(DotPrefab, DotPrefab.position, DotPrefab.rotation); dot.GetComponent <Renderer>().enabled = false; dot.parent = transform; _uiDots.Add(dot); } // The relative positions at which those dots are located _dotPositions = new List <Vector3> (9); Vector3 originPoint = new Vector3(0f, 0f, -0.3f); Vector3 zeroRotation = originPoint + Vector3.right * 9.7f; _dotPositions.Add(originPoint); _dotPositions.Add(zeroRotation); _dotPositions.Add(ZoneGraph.RotatePointAroundPivot(zeroRotation, originPoint, Vector3.forward * 15.0f)); _dotPositions.Add(ZoneGraph.RotatePointAroundPivot(zeroRotation, originPoint, Vector3.forward * 90.0f)); _dotPositions.Add(ZoneGraph.RotatePointAroundPivot(zeroRotation, originPoint, Vector3.forward * 165.0f)); _dotPositions.Add(ZoneGraph.RotatePointAroundPivot(zeroRotation, originPoint, Vector3.forward * 180.0f)); _dotPositions.Add(ZoneGraph.RotatePointAroundPivot(zeroRotation, originPoint, Vector3.forward * 235.0f)); _dotPositions.Add(ZoneGraph.RotatePointAroundPivot(zeroRotation, originPoint, Vector3.forward * 270.0f)); _dotPositions.Add(ZoneGraph.RotatePointAroundPivot(zeroRotation, originPoint, Vector3.forward * 305.0f)); // Set up new update methods to show the GUI elements StartCoroutine(DisplayLeftHandSide()); StartCoroutine(DisplayRightHandSide()); }
// Draw code IEnumerator DisplayRightHandSide() { // We're essentially replicating another update loop for rendering the right hand side while (true) { yield return(null); // Make the images visible as appropriate bool actTouched = _actionID != -1; _blueCircle.GetComponent <Renderer>().enabled = actTouched; _selections.GetComponent <Renderer>().enabled = actTouched; _jumpSign.GetComponent <Renderer>().enabled = actTouched && GameManager.Player.CanInputJump; _attack1Sign.GetComponent <Renderer>().enabled = actTouched && GameManager.Player.CanInputAttack; _attack2Sign.GetComponent <Renderer>().enabled = actTouched && GameManager.Player.CanInputAttack; _pickupSign.GetComponent <Renderer>().enabled = actTouched && GameManager.Player.CanInputPickup; _glowOff.GetComponent <Renderer>().enabled = actTouched; // Make the dots visible as appropriate _uiDots [0].GetComponent <Renderer>().enabled = actTouched; _uiDots [1].GetComponent <Renderer>().enabled = actTouched && GameManager.Player.CanInputAttack; _uiDots [2].GetComponent <Renderer>().enabled = actTouched && (GameManager.Player.CanInputAttack || GameManager.Player.CanInputJump); _uiDots [3].GetComponent <Renderer>().enabled = actTouched && GameManager.Player.CanInputJump; _uiDots [4].GetComponent <Renderer>().enabled = actTouched && (GameManager.Player.CanInputJump || GameManager.Player.CanInputAttack); _uiDots [5].GetComponent <Renderer>().enabled = actTouched && GameManager.Player.CanInputAttack; _uiDots [6].GetComponent <Renderer>().enabled = actTouched && (GameManager.Player.CanInputAttack || GameManager.Player.CanInputPickup); _uiDots [7].GetComponent <Renderer>().enabled = actTouched && GameManager.Player.CanInputPickup; _uiDots [8].GetComponent <Renderer>().enabled = actTouched && (GameManager.Player.CanInputPickup || GameManager.Player.CanInputAttack); // We don't need to move + color things if they're not visible if (!actTouched) { continue; } // Put the images at the correct spot Vector3 pos = ConvertTouchPosToWorldPoint(_actionStartPos); _blueCircle.position = pos; _selections.position = pos + SelectionsPrefab.position; _selections.GetComponent <Renderer>().material.color = Color.white; _jumpSign.position = pos + JumpSignPrefab.position; _jumpSign.GetComponent <Renderer>().material.color = Color.white; _attack1Sign.position = pos + AttackSignPrefab.position; _attack1Sign.GetComponent <Renderer>().material.color = Color.white; _attack2Sign.position = pos + AttackSignPrefab.position + Vector3.left * 2 * AttackSignPrefab.position.x; _attack2Sign.GetComponent <Renderer>().material.color = Color.white; _pickupSign.position = pos + ItemPickupSignPrefab.position; _pickupSign.GetComponent <Renderer>().material.color = Color.white; // Put the dots at the correct position for (int dot = 0; dot < _uiDots.Count; dot++) { _uiDots [dot].transform.position = pos + _dotPositions [dot]; _uiDots [dot].GetComponent <Renderer>().material.color = Color.white; } // Put the glow-off at the correct location float deg = CalculateActionDegree(); Vector3 originPoint = pos + GlowOffPrefab.position; Vector3 zeroRotation = originPoint + Vector3.right * 9.0f; _glowOff.position = ZoneGraph.RotatePointAroundPivot(zeroRotation, originPoint, Vector3.forward * deg); _glowOff.rotation = Quaternion.Euler(Vector3.forward * deg); _glowOff.GetComponent <Renderer>().material.color = Color.white; // Color as appropriate if (IsInteraction(deg)) { _selections.GetComponent <Renderer>().material.color = Color.black; _glowOff.GetComponent <Renderer>().enabled = false; _uiDots [0].GetComponent <Renderer>().material.color = Color.black; } else if (GameManager.Player.CanInputJump && (IsJumpLeft(deg) || IsJumpUp(deg) || IsJumpRight(deg))) { _selections.GetComponent <Renderer>().material.color = Color.blue; _jumpSign.GetComponent <Renderer>().material.color = Color.blue; _glowOff.GetComponent <Renderer>().material.color = Color.blue; if (IsJumpRight(deg)) { _uiDots [2].GetComponent <Renderer>().material.color = Color.blue; } else if (IsJumpUp(deg)) { _uiDots [3].GetComponent <Renderer>().material.color = Color.blue; } if (IsJumpLeft(deg)) { _uiDots [4].GetComponent <Renderer>().material.color = Color.blue; } } else if (GameManager.Player.CanInputAttack && (IsAttackLeft(deg) || IsAttackRight(deg))) { _selections.GetComponent <Renderer>().material.color = Color.red; _glowOff.GetComponent <Renderer>().material.color = Color.red; if (IsAttackRight(deg)) { _attack1Sign.GetComponent <Renderer>().material.color = Color.red; _uiDots [1].GetComponent <Renderer>().material.color = Color.red; _uiDots [2].GetComponent <Renderer>().material.color = Color.red; _uiDots [7].GetComponent <Renderer>().material.color = Color.red; } else if (IsAttackLeft(deg)) { _attack2Sign.GetComponent <Renderer>().material.color = Color.red; _uiDots [4].GetComponent <Renderer>().material.color = Color.red; _uiDots [5].GetComponent <Renderer>().material.color = Color.red; _uiDots [6].GetComponent <Renderer>().material.color = Color.red; } } else if (GameManager.Player.CanInputPickup && IsPickup(deg)) { _selections.GetComponent <Renderer>().material.color = Color.green; _pickupSign.GetComponent <Renderer>().material.color = Color.green; _glowOff.GetComponent <Renderer>().material.color = Color.green; _uiDots [6].GetComponent <Renderer>().material.color = Color.green; _uiDots [7].GetComponent <Renderer>().material.color = Color.green; _uiDots [8].GetComponent <Renderer>().material.color = Color.green; } } }