コード例 #1
0
    public GameObject CreateNewAsteroidHazard(Vector2 location, Tappable target, float speedOfMovement, float health)
    {
        GameObject instantiatedAsteroidHazard = (GameObject)(Instantiate(asteroidHazard, location, Quaternion.identity));
        Vector2    diff = target.transform.position - instantiatedAsteroidHazard.transform.position;

        instantiatedAsteroidHazard.GetComponent <Rigidbody2D> ().velocity = diff.normalized * speedOfMovement;
        instantiatedAsteroidHazard.transform.localScale = Vector3.one * (health / 10.0f);
        instantiatedAsteroidHazard.GetComponent <Damageable> ().maxHealth = health;
        return(instantiatedAsteroidHazard);
    }
コード例 #2
0
    public void Decenter()
    {
        if (lerpToZCoroutine != null)
        {
            StopCoroutine(lerpToZCoroutine);
        }

        lerpToZCoroutine = LerpTransformToZ(resetPosition.z);
        StartCoroutine(lerpToZCoroutine);

        centeredOn = null;
    }
コード例 #3
0
    public void CenterOn(Tappable other)
    {
        if (lerpToZCoroutine != null)
        {
            StopCoroutine(lerpToZCoroutine);
        }

        lerpToZCoroutine = LerpTransformToZ(-6 * other.transform.localScale.x);
        StartCoroutine(lerpToZCoroutine);

        centeredOn = other;
    }
コード例 #4
0
    private IEnumerator CreateEnemies()
    {
        while (true)
        {
            float   xPositionOfInstantiation = (((int)(Random.Range(0, 2))) == 0 ? -1 : 1) * (70 + Random.Range(0, 30));
            float   yPositionOfInstantiation = (((int)(Random.Range(0, 2))) == 0 ? -1 : 1) * (70 + Random.Range(0, 30));
            Vector2 positionOfInstantiation  = new Vector2(xPositionOfInstantiation, yPositionOfInstantiation);

            Tappable target = GameObject.FindGameObjectWithTag("Space Station").GetComponent <Tappable> ();

            MasterCreator.instance.CreateNewAsteroidHazard(positionOfInstantiation, target, 3, Random.Range(8, 13));

            yield return(new WaitForSeconds(15));
        }
    }
コード例 #5
0
    void OnTap(Vector2 position)
    {
        Vector3    hitPos = GetComponent <Camera> ().ScreenToWorldPoint(position);
        Collider2D coll   = Physics2D.OverlapPoint(hitPos);

        if (coll != null)
        {
            Tappable q = coll.GetComponent <Tappable> ();
            if (q != null)
            {
                q.OnTap();
                return;
            }
        }
        OnBackgroundTap(hitPos);
    }
コード例 #6
0
    void OnTapDown()
    {
        _tapTimer = 0;

        // Cast a ray to the mouse position to see if anything is tapped
        RaycastHit hit;
        Ray        ray = _camera.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit))
        {
            _tapped = hit.transform.gameObject;
            Tappable tappable = _tapped.GetComponent <Tappable>();
            if (tappable)
            {
                tappable.onPress.Invoke();
            }
        }
    }
コード例 #7
0
        protected override void OnInputDown(int pointerId, float2 inputPos)
        {
            // Get entity under pointer
            var pointerRaycastHit = GetPointerRaycastHit(inputPos, m_CollisionFilter);
            var pointerEntity     = pointerRaycastHit.Entity;

            // Only target entities with Tappable component
            if (pointerEntity != Entity.Null && HasComponent <Tappable>(pointerEntity))
            {
                // Set tap data on entity that was pressed
                var tappable = new Tappable
                {
                    PointerId   = pointerId,
                    TimePressed = Time.ElapsedTime,
                    IsPressed   = true
                };

                SetComponent(pointerEntity, tappable);
            }
        }
コード例 #8
0
    private void onTap(Transform tapTarget)
    {
        if (tapTarget == null)
        {
            return;
        }

        Debug.Log($"Tap on {tapTarget.name}");

        Tappable tappable = tapTarget.GetComponent <Tappable>();

        tappable?.onTap();

        Swipeable swipeable = tapTarget.GetComponent <Swipeable>();

        if (swipeable != null)
        {
            currentSwipe = swipeable.onSwipeStart();
        }
    }
コード例 #9
0
    void OnTapUp()
    {
        if (!_tapped)
        {
            return;
        }
        Tappable tappable = _tapped.GetComponent <Tappable>();

        if (tappable)
        {
            if (_tapTimer <= tapTime)
            {
                tappable.onTap.Invoke();
            }
            else
            {
                tappable.onTapUp.Invoke();
            }
        }
        _tapped = null;
    }
コード例 #10
0
	// Use this for initialization

	void Start () {
		parent = transform.parent.gameObject.GetComponent<Tappable>();
	}
コード例 #11
0
    public void InitializeWith(Tappable other)
    {
        //Make sure that the user didn't just click on the background.
        if (other.gameObject.name.Equals("Nothingness"))
        {
            //If we just double-tapped on nothingness, return the camera to its usual position.
            if (Time.time - lastTapOnNothingness < .5f)
            {
                CameraMovement.instance.Decenter();
                DisableAllActions();
                UserConsole.instance.Clear();
                currentlyDirecting = false;
                currentlySelected  = null;
            }

            lastTapOnNothingness = Time.time;
            return;
        }

        if (currentlySelected != null)
        {
            if (currentlyDirecting)
            {
                currentlySelected.GetComponent <Directable> ().DirectTo(other.transform);
                currentlyDirecting = false;
                UserConsole.instance.Clear();
                currentlySelected = null;
                return;
            }
            else
            {
                DisableAllActions();
            }
        }

        //Zoom in on the item.
        CameraMovement.instance.CenterOn(other);

        //Play the opening animation.
        GetComponent <Animator> ().SetTrigger("PlayOpening");

        //Set each component active depending on whether or not it has the required components.
        //Make sure that the upgradeable component exists on this item first.  .
        currentlySelected = other;

        if (other.gameObject.GetComponent <Upgradeable> () != null)
        {
            UpdateUpgradeCosts();
            UpdateUpgradeSliders();

            if (other.gameObject.GetComponent <Damageable> () != null)
            {
                shielding.objectComp.SetActive(true);
            }

            if (other.gameObject.GetComponent <Directable> () != null)
            {
                moveSpeed.objectComp.SetActive(true);
            }

            if (other.gameObject.GetComponent <GunController> () != null)
            {
                fireSpeed.objectComp.SetActive(true);
                fireDamage.objectComp.SetActive(true);
            }

            if (other.gameObject.GetComponent <TargetingControl> () != null)
            {
                targeting.objectComp.SetActive(true);
            }
        }

        if (other.gameObject.GetComponent <Directable> () != null)
        {
            directTo.objectComp.SetActive(true);
        }

        if (other.gameObject.CompareTag("Space Station"))
        {
            NewPurchaseController.instance.SetState(true);
        }
    }