/// <summary> /// Function that replaces the old Sprite Collision system by a Pixel-Perfect Collision system. /// </summary> /// <returns>true if there's a collision, otherwise false</returns> public virtual bool HitTestPP() { if (selfAbs.Overlaps(PlayerController.instance.playerAbs)) { if (needUpdateTex) { texture = ((Texture2D)GetComponent <Image>().mainTexture).GetPixels32(); needUpdateTex = false; } /*Rect rectProjectile = new Rect(new Vector2(selfAbs.x + selfAbs.width * (self.anchorMax.x - 0.5f), selfAbs.y + selfAbs.height * (self.anchorMax.y - 0.5f)), * new Vector2(selfAbs.width, selfAbs.height));*/ Color32[] tempPlayerHitbox = new Color32[Mathf.RoundToInt(PlayerController.instance.playerAbs.width) * Mathf.RoundToInt(PlayerController.instance.playerAbs.height)]; for (int i = 0; i < tempPlayerHitbox.Length; i++) { tempPlayerHitbox[i].a = 255; } Vector2 positionPlayerFromProjectile = (Vector2)PlayerController.instance.self.position - selfAbs.position - (selfAbs.size + PlayerController.instance.playerAbs.size) / 2; return(UnitaleUtil.TestPP(tempPlayerHitbox, texture, ctrl.sprite.rotation, Mathf.RoundToInt(PlayerController.instance.playerAbs.height), GetComponent <Image>().mainTexture.height, new Vector2(ctrl.sprite.xscale, ctrl.sprite.yscale), positionPlayerFromProjectile)); //Color32[] colors = UnitaleUtil.RotateMatrixOld(texture, ctrl.sprite.rotation, (int)GetComponent<Image>().sprite.rect.height, self.localScale, out sizeDelta); /*Texture2D tex = new Texture2D((int)sizeDelta.x, (int)sizeDelta.y); * tex.SetPixels32(colors); * tex.Apply(false); * byte[] bytes = tex.EncodeToPNG(); * File.WriteAllBytes(Application.dataPath + "/SavedScreen" + count++ +".png", bytes);*/ } return(false); }
/// <summary> /// Function that replaces the old Sprite Collision system by a Pixel-Perfect Collision system. /// </summary> /// <returns>true if there's a collision, otherwise false</returns> public bool HitTestPP() { if (selfAbs.Overlaps(PlayerController.instance.playerAbs)) { if (needUpdateTex) { texture = ((Texture2D)img.mainTexture).GetPixels32(); needUpdateTex = false; } if (ControlPanel.instance.MinimumAlpha == 0) { if (img.color.a == 0) { return(false); } } else if (img.color.a < ControlPanel.instance.MinimumAlpha) { return(false); } Vector2 positionPlayerFromProjectile = (Vector2)PlayerController.instance.self.position - selfAbs.position - (selfAbs.size + PlayerController.instance.playerAbs.size) / 2; return(UnitaleUtil.TestPP(playerHitbox, texture, ctrl.sprite.rotation, 8, img.mainTexture.height, new Vector2(ctrl.sprite.xscale, ctrl.sprite.yscale), positionPlayerFromProjectile, img.color.a)); } return(false); }
/// <summary> /// Function that replaces the old Sprite Collision system by a Pixel-Perfect Collision system. /// </summary> /// <returns>true if there's a collision, otherwise false</returns> public bool HitTestPP() { if (!selfAbs.Overlaps(PlayerController.instance.playerAbs)) { return(false); } // TODO: Store a table of textures instead of a single texture and replace it when it's not on anymore? // Ex: animated bullets will often need to reload their sprite if (needUpdateTex) { texture = ((Texture2D)img.mainTexture).GetPixels32(); needUpdateTex = false; } Vector2 positionPlayerFromProjectile = (Vector2)PlayerController.instance.self.position - selfAbs.position - (selfAbs.size + PlayerController.instance.playerAbs.size) / 2; return(UnitaleUtil.TestPP(playerHitbox, texture, ctrl.sprite.rotation, 8, img.mainTexture.height, new Vector2(ctrl.sprite.xscale, ctrl.sprite.yscale), positionPlayerFromProjectile)); }