Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            if (
                Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100)
                )
            {
                Selectable newSelected = hit.collider.gameObject.GetComponentInParent <Selectable>();

                if (newSelected != null)
                {
                    if (_selected != null)
                    {
                        _selected.Deselect();
                    }

                    _selected = newSelected;
                    _selected.Select();
                }
                else
                {
                    if (_selected != null)
                    {
                        _selected.Deselect();
                        _selected = null;
                    }
                }
            }
        }
    }
Example #2
0
    private void DivisibleInput()
    {
        if (this.playerNetworkView.isMine)
        {
            if (Input.GetKeyDown(KeyCode.S) && this.ownerSelectable.isSelected && this.isReady && (!this.ownerAttackable.isReadyToAttack || !this.ownerAttackable.isAttacking) && this.canDivide)
            {
                Analytics.Instance.AddEvent("S key pressed to split selected units. Count: " + Selectable.selectedObjects.Count.ToString());

                for (int j = 0; j < Selectable.selectedObjects.Count; j++)
                {
                    Selectable ownerSelectable = Selectable.selectedObjects[j];
                    if (ownerSelectable == null)
                    {
                        continue;
                    }
                    ownerSelectable.Deselect();
                    Divisible ownerDivisible = ownerSelectable.gameObject.GetComponent <Divisible>();
                    ownerDivisible.SetDivisibleNotReady();

                    for (int i = 0; i < this.numberOfUnitsPerSpawn; i++)
                    {
                        Vector3    spawnedLocation = ownerSelectable.gameObject.transform.position;
                        GameObject unit            = (GameObject)Network.Instantiate(Resources.Load("Prefabs/Player"), spawnedLocation, Quaternion.identity, 0);
                        //Clones will not have parentheses around the remote node label (client, or server).
                        unit.name = (Network.isClient ? "client " : "server ") + System.Guid.NewGuid();

                        HealthBar foo = unit.GetComponent <HealthBar>();
                        HealthBar bar = this.gameObject.GetComponent <HealthBar>();
                        if (foo != null && bar != null)
                        {
                            foo.currentHealth    = bar.currentHealth;
                            foo.maxHealth        = bar.maxHealth;
                            foo.healthPercentage = bar.healthPercentage;
                        }

                        Selectable spawnedSelectable = unit.GetComponentInChildren <Selectable>();
                        spawnedSelectable.Deselect();
                        ownerSelectable.Deselect();

                        if (!Debugging.debugEnabled)
                        {
                            NetworkView view = unit.GetComponent <NetworkView>();
                            if (this.playerNetworkView != null && view != null)
                            {
                                float randomValue = Random.Range(-180f, 180f);
                                this.playerNetworkView.RPC("RPC_Add", RPCMode.AllBuffered, ownerSelectable.GetComponent <NetworkView>().viewID, view.viewID, randomValue);
                            }
                        }
                        else
                        {
                            Debug.LogWarning("Debug flag is enabled.");
                        }
                    }
                }
            }
        }
    }
Example #3
0
 /**
  * Selects a selectable
  */
 public void Select(Selectable s)
 {
     if (Active != null)
     {
         Active.Deselect();
     }
     if (s == null)
     {
         Debug.LogError("Selectable is null, should happen");
         return;
     }
     Active = s;
     Active.Select();
 }
Example #4
0
 private void ChangeSelection(Selectable next)
 {
     if (next != null)
     {
         selected.Deselect();
         selected = next;
         selected.Select();
     }
     else
     {
         if (onInvalidSelection != null)
         {
             onInvalidSelection.Invoke(selected.gameObject);
         }
     }
 }
Example #5
0
    public void Update()
    {
        if (this.pairs.Count > 0)
        {
            for (int i = 0; i < this.pairs.Count; i++)
            {
                if (this.pairs[i].elapsedTime < 1f)
                {
                    MoveTo(i);
                    Scale(i, 0f, 1f);
                    MergeUpdate(i);
                }
                else
                {
                    MergePair pair = this.pairs[i];
                    if (pair.second != null)
                    {
                        Network.Destroy(pair.second);
                    }
                    if (pair.first != null)
                    {
                        Selectable select = pair.first.GetComponent <Selectable>();
                        if (select)
                        {
                            select.EnableSelection();
                            select.Deselect();
                        }
                        Divisible div = pair.first.GetComponent <Divisible>();
                        if (div != null)
                        {
                            div.SetDivisible(false);
                        }
                    }

                    if (pair.first == null || pair.second == null || pair.confirmedDestroyed)
                    {
                        this.pendingToRemove.Add(pair);
                        break;
                    }
                }
            }
        }
        if (this.pendingToRemove.Count > 0)
        {
            foreach (MergePair pair in this.pendingToRemove)
            {
                if (this.pairs.Contains(pair))
                {
                    Selectable select = pair.first.GetComponent <Selectable>();
                    if (select != null)
                    {
                        select.EnableSelection();
                        select.Deselect();
                    }
                    this.pairs.Remove(pair);
                }
            }
            this.pendingToRemove.Clear();
        }
    }
 void ClearSelection()
 {
     if (currentSelection != null)
     {
         currentSelection.Deselect();
         currentSelection = null;
     }
 }
Example #7
0
 /// <summary>
 /// Deselect the current selectable if it's assigned.
 /// </summary>
 private void DeselectCurrent()
 {
     // Deselect the current selectable
     if (selectable != null)
     {
         selectable.Deselect();
         selectable = null;
     }
 }
Example #8
0
        public IEnumerator ApplyMode(IEnumerable <VisualPayload> payloads)
        {
            switch (OperationToPerform)
            {
            case SelectionOperation.Select:
            {
                var iterator = Selectable.Select(payloads);
                while (iterator.MoveNext( ))
                {
                    yield return(null);
                }
                break;
            }

            case SelectionOperation.Deselect:
            {
                var iterator = Selectable.Deselect(payloads);
                while (iterator.MoveNext())
                {
                    yield return(null);
                }
                break;
            }

            case SelectionOperation.SelectOnly:
            {
                var iterator = Selectable.SelectOnly(payloads);
                while (iterator.MoveNext())
                {
                    yield return(null);
                }
                break;
            }

            case SelectionOperation.ToggleFullySelected:
            {
                var iterator = Selectable.ToggleFullySelected(payloads);
                while (iterator.MoveNext())
                {
                    yield return(null);
                }
                break;
            }

            case SelectionOperation.DoNothing:
            {
                yield return(null);

                break;
            }

            default:
            {
                throw new NotImplementedException("Selection mode not implemented");
            }
            }
        }
Example #9
0
 void SelectNew(Selectable selectable)
 {
     if (selected != null)
     {
         selected.Deselect();
     }
     selected = selectable;
     selectable.Select();
     selected.CreateInfo();
     if (selected.ownerID == GameManager.instance.localPlayer.playerID)
     {
         selected.CreateAbilites();
     }
     else
     {
         GameManager.instance.ui.ClearAbilities();
     }
 }
 public void Deselect(Selectable s, bool removeItem = true)
 {
     s.Deselect();
     if (removeItem)
     {
         selected.Remove(s);
     }
     Destroy(s.selectionObject.gameObject);
 }
Example #11
0
        protected virtual void Update()
        {
            // Is this selected and has a selecting finger?
            if (Selectable != null && Selectable.IsSelected == true)
            {
                var finger = Selectable.SelectingFinger;

                if (finger != null)
                {
                    // Camera exists?
                    var camera = LeanTouch.GetCamera(null);

                    if (camera != null)
                    {
                        // Find the screen point of the finger using the depth of this block
                        var screenPoint = new Vector3(finger.ScreenPosition.x, finger.ScreenPosition.y, camera.WorldToScreenPoint(transform.position).z);

                        // Find the world space point under the finger
                        var worldPoint = camera.ScreenToWorldPoint(screenPoint);

                        // Find the block coordinate at this point
                        var dragX = Mathf.RoundToInt(worldPoint.x / BlockSize);
                        var dragY = Mathf.RoundToInt(worldPoint.y / BlockSize);

                        // Is this block right next to this one?
                        var distX = Mathf.Abs(X - dragX);
                        var distY = Mathf.Abs(Y - dragY);

                        if (distX + distY == 1)
                        {
                            // Swap blocks if one exists at this coordinate
                            var block = FindBlock(dragX, dragY);

                            if (block != null)
                            {
                                Swap(this, block);

                                if (DeselectOnSwap == true)
                                {
                                    Selectable.Deselect();
                                }
                            }
                        }
                    }
                }
            }

            // Smoothly move to new position
            var targetPosition = Vector3.zero;
            var factor         = LeanTouch.GetDampenFactor(Dampening, Time.deltaTime);

            targetPosition.x = X * BlockSize;
            targetPosition.y = Y * BlockSize;

            transform.localPosition = Vector3.Lerp(transform.localPosition, targetPosition, factor);
        }
    public void Deselect(Selectable selectable)
    {
        if (selectable == null)
            return;

        if (mSelected.Contains (selectable))
            mSelected.Remove (selectable);

        selectable.Deselect ();
    }
Example #13
0
    //=================================================================================
    //Public Variables Members
    //=================================================================================

    // we make sure to select 1 object at any given time
    public void Select(Selectable Selected)
    {
        if (CurrentlySelected != null)
        {
            CurrentlySelected.Deselect();
        }

        CurrentlySelected = Selected;
        CurrentlySelected.Select();
    }
Example #14
0
    public void Deselect(Selectable selectable)
    {
        if (selectable == null)
        {
            return;
        }

        if (mSelected.Contains(selectable))
        {
            mSelected.Remove(selectable);
        }

        selectable.Deselect();
    }
    private void SelectNewObject(Selectable selectable)
    {
        if (currentSelected != null)
        {
            currentSelected.Deselect();
        }

        currentSelected = selectable;

        if (currentSelected != null)
        {
            currentSelected.Select();
        }
    }
Example #16
0
        protected virtual void Update()
        {
            // Is this selected and has a selecting finger?
            if (Selectable.IsSelected == true)
            {
                var finger = Selectable.SelectingFinger;

                if (finger != null)
                {
                    // Find the world space point under the finger
                    var dragPoint = ScreenDepth.Convert(finger.ScreenPosition, gameObject);

                    // Find the block coordinate at this point
                    var dragX = Mathf.RoundToInt(dragPoint.x / BlockSize);
                    var dragY = Mathf.RoundToInt(dragPoint.y / BlockSize);

                    // Is this block right next to this one?
                    var distX = Mathf.Abs(X - dragX);
                    var distY = Mathf.Abs(Y - dragY);

                    if (distX + distY == 1)
                    {
                        // Swap blocks if one exists at this coordinate
                        var block = FindBlock(dragX, dragY);

                        if (block != null)
                        {
                            Swap(this, block);

                            if (DeselectOnSwap == true)
                            {
                                Selectable.Deselect();
                            }
                        }
                    }
                }
            }

            // Smoothly move to new position
            var targetPosition = Vector3.zero;
            var factor         = LeanTouch.GetDampenFactor(Dampening, Time.deltaTime);

            targetPosition.x = X * BlockSize;
            targetPosition.y = Y * BlockSize;

            transform.localPosition = Vector3.Lerp(transform.localPosition, targetPosition, factor);
        }
Example #17
0
 public void Deselect()
 {
     if (selected)
     {
         GameObject deselected = selected.gameObject;
         selected.Deselect();
         Deletable deletable = selected.GetComponent <Deletable>();
         if (deletable)
         {
             deletable.OnDelete -= Deselect;
         }
         selected = null;
         if (OnDeselect != null)
         {
             OnDeselect(deselected);
         }
     }
 }
Example #18
0
 private void Collect()
 {
     collectableObject.OnCollected();
     selectable.Deselect();
     Destroy(gameObject);
 }
Example #19
0
    public MergePair(GameObject a, GameObject b)
    {
        this.first                 = a;
        this.second                = b;
        this.elapsedTime           = 0f;
        this.firstInitialPosition  = a.transform.position;
        this.secondInitialPosition = b.transform.position;
        this.firstInitialScale     = a.transform.localScale;
        this.secondInitialScale    = b.transform.localScale;
        this.confirmedDestroyed    = false;

        HealthBar health = a.GetComponent <HealthBar>();

        if (health != null)
        {
            health.currentHealth   *= 2;
            health.maxHealth       *= 2;
            health.healthPercentage = (float)health.currentHealth / (float)health.maxHealth;
        }

        health = b.GetComponent <HealthBar>();
        if (health != null)
        {
            health.currentHealth   *= 2;
            health.maxHealth       *= 2;
            health.healthPercentage = (float)health.currentHealth / (float)health.maxHealth;
        }

        Attackable attack = a.GetComponent <Attackable>();

        if (attack != null)
        {
            attack.attackPower *= 2;
        }
        attack = b.GetComponent <Attackable>();
        if (attack != null)
        {
            attack.attackPower *= 2;
        }

        Level level = a.GetComponent <Level>();

        if (level != null)
        {
            level.IncrementLevel();
        }
        level = b.GetComponent <Level>();
        if (level != null)
        {
            level.IncrementLevel();
        }

        Selectable select = a.GetComponent <Selectable>();

        if (select != null)
        {
            select.Deselect();
        }
        select = b.GetComponent <Selectable>();
        if (select != null)
        {
            select.Deselect();
        }

        //Mergeable merge = a.GetComponent<Mergeable>();
        //if (merge != null) {
        //	merge.mergeLevel++;
        //}
        //merge = b.GetComponent<Mergeable>();
        //if (merge != null) {
        //	merge.mergeLevel++;
        //}
    }