/// <summary> /// Release the coroutine. /// </summary> /// <returns>The coroutine.</returns> private IEnumerator ReleaseCoroutine() { Image image = CommonUtil.FindChildByTag(transform, "Fill").GetComponent <Image> (); while (image.fillAmount > 0) { image.fillAmount -= 0.02f; yield return(new WaitForSeconds(0.005f)); } }
/// <summary> /// On the start hit collider event. /// </summary> /// <param name="hit2d">Hit2d.</param> private void OnStartHitCollider(RaycastHit2D hit2d) { path = hit2d.transform.GetComponentInParent <Path> (); pathFillImage = CommonUtil.FindChildByTag(path.transform, "Fill").GetComponent <Image> (); if (path.completed || !shape.IsCurrentPath(path)) { ReleasePath(); } else { path.StopAllCoroutines(); CommonUtil.FindChildByTag(path.transform, "Fill").GetComponent <Image> ().color = colorPallet; } }
/// <summary> /// Create new shape. /// </summary> private void CreateShape() { timer.Reset(); winEffect.gameObject.SetActive(false); GameObject.Find("ResetConfirmDialog").GetComponent <Dialog> ().Hide(); Area.Hide(); winDialog.Hide(); GameObject.Find("NextButton").GetComponent <Animator> ().SetBool("Select", false); Shape shapeComponent = GameObject.FindObjectOfType <Shape> (); if (shapeComponent != null) { Destroy(shapeComponent.gameObject); } try { shapeOrder.text = (ShapesManager.Shape.selectedShapeID + 1) + "/" + ShapesManager.instance.shapes.Count; ShapesManager.instance.lastSelectedGroup = ShapesManager.Shape.selectedShapeID - 1; GameObject shapePrefab = ShapesManager.instance.GetCurrentShape().gamePrefab; GameObject shapeGameObject = Instantiate(shapePrefab, Vector3.zero, Quaternion.identity) as GameObject; shapeGameObject.transform.SetParent(shapeParent); shapeGameObject.transform.localPosition = shapePrefab.transform.localPosition; shapeGameObject.name = shapePrefab.name; shapeGameObject.transform.localScale = shapePrefab.transform.localScale; shape = GameObject.FindObjectOfType <Shape> (); } catch (System.Exception ex) { //Catch the exception or display an alert } if (shape == null) { return; } Spell(); if (writeText != null) { writeText.text = "Write the " + shapeLabel.ToLower() + " '" + shape.GetTitle() + "'"; } Transform restConfirmMessage = CommonUtil.FindChildByTag(GameObject.Find("ResetConfirmDialog").transform, "Message"); restConfirmMessage.GetComponent <Text> ().text = "Reset " + shapeLabel + " " + shape.GetTitle() + " ?"; EnableGameManager(); }
/// <summary> /// On shape completed event. /// </summary> private void OnShapeComplete() { //brightEffect.GetComponent<ParticleEmitter> ().emit = false; Animator shapeAnimator = shape.GetComponent <Animator> (); shapeAnimator.SetBool(shape.name, false); shapeAnimator.SetTrigger("Completed"); //ShapesManager.Shape.StarsNumber collectedStars = Progress.instance.starsNumber; //AlphabetDataManager.SaveShapeStars(ShapesManager.Shape.selectedShapeID, collectedStars); //if (ShapesManager.Shape.selectedShapeID + 1 < ShapesManager.instance.shapes.Count) //{ //AlphabetDataManager.SaveShapeLockedStatus (ShapesManager.Shape.selectedShapeID+ 1, false); //} List <Transform> paths = CommonUtil.FindChildrenByTag(shape.transform.Find("Paths"), "Path"); int from, to; string [] slices; foreach (Transform p in paths) { slices = p.name.Split('-'); from = int.Parse(slices [1]); to = int.Parse(slices [2]); AlphabetDataManager.SaveShapePathColor(ShapesManager.Shape.selectedShapeID, from, to, CommonUtil.FindChildByTag(p, "Fill").GetComponent <Image> ().color); } winParticles.Play(); brightCG.alpha = 1; onWinImediateBlock.Execute(); //StartCoroutine(AfterComplete()); }
/// <summary> /// On shape completed event. /// </summary> private void OnShapeComplete() { DisableHand(); //brightEffect.GetComponent<ParticleEmitter> ().emit = false; Animator shapeAnimator = shape.GetComponent <Animator> (); shapeAnimator.SetBool(shape.name, false); shapeAnimator.SetTrigger("Completed"); ShapesManager.Shape.StarsNumber collectedStars = Progress.instance.starsNumber; AlphabetDataManager.SaveShapeStars(ShapesManager.Shape.selectedShapeID, collectedStars); if (ShapesManager.Shape.selectedShapeID + 1 < ShapesManager.instance.shapes.Count) { AlphabetDataManager.SaveShapeLockedStatus(ShapesManager.Shape.selectedShapeID + 1, false); } List <Transform> paths = CommonUtil.FindChildrenByTag(shape.transform.Find("Paths"), "Path"); int from, to; string [] slices; foreach (Transform p in paths) { slices = p.name.Split('-'); from = int.Parse(slices [1]); to = int.Parse(slices [2]); AlphabetDataManager.SaveShapePathColor(ShapesManager.Shape.selectedShapeID, from, to, CommonUtil.FindChildByTag(p, "Fill").GetComponent <Image> ().color); } timer.Stop(); Area.Show(); winDialog.Show(); GameObject.Find("NextButton").GetComponent <Animator> ().SetTrigger("Select"); winEffect.gameObject.SetActive(true); if (correctSFX != null && effectsAudioSource != null) { CommonUtil.PlayOneShotClipAt(completedSFX, Vector3.zero, effectsAudioSource.volume); } }
/// <summary> /// Creates the shapes in Groups. /// </summary> private IEnumerator CreateShapes() { yield return(0); //The ID of the shape int ID = 0; pointersParent.gameObject.SetActive(false); groupsParent.gameObject.SetActive(false); //The group of the shape GameObject shapesGroup = null; //The index of the group int groupIndex = 0; //Create Shapes inside groups for (int i = 0; i < ShapesManager.instance.shapes.Count; i++) { if (i % shapesPerGroup == 0) { groupIndex = (i / shapesPerGroup); shapesGroup = Group.CreateGroup(shapesGroupPrefab, groupsParent, groupIndex, columnsPerGroup); if (!EnableGroupGridLayout) { shapesGroup.GetComponent <GridLayoutGroup>().enabled = false; } if (createGroupsPointers) { Pointer.CreatePointer(groupIndex, shapesGroup, pointerPrefab, pointersParent); } } //Create Shape ID = (i); //the id of the shape GameObject tableShapeGameObject = Instantiate(shapePrefab, Vector3.zero, Quaternion.identity) as GameObject; tableShapeGameObject.transform.SetParent(shapesGroup.transform); //setting up the shape's parent TableShape tableShapeComponent = tableShapeGameObject.GetComponent <TableShape> (); //get TableShape Component tableShapeComponent.ID = ID; //setting up shape ID tableShapeGameObject.name = "Shape-" + ID; //shape name tableShapeGameObject.transform.localScale = Vector3.one; tableShapeGameObject.transform.localPosition = Vector3.zero; tableShapeGameObject.GetComponent <RectTransform> ().offsetMax = Vector2.zero; tableShapeGameObject.GetComponent <RectTransform> ().offsetMin = Vector2.zero; GameObject uiShape = Instantiate(ShapesManager.instance.shapes[i].gamePrefab, Vector3.zero, Quaternion.identity) as GameObject; uiShape.transform.SetParent(tableShapeGameObject.transform.Find("Content")); RectTransform rectTransform = tableShapeGameObject.transform.Find("Content").GetComponent <RectTransform>(); float ratio = Mathf.Max(Screen.width, Screen.height) / 1000.0f; //set up the scale uiShape.transform.localScale = new Vector3(ratio * 0.7f, ratio * 0.7f); uiShape.GetComponent <RectTransform>().anchoredPosition3D = Vector3.zero; //release unwanted resources uiShape.GetComponent <Shape>().enabled = false; uiShape.GetComponent <Animator>().enabled = false; uiShape.transform.Find("TracingHand").gameObject.SetActive(false); uiShape.transform.Find("Collider").gameObject.SetActive(false); Animator[] animators = uiShape.transform.GetComponentsInChildren <Animator>(); foreach (Animator a in animators) { a.enabled = false; } int from, to; string [] slices; List <Transform> paths = CommonUtil.FindChildrenByTag(uiShape.transform.Find("Paths"), "Path"); foreach (Transform p in paths) { slices = p.name.Split('-'); from = int.Parse(slices [1]); to = int.Parse(slices [2]); p.Find("Start").gameObject.SetActive(false); Image img = CommonUtil.FindChildByTag(p, "Fill").GetComponent <Image>(); if (PlayerPrefs.HasKey(AlphabetDataManager.GetPathStrKey(ID, from, to))) { List <Transform> numbers = CommonUtil.FindChildrenByTag(p.transform.Find("Numbers"), "Number"); foreach (Transform n in numbers) { n.gameObject.SetActive(false); } img.fillAmount = 1; img.color = AlphabetDataManager.GetShapePathColor(ID, from, to); } } tableShapeGameObject.GetComponent <Button> ().onClick.AddListener(() => GameObject.FindObjectOfType <UIEvents> ().AlbumShapeEvent(tableShapeGameObject.GetComponent <TableShape> ())); SettingUpTableShape(ShapesManager.instance.shapes[ID], tableShapeComponent, ID, groupIndex); //setting up the shape contents (stars number ,islocked,...etc) } collectedStarsText.text = collectedStars + "/" + (3 * ShapesManager.instance.shapes.Count); if (ShapesManager.instance.shapes.Count == 0) { Debug.Log("There are no Shapes found"); } else { Debug.Log("New shapes have been created"); } loading.SetActive(false); pointersParent.gameObject.SetActive(true); groupsParent.gameObject.SetActive(true); ScrollSlider.instance.Init(); }