示例#1
0
文件: Equipment.cs 项目: yinlei/iss
    protected virtual void Start()
    {
        Config = GameObject.FindWithTag("Config").GetComponent <Config> ();
        Trans  = transform;

        Available = AvailableAtStart;

        // there is some realy black magic going on in here
        // can't explain that to anyone
        // just to find out the tween target of this GameObject
        TweenTargets = new System.Object[0];
        foreach (TweenInfo tweenInfo in HOTween.GetTweenInfos())
        {
            System.Object obj = tweenInfo.targets[0];

            foreach (Component component in gameObject.GetComponents <Component>())
            {
                if (component.Equals(obj))
                {
                    int oldSize = TweenTargets.Length;
                    System.Array.Resize <System.Object> (ref TweenTargets, oldSize + 1);
                    TweenTargets[oldSize] = obj; // all for this stupid line of code
                }
            }
        }

        foreach (Object tweenTarget in TweenTargets)
        {
            HOTween.Complete(tweenTarget);    // set to stored position
        }
    }
    void Update()
    {
        if (gameIsRunning)
        {
            timer += Time.deltaTime;
            if (timer >= 1.0f)
            {
                timeRemaining--;
                timer         = 0.0f;
                timeText.text = "Time: " + timeRemaining;
                CheckTimeRemaining();
            }

            bool shouldTransit = false;

            // Check if the player clicked on the left mouse button and if there is no animation playing
            if (Input.GetButtonDown("Fire1") && HOTween.GetTweenInfos() == null)
            {
                Destroy(currentIndicator);

                // Get the clicked GameObject
                RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);

                if (hit.transform != null)
                {
                    // Check if the user already selected a gem
                    if (firstObject == null)
                    {
                        firstObject = hit.transform.gameObject;
                    }
                    else
                    {
                        secondObject  = hit.transform.gameObject;
                        shouldTransit = true;
                    }

                    // Set the current indicator
                    AudioManager.Instance.PlayAudioClip(AudioManager.Instance.sfxSelectItem);
                    currentIndicator = GameObject.Instantiate(indicator, new Vector3(hit.transform.position.x,
                                                                                     hit.transform.position.y, -1),
                                                              transform.rotation) as GameObject;

                    // If two gems are selected, we will swap them
                    if (shouldTransit)
                    {
                        // Get the distance between the 2 gems
                        var distance = firstObject.transform.position - secondObject.transform.position;

                        // Check if they are neighbors, otherwise we will NOT swap them
                        if (Mathf.Abs(distance.x) <= 1 && Mathf.Abs(distance.y) <= 1)
                        {
                            // If we dont want the player to swap diagonally
                            if (!canTransitDiagonally)
                            {
                                if (distance.x != 0 && distance.y != 0)
                                {
                                    Destroy(currentIndicator);
                                    firstObject  = null;
                                    secondObject = null;
                                    return;
                                }
                            }

                            // Animate the transition
                            DoSwapMotion(firstObject.transform, secondObject.transform);
                            // Swap the objects in the array of shapes
                            DoSwapTile(firstObject, secondObject, ref arrayOfShapes);
                        }
                        // Otherwise, the gems are NOT neighbors, so don't do anything
                        else
                        {
                            firstObject  = null;
                            secondObject = null;
                        }
                        Destroy(currentIndicator);
                    }
                }
            }

            // If no animation is playing
            if (HOTween.GetTweenInfos() == null)
            {
                // Search for matches
                var Matches = FindMatch(arrayOfShapes);

                // If we find any matches
                if (Matches.Count > 0)
                {
                    // Update the score
                    UpdateScore(Matches.Count * scoreIncrement);

                    // Play the matching sound
                    AudioManager.Instance.PlayAudioClip(AudioManager.Instance.sfxPoint);

                    foreach (GameObject go in Matches)
                    {
                        // Create and destroy the particle effect for matching
                        var destroyingParticle = GameObject.Instantiate(particleEffectWhenMatch as GameObject, new Vector3(go.transform.position.x, go.transform.position.y, -2), transform.rotation) as GameObject;
                        Destroy(destroyingParticle, 1f);

                        // Replace the matching space with an empty object
                        arrayOfShapes[(int)go.transform.position.x, (int)go.transform.position.y] = GameObject.Instantiate(emptyGameobject, new Vector3((int)go.transform.position.x, (int)go.transform.position.y, -1), transform.rotation) as GameObject;

                        //Destroy the matching gems
                        Destroy(go, 0.1f);
                    }

                    firstObject  = null;
                    secondObject = null;

                    // Move the gems down to replace the empty objects
                    DoEmptyDown(ref arrayOfShapes);
                }
                // If no matching gems are found, remake the gems at their places
                else if (firstObject != null && secondObject != null)
                {
                    // Animate the gems
                    DoSwapMotion(firstObject.transform, secondObject.transform);
                    // Swap the gems in the array of shapes
                    DoSwapTile(firstObject, secondObject, ref arrayOfShapes);

                    firstObject  = null;
                    secondObject = null;
                }
            }
        }
    }     // END OF: Update()
示例#3
0
        // ===================================================================================
        // UNITY METHODS ---------------------------------------------------------------------

        override public void OnInspectorGUI()
        {
            HOGUIStyle.InitGUI();

            EditorGUIUtility.LookLikeControls(_labelsWidth, _fieldsWidth);

            GUILayout.Space(4);
#if MICRO
            GUILayout.Label("HOTweenMicro v" + HOTween.VERSION);
#else
            GUILayout.Label("HOTween v" + HOTween.VERSION);
#endif
            GUILayout.Space(4);

            TweenInfo[] twInfos = HOTween.GetTweenInfos();
            if (twInfos == null)
            {
                GUILayout.Label("No tweens");
                return;
            }

            // Store and display tot running/paused/disabled tweens.
            int totTweens = twInfos.Length;
            List <TweenInfo> runningTweens   = new List <TweenInfo>();
            List <TweenInfo> pausedTweens    = new List <TweenInfo>();
            List <TweenInfo> completedTweens = new List <TweenInfo>();
            List <TweenInfo> disabledTweens  = new List <TweenInfo>();
            foreach (TweenInfo twInfo in twInfos)
            {
                if (!twInfo.isEnabled)
                {
                    disabledTweens.Add(twInfo);
                }
                else if (twInfo.isComplete)
                {
                    completedTweens.Add(twInfo);
                }
                else if (twInfo.isPaused)
                {
                    pausedTweens.Add(twInfo);
                }
                else
                {
                    runningTweens.Add(twInfo);
                }
            }
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.Label("Tweens (tot - running/paused/completed/disabled):\n" + totTweens + " - " + runningTweens.Count + "/" + "/" + pausedTweens.Count + "/" + completedTweens.Count + "/" + disabledTweens.Count);
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            // Draw play/pause/kill all buttons
            GUILayout.Space(4);
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Play All", HOGUIStyle.BtTinyStyle, GUILayout.Width(76)))
            {
                HOTween.Play();
            }
            if (GUILayout.Button("Pause All", HOGUIStyle.BtTinyStyle, GUILayout.Width(76)))
            {
                HOTween.Pause();
            }
            if (GUILayout.Button("Complete All", HOGUIStyle.BtTinyStyle, GUILayout.Width(86)))
            {
                HOTween.Complete();
            }
            if (GUILayout.Button("Kill All", HOGUIStyle.BtTinyStyle, GUILayout.Width(76)))
            {
                HOTween.Kill();
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            // Display data for each tween (divided by running/paused/completed/disabled)
            for (int i = 0; i < 4; ++i)
            {
                TweenGroup       twGroup;
                List <TweenInfo> targetInfos;
                string           groupLabel;
                switch (i)
                {
                case 0:
                    twGroup     = TweenGroup.Running;
                    targetInfos = runningTweens;
                    groupLabel  = "Running";
                    break;

                case 1:
                    twGroup     = TweenGroup.Paused;
                    targetInfos = pausedTweens;
                    groupLabel  = "Paused";
                    break;

                case 2:
                    twGroup     = TweenGroup.Completed;
                    targetInfos = completedTweens;
                    groupLabel  = "Completed but not killed";
                    break;

                default:
                    twGroup     = TweenGroup.Disabled;
                    targetInfos = disabledTweens;
                    groupLabel  = "Disabled";
                    break;
                }

                if (targetInfos.Count == 0)
                {
                    continue;
                }
                GUILayout.Space(8);
                GUILayout.BeginVertical(HOGUIStyle.BoxStyleRegular);
                GUILayout.BeginHorizontal();
                GUILayout.Label(groupLabel + " Tweens (" + targetInfos.Count + ")", HOGUIStyle.TitleStyle, GUILayout.ExpandWidth(false));
                GUILayout.FlexibleSpace();
                GUILayout.Label("Click a target to select it");
                GUILayout.EndHorizontal();
                GUILayout.Space(6);
                foreach (TweenInfo twInfo in targetInfos)
                {
                    GUILayout.BeginVertical(GUI.skin.box);
                    if (twInfo.isSequence)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label("[Sequence]", HOGUIStyle.LabelSmallStyle);
                        if (twGroup != TweenGroup.Disabled)
                        {
                            DrawTargetButtons(twInfo, twGroup);
                        }
                        GUILayout.EndHorizontal();
                        DrawInfo(twInfo);
                        foreach (object twTarget in twInfo.targets)
                        {
                            DrawTarget(twInfo, twTarget, twGroup, true);
                        }
                    }
                    else
                    {
                        DrawTarget(twInfo, twInfo.targets[0], twGroup, false);
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndVertical();
            }
        }
示例#4
0
文件: Main.cs 项目: ssataree/ssagree
    // Update is called once per frame
    void Update()
    {
        bool shouldTransit = false;
        var  direction     = Swipe();

        if (direction != Direction.NONE)
        {
            //Detecting if the player clicked on the left mouse button and also if there is no animation playing
            if (HOTween.GetTweenInfos() == null)
            {
                Destroy(_currentIndicator);
                //The 3 following lines is to get the clicked GameObject and getting the RaycastHit2D that will help us know the clicked object
                //Ray ray   = Camera.main.ScreenPointToRay (Input.mousePosition);
                RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(_firstPressPos), Vector2.zero);
                if (hit.transform != null)
                {  //To know if the user already selected a tile or not yet
                    if (_FirstObject == null)

                    {
                        _FirstObject = hit.transform.gameObject;
                        if (direction != Direction.STATIONARY)
                        {
                            Vector3 hit2Position = hit.transform.position;
                            switch (direction)
                            {
                            case Direction.UP:
                                hit2Position.y++; break;

                            case Direction.DOWN:
                                hit2Position.y--;  break;

                            case Direction.LEFT:
                                hit2Position.x--; break;

                            case Direction.RIGHT:
                                hit2Position.x++; break;
                            }

                            RaycastHit2D hit2 = Physics2D.Raycast(hit2Position, Vector2.zero);
                            if (hit2.transform != null)
                            {
                                _SecondObject = hit2.transform.gameObject;
                                shouldTransit = true;
                            }
                        }
                    }
                    else
                    {
                        _SecondObject = hit.transform.gameObject;
                        shouldTransit = true;
                    }

                    _currentIndicator = GameObject.Instantiate(_indicator, new Vector3(hit.transform.gameObject.transform.position.x, hit.transform.gameObject.transform.position.y, -1), transform.rotation) as GameObject;
                    //If the user select the second tile we will swap the two tile and animate them
                    if (shouldTransit)
                    {
                        //Getting the position between the 2 tiles
                        var distance = _FirstObject.transform.position - _SecondObject.transform.position;
                        //Testing if the 2 tiles are next to each others otherwise we will not swap them
                        if (Mathf.Abs(distance.x) <= 1 && Mathf.Abs(distance.y) <= 1)
                        {   //If we dont want the player to swap diagonally
                            if (!_canTransitDiagonally)
                            {
                                if (distance.x != 0 && distance.y != 0)
                                {
                                    Destroy(_currentIndicator);
                                    _FirstObject  = null;
                                    _SecondObject = null;
                                    return;
                                }
                            }
                            //Animate the transition
                            DoSwapMotion(_FirstObject.transform, _SecondObject.transform);
                            //Swap the object in array
                            DoSwapTile(_FirstObject, _SecondObject, ref _arrayOfShapes);
                        }
                        else
                        {
                            _FirstObject  = null;
                            _SecondObject = null;
                        }
                        Destroy(_currentIndicator);
                    }
                }
            }
        }
        //If no animation is playing
        if (HOTween.GetTweenInfos() == null)
        {
            var Matches = FindMatch(_arrayOfShapes);
            //If we find a matched tiles
            if (Matches.Count > 0)
            {//Update the score
                _scoreTotal += Matches.Count * _scoreIncrement;

                foreach (GameObject go in Matches)
                {
                    //Playing the matching sound
                    GetComponent <AudioSource>().PlayOneShot(MatchSound);
                    //Creating and destroying the effect of matching
                    var destroyingParticle = GameObject.Instantiate(_particleEffectWhenMatch as GameObject, new Vector3(go.transform.position.x, go.transform.position.y, -2), transform.rotation) as GameObject;
                    Destroy(destroyingParticle, 1f);
                    //Replace the matching tile with an empty one
                    _arrayOfShapes[(int)go.transform.position.x, (int)go.transform.position.y] = GameObject.Instantiate(_emptyGameobject, new Vector3((int)go.transform.position.x, (int)go.transform.position.y, -1), transform.rotation) as GameObject;
                    //Destroy the ancient matching tiles
                    Destroy(go, 0.1f);
                    go.SetActive(false);
                    //go.GetComponent<PoolObject>().Release(0.1f);
                }
                _FirstObject  = null;
                _SecondObject = null;
                //Moving the tiles down to replace the empty ones
                DoEmptyDown(ref _arrayOfShapes);
            }
            //If no matching tiles are found remake the tiles at their places
            else if (_FirstObject != null &&
                     _SecondObject != null
                     )
            {
                //Animate the tiles
                DoSwapMotion(_FirstObject.transform, _SecondObject.transform);
                //Swap the tiles in the array
                DoSwapTile(_FirstObject, _SecondObject, ref _arrayOfShapes);
                _FirstObject  = null;
                _SecondObject = null;
            }
        }
        //Update the score
        (GetComponent(typeof(TextMesh)) as TextMesh).text = _scoreTotal.ToString();
    }
示例#5
0
    // Update is called once per frame
    void Update()
    {
        ArrayList Matches = new ArrayList();

        if (isPaused)
        {
            return;
        }
        var  Infos2         = HOTween.GetTweenInfos();
        bool gemIsTweening2 = false;

        if (Infos2 != null)
        {
            for (var x = 0; x <= _arrayOfShapes.GetUpperBound(0); x++)
            {
                for (var y = 0; y <= _arrayOfShapes.GetUpperBound(1); y++)
                {
                    if (HOTween.GetTweenersByTarget(_arrayOfShapes[x, y].transform, false).Count > 0)
                    {
                        gemIsTweening2 = true;
                    }
                }
            }
        }

        //If no animation is playing
        if (!gemIsTweening2)
        {
            Matches.AddRange(FindMatch(_arrayOfShapes));
            //If we find a matched tiles
            if (Matches.Count > 0)
            {//timing-=0.9f;
                if (timing < 0)
                {
                    timing = 0;
                }

                //Update the score
                _scoreTotal += Matches.Count * _scoreIncrement;

                foreach (GameObject go in Matches)
                {
                    Debug.Log(go.tag);

                    //Playing the matching sound
                    GetComponent <AudioSource>().PlayOneShot(MatchSound);
                    //Creating and destroying the effect of matching
                    var destroyingParticle = GameObject.Instantiate(_particleEffectWhenMatch as GameObject, new Vector3(go.transform.position.x, go.transform.position.y, -2), transform.rotation) as GameObject;
                    Destroy(destroyingParticle, 1f);

                    //Replace the matching tile with an empty one
                    foreach (Tweener t in HOTween.GetTweenersByTarget(go.transform, true))
                    {
                        t.Kill();
                    }
                    //Destroy the ancient matching tiles
                    Destroy(go);
                }
                _FirstObject  = null;
                _SecondObject = null;
                //Moving the tiles down to replace the empty ones
                DoEmptyDown(ref _arrayOfShapes);
            }
            //If no matching tiles are found remake the tiles at their places
            else if (_FirstObject != null &&
                     _SecondObject != null
                     )
            {
                //Animate the tiles
                DoSwapMotion(_FirstObject.transform, _SecondObject.transform);
                //Swap the tiles in the array
                DoSwapTile(_FirstObject, _SecondObject, ref _arrayOfShapes);
                _FirstObject  = null;
                _SecondObject = null;
            }
        }
        if (!isPaused)
        {
            timing  += 0.001f;
            progress = (float)(timing * _timerCoef);
            _Time.transform.localScale = new Vector3(Mathf.Clamp01(progress), _Time.transform.localScale.y, 0);
        }
        if (Mathf.Clamp01(progress) >= 1)
        {
            isEnded  = true;
            isPaused = true;
        }
        (GetComponent(typeof(TextMesh)) as TextMesh).text = _scoreTotal.ToString();

        UpdateLevel(Matches.Count * _scoreIncrement);
    }