예제 #1
0
        /// <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);
            }
        }
예제 #2
0
        /// <summary>
        /// Linear fill method.
        /// </summary>
        private void LinearFill()
        {
            clickPostion = Camera.main.ScreenToWorldPoint(Input.mousePosition);

            Vector3 rotation = path.transform.eulerAngles;

            rotation.z -= path.offset;

            Rect rect = CommonUtil.RectTransformToScreenSpace(path.GetComponent <RectTransform> ());

            Vector3 pos1 = Vector3.zero, pos2 = Vector3.zero;

            if (path.type == Path.ShapeType.Horizontal)
            {
                pos1.x = path.transform.position.x - Mathf.Sin(rotation.z * Mathf.Deg2Rad) * rect.width / 2.0f;
                pos1.y = path.transform.position.y - Mathf.Cos(rotation.z * Mathf.Deg2Rad) * rect.width / 2.0f;

                pos2.x = path.transform.position.x + Mathf.Sin(rotation.z * Mathf.Deg2Rad) * rect.width / 2.0f;
                pos2.y = path.transform.position.y + Mathf.Cos(rotation.z * Mathf.Deg2Rad) * rect.width / 2.0f;
            }
            else
            {
                pos1.x = path.transform.position.x - Mathf.Cos(rotation.z * Mathf.Deg2Rad) * rect.height / 2.0f;
                pos1.y = path.transform.position.y - Mathf.Sin(rotation.z * Mathf.Deg2Rad) * rect.height / 2.0f;

                pos2.x = path.transform.position.x + Mathf.Cos(rotation.z * Mathf.Deg2Rad) * rect.height / 2.0f;
                pos2.y = path.transform.position.y + Mathf.Sin(rotation.z * Mathf.Deg2Rad) * rect.height / 2.0f;
            }

            pos1.z = path.transform.position.z;
            pos2.z = path.transform.position.z;

            GameObject obj1 = GameObject.Find("obj1");

            if (obj1 == null)
            {
                obj1 = new GameObject("obj1");
            }

            GameObject obj2 = GameObject.Find("obj2");

            if (obj2 == null)
            {
                obj2 = new GameObject("obj2");
            }

            if (path.flip)
            {
                Vector3 temp = pos2;
                pos2 = pos1;
                pos1 = temp;
            }

            obj1.transform.position = pos1;
            obj2.transform.position = pos2;

            clickPostion.x           = Mathf.Clamp(clickPostion.x, Mathf.Min(pos1.x, pos2.x), Mathf.Max(pos1.x, pos2.x));
            clickPostion.y           = Mathf.Clamp(clickPostion.y, Mathf.Min(pos1.y, pos2.y), Mathf.Max(pos1.y, pos2.y));
            fillAmount               = Vector2.Distance(clickPostion, pos1) / Vector2.Distance(pos1, pos2);
            pathFillImage.fillAmount = fillAmount;
            CheckPathComplete();
        }
예제 #3
0
        // Update is called once per frame
        void Update()
        {
            //Game Logic is here

            DrawHand(GetCurrentPlatformClickPosition(Camera.main));
            DrawBrightEffect(GetCurrentPlatformClickPosition(Camera.main));

            if (shape == null)
            {
                return;
            }

            if (shape.completed)
            {
                return;
            }

            if (Input.GetMouseButtonDown(0))
            {
                //if (!shape.completed)
                //brightEffect.GetComponent<ParticleEmitter> ().emit = true;

                hit2d = Physics2D.Raycast(GetCurrentPlatformClickPosition(Camera.main), Vector2.zero);
                if (hit2d.collider != null)
                {
                    if (hit2d.transform.tag == "Start")
                    {
                        OnStartHitCollider(hit2d);
                        shape.CancelInvoke();
                        shape.DisableTracingHand();
                        EnableHand();
                    }
                    else if (hit2d.transform.tag == "Collider")
                    {
                        shape.DisableTracingHand();
                        EnableHand();
                    }
                }
            }
            else if (Input.GetMouseButtonUp(0))
            {
                //brightEffect.GetComponent<ParticleEmitter> ().emit = false;
                DisableHand();
                shape.Invoke("EnableTracingHand", 1);
                ResetPath();
            }

            if (!isRunning || path == null || pathFillImage == null)
            {
                return;
            }

            if (path.completed)
            {
                return;
            }

            hit2d = Physics2D.Raycast(GetCurrentPlatformClickPosition(Camera.main), Vector2.zero);
            if (hit2d.collider == null)
            {
                if (correctSFX != null && effectsAudioSource != null)
                {
                    CommonUtil.PlayOneShotClipAt(wrongSFX, Vector3.zero, effectsAudioSource.volume);
                }
                ResetPath();
                return;
            }

            if (path.fillMethod == Path.FillMethod.Radial)
            {
                RadialFill();
            }
            else if (path.fillMethod == Path.FillMethod.Linear)
            {
                LinearFill();
            }
            else if (path.fillMethod == Path.FillMethod.Point)
            {
                PointFill();
            }
        }
예제 #4
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();
        }
 /// <summary>
 /// Save the shape locked status.
 /// </summary>
 /// <param name="ID">The ID of the shape.</param>
 /// <param name="isLocked">Whether the shape is locked or not.</param>
 public static void SaveShapeLockedStatus(int ID, bool isLocked)
 {
     PlayerPrefs.SetInt(GetLockedStrKey(ID), CommonUtil.TrueFalseBoolToZeroOne(isLocked));
     PlayerPrefs.Save();
 }
 /// <summary>
 /// Save the shape stars.
 /// </summary>
 /// <param name="ID">The ID of the shape.</param>
 /// <param name="stars">Stars.</param>
 public static void SaveShapeStars(int ID, ShapesManager.Shape.StarsNumber stars)
 {
     PlayerPrefs.SetInt(GetStarsStrKey(ID), CommonUtil.ShapeStarsNumberEnumToIntNumber(stars));
     PlayerPrefs.Save();
 }