Пример #1
0
    /// <summary>
    /// Save the status of the shape(stars,path colors) .
    /// </summary>
    private void SaveShapeStatus(List <Shape> shapes)
    {
        DataManager.SaveShapeStars(TableShape.selectedShape.ID, CommonUtil.GetTableShapeStars(GameObject.FindObjectOfType <Progress> ().starsNumber), shapesManager);
        if (TableShape.selectedShape.ID + 1 <= shapesManager.shapes.Count)
        {
            DataManager.SaveShapeLockedStatus(TableShape.selectedShape.ID + 1, false, shapesManager);
        }

        int compundID = 0;

        foreach (Shape s in shapes)
        {
            if (compoundShape != null)
            {
                compundID = compoundShape.GetShapeIndexByInstanceID(s.GetInstanceID());
            }
            List <Transform> paths = CommonUtil.FindChildrenByTag(s.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]);
                DataManager.SaveShapePathColor(TableShape.selectedShape.ID, compundID, from, to, CommonUtil.FindChildByTag(p, "Fill").GetComponent <Image> ().color, shapesManager);
            }
        }
    }
Пример #2
0
    /// <summary>
    /// Creates the shapes in Groups.
    /// </summary>
    private IEnumerator CreateShapes()
    {
        yield return(0);

        //Clear current shapes list
        shapes.Clear();

        //The ID of the shape
        int ID = 0;

        //The scale ratio for the shape
        float ratio = Mathf.Max(Screen.width, Screen.height) / 1000.0f;

        //The group of the shape
        GameObject shapesGroup = null;

        //The index of the group
        int groupIndex = 0;

        pointersParent.gameObject.SetActive(false);
        groupsParent.gameObject.SetActive(false);

        //Create Shapes inside groups
        for (int i = 0; i < shapesManager.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 + 1);                                                                       //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.GetComponent <RectTransform> ().offsetMax = Vector2.zero;
            tableShapeGameObject.GetComponent <RectTransform> ().offsetMin = Vector2.zero;

            GameObject uiShape = Instantiate(shapesManager.shapes [i].gamePrefab, Vector3.zero, Quaternion.identity) as GameObject;

            uiShape.transform.SetParent(tableShapeGameObject.transform.Find("Content"));

            RectTransform rectTransform = tableShapeGameObject.transform.Find("Content").GetComponent <RectTransform> ();

            uiShape.transform.localScale = new Vector3(ratio * shapeScaleFactor, ratio * shapeScaleFactor);
            uiShape.GetComponent <RectTransform> ().anchoredPosition3D = Vector3.zero;

            List <Shape> shapeComponents = new List <Shape> ();
            if (uiShape.GetComponent <CompoundShape> () != null)
            {
                Shape[] tempS = uiShape.GetComponentsInChildren <Shape> ();
                foreach (Shape s in tempS)
                {
                    shapeComponents.Add(s);
                }
            }
            else
            {
                shapeComponents.Add(uiShape.GetComponent <Shape> ());
            }

            int compoundID;
            for (int s = 0; s < shapeComponents.Count; s++)
            {
                CompoundShape compundShape = shapeComponents [s].transform.parent.GetComponent <CompoundShape> ();
                compoundID = 0;
                if (compundShape != null)
                {
                    compoundID = compundShape.GetShapeIndexByInstanceID(shapeComponents[s].GetInstanceID());
                }

                shapeComponents[s].enabled = false;
                //release unwanted resources
                shapeComponents[s].GetComponent <Animator> ().enabled = false;
                shapeComponents[s].transform.Find("TracingHand").gameObject.SetActive(false);
                shapeComponents[s].transform.Find("Collider").gameObject.SetActive(false);

                Animator[] animators = shapeComponents[s].transform.GetComponentsInChildren <Animator> ();
                foreach (Animator a in animators)
                {
                    a.enabled = false;
                }

                int              from, to;
                string[]         slices;
                List <Transform> paths = CommonUtil.FindChildrenByTag(shapeComponents[s].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(DataManager.GetPathStrKey(ID, compoundID, from, to, shapesManager)))
                    {
                        List <Transform> numbers = CommonUtil.FindChildrenByTag(p.transform.Find("Numbers"), "Number");
                        foreach (Transform n in numbers)
                        {
                            n.gameObject.SetActive(false);
                        }
                        img.fillAmount = 1;
                        img.color      = DataManager.GetShapePathColor(ID, compoundID, from, to, shapesManager);
                    }
                }
            }
            tableShapeGameObject.GetComponent <Button> ().onClick.AddListener(() => GameObject.FindObjectOfType <UIEvents> ().AlbumShapeEvent(tableShapeGameObject.GetComponent <TableShape> ()));

            SettingUpShape(tableShapeComponent, ID, groupIndex); //setting up the shape contents (stars number ,islocked,...)
            shapes.Add(tableShapeComponent);                     //add table shape component to the list
        }

        collectedStarsText.text = collectedStars + "/" + (3 * shapesManager.shapes.Count);
        if (shapesManager.shapes.Count == 0)
        {
            Debug.Log("There are no Shapes found");
        }
        else
        {
            Debug.Log("New shapes have been created");
        }

        GameObject.Find("Loading").SetActive(false);

        pointersParent.gameObject.SetActive(true);
        groupsParent.gameObject.SetActive(true);

        GameObject.FindObjectOfType <ScrollSlider> ().Init();
    }