예제 #1
0
        /// <summary>
        /// Settings up the table shape contents in the table.
        /// </summary>
        /// <param name="tableShape">Table shape reference.</param>
        /// <param name="ID">ID of the shape.</param>
        /// <param name="groupIndex">Index of the group.</param>
        private void SettingUpTableShape(ShapesManager.Shape shape, TableShape tableShape, int ID, int groupIndex)
        {
            if (tableShape == null)
            {
                return;
            }

            shape.isLocked    = AlphabetDataManager.IsShapeLocked(ID);
            shape.starsNumber = AlphabetDataManager.GetShapeStars(ID);

            if (tableShape.ID == 0)
            {
                shape.isLocked = false;
            }

            if (!shape.isLocked)
            {
                tableShape.transform.Find("Cover").gameObject.SetActive(false);
                tableShape.transform.Find("Lock").gameObject.SetActive(false);
            }
            else
            {
                tableShape.transform.Find("Stars").gameObject.SetActive(false);
            }

            //Set Last reached shape
            if (!shape.isLocked)
            {
                if (PlayerPrefs.HasKey(AlphabetDataManager.GetLockedStrKey(ID + 1)))
                {
                    if (AlphabetDataManager.IsShapeLocked(ID + 1))
                    {
                        SetSelectedGroup(groupIndex);
                    }
                }
                else if (!PlayerPrefs.HasKey(AlphabetDataManager.GetStarsStrKey(ID)))
                {
                    SetSelectedGroup(groupIndex);
                }
            }

            tempTransform = tableShape.transform.Find("Stars");

            //Apply the current Stars Rating
            if (shape.starsNumber == ShapesManager.Shape.StarsNumber.ONE)
            {                            //One Star
                tempTransform.Find("FirstStar").GetComponent <Image> ().sprite  = starOn;
                tempTransform.Find("SecondStar").GetComponent <Image> ().sprite = starOff;
                tempTransform.Find("ThirdStar").GetComponent <Image> ().sprite  = starOff;
                collectedStars += 1;
            }
            else if (shape.starsNumber == ShapesManager.Shape.StarsNumber.TWO)
            {                            //Two Stars
                tempTransform.Find("FirstStar").GetComponent <Image> ().sprite  = starOn;
                tempTransform.Find("SecondStar").GetComponent <Image> ().sprite = starOn;
                tempTransform.Find("ThirdStar").GetComponent <Image> ().sprite  = starOff;
                collectedStars += 2;
            }
            else if (shape.starsNumber == ShapesManager.Shape.StarsNumber.THREE)
            {                            //Three Stars
                tempTransform.Find("FirstStar").GetComponent <Image> ().sprite  = starOn;
                tempTransform.Find("SecondStar").GetComponent <Image> ().sprite = starOn;
                tempTransform.Find("ThirdStar").GetComponent <Image> ().sprite  = starOn;
                collectedStars += 3;
            }
            else                                //Zero Stars
            {
                tempTransform.Find("FirstStar").GetComponent <Image> ().sprite  = starOff;
                tempTransform.Find("SecondStar").GetComponent <Image> ().sprite = starOff;
                tempTransform.Find("ThirdStar").GetComponent <Image> ().sprite  = starOff;
            }
        }
예제 #2
0
        /// <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();
        }