protected virtual void Update() { // Required key is down? if (Input.GetKeyDown(Requires) == true) { // Main camera exists? var mainCamera = Camera.main; if (mainCamera != null) { // World position of the mouse var position = D2dHelper.ScreenToWorldPosition(Input.mousePosition, Intercept, mainCamera); // Read the destructible and alpha at this position var destructible = default(D2dDestructible); var alpha = default(Color32); if (D2dDestructible.TrySampleAlphaAll(position, ref destructible, ref alpha) == true) { Debug.Log("Read " + destructible + " with alpha: " + alpha); } else { Debug.Log("Read nothing."); } } } }
protected virtual void Update() { // Touching the screen? inputManager.Update(Requires); if (inputManager.Fingers.Count > 0) { // Main camera exists? var mainCamera = Camera.main; if (mainCamera != null) { // World position of the mouse var position = D2dHelper.ScreenToWorldPosition(inputManager.Fingers[0].PositionA, Intercept, mainCamera); // Read the destructible and alpha at this position var destructible = default(D2dDestructible); var alpha = default(Color32); if (D2dDestructible.TrySampleAlphaAll(position, ref destructible, ref alpha) == true) { Debug.Log("Read " + destructible + " with alpha: " + alpha); } else { Debug.Log("Read nothing."); } } } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Mouse0)) { var mainCamera = Camera.main; var startPos = D2dHelper.ScreenToWorldPosition(Input.mousePosition, 0, mainCamera); Spawn(startPos); } }
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); } }
protected virtual void FixedUpdate() { if (Target != null) { // Get the main camera var mainCamera = Camera.main; // Begin dragging if (Input.GetKey(Requires) == true) { var position = D2dHelper.ScreenToWorldPosition(Input.mousePosition, Intercept, mainCamera); var factor = D2dHelper.DampenFactor(Dampening, Time.fixedDeltaTime); Target.velocity += (Vector2)(position - Target.transform.position) * factor; } } }
void Playing_Update() { // Required key is down? if (Input.GetKeyDown(KeyCode.Mouse0) == true) { // Get screen ray of mouse position explosionPosition = D2dHelper.ScreenToWorldPosition(Input.mousePosition, Intercept, mainCam); var collider = Physics2D.OverlapPoint(explosionPosition); if (collider != null) { var commonBox = collider.GetComponentInParent <CommonBox>(); if (commonBox != null) { commonBox.AddFire(explosionPosition); } //var destructible = collider.GetComponentInParent<D2dDestructible>(); //if (destructible != null) //{ // // Register split event // destructible.OnEndSplit.AddListener(OnEndSplit); // // Split via fracture // D2dQuadFracturer.Fracture(destructible, FractureCount, 0.5f); // // Unregister split event // destructible.OnEndSplit.RemoveListener(OnEndSplit); // // Spawn explosion prefab? // if (ExplosionPrefab != null) // { // var worldRotation = Quaternion.Euler(0.0f, 0.0f, UnityEngine.Random.Range(0.0f, 360.0f)); // Random rotation around Z axis // Instantiate(ExplosionPrefab, explosionPosition, worldRotation); // } //} } } }
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; } } } }
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); } } }
protected virtual void Update() { // Main camera exists? var mainCamera = Camera.main; if (mainCamera != null) { // World position of the mouse var position = D2dHelper.ScreenToWorldPosition(Input.mousePosition, Intercept, mainCamera); // Begin dragging if (Input.GetKey(Requires) == true && down == false) { down = true; } // End dragging if (Input.GetKey(Requires) == false && down == true) { down = false; // 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); } } } // Update indicator? if (down == true && IndicatorPrefab != null) { if (indicatorInstance == null) { indicatorInstance = Instantiate(IndicatorPrefab); indicatorScale = indicatorInstance.transform.localScale; indicatorInstance.SetActive(true); } indicatorInstance.transform.position = position; indicatorInstance.transform.localScale = Vector3.Scale(indicatorScale, new Vector3(Size.x, Size.y, 1.0f)); } // Destroy indicator? else if (indicatorInstance != null) { Destroy(indicatorInstance.gameObject); } } }
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(); } } } } }
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(); } } } } }
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) { // Calc values var startPos = D2dHelper.ScreenToWorldPosition(startMousePosition, Intercept, mainCamera); var currentPos = D2dHelper.ScreenToWorldPosition(Input.mousePosition, Intercept, mainCamera); var angle = GetAngleAndClampCurrentPos(startPos, ref currentPos) + ProjectileAngle + Random.Range(-ProjectileSpread, ProjectileSpread); // Spawn var projectile = Instantiate(ProjectilePrefab, startPos, Quaternion.Euler(0.0f, 0.0f, -angle)); projectile.SetActive(true); // Apply velocity? var rigidbody2D = projectile.GetComponent <Rigidbody2D>(); if (rigidbody2D != null) { rigidbody2D.velocity = (currentPos - startPos) * ProjectileSpeed; } } } // Update indicator? if (down == true && mainCamera != null && IndicatorPrefab != null) { if (indicatorInstance == null) { indicatorInstance = Instantiate(IndicatorPrefab); indicatorInstance.gameObject.SetActive(true); } var startPos = D2dHelper.ScreenToWorldPosition(startMousePosition, Intercept, mainCamera); var currentPos = D2dHelper.ScreenToWorldPosition(Input.mousePosition, Intercept, mainCamera); var angle = GetAngleAndClampCurrentPos(startPos, ref currentPos); var scale = Vector3.Distance(currentPos, startPos) * Scale; // 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); } }