public void Partition(int partitionCount, GameObject pieceReference, GameObject original) { this.outlineRenderers.Clear(); partitions = getPartitions(); GameObject temp; SpriteRenderer sprite = original.GetComponent <SpriteRenderer> (); Vector2 pos; this.original = original.GetComponent <PartitionableObject_v2> (); this.AdjustCamera(); this.partitionPointer = -1; float prevPieceX = 0f; Debug.Log("<color=yellow>PartitionCount clone is " + partitionCount + "</color>"); for (int x = 0; x < partitionCount; x++) { pos = new Vector2(gameObject.transform.position.x, gameObject.transform.position.y); temp = Instantiate(original.GetComponent <PartitionableObject_v2>().partitionPiece, pos, Quaternion.identity); // temp.transform.localScale = new Vector2 (original.transform.localScale.x / partitionCount, original.transform.localScale.y); // temp.transform.localScale = new Vector2 (temp.transform.localScale.x-scaleReduction, temp.transform.localScale.y-scaleReduction); temp.transform.localScale = new Vector2(original.transform.localScale.x / partitionCount + .5f, gameObject.transform.localScale.y); temp.GetComponent <SpriteRenderer> ().sortingLayerName = "Clone Partition"; temp.SetActive(true); temp.name = "partition_" + x; temp.tag = "Partition Instance"; temp.transform.SetParent(gameObject.transform); Bounds cloneBounds = gameObject.GetComponent <SpriteRenderer> ().bounds; Vector2 locPos = new Vector2(cloneBounds.center.x - (cloneBounds.extents.x - (cloneBounds.extents.x / partitionCount)) + prevPieceX, cloneBounds.center.y); temp.transform.position = locPos; temp.AddComponent <RectTransform> (); this.GenerateOutline(temp); prevPieceX += (cloneBounds.size.x / partitionCount); partitions.Add(temp); this.highlightPartition(x, false); } // if (!this.fractionLabel.gameObject.activeInHierarchy) // Debug.LogError ("Fraction Label is DISABLED!!!"); // Debug.Log ("Partition Count: " + partitions.Count); this.fractionLabel.Enable(); this.fractionLabel.UpdateValue(0, partitionCount); }
IEnumerator animateFill() { gameObject.GetComponent <SpriteRenderer> ().enabled = false; List <Vector3> newPositions = new List <Vector3> (); Vector3 originalPosition; int partitionSize = this.partitions.Count; // TODO: Changed from .Capacity int originalPartitionSize = (int)original.GetPartitionCount(); Vector3 reference = GetPositionReference(this.fractionLabel.GetValue(), original.GetValue()); RectTransform rectTransform = original.GetComponent <RectTransform> (); // RectTransform rectTransform = original.GetComponentInChildren<PartitionableObjectOutline> ().gameObject.GetComponent<RectTransform>(); // int smallerPartition; // if (partitionSize < originalPartitionSize) { // smallerPartition = partitionSize; // } else { // smallerPartition = originalPartitionSize; // } // int computedSize; // if (partitionSize < originalPartitionSize) { //// computedSize = partitionSize / originalPartitionSize; // computedSize = originalPartitionSize / partitionSize; // } // else { // computedSize = partitionSize / originalPartitionSize; //// computedSize = originalPartitionSize / partitionSize; // } // If correct if (original.isFilled(this.partitionPointer + 1, this.partitions.Count)) { for (int i = 0; i < partitionSize; i++) { // If partition is highlighted, go to reference bottom if (partitions [i].gameObject.GetComponent <SpriteRenderer> ().color == highlightColor) { originalPosition = new Vector3(partitions [i].gameObject.transform.position.x, reference.y, partitions [i].gameObject.transform.position.z); } else { originalPosition = new Vector3(partitions [i].gameObject.transform.position.x, reference.y, partitions [i].gameObject.transform.position.z); } newPositions.Add(originalPosition); } } else { for (int i = 0; i < partitionSize; i++) { // If partition is highlighted, go to reference bottom if (partitions [i].gameObject.GetComponent <SpriteRenderer> ().color == highlightColor) { originalPosition = new Vector3(partitions [i].gameObject.transform.position.x, reference.y, partitions [i].gameObject.transform.position.z); } else { originalPosition = partitions [i].transform.position; partitions [i].gameObject.SetActive(false); } newPositions.Add(originalPosition); } } // for (int i = 0; i < partitionSize; i++) { // // // If Correct (original is filled) // if (original.isFilled (this.partitionPointer + 1, this.partitions.Count)) { // // // If not highlighted, stay (Note: Original has partitions reversed) // if (original.GetPartitions()[i].gameObject.GetComponent<SpriteRenderer> ().color == original.GetHighlightColor()) { // // originalPosition = partitions [i].transform.position; // partitions [i].gameObject.SetActive (false); //// this.outlineRenderers [i].startColor = highlightColor; //// this.outlineRenderers [i].endColor = highlightColor; // } // // // If highlighted, animate to a certain position // else { //// originalPosition = new Vector3 (original.GetPartitions () [i].gameObject.transform.position.x, //// reference.y, partitions [i].gameObject.transform.position.z); // originalPosition = new Vector3 (partitions [i].gameObject.transform.position.x, // reference.y, partitions [i].gameObject.transform.position.z); // // //// partitions[i].gameObject.GetComponent<SpriteRenderer> ().enabled = false; // // new Vector3 (original.GetPartitions () [i].gameObject.transform.position.x, // // original.gameObject.transform.position.y, partitions [i].gameObject.transform.position.z); // } // } // // If wrong // else { // // If highlighted // if (partitions [i].gameObject.GetComponent<SpriteRenderer> ().color == highlightColor) { //// originalPosition = new Vector3 (partitions [i].gameObject.transform.position.x, //// original.gameObject.transform.position.y + rectTransform.rect.height, partitions [i].gameObject.transform.position.z); // //// originalPosition = new Vector3 (partitions [i].gameObject.transform.position.x, //// reference.y, partitions [i].gameObject.transform.position.z); // // originalPosition = new Vector3 (partitions [i].gameObject.transform.position.x, // reference.y, partitions [i].gameObject.transform.position.z); // //// partitions [i].gameObject.GetComponent<SpriteRenderer> ().color = filledColor; //// this.ChangeColorOutline (i, filledOutlineColor); // } // // If not highlighted // else { // originalPosition = partitions [i].transform.position; // partitions [i].gameObject.SetActive (false); // } // } // newPositions.Add (originalPosition); // } Vector3 newPosition = newPositions [0]; // new Vector3 (original.GetPartitions()[0].gameObject.transform.position.x, original.gameObject.transform.position.y, partitions [0].gameObject.transform.position.z); SoundManager.Instance.Play(AudibleNames.LCDInterface.INCREASE, false); this.ChangeSpriteOpacity(0.0f); // this.spriteRenderer.color = Color.clear; // Hide sprite renderer yield return(new WaitForSecondsRealtime(0.4f)); this.ColorActivePartitions(); // Change the selected partitions to gold yield return(new WaitForSecondsRealtime(0.9f)); // Wait for a while to show the clone fill while (partitions [0].gameObject.transform.position != newPosition) { for (int i = 0; i < partitionSize; i++) { if (partitions[i].gameObject.activeInHierarchy) { partitions [i].gameObject.transform.position = Vector3.MoveTowards(partitions[i].gameObject.transform.position, newPositions[i], animationSpeed * Time.unscaledDeltaTime); } // partitions [i].gameObject.transform.position = Vector3.MoveTowards (partitions[i].gameObject.transform.position, // new Vector3(partitions[i].gameObject.transform.position.x, partitions[i].gameObject.transform.position.y-10, partitions[i].gameObject.transform.position.z), // animationSpeed*Time.unscaledDeltaTime); } yield return(null); } // SoundManager.Instance.Play (AudibleNames.LCDInterface.DECREASE, false); // TODO Sound // yield return new WaitForSecondsRealtime (0.5f); if (this.isCorrect) { resultsUI.PlaySuccess(); Debug.Log("<color=red>ENTER RESULTS</color>"); while (resultsUI.IsPlaying()) { Debug.Log("<color=red>ISPLAYING</color>"); yield return(null); } this.original.GetHintBubbleManager().Deactivate(); this.original.GetHintBubbleManager().HideHint(); yield return(new WaitForSecondsRealtime(0.5f)); } else { // Show what's wrong // yield return new WaitForSecondsRealtime(1.0f); SoundManager.Instance.Play(AudibleNames.LCDInterface.DECREASE, false); // TODO Sound // SoundManager.Instance.Play (AudibleNames.Results.MISTAKE, false); } yield return(new WaitForSecondsRealtime(0.5f)); if (!isCorrect) { SoundManager.Instance.Play(AudibleNames.Results.MISTAKE, false); } Debug.Log("<color=red>EXIT RESULTS</color>"); // yield return new WaitForSeconds (completionPause); // pauseController.HideOverlay (); this.transform.parent.gameObject.GetComponent <PartitionableObject_v2> ().Fill(this.partitionPointer + 1, this.partitions.Count); original.ClearPartitions(); original.SetFilling(false); Destroy(gameObject); GameController_v7.Instance.GetPauseController().Continue(); }