예제 #1
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;

                // 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);
            }
        }
예제 #2
0
        public void Slice()
        {
            var positionA = transform.position;
            var positionB = transform.TransformPoint(0.0f, 1.0f, 0.0f);

            D2dSlice.All(Paint, positionA, positionB, Thickness, Shape, Color, Layers);

            // The slice won't happen until next frame, so delay the force application
            if (Force != 0.0f)
            {
                StartCoroutine(DelayedForce(positionA, positionB));
            }

            if (ParticleSystem != null && ParticlesPerUnit > 0.0f)
            {
                var particleCount = Mathf.CeilToInt(Vector3.Distance(positionA, positionB) * ParticlesPerUnit);

                if (particleCount > 0.0f)
                {
                    var emitParams = new ParticleSystem.EmitParams();
                    var positionD  = positionB - positionA;

                    if (ParticlesRandom == true)
                    {
                        for (var i = 0; i < particleCount; i++)
                        {
                            emitParams.position = positionA + positionD * Random.value;
                            emitParams.velocity = Random.insideUnitSphere;

                            ParticleSystem.Emit(emitParams, 1);
                        }
                    }
                    else
                    {
                        var step = positionD / particleCount;

                        emitParams.position = positionA + step * 0.5f;

                        for (var i = 0; i < particleCount; i++)
                        {
                            emitParams.velocity = Random.insideUnitSphere;

                            ParticleSystem.Emit(emitParams, 1);

                            emitParams.position += step;
                        }
                    }
                }
            }
        }