private void OnDestroy() { if (m_CurrentTarget == null) { return; } switch (m_CurrentType) { case eMapPointType.FISH: FishAI fish = m_CurrentTarget.GetComponent <FishAI>(); fish.OnSpawn -= ShowPoint; fish.OnDeath -= HidePoint; break; case eMapPointType.MISSIONTOWER: MissionTower missionTower = m_CurrentTarget.GetComponent <MissionTower>(); missionTower.OnActive -= CompletePoint; missionTower.OnActivating -= MobManager.m_Instance.StopAutoSpawn; missionTower.OnActive -= MobManager.m_Instance.StartAutoSpawn; UIPanelMap.Instance.DisplayPoint -= ShowPoint; UIPanelMap.Instance.HidePoint -= ClosePoint; break; case eMapPointType.PLAYER: UIPanelMap.Instance.DisplayPoint -= ShowPoint; UIPanelMap.Instance.HidePoint -= ClosePoint; m_CurrentPlayer.OnSpawnBegin -= ShowPoint; m_CurrentPlayer.OnDeathBegin -= HidePoint; break; } }
public void Init(GameObject target, eMapPointType type) { m_CurrentTarget = target; m_CurrentType = type; FindRadarCenter(); CalculatePosition(); switch (type) { case eMapPointType.FISH: FishAI fish = target.GetComponent <FishAI>(); fish.OnSpawn += ShowPoint; fish.OnDeath += HidePoint; break; case eMapPointType.MISSIONTOWER: m_Image = this.GetComponent <Image>(); //m_Color.r = 0.2666f; //m_Color.g = 0.843f; //m_Color.b = 1; m_Color = m_Image.color; MissionTower missionTower = target.GetComponent <MissionTower>(); missionTower.OnActive += CompletePoint; missionTower.OnActivating += MobManager.m_Instance.StopAutoSpawn; missionTower.OnActive += MobManager.m_Instance.StartAutoSpawn; UIPanelMap.Instance.DisplayPoint += ShowPoint; UIPanelMap.Instance.HidePoint += ClosePoint; break; } }
public void Init(AnimalInfo info, FishingArea containingArea) { base.Init(info); ContainingArea = containingArea; MouthPivotOffset = transform.Find("Mouth Pivot").localPosition; _aiBehaviour = new FishAI(this); Behaviour = DoWander; }
public void Start() { Age = 0.0f; energyState = GetComponent <EnergyState>(); movementCapability = GetComponent <MovementCapability>(); eater = GetComponent <EatOnCollide>(); edible = GetComponent <EdibleState>(); massMove = GetComponent <MovementBasedOnMass>(); ai = GetComponent <FishAI>(); if (ColorTarget != null) { mesh = ColorTarget.GetComponent <MeshRenderer>(); } }
public List <GameObject> getFishAtDepth(float depth) { List <GameObject> list = new List <GameObject>(); for (int i = 0; i < myFish.Count; i++) { GameObject currentFish = myFish[i]; FishAI fai = currentFish.GetComponent <FishAI>(); if (fai != null) { list.Add(currentFish); } } return(list); }
void FlockRules() { GameObject[] gos; gos = FlockManager.instance.allFishes; Vector3 vCentre = Vector3.zero; Vector3 vAvoid = Vector3.zero; float globalSpeed = 0.01f; float nDistance; int groupSize = 0; foreach (GameObject go in gos) { if (go != this.gameObject) { nDistance = Vector3.Distance(go.transform.position, this.transform.position); if (nDistance <= FlockManager.instance.neighbourDist) { vCentre += go.transform.position; groupSize++; if (nDistance < 1.0f) { vAvoid = vAvoid + (this.transform.position - go.transform.position); } FishAI goGameObj = go.GetComponent <FishAI>(); globalSpeed = globalSpeed + goGameObj.speed; } } } if (groupSize > 0) { vCentre = vCentre / groupSize + (FlockManager.instance.goalPosition - this.transform.position); speed = globalSpeed / groupSize; Vector3 direction = (vCentre + vAvoid) - transform.position; if (direction != Vector3.zero) { transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(direction), FlockManager.instance.rotationSpeed * Time.deltaTime); } } }
private void OnDisable() { if (m_CurrentTarget == null) { return; } switch (m_CurrentType) { case eMapPointType.FISH: FishAI fish = m_CurrentTarget.GetComponent <FishAI>(); fish.OnSpawn -= ShowPoint; fish.OnDeath -= HidePoint; break; case eMapPointType.PATROL: PatrolAI patrol = m_CurrentTarget.GetComponent <PatrolAI>(); patrol.OnSpawn -= ShowPoint; patrol.OnDeath -= HidePoint; break; case eMapPointType.FISHVARIANT: FishVariantAI fishVariant = m_CurrentTarget.GetComponent <FishVariantAI>(); fishVariant.OnSpawn -= ShowPoint; fishVariant.OnDeath -= HidePoint; break; case eMapPointType.TANK: TankAI tank = m_CurrentTarget.GetComponent <TankAI>(); tank.OnSpawn -= ShowPoint; tank.OnDeath -= HidePoint; break; //case eMapPointType.PLAYER: // m_CurrentPlayer.OnSpawnBegin -= ShowPoint; // m_CurrentPlayer.OnDeathBegin -= HidePoint; // break; } UIPanelRadar.Instance.UpdatePoint -= UpdatePosition; }
public List <GameObject> GetNearbyFish(float depth) { List <GameObject> nearbyFish = new List <GameObject>(); List <GameObject> fish = fishManager.getFishAtDepth(depth); foreach (GameObject f in fish) { FishAI fai = f.GetComponent <FishAI>(); float disty = Mathf.Abs(depth - f.transform.position.y); if (disty <= rangeY) { Vector2 myPos = new Vector2(playerCamera.transform.position.x, playerCamera.transform.position.z); Vector2 fishPos = new Vector2(f.transform.position.x, f.transform.position.z); if (Vector2.Distance(myPos, fishPos) <= rangeX) { nearbyFish.Add(f); } } } return(nearbyFish); }
public void CreateFish(int id, int startY, PathCreator path, bool allowAutoDespawn) { bool reversed = Random.value >= 0.5; float startX = Random.Range(-250, -550); //print("Spawning fish with ID: " + id); GameObject fish = Instantiate(fishPrefab, new Vector3(0, 0, 0), Quaternion.identity); // fish.transform.SetParent(submarineCanvas.transform); myFish.Add(fish); if (allowAutoDespawn) { idleFish.Add(fish); } FishAI fai = fish.GetComponent <FishAI>(); fai.id = id; fai.myManager = this; fai.gameState = gameState; fai.startDepth = gameState.CurrentDepth; fai.worldX = startX; fai.worldY = startY; fai.myPath = path; fai.endOfPathBehaviour = EndOfPathInstruction.Loop; fai.myBillBoard.target = playerCamera.transform; fai.dstTravelled = Random.Range(0f, 100f); fai.applyJitterToSpwawn = applyJitterToSpwawn; fai.allowAutoDespawn = allowAutoDespawn; if (reversed) { fai.reverseDirection = true; fai.transform.localScale = new Vector3(fai.transform.localScale.x * -1, fai.transform.localScale.y, fai.transform.localScale.z); } }
public void Init(GameObject target, eMapPointType type) { m_CurrentTarget = target; m_CurrentType = type; m_Image = this.GetComponent <Image>(); m_Color = m_Image.color; FindRadarCenter(); CalculatePosition(); switch (m_CurrentType) { case eMapPointType.FISH: FishAI fish = target.GetComponent <FishAI>(); fish.OnSpawn += ShowPoint; fish.OnDeath += HidePoint; break; case eMapPointType.PATROL: PatrolAI patrol = target.GetComponent <PatrolAI>(); patrol.OnSpawn += ShowPoint; patrol.OnDeath += HidePoint; break; case eMapPointType.FISHVARIANT: FishVariantAI fishVariant = target.GetComponent <FishVariantAI>(); fishVariant.OnSpawn += ShowPoint; fishVariant.OnDeath += HidePoint; break; case eMapPointType.TANK: TankAI tank = target.GetComponent <TankAI>(); tank.OnSpawn += ShowPoint; tank.OnDeath += HidePoint; break; } UIPanelRadar.Instance.UpdatePoint += UpdatePosition; }
public override void InitAI() { ai = new FishAI(this); }
void Start() { ai = transform.parent.GetComponent <FishAI>(); }
void Start() { health = Random.Range(minHealth, maxHealth); ai = GetComponent <FishAI>(); }
public void OnPointerClick(PointerEventData eventData) { if (cameraIdleCursor.gameObject.activeInHierarchy) { gameState.Camera = GameState.CameraState.Disarm; } else if (cameraCursor.gameObject.activeInHierarchy) { if (camFlash > 0) { // Debug.Log("Camera cooldown"); return; } // Debug.Log("Taking a picture"); // camera flash FireCameraFlash(); // camera sound FindObjectOfType <ambientSoundController>()?.PlayCamera(); // Find out which window we are taking a pic from RectTransform camTarget = null; Rect newRect = new Rect(); Vector3[] worldCorners = new Vector3[4]; foreach (var ct in cameraTargets) { ct.GetWorldCorners(worldCorners); newRect = new Rect(worldCorners[0], worldCorners[2] - worldCorners[0]); if (newRect.Contains(Input.mousePosition)) { camTarget = ct; break; } } if (camTarget == null) { return; } // Find the ray parameters Vector2 mousePos = eventData.position; Vector2 rectPos = new Vector2(newRect.x, newRect.y); Vector2 rectSize = new Vector2(newRect.width, newRect.height); //Debug.Log(mousePos); //Debug.Log(rectPos); //Debug.Log(rectSize); var texture = camTarget.GetComponent <UnityEngine.UI.RawImage>().texture; Camera activeCamera = null; if (cameraFront.targetTexture == texture) { activeCamera = cameraFront; } else if (cameraLeft.targetTexture == texture) { activeCamera = cameraLeft; } else if (cameraRight.targetTexture == texture) { activeCamera = cameraRight; } if (activeCamera == null) { return; } //Debug.Log(activeCamera.pixelRect); Vector2 camRectSize = new Vector2(activeCamera.pixelWidth, activeCamera.pixelHeight); Vector2 localPos = (mousePos - rectPos) / rectSize * camRectSize; //Debug.Log(localPos); // Annihilate the fishes with a barrage of deadly raytraces int fishcount = 0; for (int i = -320; i <= 320; i += 64) { for (int j = -192; j <= 192; j += 64) { var rayScreenPos = localPos + new Vector2(i, j); if (activeCamera.pixelRect.Contains(rayScreenPos)) { //Debug.Log(rayScreenPos); var ray = activeCamera.ScreenPointToRay(rayScreenPos); //var ray = new Ray(activeCamera.transform.position, activeCamera.transform.forward*5+activeCamera.transform.localToWorldMatrix.MultiplyVector(new Vector3(i/2, j/2, 0))); //Debug.DrawRay(ray.origin, ray.direction*20, Color.magenta, 20f); //Debug.Log(ray); var hits = Physics.RaycastAll(ray.origin, ray.direction, 500); foreach (var hit in hits) { // print(hit.transform.gameObject.name); FishAI fish = hit.transform.GetComponent <FishAI>(); if (fish != null) { bool newCatch = fish.Catch(); // TODO: sound if something is catched? fishcount++; if (newCatch) { FindObjectOfType <ambientSoundController>()?.PlaySuccess(); } } MoveAlongPath monsterPath = hit.transform.GetComponent <MoveAlongPath>(); if (monsterPath != null && !gameState.tookFotoOfMonster) { print("You took a picture of the monster! Ending game..."); gameState.tookFotoOfMonster = true; gameState.Camera = GameState.CameraState.Disarm; } } } } } // Debug.Log("Hit fish " + fishcount + " times while taking a picture"); } }
public FishAIStateManager(FishAI fai) { fishAI = fai; }