//SheepController SpawnSheep() //{ // SheepController sheep = sheepControllersPool[currentSheepPoolCursor]; // SheepConfigData sheepConfigData = ConfigManager.Instance.GetSheepConfigByType(1); // sheep.InitSheep(sheepConfigData.Sheepvalue, sheepConfigData.Speed); // currentSheepPoolCursor++; // if (currentSheepPoolCursor >= numOfSheep) // currentSheepPoolCursor = 0; // float x = UnityEngine.Random.Range(spawningBox.bounds.center.x - spawningBox.bounds.extents.x, spawningBox.bounds.center.x + spawningBox.bounds.extents.x); // float z = UnityEngine.Random.Range(spawningBox.bounds.center.z - spawningBox.bounds.extents.z, spawningBox.bounds.center.z + spawningBox.bounds.extents.z); // sheep.transform.position = new Vector3(x, 1.8f, z); // sheep.transform.localEulerAngles = new Vector3(0, UnityEngine.Random.Range(0,360), 0); // sheep.gameObject.SetActive(true); // activeSheeps.Add(sheep); // return sheep; //} public void PutSheepBackToCage(SheepController sheepController) { float x = UnityEngine.Random.Range(spawningBox.bounds.center.x - spawningBox.bounds.extents.x, spawningBox.bounds.center.x + spawningBox.bounds.extents.x); float z = UnityEngine.Random.Range(spawningBox.bounds.center.z - spawningBox.bounds.extents.z, spawningBox.bounds.center.z + spawningBox.bounds.extents.z); sheepController.transform.position = new Vector3(x, 1.8f, z); sheepController.ResetState(); if (!activeSheeps.Contains(sheepController)) { activeSheeps.Add(sheepController); } currentSheepInCage++; LevelConfigData lvlConfig = ConfigManager.Instance.GetLevelConfigByLevel(DataManager.Instance.PlayerData.userLevel); txtLimitSheep.text = currentSheepInCage + "/" + lvlConfig.Maxsheep; }
private void UpdateNeighbours() { List <Vector2f> points = new List <Vector2f>(); // prepare for Fortunes algorithm and clear neighbours foreach (SheepController sheep in sheepList) { sheep.metricNeighbours.Clear(); sheep.voronoiNeighbours.Clear(); points.Add(new Vector2f(sheep.transform.position.x, sheep.transform.position.z, sheep.id)); } // get metric neighbours SheepController firstSheep, secondSheep; for (int i = 0; i < sheepList.Count; i++) { firstSheep = sheepList[i]; for (int j = i + 1; j < sheepList.Count; j++) { secondSheep = sheepList[j]; // dist? if ((firstSheep.transform.position - secondSheep.transform.position).sqrMagnitude < firstSheep.r_o2) { firstSheep.metricNeighbours.Add(secondSheep); secondSheep.metricNeighbours.Add(firstSheep); } } } // voronoi neighbours Rectf bounds = new Rectf(0.0f, 0.0f, fieldSize, fieldSize); Voronoi voronoi = new Voronoi(points, bounds); foreach (Vector2f pt in points) { SheepController sheep = sheepList[pt.id]; foreach (Vector2f neighbourPt in voronoi.NeighborSitesForSite(pt)) { SheepController neighbour = sheepList[neighbourPt.id]; sheep.voronoiNeighbours.Add(neighbour); } } }
private void OnTriggerEnter2D(Collider2D collision) // Should this live here or on the sheep/wolf? { if (collision.gameObject.CompareTag("Sheep")) { SheepController sheep = collision.gameObject.GetComponent <SheepController>(); if (sheep) { sheep.UnpanicSheep(); sheep.ChangeVelocity(transform.position, velocity); } // unpanic sheep from dashjump } else if (collision.gameObject.CompareTag("Wolf")) { WolfController wolf = collision.gameObject.GetComponent <WolfController>(); wolf.Die(); } }
public SheepController FindClosest(Vector3 pos, float maxDist, SheepController ignore = null) { // Max distance of closest sheep float closestDst = maxDist * maxDist; SheepController closest = null; // Find closest sheep to kill foreach (SheepController s in sheep) { float dist = (s.transform.position - pos).sqrMagnitude; if (s != ignore && dist <= closestDst) { closestDst = dist; closest = s; } } return(closest); }
private void OnTriggerEnter2D(Collider2D collision) { // lightning hits sheep if (collision.gameObject.CompareTag("Sheep")) { SheepController sheep = collision.gameObject.GetComponent <SheepController>(); if (sheep.isPanicked == false) { sheep.PanicSheep(); sheep.ChangeVelocity(transform.position, sheepHitVelocity); } else if (collision.gameObject.CompareTag("Wolf")) { WolfController wolf = collision.gameObject.GetComponent <WolfController>(); wolf.Die(); } } }
void LoadSheep(List <SheepData> sheepDatas) { int sheepCount = sheepDatas.Count; for (int i = 0; i < sheepCount; ++i) { SheepController sheep = SheepFactory.Instance.CreateNewSheep(sheepDatas[i].sheepType); sheep.InitSheep(sheepDatas[i].sheepType); sheep.transform.position = sheepDatas[i].position; sheep.transform.localEulerAngles = sheepDatas[i].localEulerAngles; switch ((SheepController.SheepState)sheepDatas[i].sheepState) { case SheepController.SheepState.Idle: currentSheepInCage++; break; case SheepController.SheepState.IsMovingOut: sheep.MoveOutOfCage(); break; case SheepController.SheepState.Running: sheep.transform.localEulerAngles = new Vector3(0, 90, 0); sheep.transform.position = beginPos.position; sheep.transform.position = sheep.transform.position + UnityEngine.Random.Range(-3, 0) * sheep.transform.forward; sheep.DOMoveOnPath(); break; case SheepController.SheepState.Jumping: sheep.DoJumpOverFence(); break; case SheepController.SheepState.Picking: var pos = sheep.transform.position; pos.y = 1.8f; sheep.transform.position = pos; currentSheepInCage++; break; default: break; } activeSheeps.Add(sheep); } }
void SpawnSheep() { // cleanup int i = 0; sheepList.Clear(); GameObject[] sheep = GameObject.FindGameObjectsWithTag("Sheep"); for (i = 0; i < sheep.Length; i++) { Destroy(sheep[i]); } // spawn Vector3 position; GameObject newSheep; i = 0; while (i < nOfSheep) { position = new Vector3(Random.Range(minSpawnX, maxSpawnX), .0f, Random.Range(minSpawnZ, maxSpawnZ)); float randomFloat = Random.Range(minSheepSize, 1.0f); newSheep = (GameObject)Instantiate(sheepPrefab, position, Quaternion.identity); newSheep.transform.localScale = new Vector3(randomFloat, randomFloat, randomFloat); SheepController sc = newSheep.GetComponent <SheepController>(); FlowSheepController fsc = newSheep.GetComponent <FlowSheepController>(); if (sheepBehaviour == Enums.SheepBehaviour.Individual) { fsc.enabled = false; sc.id = i; sheepList.Add(sc); } else { sc.enabled = false; fsc.id = i; flowSheepList.Add(fsc); } i++; } }
public void Flee(Vector3 pos, float dist, float time) { if (state == State.DEAD) { return; } if (state == State.SLEEPING) { state = State.ALIVE; panic = Mathf.Max(0, panic) + 2; if (Random.Range(0, 2) == 0) { SheepManager.instance.SpawnPopup(transform.position, panicMehs[Random.Range(0, mehs.Length)]); sound.pitch = Random.Range(1.1F, 1.2F); sound.PlayOneShot(mehSounds[Random.Range(0, mehSounds.Length)]); } } else { if (panic > 1) { if (Random.Range(0, 3) == 0) { SheepManager.instance.SpawnPopup(transform.position, panicMehs[Random.Range(0, mehs.Length)]); sound.pitch = Random.Range(1F, 1.2F); sound.PlayOneShot(mehSounds[Random.Range(0, mehSounds.Length)]); } } else if (Random.Range(0, 3) == 0) { sound.pitch = Random.Range(0.95F, 1.2F); sound.PlayOneShot(mehSounds[Random.Range(0, mehSounds.Length)]); } panic = Mathf.Max(0, panic) + 1; } agent.destination = transform.position + (transform.position - pos).normalized * dist; agent.speed = Mathf.Max(agent.speed, speed * Random.Range(1.25F + Mathf.Max(0, panic), 1.5F + panic + Mathf.Max(0, panic))); pathTime = Time.time + time; sleepTimer = 0; follow = this; }
public bool KillClosest(Vector3 pos) { SheepController closest = FindClosest(pos, infectDistance); // Kill closes sheep if (closest != null) { closest.Kill(); // Endgame when all sheeps are gone if (sheep.Count == 0) { EndGame(); } return(true); } return(false); }
public void AddSheeps(int n) { for (int i = 0; i < n; i++) { GameObject temp = Instantiate(sheepPrefab, transform); temp.transform.position = new Vector3(transform.position.x + Random.Range(-size.x / 2, size.x / 2), 1, transform.position.z + Random.Range(-size.z / 2, size.z / 2)); SheepController tempController = temp.GetComponentInChildren <SheepController>(); if (tempController == null) { Debug.LogError("[Herd] AddSheeps: no controller found"); } else { sheeps.Add(tempController); tempController.Init(); } } }
private void CheckForCollisions() { Collider[] hitColliders = Physics.OverlapBox(gameObject.transform.position, transform.localScale / 2, Quaternion.identity); int i = 0; while (i < hitColliders.Length) { if (hitColliders[i].GetComponent <SheepController>()) { SheepController sc = hitColliders[i].GetComponent <SheepController>(); sc.onDeathPartcileSystemTransform.parent = null; sc.onDeathPartcileSystem.Play(); sc.gameObject.SetActive(false); sc.transform.position = new Vector3(1000, 1000, 1000); sc.GetComponent <NavMeshAgent>().Warp(new Vector3(1000, 1000, 1000)); LevelController.Instance.SheepReachedGoal(); } i++; } }
public override void CollectObservations(VectorSensor sensor) { // space size: 10 // current positions: 2 wolfSquareController = wolf.Square().GetComponent <SquareController>(); sensor.AddObservation(wolfSquareController.column / (float)gameManager.columns); sensor.AddObservation(wolfSquareController.row / (float)gameManager.rows); // position of the sheep: 4 x (1+1) = 8 foreach (SheepController shp in gameManager.sheep) { SheepController shpController = shp.GetComponent <SheepController>(); shpSquareController = shpController.Square().GetComponent <SquareController>(); sensor.AddObservation(shpSquareController.column / (float)gameManager.columns); sensor.AddObservation(shpSquareController.row / (float)gameManager.rows); } haveObservation = true; }
private void OnCollisionEnter2D(Collision2D collision) // collision refers to other object { if (collision.gameObject.CompareTag("Sheep")) { SheepController otherSheep = collision.gameObject.GetComponent <SheepController>(); if (isPanicked) //if this sheep is spooked { if (otherSheep) { otherSheep.PanicSheep(); } // Panic the other sheep } GenerateMovementDir(); // change direction of this sheep if (otherSheep) { otherSheep.GenerateMovementDir(); } // change direction of other sheep } else if (collision.gameObject.CompareTag("Wolf")) // this sheep runs into a wolf { sheepRb.velocity = new Vector2(0f, 0f); GenerateMovementDir(); } else if (collision.gameObject.CompareTag("Boundary")) //switch direction if we hit edge of map { if (Mathf.Abs(collision.relativeVelocity.x) > Mathf.Abs(collision.relativeVelocity.y)) // if hitting a side wall { sheepRb.velocity = new Vector2(-sheepRb.velocity.x, sheepRb.velocity.y); movementDir = new Vector2(-movementDir.x, movementDir.y); } else // if hitting a top/bot wall { sheepRb.velocity = new Vector2(sheepRb.velocity.x, -sheepRb.velocity.y); movementDir = new Vector2(movementDir.x, -movementDir.y); } } }
void Start() { agent = GetComponent <NavMeshAgent>(); anim = GetComponentInChildren <Animator>(); sound = GetComponent <AudioSource>(); indicatorMat = indicator.GetComponent <MeshRenderer>().material; if (Random.Range(0, 5) == 0) { GetComponentInChildren <MeshRenderer>().material = blackMaterial; } speed = Random.Range(minSpeed, maxSpeed); followChance = Random.Range(minFollowChance, maxFollowChance); float scale = Random.Range(0.8F, 1.5F); transform.localScale *= scale; indicator.localScale /= scale; follow = this; floatOffset = Random.Range(0, Mathf.PI * 2); rotOffset = Random.Range(0, 360); sleepWaitTime = Random.Range(minSleepWaitTime, maxSleepWaitTime); }
public void OnPointerClick(PointerEventData eventData) { //if (occupant != null) { return; }; switch (eventData.button) { case PointerEventData.InputButton.Left: if (gameManager.Turn == Player.Wolf) { if (gameManager.WolfMovePossible(this)) { gameManager.wolfNextMove = this; gameManager.turnDone = false; } } if (!gameManager.selectedObject) { return; } ; if (gameManager.Turn == Player.Sheep) { SheepController sheepController = gameManager.selectedObject.GetComponent <SheepController>(); if (gameManager.SheepMovePossible(sheepController, this)) { gameManager.sheepNextMove = this; gameManager.sheepNext = sheepController; gameManager.turnDone = false; } } break; } }
void GenerateSheeps(bool isHorizontal) { removeAllSheeps(); int rowCount = 7; float offset = 1.3f; float yRowOffset = offset * Mathf.Sqrt(3) / 2; float startX = 0.5f - (offset * 4) / 2; float startY = -3.7f; float rowXoffset = 0.75f; float minX = float.MaxValue; float minY = float.MaxValue; float maxX = float.MinValue; float maxY = float.MinValue; int number = 0; List <int> indices = GenerateRandomNumberList(); for (int i = 0; i < rowCount; i++) { if (i % 2 != 0) { for (int j = 0; j < 4; j++) { GameObject dot = Instantiate(SheepPrefab); float randX = Random.Range(0.0f, 0.10f) - 0.05f; float randY = Random.Range(0.0f, 0.10f) - 0.05f; dot.transform.position = new Vector3(startX + j * offset + randX, 0, startY + i * yRowOffset + randY); SheepController controller = dot.GetComponent <SheepController>(); float randomSize = Random.Range(0.8f, 1.2f); controller.setSize(randomSize); controller.setNumber(indices[number]); number++; SheepList.Add(controller); if (dot.transform.position.x - dot.transform.localScale.x < minX) { minX = dot.transform.position.x - dot.transform.localScale.x; } if (dot.transform.position.x + dot.transform.localScale.x > maxX) { maxX = dot.transform.position.x + dot.transform.localScale.x; } if (dot.transform.position.z - dot.transform.localScale.z < minY) { minY = dot.transform.position.z - dot.transform.localScale.z; } if (dot.transform.position.z + dot.transform.localScale.z > maxY) { maxY = dot.transform.position.z + dot.transform.localScale.z; } } } else { for (int j = 0; j < 3; j++) { GameObject dot = Instantiate(SheepPrefab); float randX = Random.Range(0.0f, 0.10f) - 0.05f; float randY = Random.Range(0.0f, 0.10f) - 0.05f; dot.transform.position = new Vector3(startX + j * offset + rowXoffset + randX, 0, startY + i * yRowOffset + randY); SheepController controller = dot.GetComponent <SheepController>(); float randomSize = Random.Range(0.8f, 1.2f); controller.setSize(randomSize); controller.setNumber(indices[number]); number++; SheepList.Add(controller); if (dot.transform.position.x - dot.transform.localScale.x < minX) { minX = dot.transform.position.x - dot.transform.localScale.x; } if (dot.transform.position.x + dot.transform.localScale.x > maxX) { maxX = dot.transform.position.x + dot.transform.localScale.x; } if (dot.transform.position.z - dot.transform.localScale.z < minY) { minY = dot.transform.position.z - dot.transform.localScale.z; } if (dot.transform.position.z + dot.transform.localScale.z > maxY) { maxY = dot.transform.position.z + dot.transform.localScale.z; } } } } float x = (minX + maxX) / 2; float y = (minY + maxY) / 2; if (isHorizontal) { foreach (var dot in SheepList) { Vector3 temp = dot.gameObject.transform.position; temp.x = dot.gameObject.transform.position.z; temp.z = dot.gameObject.transform.position.x; dot.gameObject.transform.position = temp; } var tempX = x; x = y; y = tempX; } Camera camera = FindObjectOfType <Camera>(); if (isHorizontal) { camera.orthographicSize = 3.5f; } Vector3 oldPos = camera.gameObject.transform.position; oldPos.x = x; oldPos.z = y; camera.gameObject.transform.position = oldPos; }
// Use this for initialization void Start() { myController = transform.parent.GetComponent<SheepController>(); }
protected virtual void Sheep_OnDeselection(SheepSelector s) { currentSheep.OnMoveOrder -= Sheep_OnMoveOrder; currentSheep = null; }
void Update() { indicator.transform.localPosition = Vector3.up * (0.6F + 0.1F * Mathf.Cos(Time.time * 3 + floatOffset)); indicator.transform.rotation = Quaternion.Euler(45, Time.time * 90 + rotOffset, 45); anim.SetFloat("velocity", agent.velocity.magnitude); if (state == State.DEAD) { return; } if (panic > 5 || (maxPanicCounter > 3 && panic > 3) || (maxPanicCounter > 9)) { Kill(); return; } if (panic > 1) { sickTimer += Time.deltaTime; if (sickTimer > minSickTime) { sickTimer = 0; maxPanicCounter += 1; if (maxPanicCounter > 3) { state = State.SICK; } return; } } if (state == State.SLEEPING) { if (Random.Range(0, 200) == 0) { SheepManager.instance.SpawnPopup(transform.position, sleepyMehs[Random.Range(0, sleepyMehs.Length)]); } sleepTimer -= Time.deltaTime; if (sleepTimer <= 0) { panic = 0; sleepTimer = 0; state = State.ALIVE; } else { return; } } if (panic < -5 && (state == State.ALIVE || state == State.SICK)) { sleepTimer += Time.deltaTime; if (sleepTimer > sleepWaitTime) { SheepManager.instance.SpawnPopup(transform.position, sleepyMehs[Random.Range(0, sleepyMehs.Length)]); sleepTimer = Random.Range(maxSleepTime * 0.5F, maxSleepTime); state = State.SLEEPING; indicatorMat.color = new Color(-0.2F, 0, 1); follow = this; pathTime = 0; agent.destination = transform.position; sleepWaitTime = Random.Range(minSleepWaitTime, maxSleepWaitTime); if (maxPanicCounter > 0) { maxPanicCounter -= 1; } return; } } if (state == State.ALIVE) { indicatorMat.color = new Color(Mathf.Clamp01(panic), Mathf.Clamp01(1 - (panic - 1)), 0); panic = panic - Time.deltaTime; } else if (state == State.SICK) { infecTimer += Time.deltaTime; if (infecTimer > maxInfecTime) { infecTimer = 0; if (maxPanicCounter > 3 && Random.Range(0, 4) == 0) { if (SheepManager.instance.InfectClosest(transform.position, this)) { maxPanicCounter -= 1; } } } indicatorMat.color = new Color(0.5F, 0, 0.5F); panic = panic - Time.deltaTime; } else if (state == State.LOVE) { indicatorMat.color = new Color(1.0F, 0.4F, 0.6F); if (panic > 0) { state = State.ALIVE; } } if (state == State.LOVE) { if (!heartSystem.isPlaying) { heartSystem.Play(); } } else if (heartSystem.isPlaying) { heartSystem.Stop(); } if (Time.time > pathTime || panic > 0 && (agent.destination - transform.position).sqrMagnitude < 1) { SetTarget(); } // Only follow alive sheeps, else follow self if (follow != this) { if (follow.state != State.ALIVE) { if (follow.state == State.DEAD && state == State.LOVE) { Kill(); return; } follow = this; } else { agent.destination = follow.transform.position; } } // Avoid piles Vector3 avoidVec; if (panic < 2F && SheepManager.instance.AvoidPiles(transform.position, out avoidVec)) { agent.destination = transform.position + avoidVec.normalized * SheepManager.instance.pileAvoidDist; agent.speed = speed * Random.Range(1.5F, 2F); pathTime = Time.time + 2; panic += 0.5F * Time.deltaTime; if (!avoidedLastF) { SheepManager.instance.SpawnPopup(transform.position, "!"); } avoidedLastF = true; } else { avoidedLastF = false; } if (state == State.LOVE) { if (Random.Range(0, 500) == 0) { sound.pitch = Random.Range(0.95F, 1.05F); sound.PlayOneShot(mehSounds[Random.Range(0, mehSounds.Length)]); SheepManager.instance.SpawnPopup(transform.position, mehs[Random.Range(0, mehs.Length)] + " ❤️"); } } else if (Random.Range(0, 1000) == 0) { sound.pitch = Random.Range(0.95F, 1.05F); sound.PlayOneShot(mehSounds[Random.Range(0, mehSounds.Length)]); SheepManager.instance.SpawnPopup(transform.position, mehs[Random.Range(0, mehs.Length)]); } else if (Random.Range(0, 500) == 0) { sound.PlayOneShot(mehSounds[Random.Range(0, mehSounds.Length)]); } }
public override void OnActionReceived(float[] branches) { if (!haveObservation) { return; } // 1 branch // 0 = {sheep = 0; row = 1; col = -1} // 1 = {sheep = 0; row = 1; col = 1} // 2 = {sheep = 1; row = 1; col = -1} // 3 = {sheep = 1; row = 1; col = 1} // 4 = {sheep = 2; row = 1; col = -1} // 5 = {sheep = 2; row = 1; col = 1} // 6 = {sheep = 3; row = 1; col = -1} // 7 = {sheep = 3; row = 1; col = 1} int selection = Mathf.FloorToInt(branches[0]); int sheep = 0, row = 0, col = 0; // which way to go if (selection == 0) { sheep = 0; row = 1; col = -1; } ; if (selection == 1) { sheep = 0; row = 1; col = 1; } ; if (selection == 2) { sheep = 1; row = 1; col = -1; } ; if (selection == 3) { sheep = 1; row = 1; col = 1; } ; if (selection == 4) { sheep = 2; row = 1; col = -1; } ; if (selection == 5) { sheep = 2; row = 1; col = 1; } ; if (selection == 6) { sheep = 3; row = 1; col = -1; } ; if (selection == 7) { sheep = 3; row = 1; col = 1; } ; // which sheep gameManager.sheepNext = gameManager.sheep[sheep]; SheepController shController = gameManager.sheep[sheep].GetComponent <SheepController>(); SquareController squareController = shController.Square().GetComponent <SquareController>(); // which square int nextRow = squareController.row + row; int nextCol = squareController.column + col; SquareController nextSquare = gameManager.squares[nextCol, nextRow]; gameManager.sheepNextMove = nextSquare; }
void Awake() { woolBall = GameObject.FindGameObjectWithTag("WoolBall"); sheepController = FindObjectOfType <SheepController> (); sheepStamina = FindObjectOfType <SheepStamina> (); }
public void OnKillSheep(SheepController s) { sheep.Remove(s); }
private void Update() { if (Input.GetKeyDown(KeyCode.Alpha1)) { BoostTimer.Instance.ActiveBoost(BoostType.SheepSpeedUp); BoostSpeedOnce(); } if (Input.GetKeyDown(KeyCode.Alpha2)) { BoostTimer.Instance.ActiveBoost(BoostType.x2SheepValue); } if (Input.GetKeyDown(KeyCode.Alpha3)) { BoostTimer.Instance.ActiveBoost(BoostType.SuperBox); } if (Input.GetKeyDown(KeyCode.Alpha4)) { BoostTimer.Instance.ActiveBoost(BoostType.AutoMerge); } if (isOnCutScene) { if (camCart.m_Position == camPath.PathLength && camTarget.gameObject.activeSelf) { camTarget.gameObject.SetActive(false); camOverrall.gameObject.SetActive(true); DOVirtual.DelayedCall(2f, () => { //camOverrall.gameObject.SetActive(false); Destroy(camTarget.gameObject); Destroy(camOverrall.gameObject); Destroy(camCart.transform.parent.gameObject); Destroy(mainCam.GetComponent <Cinemachine.CinemachineBrain>()); cameraHandler.enabled = true; isOnCutScene = false; SheepController sheepController = SheepFactory.Instance.CreateNewSheep(1); GameController.Instance.PutSheepBackToCage(sheepController); SimpleResourcesManager.Instance.ShowParticle("MergeFx", sheepController.transform.position, 1); }); } } else { if (BoostTimer.Instance.IsAutoMerge) { AutoMergeSheep(); } //Mouse down if (Input.GetMouseButtonDown(0)) { Ray camRay = mainCam.ScreenPointToRay(Input.mousePosition); RaycastHit rayHit; int farmerLayer = LayerMask.GetMask("Farmer"); int sheepLayer = LayerMask.GetMask("Sheep"); if (Physics.Raycast(camRay, out rayHit, float.MaxValue, farmerLayer)) { farmer.Waving(); BoostSpeedOnce(); } else if (Physics.Raycast(camRay, out rayHit, float.MaxValue, sheepLayer)) { SheepController sheepController = rayHit.collider.GetComponent <SheepController>(); if (sheepController.SheepStateProp == SheepController.SheepState.Idle) { pickingSheep = sheepController; var pos = lastPickingPos = pickingSheep.transform.position; pos.y += 0.5f; pickingSheep.transform.position = pos; cameraHandler.enabled = false; pickingSheep.SetIsPickingUp(true); moveOutTrigger.gameObject.SetActive(true); } else if (sheepController.SheepStateProp == SheepController.SheepState.Running) { if (!this.IsCageFull()) { PutSheepBackToCage(sheepController); } else { //TODO: Show TextNofity } } //MarkCanMergeSheep(pickingSheep); } } else if (Input.GetMouseButton(0)) //Mouse move { if (pickingSheep != null) { float currentHeight = pickingSheep.transform.position.y; Ray camRay = GameController.Instance.mainCam.ScreenPointToRay(Input.mousePosition); RaycastHit rayHit; int groundLayer = LayerMask.GetMask("Island"); if (Physics.Raycast(camRay, out rayHit, float.MaxValue, groundLayer)) { Vector3 mouseWorldPos = rayHit.point; mouseWorldPos.y = currentHeight; pickingSheep.transform.position = mouseWorldPos; } int sheepLayer = LayerMask.GetMask("Sheep"); if (Physics.Raycast(camRay, out rayHit, float.MaxValue, sheepLayer)) { SheepController selectSheep = rayHit.collider.GetComponent <SheepController>(); if (lastCanMergeSheep != null && lastCanMergeSheep != selectSheep) { lastCanMergeSheep.SetCanMerge(false); } if (selectSheep.SheepStateProp == SheepController.SheepState.Idle && selectSheep.SheepType == pickingSheep.SheepType) { selectSheep.SetCanMerge(true); } lastCanMergeSheep = selectSheep; } else { if (lastCanMergeSheep != null) { lastCanMergeSheep.SetCanMerge(false); } } } } else if (Input.GetMouseButtonUp(0)) { if (pickingSheep != null) { Ray camRay = GameController.Instance.mainCam.ScreenPointToRay(Input.mousePosition); RaycastHit rayHit; int sheepLayer = LayerMask.GetMask("Sheep"); int roadLayer = LayerMask.GetMask("Road"); int islandLayer = LayerMask.GetMask("Island"); int groundLayer = LayerMask.GetMask("Ground"); bool hitSheep = Physics.Raycast(camRay, out rayHit, float.MaxValue, sheepLayer); if (hitSheep && rayHit.collider.GetComponent <SheepController>().SheepStateProp == SheepController.SheepState.Idle) { SheepController selectSheep = rayHit.collider.GetComponent <SheepController>(); if (selectSheep.SheepType < numOfSheepType && selectSheep.SheepStateProp == SheepController.SheepState.Idle && selectSheep.SheepType == pickingSheep.SheepType) { //DoMerge(); DoMerge(pickingSheep, selectSheep); } else { var pos = pickingSheep.transform.position; pos.y -= 0.5f; pickingSheep.transform.position = pos; } } else if (Physics.Raycast(camRay, out rayHit, float.MaxValue, groundLayer)) { var pos = pickingSheep.transform.position; pos.y -= 0.5f; pickingSheep.transform.position = pos; } else if (Physics.Raycast(camRay, out rayHit, float.MaxValue, islandLayer)) { pickingSheep.transform.position = lastPickingPos; OpenGateLeaveSheepOut(pickingSheep); } pickingSheep.SetIsPickingUp(false); pickingSheep = null; lastCanMergeSheep = null; cameraHandler.enabled = true; moveOutTrigger.gameObject.SetActive(false); } } } }
private void Start() { ConfigManager.Instance.LoadConfig(); SimpleResourcesManager.Instance.LoadResource(); DialogManager.Instance.LoadDialog(); DataManager.Instance.LoadData((isSuccess) => { BoostTimer.Instance.SetUp(); DataManager.Instance.PlayerData.userPlayTime += 1; currentSheepValue = DataManager.Instance.PlayerData.userSheepCoin; LoadSheep(DataManager.Instance.PlayerData.sheepDatas); string content = string.Format("<sprite>sheepIcon</sprite>{0}", BigNumbers.BigNumber.ToShortString(currentSheepValue.ToString("F0"), 4)); txtTopCountingText.SetText(content); LevelConfigData lvlConfig = ConfigManager.Instance.GetLevelConfigByLevel(DataManager.Instance.PlayerData.userLevel); float lvlProgressVal = DataManager.Instance.PlayerData.userExp * 1.0f / lvlConfig.Maxexp; txtLevelProgress.text = "Lv. " + DataManager.Instance.PlayerData.userLevel + "- <color=white>" + (lvlProgressVal * 100).ToString("F0") + "%"; lvlProgress.fillAmount = lvlProgressVal; txtLimitSheep.text = currentSheepInCage + "/" + lvlConfig.Maxsheep; if (DataManager.Instance.PlayerData.userLevel >= 3) { SpawnTimer.Instance.Setup(); } if (isOnCutScene && DataManager.Instance.PlayerData.userPlayTime == 1) { camTarget.gameObject.SetActive(true); cameraHandler.enabled = false; cutSceneSheep.gameObject.SetActive(true); mainCam.GetComponent <Cinemachine.CinemachineBrain>().enabled = true; OpenGateLeaveSheepOut(cutSceneSheep); SheepConfigData sheepConfigData = ConfigManager.Instance.GetSheepConfigByType(1); cutSceneSheep.InitSheep(sheepConfigData.Sheepvalue, sheepConfigData.Speed); } else { Destroy(camTarget.gameObject); Destroy(camOverrall.gameObject); Destroy(camCart.transform.parent.gameObject); Destroy(mainCam.GetComponent <Cinemachine.CinemachineBrain>()); cameraHandler.enabled = true; cutSceneSheep.gameObject.SetActive(false); if (DataManager.Instance.PlayerData.userPlayTime == 1) { int initSheepCount = 1; for (int i = 0; i < initSheepCount; ++i) { SheepController sheepController = SheepFactory.Instance.CreateNewSheep(1); GameController.Instance.PutSheepBackToCage(sheepController); SimpleResourcesManager.Instance.ShowParticle("MergeFx", sheepController.transform.position, 1); } } } }); }
void Start() { sheepController = FindObjectOfType <SheepController> (); sleepwalker = FindObjectOfType <Sleepwalker> (); }
void Start() { // anim = GetComponent<Animator>(); sheepController = FindObjectOfType <SheepController> (); rb2d = gameObject.GetComponent <Rigidbody2D>(); }