public int m_poolAmount = 20;//amount of each type of explosion // Use this for initialization void Start() { //object pooling m_player = GameObject.FindObjectOfType <Player>(); m_camera = GameObject.FindObjectOfType <IsoCam>(); for (int numType = 0; numType < m_explosionPrefabs.Length; ++numType) { List <ExplosionItem> explosionType = new List <ExplosionItem>(); for (uint i = 0; i < m_poolAmount; ++i) { if (m_explosionPrefabs[numType] != null) { ExplosionItem newExplosion = new ExplosionItem(); newExplosion.m_object = (GameObject)Instantiate(m_explosionPrefabs[numType], this.transform); Explosion explosionScript = newExplosion.m_object.GetComponent <Explosion>(); if (explosionScript != null) { newExplosion.m_shockWaveStrength = explosionScript.m_shockWaveStrength; newExplosion.m_type = explosionScript.m_type; } newExplosion.m_object.SetActive(false); explosionType.Add(newExplosion); } } m_explosionPool.Add(explosionType); } }
public void StartBuildMode() { if (!isActivated) { isActivated = true; isAnimating = true; //Turn off Player playerMovement.lockMovements = true; playerMovement.isThinking = true; //Set Cursor as Target IsoCam isoCam = playerMovement.playerCamera.GetComponent <IsoCam>(); OrbitCam orbitCam = playerMovement.playerCamera.GetComponent <OrbitCam>(); if (isoCam != null) { isoCam.target = cameraTarget.transform; } else if (orbitCam != null) { orbitCam.target = cameraTarget.transform; } Vector3 playerPos = player.transform.position + Vector3.up; WorldChunk localChunk = worldStateManager.IsInsideWorldChunk(playerPos); if (localChunk != null) { Vector3 newPos = SnapToGrid(playerPos, localChunk); newPos.y = Mathf.Clamp(newPos.y, 0.5f, 10.5f); cursor.transform.position = newPos; actualCursorPos = cursor.transform.position; fluidCursor.transform.position = newPos; cameraTarget.transform.position = newPos; } StartCoroutine(DoSwapAnimation()); itemsPanel.SetActive(true); foreach (ItemHide itemHide in FindObjectsOfType <ItemHide>()) { itemHide.UpdateAvailablilty(); } ChangeSelection(currentSelection); foreach (PhysicsPrefab prefab in FindObjectsOfType <PhysicsPrefab>()) { prefab.Reset(); prefab.GetComponent <Rigidbody>().isKinematic = true; } SetupCursorObject(); } }
private void Awake() { if (m_playerCamera == null) { m_playerCamera = this; } else if (m_playerCamera != null) { Destroy(gameObject); } m_isometricCamera = GetComponent <Camera>(); }
public void EndBuildMode() { if (isActivated) { isActivated = false; isAnimating = true; //Turn off Player playerMovement.lockMovements = false; playerMovement.isThinking = false; //Set Cursor as Target IsoCam isoCam = playerMovement.playerCamera.GetComponent <IsoCam>(); OrbitCam orbitCam = playerMovement.playerCamera.GetComponent <OrbitCam>(); if (isoCam != null) { isoCam.target = playerMovement.transform; } else if (orbitCam != null) { orbitCam.target = playerMovement.transform; } StartCoroutine(DoSwapAnimation()); itemsPanel.SetActive(false); foreach (PhysicsPrefab prefab in FindObjectsOfType <PhysicsPrefab>()) { prefab.GetComponent <Rigidbody>().isKinematic = false; } if (cursorObject != null) { Destroy(cursorObject); } } }
private void Update() { cameraTarget.GetComponent <FluidCursor>().isLocked = isLocked; //User Inputs if (!isLocked && InputManager.controllers.Count > 0 && !PauseMenu.isPaused) { InputDevice inputDevice = InputManager.controllers[0]; if (!isAnimating && inputDevice.GetButtonWithLock("BuildMode")) { //Stop Any Hiding if (buildHideCoroutine != null) { StopCoroutine(buildHideCoroutine); StopCoroutine(playHideCoroutine); } if (isActivated) { EndBuildMode(); } else { StartBuildMode(); } hideTimer = 5f; isHiding = false; } if (isActivated) { //Map Cursor to Grid Vector3 mousePos; if (inputDevice.inputType == InputType.Keyboard) { mousePos = fluidCursor.transform.position; } else { mousePos = cameraTarget.transform.position; } mousePos.y = cameraTarget.GetComponent <FluidCursor>().GetActualPos().y; WorldChunk insideChunk = worldStateManager.IsInsideWorldChunk(mousePos); bool validCursor = insideChunk != null; if (validCursor) { actualCursorPos = worldStateManager.ChunkToWorld(insideChunk, worldStateManager.WorldToChunk(insideChunk, mousePos)); cursor.transform.position = actualCursorPos; } //Move the Cursor mousePos.y = cameraTarget.transform.position.y; fluidCursor.transform.position = mousePos; bool build = false, delete = false; int rotate = 0; //Build Controls build = inputDevice.GetButton("Create"); delete = inputDevice.GetButton("Delete"); //Rotation rotate = inputDevice.GetIntInputWithDelay("Rotate", 0.3f, Time.deltaTime); //Item Swapping int maxKeys = 10; if (inputDevice.inputType == InputType.Keyboard) { for (int i = 1; i < maxKeys; i++) { if (inputDevice.GetButtonWithLock("Item" + i)) { ChangeSelection(i); } } } else { int itemSwitch = inputDevice.GetIntInputWithDelay("ItemSwitch", 0.25f, Time.deltaTime); if (itemSwitch != 0) { int max = FindObjectOfType <BuildingPartDatabaseManager>().GetBuildingPartCount() + 1; ChangeSelection(MathHelper.NumClamp(currentSelection + itemSwitch, 1, Mathf.Min(max, maxKeys))); } } IsoCam isoCam = playerMovement.playerCamera.GetComponent <IsoCam>(); //Mouse Controls if (inputDevice.inputType == InputType.Keyboard) { Ray ray = playerMovement.playerCamera.ScreenPointToRay(Input.mousePosition); float hit; Plane plane = new Plane(Vector3.up, -fluidCursor.transform.position.y); if (plane.Raycast(ray, out hit)) { Vector3 hitPoint = ray.GetPoint(hit); hitPoint.y = fluidCursor.transform.position.y; fluidCursor.transform.position = hitPoint; } Debug.DrawRay(ray.origin, ray.direction, Color.red); } if (validCursor && inputDevice.inputType == InputType.Keyboard) { if (!RectTransformUtility.RectangleContainsScreenPoint(itemsPanel.GetComponent <RectTransform>(), Input.mousePosition, Camera.main)) { build = InputManager.GetClickHold(0); delete = InputManager.GetClickHold(1); } } grid.transform.position = Vector3.Scale(grid.transform.position, new Vector3(1f, 0f, 1f)) + Vector3.Scale(actualCursorPos, new Vector3(0f, 1f, 0f)) + new Vector3(0f, 0.06f, 0f); //Do Build Inputs if (build) { worldStateManager.CreateItem(currentSelection, actualCursorPos, rotationAmount); } else { worldStateManager.buildLock = false; } if (delete) { worldStateManager.DeleteItem(actualCursorPos); } //Do Rotating if (rotate != 0) { rotationAmount -= rotate * 90f; } lerpingRotationAmount = Mathf.Lerp(lerpingRotationAmount, rotationAmount, Time.deltaTime * lerpAmount); cursor.transform.rotation = Quaternion.identity * Quaternion.AngleAxis(lerpingRotationAmount, Vector3.up); } } if (cursorObject != null) { if (worldStateManager.CanPlace(currentSelection, actualCursorPos)) { currentCursorMaterial.color = validCursor; } else { currentCursorMaterial.color = invalidCursor; } } if (hideTimer > 0f) { hideTimer -= Time.deltaTime; } else if (!isHiding) { isHiding = true; buildHideCoroutine = StartCoroutine(FlipFade(buildModeImage, 0f)); playHideCoroutine = StartCoroutine(FlipFade(playModeImage, 0f)); } cursor.SetActive(isActivated); fluidCursor.SetActive(isActivated); grid.SetActive(isActivated); }
protected override void Update() { if (Input.GetMouseButtonDown(0) && cooldownBoolean == false) // When the left mouse button is pressed { Ray ray = IsoCam.ScreenPointToRay(Input.mousePosition); // Fire a ray from the main camera to the click position RaycastHit hit; //store the resulting hit if (Physics.Raycast(ray, out hit, Mathf.Infinity)) // if the hit coordiantes are on a valid collider within 500 units { NavMeshHit navmeshHit; // provide reference for a raycast hit on the navmesh int walkableMask = 1 << NavMesh.GetAreaFromName("Walkable"); // check if the nav mesh hit location was on a walkable layer/area if (NavMesh.SamplePosition(hit.point, out navmeshHit, 5.5f, walkableMask)) //if the ray position returns a walkable sample position { //print(hit.collider.gameObject.name + ", " + navmeshHit.mask); //uncomment if you require to know what the raycast is hitting for debugging NavMeshPath path = new NavMeshPath(); // create a reference for a nav mesh path Agent.CalculatePath(navmeshHit.position, path); //The agent calculates a path to the hit location on nav mesh if (path.status == NavMeshPathStatus.PathPartial || path.status == NavMeshPathStatus.PathInvalid) // if the agent calculates an impartial path { print("no path"); } else if (path.status == NavMeshPathStatus.PathComplete) // if the agent calculates a full path to destination point { //print("has path"); Agent.SetDestination(navmeshHit.position); // set the hit location on the nav mesh to the target destination for the agent Instantiate(ClickEffect, hit.point, Quaternion.LookRotation(hit.normal)); //spawn the click effect at the hit location if (hadTutorialClick == false) { hadTutorialClick = true; StartCoroutine(FadeTextToZeroAlpha(1f, tutorialClick)); tutorialClickParticle.Stop(); } } } } } // ANIMATION CONTROLLING BASED ON DISTANCE FROM TARGET DESTINATION ----------------------------------------------------------------------------- if (Agent.remainingDistance > Agent.stoppingDistance) // If remaining distance on path is greater than stopping distance { AdirAnim.SetBool("Walking", true); // play walking animation } else { AdirAnim.SetBool("Walking", false); //stop playing walking animation } //Tutorial checks if (check.waterPresent == true && fireOnce == false) { fireOnce = true; hadTutorialFlow = true; StartCoroutine(FadeTextToZeroAlpha(1f, tutorialFlow)); tutorialFlowParticle.Stop(); } }