コード例 #1
0
ファイル: D2dDragToShoot.cs プロジェクト: Gr1nS1de/hg-01
        protected virtual void Update()
        {
            // Get main camera
            var mainCamera = Camera.main;

            // Begin dragging
            if (Input.GetKey(Requires) == true && down == false)
            {
                down = true;
                startMousePosition = Input.mousePosition;
            }

            // Dragging finger released?
            if (Input.GetKey(Requires) == false && down == true)
            {
                down = false;

                // Impact prefab exists?
                if (ImpactPrefab != null)
                {
                    // Main camera exists?
                    if (mainCamera != null)
                    {
                        // Find start and end world points
                        var startPos = mainCamera.ScreenToWorldPoint(startMousePosition);
                        var endPos   = mainCamera.ScreenToWorldPoint(Input.mousePosition);

                        // Extend end pos to raycast hit
                        CalculateEndPos(startPos, ref endPos);

                        // Spawn explosion there
                        Instantiate(ImpactPrefab, endPos, Quaternion.identity);
                    }
                }
            }

            // Update indicator?
            if (down == true && mainCamera != null && IndicatorPrefab != null)
            {
                if (indicatorInstance == null)
                {
                    indicatorInstance = Instantiate(IndicatorPrefab);
                }

                var startPos = mainCamera.ScreenToWorldPoint(startMousePosition);
                var endPos   = mainCamera.ScreenToWorldPoint(Input.mousePosition); CalculateEndPos(startPos, ref endPos);
                var scale    = Vector3.Distance(endPos, startPos);
                var angle    = D2dHelper.Atan2(endPos - startPos) * Mathf.Rad2Deg;

                // Transform the indicator so it lines up with the slice
                indicatorInstance.transform.position   = new Vector3(startPos.x, startPos.y, indicatorInstance.transform.position.z);
                indicatorInstance.transform.rotation   = Quaternion.Euler(0.0f, 0.0f, -angle);
                indicatorInstance.transform.localScale = new Vector3(Thickness, scale, scale);
            }
            // Destroy indicator?
            else if (indicatorInstance != null)
            {
                Destroy(indicatorInstance.gameObject);
            }
        }
コード例 #2
0
        /// <summary>This will return the transformation matrix used to convert between world space and slice sprite space.</summary>
        public static Matrix4x4 CalculateMatrix(Vector2 startPos, Vector2 endPos, float thickness)
        {
            var mid   = (startPos + endPos) / 2.0f;
            var vec   = endPos - startPos;
            var size  = new Vector2(thickness, vec.magnitude);
            var angle = D2dHelper.Atan2(vec) * -Mathf.Rad2Deg;

            return(D2dStamp.CalculateMatrix(mid, size, angle));
        }
コード例 #3
0
ファイル: D2dSlicer.cs プロジェクト: zxx2112/TankBattle
        /// <summary>This will transform the current slicer between the input positions.</summary>
        public void SetTransform(Vector2 positionA, Vector2 positionB)
        {
            var scale = Vector2.Distance(positionB, positionA);
            var angle = D2dHelper.Atan2(positionB - positionA) * Mathf.Rad2Deg;

            // Transform the indicator so it lines up with the slice
            transform.position   = positionA;
            transform.rotation   = Quaternion.Euler(0.0f, 0.0f, -angle);
            transform.localScale = new Vector3(Thickness, scale, scale);
        }
コード例 #4
0
        protected virtual void Update()
        {
            // Get the main camera?
            if (mainCamera == null)
            {
                mainCamera = Camera.main;
            }

            // Begin dragging
            if (Input.GetKey(Requires) == true && down == false)
            {
                down = true;
                startMousePosition = Input.mousePosition;
            }

            // End dragging
            if (Input.GetKey(Requires) == false && down == true)
            {
                down = false;

                // Slice all Destructibles?
                if (mainCamera != null)
                {
                    var endMousePosition = Input.mousePosition;
                    var startPos         = mainCamera.ScreenToWorldPoint(startMousePosition);
                    var endPos           = mainCamera.ScreenToWorldPoint(endMousePosition);

                    D2dDestructible.SliceAll(startPos, endPos, Thickness, StampTex, Hardness);
                }
            }

            // Update indicator?
            if (down == true && mainCamera != null && IndicatorPrefab != null)
            {
                if (indicatorInstance == null)
                {
                    indicatorInstance = Instantiate(IndicatorPrefab);
                }

                var startPos   = mainCamera.ScreenToWorldPoint(startMousePosition);
                var currentPos = mainCamera.ScreenToWorldPoint(Input.mousePosition);
                var scale      = Vector3.Distance(currentPos, startPos);
                var angle      = D2dHelper.Atan2(currentPos - startPos) * Mathf.Rad2Deg;

                // Transform the indicator so it lines up with the slice
                indicatorInstance.transform.position   = new Vector3(startPos.x, startPos.y, indicatorInstance.transform.position.z);
                indicatorInstance.transform.rotation   = Quaternion.Euler(0.0f, 0.0f, -angle);
                indicatorInstance.transform.localScale = new Vector3(Thickness, scale, scale);
            }
            // Destroy indicator?
            else if (indicatorInstance != null)
            {
                Destroy(indicatorInstance.gameObject);
            }
        }
コード例 #5
0
ファイル: D2dDragToSlice.cs プロジェクト: zxx2112/TankBattle
        protected virtual void Update()
        {
            // Get the main camera
            var mainCamera = Camera.main;

            // Begin dragging
            if (Input.GetKey(Requires) == true && down == false)
            {
                down = true;
                startMousePosition = Input.mousePosition;
            }

            // End dragging
            if (Input.GetKey(Requires) == false && down == true)
            {
                down = false;

                // Main camera exists?
                if (mainCamera != null)
                {
                    var endMousePosition = Input.mousePosition;
                    var startPos         = D2dHelper.ScreenToWorldPosition(startMousePosition, Intercept, mainCamera);
                    var endPos           = D2dHelper.ScreenToWorldPosition(endMousePosition, Intercept, mainCamera);

                    D2dSlice.All(Paint, startPos, endPos, Thickness, Shape, Color, Layers);
                }
            }

            // Update indicator?
            if (down == true && mainCamera != null && IndicatorPrefab != null)
            {
                if (indicatorInstance == null)
                {
                    indicatorInstance = Instantiate(IndicatorPrefab);
                }

                var startPos   = D2dHelper.ScreenToWorldPosition(startMousePosition, Intercept, mainCamera);
                var currentPos = D2dHelper.ScreenToWorldPosition(Input.mousePosition, Intercept, mainCamera);
                var scale      = Vector3.Distance(currentPos, startPos);
                var angle      = D2dHelper.Atan2(currentPos - startPos) * Mathf.Rad2Deg;

                // Transform the indicator so it lines up with the slice
                indicatorInstance.transform.position   = startPos;
                indicatorInstance.transform.rotation   = Quaternion.Euler(0.0f, 0.0f, -angle);
                indicatorInstance.transform.localScale = new Vector3(Thickness, scale, scale);
            }
            // Destroy indicator?
            else if (indicatorInstance != null)
            {
                Destroy(indicatorInstance.gameObject);
            }
        }
コード例 #6
0
        protected virtual void Update()
        {
            // Get the main camera
            var mainCamera = Camera.main;

            // Begin dragging
            if (Input.GetKey(Requires) == true && down == false)
            {
                down = true;
                startMousePosition = Input.mousePosition;
            }

            // End dragging
            if (Input.GetKey(Requires) == false && down == true)
            {
                down = false;

                // Throw prefab?
                if (mainCamera != null && ProjectilePrefab != null)
                {
                    var projectile  = Instantiate(ProjectilePrefab);
                    var startPos    = D2dHelper.ScreenToWorldPosition(startMousePosition, Intercept, mainCamera);
                    var currentPos  = D2dHelper.ScreenToWorldPosition(Input.mousePosition, Intercept, mainCamera);
                    var angle       = D2dHelper.Atan2(currentPos - startPos) * Mathf.Rad2Deg;
                    var rigidbody2D = projectile.GetComponent <Rigidbody2D>();

                    if (rigidbody2D != null)
                    {
                        rigidbody2D.velocity = (currentPos - startPos) * ProjectileSpeed;
                    }

                    angle += Random.Range(-ProjectileSpread, ProjectileSpread);

                    projectile.transform.position = startPos;
                    projectile.transform.rotation = Quaternion.Euler(0.0f, 0.0f, -angle);
                }
            }

            // Update indicator?
            if (down == true && mainCamera != null && IndicatorPrefab != null)
            {
                if (indicatorInstance == null)
                {
                    indicatorInstance = Instantiate(IndicatorPrefab);
                }

                var startPos   = D2dHelper.ScreenToWorldPosition(startMousePosition, Intercept, mainCamera);
                var currentPos = D2dHelper.ScreenToWorldPosition(Input.mousePosition, Intercept, mainCamera);
                var scale      = Vector3.Distance(currentPos, startPos) * Scale;
                var angle      = D2dHelper.Atan2(currentPos - startPos) * Mathf.Rad2Deg;

                // Transform the indicator so it lines up with the slice
                indicatorInstance.transform.position   = startPos;
                indicatorInstance.transform.rotation   = Quaternion.Euler(0.0f, 0.0f, -angle);
                indicatorInstance.transform.localScale = new Vector3(scale, scale, scale);
            }
            // Destroy indicator?
            else if (indicatorInstance != null)
            {
                Destroy(indicatorInstance.gameObject);
            }
        }