/* Takes in a slider name, a sample index, and a t. Based on what the slider name is, will use the values to adjust the position, * and indicator. Both start slider and end slider don't use t parameter. */ public void AdjustSlider(string sliderName, int sampleIndex, float t) { if (String.Equals(sliderName, "StartSlider")) { startSliderSampleIndex = sampleIndex; float samplePercent = (float)startSliderSampleIndex / ((float)dummySampleCount - 1.0f); float newX = (samplePercent * localHalfLength * -2) + localHalfLength; startSlider.transform.localPosition = V3E.SetX(localCenter, newX); } else if (String.Equals(sliderName, "CurrentSlider")) { float samplePercent = (float)sampleIndex / ((float)dummySampleCount - 1.0f); float sliderPercent = t * (1.0f / ((float)dummySampleCount - 1.0f)) + samplePercent; float newX = (sliderPercent * localHalfLength * -2) + localHalfLength; currentSlider.transform.localPosition = V3E.SetX(localCenter, newX); } else if (String.Equals(sliderName, "EndSlider")) { endSliderSampleIndex = sampleIndex; float samplePercent = (float)endSliderSampleIndex / ((float)dummySampleCount - 1.0f); float newX = (samplePercent * localHalfLength * -2) + localHalfLength; endSlider.transform.localPosition = V3E.SetX(localCenter, newX); } else if (String.Equals(sliderName, "GhostSlider")) { float samplePercent = (float)sampleIndex / ((float)dummySampleCount - 1.0f); float sliderPercent = t * (1.0f / ((float)dummySampleCount - 1.0f)) + samplePercent; float newX = (sliderPercent * localHalfLength * -2) + localHalfLength; ghostSlider.transform.localPosition = V3E.SetX(localCenter, newX); } }
private void Update() { if (isGuiding) // If it is guiding, adjust its position, rotation and scale based on dummy's position { Vector3 newPosition = (DMS.GetSelectedDummy().transform.position - anchorPoint) / positionOffset + anchorPoint; Quaternion newRotation = Quaternion.FromToRotation(Vector3.up, (DMS.GetSelectedDummy().transform.position - anchorPoint)); float newLength = Vector3.Magnitude(DMS.GetSelectedDummy().transform.position - anchorPoint) * lengthOffset; transform.position = newPosition; transform.rotation = newRotation; transform.localScale = V3E.SetY(transform.localScale, newLength); } }
/* Takes in a finger trigger position and sliders the closest slider in one dimension relative to the finger * slider position (if the new slider position will be on the slider field). If the slider is the start slider * or the end slider then they will snap to the floored or ceiled sample respectively. Else if the slider is * the current slider, it will adjust the position with a smooth transition using t. */ private void SlideClosestSlider(Vector3 fingerTriggerPosition) { Vector3 worldCenter = transform.TransformPoint(localCenter); // Project point into two dimensions on slider field Vector3 v = fingerTriggerPosition - worldCenter; Vector3 d = Vector3.Project(v, transform.up); Vector3 pointInTwoDimensions = fingerTriggerPosition - d; // Project point into one dimension on slider field Vector3 v2 = pointInTwoDimensions - worldCenter; Vector3 d2 = Vector3.Project(v2, transform.forward); Vector3 pointInOneDimension = pointInTwoDimensions - d2; float testDistance = Vector3.Distance(pointInOneDimension, worldCenter); if (testDistance < worldHalfLength) { if (Vector3.Distance(pointInOneDimension, transform.TransformPoint(V3E.SetX(localCenter, -localHalfLength))) < Vector3.Distance(pointInOneDimension, transform.TransformPoint(V3E.SetX(localCenter, localHalfLength)))) { testDistance *= -1; // Closer to left side, so make negative since Vector3.Distance() is only magnitude } float sliderPercent = (testDistance - worldHalfLength) / (worldHalfLength * -2); if (closestSlider == startSlider) { // Find the floored sample index and adjust the start slider int flooredSampleIndex = (int)Mathf.Floor(sliderPercent * (dummySampleCount - 1)); AdjustSlider("StartSlider", flooredSampleIndex, 0.0f); DMS.AdjustStartAids(flooredSampleIndex); } else if (closestSlider == currentSlider) { // Find the floored sample index, find the t, adjust the current slider, then adjust slider indicator and dummy int flooredSampleIndex = (int)Mathf.Floor(sliderPercent * (dummySampleCount - 1)); if (flooredSampleIndex >= startSliderSampleIndex && flooredSampleIndex <= endSliderSampleIndex) { float flooredSamplePercent = (float)flooredSampleIndex / ((float)dummySampleCount - 1.0f); float t = (sliderPercent - flooredSamplePercent) / (1.0f / ((float)dummySampleCount - 1.0f)); AdjustSlider("CurrentSlider", flooredSampleIndex, t); DMS.DS_Adjust(flooredSampleIndex, t); } } else // end slider // Find the ceiled sample index and adjust end slider { int ceiledSampleIndex = (int)Mathf.Ceil(sliderPercent * (dummySampleCount - 1)); AdjustSlider("EndSlider", ceiledSampleIndex, 0.0f); DMS.AdjustEndAids(ceiledSampleIndex); } } }
private Dictionary <SE.Flavor, GameObject> ticTacPrefabDict; // Dictionary of tic tac prefabs, with their types as keys /* Takes in an tic tac flavor and a spawn amount, and spawns that many tic tacs of that flavor. Will only spawn up to the * far path limit. */ public void SpawnEnemies(SE.Flavor flavor, int spawnAmount) { if (!ticTacPrefabDict.ContainsKey(flavor)) { Debug.LogWarning("Tic Tac with flavor " + flavor + " doesn't exist."); return; } SE.PathRoute pathRoute = ticTacPrefabDict[flavor].GetComponent <TicTac>().PathRoute; Path path = (pathRoute == SE.PathRoute.Melee) ? meleePath : rangedPath; for (int i = 0; i < spawnAmount && pathLimits[2] - path.scriptDict.Count > 0; i++) { Vector3 spawnPosition = spawnPositions.Dequeue(); // Get spawn position float heightOffset = ticTacPrefabDict[flavor].transform.GetChild(0).localScale.y + (transform.position.y - (transform.localScale.y / 2.0f)); // Used to spawn object above field spawnPosition = V3E.SetY(spawnPosition, heightOffset); spawnPositions.Enqueue(spawnPosition); GameObject ticTac = Instantiate(ticTacPrefabDict[flavor], spawnPosition, Quaternion.identity); // Instantiate TicTac ticTacScript = ticTac.GetComponent <TicTac>(); ticTacScript.InitializeVariables(gameObject, collector); float delayTime = delayTimes.Dequeue(); // Get delay time delayTimes.Enqueue(delayTime); if (path.scriptDict.Count < pathLimits[0]) // Set path distance and start moving towards a new path position { ticTacScript.CurrPathDistance = SE.PathDistance.Close; ticTacScript.StartAdvanceCoroutine(((Random.insideUnitSphere * path.radii[0]) + path.centers[0]), delayTime); path.scriptDict.Add(ticTac.GetInstanceID(), ticTacScript); } else if (path.scriptDict.Count < pathLimits[1]) { ticTacScript.CurrPathDistance = SE.PathDistance.Mid; ticTacScript.StartAdvanceCoroutine(((Random.insideUnitSphere * path.radii[1]) + path.centers[1]), delayTime); path.scriptDict.Add(ticTac.GetInstanceID(), ticTacScript); } else // farPathLimit { ticTacScript.CurrPathDistance = SE.PathDistance.Far; ticTacScript.StartAdvanceCoroutine(((Random.insideUnitSphere * path.radii[2]) + path.centers[2]), delayTime); path.scriptDict.Add(ticTac.GetInstanceID(), ticTacScript); } } }
private void OnTriggerEnter(Collider other) { if (!triggered) { Vector3 hitPosition = V3E.SetY(transform.position, other.transform.position.y); // So explosion starts from inside the field rather // than at the orb's height Collider[] hitColliders = Physics.OverlapSphere(hitPosition, transform.localScale.x / 2.0f, 1 << LayerMask.NameToLayer("TicTac")); foreach (Collider hitCollider in hitColliders) { Destroy(hitCollider.GetComponent <Animator>()); Rigidbody hitRigidbody = hitCollider.GetComponent <Rigidbody>(); hitRigidbody.isKinematic = false; hitRigidbody.useGravity = true; hitRigidbody.AddExplosionForce(explosionForce, hitPosition, transform.localScale.x / 2.0f, upwardsModifier); hitTicTacs.Add(hitRigidbody.transform.parent.gameObject); } StartCoroutine(RemoveTicTacs()); triggered = true; } }
/* Takes in a path position and delay time and moves towards that path position. Waits a delay time amount of * seconds and then begins attacking once the path position has been reached. */ private IEnumerator Advance(Vector3 pathPosition, float delayTime) { yield return(new WaitForSeconds(delayTime)); animator.SetTrigger("AdvanceTrigger"); pathPosition = V3E.SetY(pathPosition, transform.position.y); // Set height of path position to tic tac's height while (Vector3.Distance(transform.position, pathPosition) > minArrivalDistance) { float step = Speed * Time.deltaTime; transform.position = Vector3.MoveTowards(transform.position, pathPosition, step); yield return(null); } transform.LookAt(V3E.SetY(collectorScript.transform.position, transform.position.y)); if (CurrPathDistance == SE.PathDistance.Close) { animator.SetTrigger("AttackTrigger"); } else { animator.SetTrigger("IdleTrigger"); } }