protected virtual void FixedUpdate()
        {
            var newPosition  = transform.position;
            var rayLength    = (newPosition - oldPosition).magnitude;
            var rayDirection = (newPosition - oldPosition).normalized;
            var hit          = Physics2D.Raycast(oldPosition, rayDirection, rayLength, RaycastMask);

            // Update old position to trail behind
            if (rayLength > MaxLength)
            {
                rayLength   = MaxLength;
                oldPosition = newPosition - rayDirection * rayLength;
            }

            transform.localScale = MaxScale * D2dHelper.Divide(rayLength, MaxLength);

            if (hit.collider != null)
            {
                if (string.IsNullOrEmpty(IgnoreTag) == true || hit.collider.tag != IgnoreTag)
                {
                    if (ExplosionPrefab != null)
                    {
                        Instantiate(ExplosionPrefab, hit.point, Quaternion.identity);
                    }

                    Destroy(gameObject);
                }
            }
        }
Beispiel #2
0
        protected virtual void Update()
        {
            if (Input.GetMouseButton(0) && Camera.main != null)
            {
                var ray      = Camera.main.ScreenPointToRay(Input.mousePosition);
                var distance = D2dHelper.Divide(ray.origin.z, ray.direction.z);
                var point    = ray.origin - ray.direction * distance;

                D2dDestructible.StampAll(point, Size, Angle, StampTex, Hardness, Layers);
            }
        }
Beispiel #3
0
        public void SubsetAlphaWith(Color32[] subData, D2dRect subRect, int newAlphaCount = -1)
        {
            var stepX = D2dHelper.Divide(alphaScale.x, alphaWidth);
            var stepY = D2dHelper.Divide(alphaScale.y, alphaHeight);

            alphaOffset.x += stepX * subRect.MinX;
            alphaOffset.y += stepY * subRect.MinY;
            alphaScale.x  += stepX * (subRect.SizeX - alphaWidth);
            alphaScale.y  += stepY * (subRect.SizeY - alphaHeight);

            FastCopyAlphaData(subData, subRect.SizeX, subRect.SizeY, newAlphaCount);

            NotifyRebuilt();
        }
Beispiel #4
0
        public void AddTriangle(D2dVector2 a, D2dVector2 b, D2dVector2 c)
        {
            if (a.Y != b.Y || a.Y != c.Y)
            {
                //var z = (a.V + b.V + c.V) / 3.0f;
                //var z1 = Vector3.MoveTowards(a.V, z, 1.0f);
                //var z2 = Vector3.MoveTowards(b.V, z, 1.0f);
                //var z3 = Vector3.MoveTowards(c.V, z, 1.0f);

                //Debug.DrawLine(z1, z2, Color.red, 10.0f);
                //Debug.DrawLine(z2, z3, Color.red, 10.0f);
                //Debug.DrawLine(z3, z1, Color.red, 10.0f);

                // Make a highest, and c lowest
                if (b.Y > a.Y)
                {
                    D2dHelper.Swap(ref a, ref b);
                }
                if (c.Y > a.Y)
                {
                    D2dHelper.Swap(ref c, ref a);
                }
                if (c.Y > b.Y)
                {
                    D2dHelper.Swap(ref b, ref c);
                }

                var fth = a.Y - c.Y;                 // Full triangle height
                var tth = a.Y - b.Y;                 // Top triangle height
                var bth = b.Y - c.Y;                 // Bottom triangle height

                // Find a to c intercept along b plane
                var inx = c.X + (a.X - c.X) * D2dHelper.Divide(bth, fth);
                var d   = new D2dVector2((int)inx, b.Y);

                // Top triangle
                var abs = D2dHelper.Divide(a.X - b.X, tth);                 // A/B slope
                var ads = D2dHelper.Divide(a.X - d.X, tth);                 // A/D slope

                AddTriangle(b.X, d.X, abs, ads, b.Y, 1, tth);

                // Bottom triangle
                var cbs = D2dHelper.Divide(c.X - b.X, bth);                 // C/B slope
                var cds = D2dHelper.Divide(c.X - d.X, bth);                 // C/D slope

                AddTriangle(b.X, d.X, cbs, cds, b.Y, -1, bth);
            }
        }
Beispiel #5
0
        public static Vector3 ScreenToWorldPosition(Vector2 screenPosition, Camera camera = null)
        {
            if (camera == null)
            {
                camera = Camera.main;
            }
            if (camera == null)
            {
                return(screenPosition);
            }

            // Get ray of screen position
            var ray = camera.ScreenPointToRay(screenPosition);

            // Find point along this ray that intersects with Z = 0
            var distance = D2dHelper.Divide(ray.origin.z, ray.direction.z);

            return(ray.origin - ray.direction * distance);
        }
Beispiel #6
0
        protected virtual void Update()
        {
            // Required key is down?
            if (Input.GetKeyDown(Requires) == true)
            {
                // Main camera exists?
                var mainCamera = Camera.main;

                if (mainCamera != null)
                {
                    // Get screen ray of mouse position
                    var ray = mainCamera.ScreenPointToRay(Input.mousePosition);

                    // Project ray onto Z=0 plane and find the point it intersects
                    var distance = D2dHelper.Divide(ray.origin.z, ray.direction.z);
                    var point    = ray.origin - ray.direction * distance;

                    // Stamp at that point
                    D2dDestructible.StampAll(point, Size, Angle, StampTex, Hardness, Layers);
                }
            }
        }