Ejemplo n.º 1
0
    public void OnItemDrag(CameraManager.CameraEvent evt)
    {
        Vector3 point = evt.point + _deltaDistance;

        point.x = Mathf.Floor(point.x);
        point.z = Mathf.Floor(point.z);

        if (point != this.transform.localPosition)
        {
            this.SetPosition(new Vector3(Mathf.Floor(point.x), 0, Mathf.Floor(point.z)));
            this.UpdateConnectedItems();

            bool isPlacable = _IsInPlacablePosition();
            if (isPlacable)
            {
                this.UI.selectionUIInstance.SetGridColor(Color.green);
            }
            else
            {
                this.UI.selectionUIInstance.SetGridColor(Color.red);
            }

            //play sound for drag item , here loop is false
            SoundManager.instance.PlaySound(SoundManager.instance.Tap1, false);
        }
    }
Ejemplo n.º 2
0
    public void OnItemDrag(CameraManager.CameraEvent evt)
    {
        Vector3 point = evt.point + _deltaDistance;

        point.x = Mathf.Floor(point.x);
        point.y = Mathf.Floor(point.y);

        if (point != this.transform.localPosition)
        {
            this.SetPosition(new Vector3(Mathf.Floor(point.x), Mathf.Floor(point.y), 0));
            this.UpdateConnectedItems();

            bool isPlacable = _IsInPlacablePosition();
            if (spriteRenderer == null)
            {
                spriteRenderer = Renderer.RenderGameobject.transform.Find("image").GetComponent <SpriteRenderer>();
            }
            spriteRenderer.sortingOrder = GroundManager.nodeHeight - (int)point.y;
            this.UI.selectionUIInstance.SetGridOrder(spriteRenderer.sortingOrder - 1);
            if (isPlacable)
            {
                this.UI.selectionUIInstance.SetGridColor(Color.green);
            }
            else
            {
                this.UI.selectionUIInstance.SetGridColor(Color.red);
            }

            //play sound for drag item , here loop is false
            SoundManager.instance.PlaySound(SoundManager.instance.Tap1, false);
        }
    }
    /// <summary>
    /// Raises the item drag event.
    /// </summary>
    /// <param name="evt">Evt.</param>
    public void OnItemDrag(CameraManager.CameraEvent evt)
    {
        if (this.gameMode == Common.GameMode.ATTACK)
        {
            return;
        }

        if (this._dragItem != null)
        {
            this._dragItem.OnItemDrag(evt);
            //			this.ShowGrid ();
        }
    }
    /// <summary>
    /// Raises the item drag start event.
    /// </summary>
    /// <param name="evt">Evt.</param>
    public void OnItemDragStart(CameraManager.CameraEvent evt)
    {
        if (this.gameMode == Common.GameMode.ATTACK)
        {
            return;
        }

        this._dragItem = evt.baseItem;
        this._dragItem.OnItemDragStart(evt);

        if (this._dragItem.itemData.name == "Wall")
        {
            this.UpdateWalls();
        }
    }
Ejemplo n.º 5
0
    public void OnItemDragStart(CameraManager.CameraEvent evt)
    {
        this._deltaDistance = this.GetPosition() - evt.point;
        GroundManager.instance.UpdateBaseItemNodes(this, GroundManager.Action.REMOVE);

        bool isPlacable = _IsInPlacablePosition();

        if (isPlacable)
        {
            this.Renderer.ShowGroundPatch(false);
            if (this.UI.selectionUIInstance != null)
            {
                this.UI.selectionUIInstance.ShowGrid(true);
            }

            this._oldPosition = this.GetPosition();
        }
    }
Ejemplo n.º 6
0
    public void OnItemDragStop(CameraManager.CameraEvent evt)
    {
        bool isPlacable = _IsInPlacablePosition();

        if (isPlacable)
        {
            this.Renderer.ShowGroundPatch(true);
            if (this.UI.selectionUIInstance != null)
            {
                this.UI.selectionUIInstance.ShowGrid(false);
            }

            GroundManager.instance.UpdateBaseItemNodes(this, GroundManager.Action.ADD);
            DataBaseManager.instance.UpdateItemData(this);

            //play sound for end drag item , here loop is false
            SoundManager.instance.PlaySound(SoundManager.instance.TapOnItem, false);
        }
    }
    /// <summary>
    /// Raises the item drag stop event.
    /// </summary>
    /// <param name="evt">Evt.</param>
    public void OnItemDragStop(CameraManager.CameraEvent evt)
    {
        if (this.gameMode == Common.GameMode.ATTACK)
        {
            return;
        }


        if (this._dragItem != null)
        {
            this._dragItem.OnItemDragStop(evt);

            if (this._dragItem.itemData.name == "Wall")
            {
                this.UpdateWalls();
            }

            this._dragItem = null;
        }
    }
Ejemplo n.º 8
0
    /// <summary>
    /// Raises the item tap event.
    /// </summary>
    /// <param name="evt">Evt.</param>
    public void OnItemTap(CameraManager.CameraEvent evt)
    {
        //		Debug.Log ("OnItemTap");
        if (this.gameMode == Common.GameMode.ATTACK)
        {
            return;
        }

        BaseItemScript tappedItem = evt.baseItem;

        if (tappedItem.Production.readyForCollection)
        {
            tappedItem.Production.Collect();
            return;
        }

        if (this.selectedItem != null)
        {
            this.selectedItem.SetSelected(false);
        }
        this.selectedItem = tappedItem;
        tappedItem.SetSelected(true);
    }
    /// <summary>
    /// Raises the tap ground event.
    /// </summary>
    /// <param name="evt">Evt.</param>
    public void OnTapGround(CameraManager.CameraEvent evt)
    {
        //		Debug.Log ("OnTapGround");

        if (this.gameMode == Common.GameMode.NORMAL)
        {
            if (this.selectedItem != null)
            {
                BaseItemScript temp = this.selectedItem;
                this.selectedItem = null;
                temp.SetSelected(false);
            }

            //			if (this._unit == null) {
            //				this._unit = this.AddItem (5492, true);
            //				this._unit.SetState (Common.State.WALK);
            //				this._unit.SetPosition (evt.point);
            //			} else {
            //				this._unit.LookAt (evt.point);
            //			}
        }

        if (this.gameMode == Common.GameMode.ATTACK)
        {
            if (selectedUnit == 0)
            {
                if (this._swordManExpended == _swordManCount)
                {
                    return;
                }

                this._swordManExpended++;

                AttackOverlayWindowScript.instance.SwordManCounter.text =
                    (this._swordManCount - _swordManExpended).ToString() + "x";
            }
            else if (selectedUnit == 1)
            {
                if (this._archerExpended == _archerCount)
                {
                    return;
                }

                this._archerExpended++;

                AttackOverlayWindowScript.instance.ArcherCounter.text =
                    (this._archerCount - _archerExpended).ToString() + "x";
            }

            int[] unitIds = new int[] { _swordMan_ID, _archer_ID };

            evt.point.x = Mathf.Clamp(evt.point.x, 0, GroundManager.instance.nodeWidth - 1);
            evt.point.z = Mathf.Clamp(evt.point.z, 0, GroundManager.instance.nodeHeight - 1);

            this._unit = this.AddItem(unitIds[selectedUnit], true, true);
            this._unit.SetPosition(evt.point);
            this._unit.Attacker.AttackNearestTarget();
            this._unit.OnItemDestroy += this.OnUnitDied;

            SoundManager.instance.PlaySound(SoundManager.instance.Yeah, false);
        }

        //		if (testCharacter != null) {
        //			testCharacter.LookAt (_builderHutInstance);
        //		}

        //		if (this._builderInstance != null) {
        //			this._builderInstance.gameObject.SetActive (true);
        //			this._builderInstance.Walker.WalkToPosition (evt.point);
        //		}

        //		if (this._swordManInstance != null) {
        //			this._swordManInstance.gameObject.SetActive (true);
        //			this._swordManInstance.Walker.WalkToPosition (evt.point);
        //		}
    }