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();
                        }
                    }
                }
            }
        }
        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);
            }
        }
Beispiel #3
0
        public void Slice()
        {
            var positionA = transform.TransformPoint(LocalStart);
            var positionB = transform.TransformPoint(LocalEnd);

            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;
                        }
                    }
                }
            }
        }