Ejemplo n.º 1
0
        protected virtual void Update()
        {
            // Update input
            inputManager.Update(Requires);

            // Make sure the camera exists
            var camera = D2dHelper.GetCamera(null);

            if (camera != null)
            {
                // Loop through all non-gui fingers
                foreach (var finger in inputManager.Fingers)
                {
                    if (finger.StartedOverGui == false)
                    {
                        // Grab extra finger data and position
                        var link     = D2dInputManager.Link.FindOrCreate(ref links, finger);
                        var position = D2dHelper.ScreenToWorldPosition(finger.PositionA, Intercept, camera);

                        // Create indiactor?
                        if (finger.Down == true)
                        {
                            link.Start = position;

                            if (IndicatorPrefab != null)
                            {
                                link.Visual = Instantiate(IndicatorPrefab);

                                link.Visual.SetActive(true);
                            }
                        }

                        // Update indicator?
                        if (finger.Set == true && link.Visual != null)
                        {
                            var scale = Vector3.Distance(position, link.Start);
                            var angle = D2dHelper.Atan2(position - link.Start) * Mathf.Rad2Deg;

                            link.Visual.transform.position   = link.Start;
                            link.Visual.transform.rotation   = Quaternion.Euler(0.0f, 0.0f, -angle);
                            link.Visual.transform.localScale = new Vector3(Thickness, scale, scale);
                        }

                        // Slice scene then clear link?
                        if (finger.Up == true)
                        {
                            D2dSlice.All(Paint, link.Start, position, Thickness, Shape, Color, Layers);

                            link.Clear();
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        protected virtual void Update()
        {
            // Update input
            inputManager.Update(KeyCode.None);

            // Make sure the camera exists
            var camera = D2dHelper.GetCamera(null);

            if (camera != null)
            {
                // Loop through all non-gui fingers
                foreach (var finger in inputManager.Fingers)
                {
                    if (finger.StartedOverGui == false)
                    {
                        var localPosition = transform.localPosition;
                        var targetX       = (finger.PositionA.x - Screen.width / 2) * MoveScale;
                        var targetY       = (finger.PositionA.y - Screen.height / 2) * MoveScale;
                        var factor        = D2dHelper.DampenFactor(MoveSpeed, Time.deltaTime);

                        localPosition.x = Mathf.Lerp(localPosition.x, targetX, factor);
                        localPosition.y = Mathf.Lerp(localPosition.y, targetY, factor);

                        transform.localPosition = localPosition;

                        // Fire?
                        if (finger.Up == true)
                        {
                            if (MuzzlePrefab != null)
                            {
                                Instantiate(MuzzlePrefab, transform.position, Quaternion.identity);
                            }

                            if (BulletPrefab != null)
                            {
                                var position = camera.ScreenToWorldPoint(finger.PositionA);

                                Instantiate(BulletPrefab, position, Quaternion.identity);
                            }
                        }

                        // Skip other fingers
                        break;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        protected virtual void FixedUpdate()
        {
            if (inputManager.Fingers.Count > 0)
            {
                // Make sure the camera exists
                var camera = D2dHelper.GetCamera(null);

                if (camera != null)
                {
                    // Make sure the target exists
                    if (Target != null)
                    {
                        // Grab world position and transition there
                        var center   = inputManager.GetAveragePosition(true);
                        var position = D2dHelper.ScreenToWorldPosition(center, Intercept, camera);
                        var factor   = D2dHelper.DampenFactor(Dampening, Time.fixedDeltaTime);

                        Target.velocity += (Vector2)(position - Target.transform.position) * factor;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void SpawnNow()
        {
            // Prefab exists?
            if (Prefab != null)
            {
                // Main camera exists?
                var camera = D2dHelper.GetCamera(Camera);

                if (camera != null)
                {
                    // World position of the mouse
                    var position = D2dHelper.ScreenToWorldPosition(Input.mousePosition, Intercept, camera);

                    // Get a random rotation around the Z axis
                    var rotation = Quaternion.Euler(0.0f, 0.0f, Random.Range(0.0f, 360.0f));

                    // Spawn prefab here
                    var clone = Instantiate(Prefab, position, rotation);

                    clone.SetActive(true);
                }
            }
        }
Ejemplo n.º 5
0
        protected virtual void Update()
        {
            if (Input.GetKeyDown(Requires) == true)
            {
                var camera = D2dHelper.GetCamera(Camera, gameObject);

                if (camera != null)
                {
                    var ray   = camera.ScreenPointToRay(Input.mousePosition);
                    var count = Physics2D.GetRayIntersectionNonAlloc(ray, raycastHit2Ds, float.PositiveInfinity, Layers);

                    if (count > 0)
                    {
                        for (var i = 0; i < count; i++)
                        {
                            var raycastHit2D = raycastHit2Ds[i];

                            if (TryFracture(raycastHit2D) == true)
                            {
                                // Spawn prefab?
                                if (Prefab != null)
                                {
                                    var clone = Instantiate(Prefab, raycastHit2D.point, Quaternion.Euler(0.0f, 0.0f, Random.Range(0.0f, 360.0f)));

                                    clone.SetActive(true);
                                }

                                if (Hit == HitType.First)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        protected virtual void Update()
        {
            // Update input
            inputManager.Update(Requires);

            // Make sure the camera exists
            var camera = D2dHelper.GetCamera(null);

            if (camera != null)
            {
                // Loop through all non-gui fingers
                foreach (var finger in inputManager.Fingers)
                {
                    if (finger.StartedOverGui == false)
                    {
                        // Grab extra finger data and position
                        var link     = D2dInputManager.Link.FindOrCreate(ref links, finger);
                        var position = D2dHelper.ScreenToWorldPosition(finger.PositionA, Intercept, camera);

                        // Create indiactor?
                        if (finger.Down == true && IndicatorPrefab != null)
                        {
                            link.Visual = Instantiate(IndicatorPrefab);
                            link.Scale  = link.Visual.transform.localScale;

                            link.Visual.SetActive(true);
                        }

                        // Update indicator?
                        if (finger.Set == true && link.Visual != null)
                        {
                            link.Visual.transform.position = position;

                            link.Visual.transform.localScale = Vector3.Scale(link.Scale, new Vector3(Size.x, Size.y, 1.0f));
                        }

                        // Clear indicator then stamp?
                        if (finger.Up == true)
                        {
                            // Stamp everything at this point?
                            if (Hit == HitType.All)
                            {
                                D2dStamp.All(Paint, position, Size, Angle, Shape, Color, Layers);
                            }

                            // Stamp the first thing at this point?
                            if (Hit == HitType.First)
                            {
                                var destructible = default(D2dDestructible);

                                if (D2dDestructible.TrySampleThrough(position, ref destructible) == true)
                                {
                                    destructible.Paint(Paint, D2dStamp.CalculateMatrix(position, Size, Angle), Shape, Color);
                                }
                            }

                            // Destroy indicator
                            link.Clear();
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        protected virtual void Update()
        {
            // Update input
            inputManager.Update(Requires);

            // Make sure the camera exists
            var camera = D2dHelper.GetCamera(null);

            if (camera != null)
            {
                // Loop through all non-gui fingers
                foreach (var finger in inputManager.Fingers)
                {
                    if (finger.StartedOverGui == false)
                    {
                        // Grab extra finger data and position
                        var link     = D2dInputManager.Link.FindOrCreate(ref links, finger);
                        var position = D2dHelper.ScreenToWorldPosition(finger.PositionA, Intercept, camera);

                        // Create indiactor?
                        if (finger.Down == true)
                        {
                            link.Start = position;

                            if (IndicatorPrefab != null)
                            {
                                link.Visual = Instantiate(IndicatorPrefab);

                                link.Visual.SetActive(true);
                            }
                        }

                        // Update indicator?
                        if (finger.Set == true && link.Visual != null)
                        {
                            var angle = GetAngleAndClampCurrentPos(link.Start, ref position);
                            var scale = Vector3.Distance(position, link.Start) * Scale;

                            link.Visual.transform.position   = link.Start;
                            link.Visual.transform.rotation   = Quaternion.Euler(0.0f, 0.0f, -angle);
                            link.Visual.transform.localScale = new Vector3(scale, scale, scale);
                        }

                        // Slice scene then clear link?
                        if (finger.Up == true)
                        {
                            var angle = GetAngleAndClampCurrentPos(link.Start, ref position) + ProjectileAngle + Random.Range(-ProjectileSpread, ProjectileSpread);

                            // Spawn
                            var projectile = Instantiate(ProjectilePrefab, link.Start, Quaternion.Euler(0.0f, 0.0f, -angle));

                            projectile.SetActive(true);

                            // Apply velocity?
                            var rigidbody2D = projectile.GetComponent <Rigidbody2D>();

                            if (rigidbody2D != null)
                            {
                                rigidbody2D.velocity = (position - link.Start) * ProjectileSpeed;
                            }

                            link.Clear();
                        }
                    }
                }
            }
        }