void Start() { if (null != m_instance) { Destroy(this); } else { m_instance = this; // Strip unused color information // Later we may need to clip a rectangle from the texture, so we'll store it as two-dimensional array for convenience m_projSplashTexturesCount = projectileSplashTextures.Length; m_projSplashTextures = new List <float[, ]>(m_projSplashTexturesCount); for (int i = 0; i < m_projSplashTexturesCount; ++i) { Texture2D texture = projectileSplashTextures[i]; int textureWidth = texture.width; int textureHeight = texture.height; Color[] currTexture = texture.GetPixels(); float[,] textureAlphas = new float[textureWidth, textureHeight]; int counter = 0; for (int x = 0; x < textureWidth; ++x) { for (int y = 0; y < textureHeight; ++y) { textureAlphas[x, y] = currTexture[counter].a; counter++; } } m_projSplashTextures.Add(textureAlphas); } } }
public static PaintProjectileManager GetInstance() { if (null == m_instance) { m_instance = new PaintProjectileManager(); } return(m_instance); }
public GameObject GetPaintballFromPool() { // Check for objects in the pool if (paintballPool.Count > 0) { // Get the last object in the pool GameObject paintball = paintballPool.Pop(); paintball.GetComponent <PaintProjectileBehavior>().startPoint = Camera.main.transform.position + Camera.main.transform.forward * 3; paintball.gameObject.SetActive(true); return(paintball); } // creates a new paintball. return(Instantiate(PaintProjectileManager.GetInstance().paintBombPrefab, Camera.main.transform.position + Camera.main.transform.forward * 3, Camera.main.transform.rotation)); }
void Start() { m_npcManager = GetComponent <NPCManager>(); UnityEngine.Debug.Assert(null != m_npcManager, "NPC Manager script is not assigned to Game Manager object."); m_projectileManager = GetComponent <PaintProjectileManager>(); UnityEngine.Debug.Assert(null != m_npcManager, "Paint Projectile Manager script is not assigned to Game Manager object."); m_state = GameStates.Menu; m_projColorCount = projectileColors.Length; // try to load highscores m_highscores = new Highscores(c_gameTimes); MyReadHighscores(); }
void OnTriggerEnter(Collider other) { // Adds paintballs to the pool PaintballPool.instance.AddPaintballToPool(gameObject); // creates particle effects. ParticleSystem cloudParticle = Instantiate(PaintProjectileManager.GetInstance().cloudParticlePrefab); ParticleSystem burstParticle = Instantiate(PaintProjectileManager.GetInstance().burstParticlePrefab); MyShaderBehavior script = null; cloudParticle.transform.position = transform.position; burstParticle.transform.position = transform.position; var cloudSettings = cloudParticle.main; var burstSettings = burstParticle.main; cloudSettings.startColor = paintColor; burstSettings.startColor = paintColor; cloudParticle.Play(); burstParticle.Play(); PaintProjectileManager manager = PaintProjectileManager.GetInstance(); for (int i = 0; i < 14; ++i) { if (Physics.Raycast(transform.position, manager.GetSphereRay(i), out RaycastHit hit, paintDiameter)) { if (hit.collider is MeshCollider) { script = hit.collider.gameObject.GetComponent <MyShaderBehavior>(); if (null != script) { script.PaintOnColored(hit.textureCoord2, manager.GetRandomProjectileSplash(), paintColor); script.PaintOnColored(hit.textureCoord2, manager.GetRandomProjectileSplash(), paintColor); } } } } if (script != null) { float value = TextureColorFillCalculator.CalculateFill(GetObjectTexture().GetPixels(), paintColor, 0) * 100; menuController.SetSliderValue(value); } }
void OnTriggerEnter(Collider other) { if (!isActive) { return; } Destroy(gameObject); ParticleSystem cloudParticle = Instantiate(GameManager.GetInstance().GetProjectileManager().cloudParticlePrefab); ParticleSystem burstParticle = Instantiate(GameManager.GetInstance().GetProjectileManager().burstParticlePrefab); cloudParticle.transform.position = transform.position; burstParticle.transform.position = transform.position; var cloudSettings = cloudParticle.main; cloudSettings.startColor = paintColor; var burstSettings = burstParticle.main; burstSettings.startColor = paintColor; cloudParticle.Play(); burstParticle.Play(); PaintProjectileManager manager = GameManager.GetInstance().GetProjectileManager(); for (int i = 0; i < 14; ++i) { RaycastHit hit; if (Physics.Raycast(transform.position, manager.GetRandomSphereRay() /*GetSphereRay(i)*/, out hit, paintDiameter)) { if (hit.collider is MeshCollider) { MyShaderBehavior script = hit.collider.gameObject.GetComponent <MyShaderBehavior>(); if (null != script) { script.PaintOnColored(hit.textureCoord2, manager.GetRandomProjectileSplash(), paintColor); } } } } INpcBehavior npcScript = other.GetComponent <INpcBehavior>(); if (null != npcScript) { npcScript.DealDamage(damage); } }
void Update() { if (cameraController.isFps && gameManager.isGame) { if (passingTime < shotTime) { passingTime += Time.deltaTime; } else { if (Input.GetMouseButton(0)) { passingTime = 0; Vector3 touchPoint = CalculateShootRay(); if (touchPoint != Vector3.zero) { GameObject paintball = PaintballPool.instance.GetPaintballFromPool(); paintball.GetComponent <PaintProjectileBehavior>().target = CalculateShootRay(); //sends its destination paintball.GetComponent <PaintProjectileBehavior>().paintColor = PaintProjectileManager.GetInstance().paintBombColor; } if (menuController.CheckSliderValue()) { StartCoroutine(FindObjectOfType <GameManager>().WinGame()); } } } } }