public static Clamp ( float value, float min, float max ) : float | ||
value | float | |
min | float | |
max | float | |
리턴 | float |
#pragma warning restore 414 KMSelectable[] ProcessTwitchCommand(string command) { command = command.ToLowerInvariant().Trim(); if (Regex.IsMatch(command, @"^press +[0-9^, |&]+$")) { command = command.Substring(6).Trim(); var presses = command.Split(new[] { ',', ' ', '|', '&' }, StringSplitOptions.RemoveEmptyEntries); var pressList = new List <KMSelectable>(); for (var i = 0; i < presses.Length; i++) { if (Regex.IsMatch(presses[i], @"^[0-9]{1,2}$")) { pressList.Add(ModuleButtons[Math.Clamp(Math.Max(1, int.Parse(presses[i].ToString())) - 1, 0, ModuleButtons.Length - 1)]); } } return(pressList.ToArray()); } if (Regex.IsMatch(command, @"^(submit|sub|s)$")) { return new[] { SubmitButton } } ; return(null); } }
public static int TagField(string label, int value) { // Make sure the tagNamesAndEditTagsButton is relatively up to date if (tagNamesAndEditTagsButton == null || EditorApplication.timeSinceStartup - timeLastUpdatedTagNames > 1) { timeLastUpdatedTagNames = EditorApplication.timeSinceStartup; var tagNames = AstarPath.FindTagNames(); tagNamesAndEditTagsButton = new string[tagNames.Length + 1]; tagNames.CopyTo(tagNamesAndEditTagsButton, 0); tagNamesAndEditTagsButton[tagNamesAndEditTagsButton.Length - 1] = "Edit Tags..."; } // Tags are between 0 and 31 value = Mathf.Clamp(value, 0, 31); var newValue = EditorGUILayout.IntPopup(label, value, tagNamesAndEditTagsButton, new [] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, -1 }); // Last element corresponds to the 'Edit Tags...' entry. Open the tag editor if (newValue == -1) { AstarPathEditor.EditTags(); } else { value = newValue; } return(value); }
void basicAttack() { lastClickedTime = Time.time; numberOfClicks++; if (numberOfClicks == 1) { animator.SetBool("basicAttack1", true); } numberOfClicks = Mathf.Clamp(numberOfClicks, 0, 3); }
public void Validate() { if (surfaceDefinition == null) { surfaceDefinition = new ChiselSurfaceDefinition(); } curveSegments = Mathf.Max(curveSegments, 2); revolveSegments = Mathf.Max(revolveSegments, 1); totalAngle = Mathf.Clamp(totalAngle, 1, 360); // TODO: constants surfaceDefinition.EnsureSize(6); }
void UpdateSolution() { updating = true; solvedMods = BombInfo.GetSolvedModuleNames().Count; if (solvedMods != prevSolvedMods) { var nowHalf = new String((countHalf) ? modLetter.Take(20).ToArray() : modLetter.Skip(20).ToArray()); shapeSolution = intShape[(Math.Clamp(nowHalf.Count(x => x == ((countUnlit) ? 'X' : 'O')), 5, 14) + ((solvedMods % 2 == 1) ? 10 : 0)) - 5]; } prevSolvedMods = solvedMods; updating = false; }
private Vector3 GetCameraClampedPosition() { // TODO: Support of many players var player = players[0]; var point = camera.WorldToViewportPoint(player.transform.position); // X target //var viewportXTarget = player.IsFacingRight ? ViewportXTarget : 1f - ViewportXTarget; var viewportXFraction = camera.WorldToViewportPoint(player.transform.position).x; //viewportXFraction = Mathf.Clamp(viewportXFraction, viewportXTarget - ViewportXTargetMaxInterval, viewportXTarget + ViewportXTargetMaxInterval); // Y target var viewportYFraction = camera.WorldToViewportPoint(player.transform.position).y; viewportYFraction = Mathf.Clamp(viewportYFraction, ViewportYMin, ViewportYMax); var delta = player.transform.position - camera.ViewportToWorldPoint(new Vector3(viewportXFraction, viewportYFraction, point.z)); return(transform.position + delta); }
void Tick() { if (Event.current.type == EventType.Repaint) { float deltaTime = Time.realtimeSinceStartup - lastUpdate; // Right at the start of a transition the deltaTime will // not be reliable, so use a very small value instead // until the next repaint if (value == 0f || value == 1f) { deltaTime = 0.001f; } deltaTime = Mathf.Clamp(deltaTime, 0.00001F, 0.1F); // Larger regions fade slightly slower deltaTime /= Mathf.Sqrt(Mathf.Max(lastRect.height, 100)); lastUpdate = Time.realtimeSinceStartup; float targetValue = open ? 1F : 0F; if (!Mathf.Approximately(targetValue, value)) { value += deltaTime * animationSpeed * Mathf.Sign(targetValue - value); value = Mathf.Clamp01(value); editor.Repaint(); if (!fancyEffects) { value = targetValue; } } else { value = targetValue; } } }
public void CircleXZ(Vector3 center, float radius, Color color, float startAngle = 0f, float endAngle = 2 *Mathf.PI) { int steps = 40; #if UNITY_EDITOR if (gizmos) { steps = (int)Mathf.Clamp(Mathf.Sqrt(radius / UnityEditor.HandleUtility.GetHandleSize((UnityEngine.Gizmos.matrix * matrix).MultiplyPoint3x4(center))) * 25, 4, 40); } #endif while (startAngle > endAngle) { startAngle -= 2 * Mathf.PI; } Vector3 prev = new Vector3(Mathf.Cos(startAngle) * radius, 0, Mathf.Sin(startAngle) * radius); for (int i = 0; i <= steps; i++) { Vector3 c = new Vector3(Mathf.Cos(Mathf.Lerp(startAngle, endAngle, i / (float)steps)) * radius, 0, Mathf.Sin(Mathf.Lerp(startAngle, endAngle, i / (float)steps)) * radius); Line(center + prev, center + c, color); prev = c; } }
void Update() { Vec3 pos; /* Cosine of the angle on the X-Z ("horizontal") plane */ float xCosTeta; /* Sine of the angle on the Z-Y ("vertical") plane */ float ySinPhi; if (this.player == null) { GO pl = null; this.rootEvent <GetPlayer>((x, y) => x.Get(out pl)); if (pl != null) { this.player = pl.transform; } return; } if (!Input.GetMouseCameraEnabled()) { /* Try to manipulate the camera using a gamepad */ xCosTeta = Global.camX * -1.0f * Input.GetCameraX(); ySinPhi = Global.camY * Input.GetCameraY(); this.wasUsingMouse = false; } else { if (this.wasUsingMouse) { /* Move the camera, using a 50px (?) circle around the mouse */ Vec3 mouseDelta = Input.GetMousePosition() - this.mouse; xCosTeta = Global.camX * -1.0f * mouseDelta.x * 0.02f; ySinPhi = Global.camY * -1.0f * mouseDelta.y * 0.02f; ySinPhi = Math.Clamp(ySinPhi, -1.0f, 1.0f); } else { /* Use the current position as the mouse's origin */ this.mouse = Input.GetMousePosition(); this.wasUsingMouse = true; xCosTeta = 0.0f; ySinPhi = 0.0f; } } xCosTeta = Math.Clamp(xCosTeta, -0.8f, 0.8f); float dist = Math.Sqrt(xCosTeta * xCosTeta + ySinPhi * ySinPhi); if (!this.wasUsingMouse && dist < 0.5f) { pos = new Vec3(this.baseDX, this.baseDY, this.baseDZ); } else { float zSinTeta = -1.0f * Math.Sqrt(1.0f - xCosTeta * xCosTeta); float zCosPhi = -1.0f * Math.Sqrt(1.0f - ySinPhi * ySinPhi); pos = new Vec3(xCosTeta, ySinPhi, (zSinTeta + zCosPhi) * 0.5f); } pos = pos.normalized * this.distance; this.lastPos = 0.75f * this.lastPos + pos * 0.25f; this.cam.position = this.player.position + this.lastPos; this.cam.LookAt(this.player); }
// Update is called once per frame void Update() { HPBar.value = hp; TimeBar.value = timeEnergy; // if player dead if (this.hp <= 0) { timeToGameRestart -= Time.deltaTime; int timetoRestartDelta = (int)timeToGameRestart; if (Input.GetKeyDown(KeyCode.R)) { timeToGameRestart = -1; } StartCoroutine(ShowMessage("Press \"r\" for restart. \n Auto restart in " + (timetoRestartDelta + 1))); if (timeToGameRestart < 0) { timeToGameRestart = 3; RestartGame(); } else { return; } } else { // number of click for attack chain if ((Time.time - lastClickedTime > maxComboDelay)) { numberOfClicks = 0; } // poruszanie i kamera if (!aim) { transform.Rotate(0f, Input.GetAxis("Mouse X") * Time.deltaTime * 225f, 0f); transform.position += transform.right * Input.GetAxis("Horizontal") * Time.deltaTime * 5f; transform.position += transform.forward * Input.GetAxis("Vertical") * Time.deltaTime * 5f; } else { if (!aimAnglesSetCorrectly) { angleVertical = transform.eulerAngles.x; angleHorizontal = transform.eulerAngles.y; aimAnglesSetCorrectly = true; } angleVertical += Input.GetAxis("Mouse Y") * Time.deltaTime * 225f; angleVertical = Mathf.Clamp(angleVertical, -35, 20); angleHorizontal += Input.GetAxis("Mouse X") * Time.deltaTime * 225f; transform.localEulerAngles = new Vector3(angleVertical, angleHorizontal, 0.0f); } // skok if (Input.GetKeyDown(KeyCode.Space) && IsGrounded()) { lastJumpTime = Time.time; body.velocity += new Vector3(0f, 5.0f, 0f); } if (IsGrounded()) { animator.SetBool("isGrounded", true); } else { animator.SetBool("isGrounded", false); } // basic attack + basic attack jump combo if (Input.GetMouseButtonDown(0)) { if (Time.time - lastJumpTime < 0.5f) { if (!IsAnyAttackBoolTrue()) { animator.SetBool("jumpAttack1", true); } } else { basicAttack(); } } // ranged attack + ranged attack jump combo if (Input.GetMouseButtonDown(1) && !IsAnyAttackBoolTrue()) { if (Time.time - lastJumpTime < 0.5f) { animator.SetBool("jumpAttack2", true); } else { animator.SetBool("rangedAttack", true); } } //special abilities energy management if (timeEnergy == 0) { timeStop = false; } if (!timeStop && !timeEnergyRegeneration && timeEnergy < 10) { timeEnergyRegeneration = true; StartCoroutine(RegenerateTimeEnergy()); } // special abilities if (Input.GetKeyDown(KeyCode.Q)) { if (timeStop || timeEnergy == 0) { timeStop = false; } else if (!timeStop && timeEnergy > 1) { timeStop = true; StartCoroutine(TimeIsStopped()); } } if (Input.GetKeyDown(KeyCode.E) && timeEnergy >= 5) { timeEnergy -= 5; transform.position = LastPositions[LastPositions.Count / 2]; hp = lastHPs[lastHPs.Count / 2]; ReLocateIndicies(LastPositions); ReLocateIndicies(lastHPs); } if (Input.GetKeyDown(KeyCode.R) && timeEnergy >= 3) { timeEnergy -= 3; transform.position = transform.Find("Player Model").Find("unityNieOgarnia").position; transform.Find("Player Model").GetComponent <Animator>().enabled = false; transform.Find("Player Model").GetComponent <Animator>().enabled = true; transform.Find("Player Model").GetComponent <Animator>().Play("Idle"); } if (Input.GetKeyDown(KeyCode.F)) { aim = !aim; if (!aim) { transform.eulerAngles = new Vector3(0.0f, transform.eulerAngles.y, transform.eulerAngles.z); } aimAnglesSetCorrectly = false; } // Attack system manager if (Manager != null) { } } }
#pragma warning restore 414 KMSelectable[] ProcessTwitchCommand(string command) { command = command.ToLowerInvariant().Trim(); if (Regex.IsMatch(command, @"^press +[0-9^, |&]+$")) { command = command.Substring(6).Trim(); var presses = command.Split(new[] { ',', ' ', '|', '&' }, StringSplitOptions.RemoveEmptyEntries); var pressList = new List <KMSelectable>(); for (int i = 0; i < presses.Length; i++) { if (Regex.IsMatch(presses[i], @"^[0-9]{1,2}$")) { pressList.Add(ModuleButtons[Math.Clamp(Math.Max(1, int.Parse(presses[i].ToString())) - 1, 0, ModuleButtons.Length - 1)]); } } return((pressList.Count > 0) ? pressList.ToArray() : null); } if (Regex.IsMatch(command, @"^show +([0-9^, |&]|all|top|bottom)+$")) { if (!ColScreen.activeSelf) { return(null); } command = command.Substring(5).Trim(); var showing = command.Split(new[] { ',', ' ', '|', '&' }, StringSplitOptions.RemoveEmptyEntries); var showList = new List <int>(); for (int i = 0; i < showing.Length; i++) { if (Regex.IsMatch(showing[i], @"^[0-9]{1,2}$")) { showList.Add(Math.Clamp(Math.Max(1, int.Parse(showing[i].ToString())) - 1, 0, ModuleButtons.Length - 1)); } else { showList.Clear(); for (int j = ((showing[i].Equals("bottom")) ? 10 : 0); j < 20 - (((showing[i].Equals("top")) ? 10 : 0)); j++) { showList.Add(j); } break; } } if (showList.Count == 0) { return(null); } StopAllCoroutines(); StartCoroutine(ShowScreen(showList)); return(new KMSelectable[0]); } if (Regex.IsMatch(command, @"^\s*(colorblind|cb)\s*$")) { ColScreen.SetActive(true); return(new KMSelectable[0]); } return(null); }
private void Update() { if (!_initCompleted) { return; } if (SuperController.singleton.freezeAnimation) { return; } #if LFE_DEBUG if (Input.GetKey("up")) { CameraTarget.centerTarget.targetCamera.enabled = false; _detector.Detector.enabled = true; } else { CameraTarget.centerTarget.targetCamera.enabled = true; _detector.Detector.enabled = true; } #endif try { _brightnessChangeCountdown -= Time.deltaTime; // run the scheduled animation if (_currentAnimation != null) { _pupilMorph.morphValueAdjustLimits = Math.Clamp(_currentAnimation.Update(), -1.5f, 2.0f); if (_currentAnimation.IsFinished) { _currentAnimation = null; // schedule a new idle _idleCountDown = UnityEngine.Random.Range(0.01f, Math.Max(IdleMaxDelayStorable.val, 0.01f)); } } var brightness = CalculateBrightness(); var currentValue = _pupilMorph.morphValue; var targetValue = BrightnessToMorphValue(brightness); var duration = 0f; if (_lastBrightness == brightness) { // maybe schedule an idle animation - but do not interrupt an animation in progress just for idle if (_currentAnimation == null && _idleCountDown < 0) { duration = Math.Max(IdleAdjustSpeedStorable.val, 0.01f); _idleSign = _idleSign * -1; targetValue = targetValue + (_idleSign * UnityEngine.Random.Range(0.01f, IdleStrengthStorable.val)); _currentAnimation = new EyeDialationAnimation(currentValue, targetValue, duration, (p) => Easings.BackEaseOut(p)); } else { _idleCountDown -= Time.deltaTime; } } else { if (_brightnessChangeCountdown <= 0) { // schedule brightness adjustment animation - override any currently running animation for this one. light always wins duration = targetValue > currentValue ? DarkAdjustSpeedStorable.val : LightAdjustSpeedStorable.val; _currentAnimation = new EyeDialationAnimation(currentValue, targetValue, duration, (p) => Easings.ElasticEaseOut(p)); _brightnessChangeCountdown = _brightnessChangeThrottle; } } _lastBrightness = brightness; } catch (Exception ex) { SuperController.LogError(ex.ToString()); } }
Vector3 Snap(ABPath path, Exactness mode, bool start, out bool forceAddPoint) { var index = start ? 0 : path.path.Count - 1; var node = path.path[index]; var nodePos = (Vector3)node.position; forceAddPoint = false; switch (mode) { case Exactness.ClosestOnNode: return(start ? path.startPoint : path.endPoint); case Exactness.SnapToNode: return(nodePos); case Exactness.Original: case Exactness.Interpolate: case Exactness.NodeConnection: Vector3 relevantPoint; if (start) { relevantPoint = adjustStartPoint != null?adjustStartPoint().ToPFV3() : path.originalStartPoint; } else { relevantPoint = path.originalEndPoint; } switch (mode) { case Exactness.Original: return(GetClampedPoint(nodePos, relevantPoint, node)); case Exactness.Interpolate: // Adjacent node to either the start node or the end node in the path var adjacentNode = path.path[Mathf.Clamp(index + (start ? 1 : -1), 0, path.path.Count - 1)]; return(VectorMath.ClosestPointOnSegment(nodePos, (Vector3)adjacentNode.position, relevantPoint)); case Exactness.NodeConnection: // This code uses some tricks to avoid allocations // even though it uses delegates heavily // The connectionBufferAddDelegate delegate simply adds whatever node // it is called with to the connectionBuffer connectionBuffer = connectionBuffer ?? new List <GraphNode>(); connectionBufferAddDelegate = connectionBufferAddDelegate ?? (System.Action <GraphNode>)connectionBuffer.Add; // Adjacent node to either the start node or the end node in the path adjacentNode = path.path[Mathf.Clamp(index + (start ? 1 : -1), 0, path.path.Count - 1)]; // Add all neighbours of #node to the connectionBuffer node.GetConnections(connectionBufferAddDelegate); var bestPos = nodePos; var bestDist = float.PositiveInfinity; // Loop through all neighbours // Do it in reverse order because the length of the connectionBuffer // will change during iteration for (int i = connectionBuffer.Count - 1; i >= 0; i--) { var neighbour = connectionBuffer[i]; // Find the closest point on the connection between the nodes // and check if the distance to that point is lower than the previous best var closest = VectorMath.ClosestPointOnSegment(nodePos, (Vector3)neighbour.position, relevantPoint); var dist = (closest.ToUnityV3() - relevantPoint).sqrMagnitude; if (dist < bestDist) { bestPos = closest; bestDist = dist; // If this node is not the adjacent node // then the path should go through the start node as well forceAddPoint = neighbour != adjacentNode; } } connectionBuffer.Clear(); return(bestPos); default: throw new System.ArgumentException("Cannot reach this point, but the compiler is not smart enough to realize that."); } default: throw new System.ArgumentException("Invalid mode"); } }
void Start() { moduleId = moduleIdCounter++; string[] choseColor = { "Yellow", "Green", "Cyan", "Blue", "Purple", "White" }; int chooseRndColor = Random.Range(0, randomColors.Length); ColScreen.transform.GetChild(0).GetComponent <TextMesh>().text = ""; buttonsColor = randomColors[chooseRndColor]; char[] moduleLetters = { 'A', 'B', 'D', 'E', 'G', 'I', 'K', 'L', 'N', 'O', 'P', 'S', 'T', 'X', 'Y' }; string[] intLetter = { "XOOOXOXXXOOXXXOOOOOOOXXXOOXXXOOXXXOOXXXO", "OOOOXOXXXOOXXXOOOOOXOXXXOOXXXOOXXXOOOOOX", "OOOOXOXXXOOXXXOOXXXOOXXXOOXXXOOXXXOOOOOX", "OOOOOOXXXXOXXXXOOOOXOXXXXOXXXXOXXXXOOOOO", "XOOOXOXXXOOXXXXOXXXXOXOOOOXXXOOXXXOXOOOX", "OOOOOXXOXXXXOXXXXOXXXXOXXXXOXXXXOXXOOOOO", "OXXXOOXXOXOXOXXOOXXXOXOXXOXXOXO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", "XOOOXOXXXOOXXXOXOOOXOXXXOOXXXOOXXXOXOOOX", "OOOOOOXOXOOOXOOOXOXOOXOXOOOXOOOXOXOOOOOO", "XOOOXOXXXOOXXXOOXXXOOXXXOOXXXOOXXXOXOOOX", "OXXXOOXXXOOXXXOOXXXOOXOXOOXOXOOXOXOXOXOX", "OXOXOXOXOXXOXOXXXOXXXXOXXXOXOXXOXOXOXOXO", "OOOOOXXOXXXXOXXXXOXXXXOXXXXOXXXXOXXOOOOO", "XXXXXXXOXXXOOOXOXXXOOOOOOOXXXOOXXXOOOOOO", "XXOXXXOXOXXOXOXXXOXXOXXXOXOXOXXXOXXXXOXX", "XXXOXXXXOXOOOOOXXOOXXOXOXOXXOXXXXOXXXXOX", "OOOOXXXXOXXXXOXXXXOXXXXOXXXXOXOXXOXXOOXX", "XXOXXXOOOXOXOXOXXOXXXXOXXXXOXXXXOXXXXOXX" }; selectLetter = Random.Range(0, intLetter.Length); var onSqrCount = intLetter[selectLetter].Count(x => x == 'O'); var offSqrCount = intLetter[selectLetter].Count(x => x == 'X'); rnd = RuleSeedable.GetRNG(); Debug.LogFormat(@"[Shapes Bombs #{0}] Using rule seed: {1}", moduleId, rnd.Seed); char[] intFullLetter = { 'A', 'B', 'D', 'E', 'G', 'I', 'K', 'L', 'N', 'O', 'P', 'S', 'T', 'X', 'Y' }; int[] chooseSequence = { Array.FindIndex(intFullLetter, x => x.Equals(moduleLetters[selectLetter])), BombInfo.GetModuleNames().Count, onSqrCount, offSqrCount, 0 }; int[] sequenceTables = new int[5]; string[] letterTables = Enumerable.Repeat("", 5).ToArray(); intShape = chooseShapes.Take(20).ToArray(); if (rnd.Seed == 1) { chooseSequence.CopyTo(sequenceTables, 0); letterTables = new[] { "KEPTALINGDOBYXS", "KINGSLEDYOPXTAB", "ONSLYPKIDTXBAEG", "ABDEGIKLNOPSTXY", "YXTSPONLKIGEDBA" }; } else if (rnd.Seed == 333) { for (int i = 0; i < sequenceTables.Length; i++) { sequenceTables[i] = 3; } for (int i = 0; i < letterTables.Length; i++) { for (int j = 0; j < 15; j++) { letterTables[i] += "K"; } } for (int i = 0; i < intShape.Length; i++) { intShape[i] = chooseShapes[3]; } } else { for (int i = 0; i < intFullLetter.Length; i++) { intFullLetter[i] = moduleLetters[ChooseUnique(15)]; } chooseSequence[0] = Array.FindIndex(intFullLetter, x => x.Equals(moduleLetters[selectLetter])); chooseSequence[4] = rnd.Next(15); pickedValues.Clear(); for (int i = 0; i < sequenceTables.Length; i++) { sequenceTables[i] = chooseSequence[ChooseUnique(5)]; } for (int i = 0; i < letterTables.Length; i++) { pickedValues.Clear(); for (int j = 0; j < 15; j++) { letterTables[i] += moduleLetters[ChooseUnique(15)].ToString(); } } pickedValues.Clear(); for (int i = 0; i < intShape.Length; i++) { intShape[i] = chooseShapes[ChooseUnique(100)]; } } myShape = intLetter[selectLetter]; modLetter = myShape; ArrowScreen.transform.GetComponent <Renderer>().material = BlackMat; NumScreen.transform.GetChild(0).GetComponent <TextMesh>().text = ""; int[] arrowDirVal = { 0, 1, -5, -1, 5, -4, 6, -6, 4 }; var logArrows = ""; for (int i = 0; i < chooseArrows.Length; i++) { chooseArrows[i] = Random.Range(0, arrowDirVal.Length); logArrows += new[] { "Center", "Right", "Up", "Left", "Down", "Right-Up", "Right-Down", "Up-Left", "Left-Down" }[chooseArrows[i]] +" (" + i + ") "; } ColScreen.SetActive(ColorblindMode.ColorblindModeActive); Debug.LogFormat(@"[Shapes Bombs #{0}] Initial letter is: {1}", moduleId, moduleLetters[selectLetter]); Debug.LogFormat(@"[Shapes Bombs #{0}] Color for the squares is: {1}", moduleId, choseColor[chooseRndColor]); Debug.LogFormat(@"[Shapes Bombs #{0}] Arrow sequence is: {1}", moduleId, logArrows); if (!buttonsColor.Equals(Color.white)) { var selectTable = letterTables[chooseRndColor]; var intStartSequence = sequenceTables[chooseRndColor]; var tableStartSequence = intStartSequence % 15; var nowLetter = Array.FindIndex(selectTable.ToCharArray(), x => x.Equals(moduleLetters[selectLetter])); for (int i = 0; i < chooseArrows.Length; i++) { if (i >= tableStartSequence) { nowLetter = GetWrapedTable(nowLetter, arrowDirVal[chooseArrows[i]], selectTable.Length, 3); } } var endSequence = Array.FindIndex(intFullLetter, x => x.Equals(selectTable[nowLetter])); Debug.LogFormat(@"[Shapes Bombs #{0}] Initial number of table is: {1}", moduleId, intStartSequence); Debug.LogFormat(@"[Shapes Bombs #{0}] Starting table arrow sequence at: {1}", moduleId, tableStartSequence); Debug.LogFormat(@"[Shapes Bombs #{0}] Letter table is:", moduleId); InputLogShape(selectTable); Debug.LogFormat(@"[Shapes Bombs #{0}] Ended table at letter: {1}", moduleId, selectTable[nowLetter]); var nowSquare = Math.Clamp(intStartSequence, 0, ModuleButtons.Length - 1); Debug.LogFormat(@"[Shapes Bombs #{0}] Initial square location is: {1}", moduleId, nowSquare + 1); Debug.LogFormat(@"[Shapes Bombs #{0}] Module starting arrow sequence at: {1}", moduleId, endSequence); for (int i = endSequence; i < chooseArrows.Length; i++) { nowSquare = GetWrapedTable(nowSquare, arrowDirVal[chooseArrows[i]] * ((modLetter[nowSquare].Equals('O')) ? 1 : -1), ModuleButtons.Length, 5); var addChar = (modLetter[nowSquare].Equals('O')) ? "X" : "O"; modLetter = modLetter.Remove(nowSquare, 1); modLetter = modLetter.Insert(nowSquare, addChar); } } getCount = ((x, y) => x.Count(z => z == y)); countUnlit = (int.Parse(BombInfo.GetSerialNumber()[5].ToString())) % 2 == 1; countHalf = ((Array.FindIndex(intFullLetter, x => x.Equals(moduleLetters[selectLetter]))) % 2 == 0); UpdateSolution(); var nowHalf = new String(((countHalf)) ? modLetter.Take(20).ToArray() : modLetter.Skip(20).ToArray()); var nowCount = getCount(nowHalf, (countUnlit) ? 'X' : 'O'); Debug.LogFormat(@"[Shapes Bombs #{0}] Counting {1} squares", moduleId, (countUnlit) ? "unlit" : "lit"); Debug.LogFormat(@"[Shapes Bombs #{0}] The final {1} square count in the {2}-half is: {3}", moduleId, (countUnlit) ? "unlit" : "lit", (countHalf) ? "upper" : "bottom", nowCount); Debug.LogFormat(@"[Shapes Bombs #{0}] Even solved modules final shape is:", moduleId); InputLogShape(intShape[Math.Clamp(nowCount, 5, 14) - 5]); Debug.LogFormat(@"[Shapes Bombs #{0}] Odd solved modules final shape is:", moduleId); InputLogShape(intShape[(Math.Clamp(nowCount, 5, 14) + 10) - 5]); var lightScalar = transform.lossyScale.x; for (int i = 0; i < ModuleButtons.Length; i++) { ModuleButtons[i].transform.GetComponent <Renderer>().material.color = buttonOFF; var nowLight = buttonLight[i] = ((i == 0) ? LightTemp : Instantiate(LightTemp)); nowLight.name = "ButtonLight" + i; nowLight.transform.parent = ModuleButtons[i].transform; nowLight.transform.localPosition = new Vector3(0.0f, 0.8f, 0.0f); nowLight.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); nowLight.range = 0.01f * lightScalar; nowLight.intensity = 0.0f; int j = i; ModuleButtons[i].OnInteract += delegate() { OnButtonPress(j, true); return(false); }; } NumScreen.OnInteract += delegate() { BombAudio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.ButtonPress, NumScreen.transform); if (arrowCoroutine != null) { StopCoroutine(arrowCoroutine); arrowCoroutine = StartCoroutine(SetArrowScreen()); } return(false); }; KMSelectable[] sideButtons = { ResetButton, EmptyButton, SubmitButton }; for (int i = 0; i < sideButtons.Length; i++) { int j = i; sideButtons[i].transform.GetComponent <Renderer>().material.color = new Color32(239, 228, 176, 255); sideButtons[i].OnInteract += delegate() { BombAudio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.ButtonPress, sideButtons[j].transform); ModuleSelect.AddInteractionPunch(0.75f); switch (j) { case 0: case 1: if (nowCoroutine == null && subCoroutine == null) { nowCoroutine = StartCoroutine(((j == 0) ? ResetLetter(intLetter[selectLetter]) : EmptyLights())); } break; default: if (!moduleSolved && nowCoroutine == null && subCoroutine == null) { if (myShape.Equals(shapeSolution)) { StopAllCoroutines(); Debug.LogFormat(@"[Shapes Bombs #{0}] Module solved!", moduleId); BombAudio.PlaySoundAtTransform("CorrectShape", transform); ArrowScreen.transform.GetComponent <Renderer>().material = BlackMat; NumScreen.transform.GetChild(0).GetComponent <TextMesh>().text = ""; moduleSolved = true; BombModule.HandlePass(); } else { var solvedModsEven = (solvedMods % 2 == 0); Debug.LogFormat(@"[Shapes Bombs #{0}] Current shape doesn't equal to the {1} final shape.", moduleId, solvedModsEven ? "even" : "odd"); Debug.LogFormat(@"[Shapes Bombs #{0}] Current shape:", moduleId); InputLogShape(myShape); BombModule.HandleStrike(); } subCoroutine = StartCoroutine(CheckSubmit()); } break; } return(false); }; } BombModule.OnActivate += Activate; }
public void BuildCompactField() { AstarProfiler.StartProfile("Build Compact Voxel Field"); //Build compact representation int spanCount = voxelArea.GetSpanCount(); voxelArea.compactSpanCount = spanCount; if (voxelArea.compactSpans == null || voxelArea.compactSpans.Length < spanCount) { voxelArea.compactSpans = new CompactVoxelSpan[spanCount]; voxelArea.areaTypes = new int[spanCount]; } uint idx = 0; int w = voxelArea.width; int d = voxelArea.depth; int wd = w * d; if (this.voxelWalkableHeight >= 0xFFFF) { Debug.LogWarning("Too high walkable height to guarantee correctness. Increase voxel height or lower walkable height."); } #if !ASTAR_RECAST_CLASS_BASED_LINKED_LIST LinkedVoxelSpan[] spans = voxelArea.linkedSpans; #endif //Parallel.For (0, voxelArea.depth, delegate (int pz) { for (int z = 0, pz = 0; z < wd; z += w, pz++) { for (int x = 0; x < w; x++) { #if !ASTAR_RECAST_CLASS_BASED_LINKED_LIST int spanIndex = x + z; if (spans[spanIndex].bottom == VoxelArea.InvalidSpanValue) { voxelArea.compactCells[x + z] = new CompactVoxelCell(0, 0); continue; } uint index = idx; uint count = 0; //Vector3 p = new Vector3(x,0,pz)*cellSize+voxelOffset; while (spanIndex != -1) { if (spans[spanIndex].area != UnwalkableArea) { int bottom = (int)spans[spanIndex].top; int next = spans[spanIndex].next; int top = next != -1 ? (int)spans[next].bottom : VoxelArea.MaxHeightInt; voxelArea.compactSpans[idx] = new CompactVoxelSpan((ushort)(bottom > 0xFFFF ? 0xFFFF : bottom), (uint)(top - bottom > 0xFFFF ? 0xFFFF : top - bottom)); voxelArea.areaTypes[idx] = spans[spanIndex].area; idx++; count++; } spanIndex = spans[spanIndex].next; } voxelArea.compactCells[x + z] = new CompactVoxelCell(index, count); #else VoxelSpan s = voxelArea.cells[x + z].firstSpan; if (s == null) { voxelArea.compactCells[x + z] = new CompactVoxelCell(0, 0); continue; } uint index = idx; uint count = 0; //Vector3 p = new Vector3(x,0,pz)*cellSize+voxelOffset; while (s != null) { if (s.area != UnwalkableArea) { int bottom = (int)s.top; int top = s.next != null ? (int)s.next.bottom : VoxelArea.MaxHeightInt; voxelArea.compactSpans[idx] = new CompactVoxelSpan((ushort)Mathf.Clamp(bottom, 0, 0xffff), (uint)Mathf.Clamp(top - bottom, 0, 0xffff)); voxelArea.areaTypes[idx] = s.area; idx++; count++; } s = s.next; } voxelArea.compactCells[x + z] = new CompactVoxelCell(index, count); #endif } } AstarProfiler.EndProfile("Build Compact Voxel Field"); }
public void VoxelizeInput(GraphTransform graphTransform, Bounds graphSpaceBounds) { AstarProfiler.StartProfile("Build Navigation Mesh"); AstarProfiler.StartProfile("Voxelizing - Step 1"); // Transform from voxel space to graph space. // then scale from voxel space (one unit equals one voxel) // Finally add min PF.Matrix4x4 voxelMatrix = PF.Matrix4x4.TRS(graphSpaceBounds.min, PF.Quaternion.identity, Vector3.one) * PF.Matrix4x4.Scale(new PF.Vector3(cellSize, cellHeight, cellSize)); transformVoxel2Graph = new GraphTransform(voxelMatrix); // Transform from voxel space to world space // add half a voxel to fix rounding transform = graphTransform * voxelMatrix * PF.Matrix4x4.TRS(new Vector3(0.5f, 0, 0.5f), PF.Quaternion.identity, Vector3.one); int maximumVoxelYCoord = (int)(graphSpaceBounds.size.y / cellHeight); AstarProfiler.EndProfile("Voxelizing - Step 1"); AstarProfiler.StartProfile("Voxelizing - Step 2 - Init"); // Cosine of the slope limit in voxel space (some tweaks are needed because the voxel space might be stretched out along the y axis) float slopeLimit = Mathf.Cos(Mathf.Atan(Mathf.Tan(maxSlope * Mathf.Deg2Rad) * (cellSize / cellHeight))); // Temporary arrays used for rasterization float[] vTris = new float[3 * 3]; float[] vOut = new float[7 * 3]; float[] vRow = new float[7 * 3]; float[] vCellOut = new float[7 * 3]; float[] vCell = new float[7 * 3]; if (inputMeshes == null) { throw new System.NullReferenceException("inputMeshes not set"); } // Find the largest lengths of vertex arrays and check for meshes which can be skipped int maxVerts = 0; for (int m = 0; m < inputMeshes.Count; m++) { maxVerts = System.Math.Max(inputMeshes[m].vertices.Length, maxVerts); } // Create buffer, here vertices will be stored multiplied with the local-to-voxel-space matrix var verts = new Vector3[maxVerts]; AstarProfiler.EndProfile("Voxelizing - Step 2 - Init"); AstarProfiler.StartProfile("Voxelizing - Step 2"); // This loop is the hottest place in the whole rasterization process // it usually accounts for around 50% of the time for (int m = 0; m < inputMeshes.Count; m++) { RasterizationMesh mesh = inputMeshes[m]; var meshMatrix = mesh.matrix; // Flip the orientation of all faces if the mesh is scaled in such a way // that the face orientations would change // This happens for example if a mesh has a negative scale along an odd number of axes // e.g it happens for the scale (-1, 1, 1) but not for (-1, -1, 1) or (1,1,1) var flipOrientation = UnityHelper.ReversesFaceOrientations(meshMatrix); Vector3[] vs = mesh.vertices; int[] tris = mesh.triangles; int trisLength = mesh.numTriangles; // Transform vertices first to world space and then to voxel space for (int i = 0; i < vs.Length; i++) { verts[i] = transform.InverseTransform(meshMatrix.MultiplyPoint3x4(vs[i])); } int mesharea = mesh.area; for (int i = 0; i < trisLength; i += 3) { Vector3 p1 = verts[tris[i]]; Vector3 p2 = verts[tris[i + 1]]; Vector3 p3 = verts[tris[i + 2]]; if (flipOrientation) { var tmp = p1; p1 = p3; p3 = tmp; } int minX = (int)(Utility.Min(p1.x, p2.x, p3.x)); int minZ = (int)(Utility.Min(p1.z, p2.z, p3.z)); int maxX = (int)System.Math.Ceiling(Utility.Max(p1.x, p2.x, p3.x)); int maxZ = (int)System.Math.Ceiling(Utility.Max(p1.z, p2.z, p3.z)); minX = Mathf.Clamp(minX, 0, voxelArea.width - 1); maxX = Mathf.Clamp(maxX, 0, voxelArea.width - 1); minZ = Mathf.Clamp(minZ, 0, voxelArea.depth - 1); maxZ = Mathf.Clamp(maxZ, 0, voxelArea.depth - 1); // Check if the mesh is completely out of bounds if (minX >= voxelArea.width || minZ >= voxelArea.depth || maxX <= 0 || maxZ <= 0) { continue; } Vector3 normal; int area; //AstarProfiler.StartProfile ("Rasterize..."); normal = Vector3.Cross(p2 - p1, p3 - p1); float cosSlopeAngle = Vector3.Dot(normal.normalized, Vector3.up); if (cosSlopeAngle < slopeLimit) { area = UnwalkableArea; } else { area = 1 + mesharea; } Utility.CopyVector(vTris, 0, p1); Utility.CopyVector(vTris, 3, p2); Utility.CopyVector(vTris, 6, p3); for (int x = minX; x <= maxX; x++) { int nrow = clipper.ClipPolygon(vTris, 3, vOut, 1F, -x + 0.5F, 0); if (nrow < 3) { continue; } nrow = clipper.ClipPolygon(vOut, nrow, vRow, -1F, x + 0.5F, 0); if (nrow < 3) { continue; } float clampZ1 = vRow[2]; float clampZ2 = vRow[2]; for (int q = 1; q < nrow; q++) { float val = vRow[q * 3 + 2]; clampZ1 = System.Math.Min(clampZ1, val); clampZ2 = System.Math.Max(clampZ2, val); } int clampZ1I = Mathf.Clamp((int)System.Math.Round(clampZ1), 0, voxelArea.depth - 1); int clampZ2I = Mathf.Clamp((int)System.Math.Round(clampZ2), 0, voxelArea.depth - 1); for (int z = clampZ1I; z <= clampZ2I; z++) { //AstarProfiler.StartFastProfile(1); int ncell = clipper.ClipPolygon(vRow, nrow, vCellOut, 1F, -z + 0.5F, 2); if (ncell < 3) { //AstarProfiler.EndFastProfile(1); continue; } ncell = clipper.ClipPolygonY(vCellOut, ncell, vCell, -1F, z + 0.5F, 2); if (ncell < 3) { //AstarProfiler.EndFastProfile(1); continue; } //AstarProfiler.EndFastProfile(1); //AstarProfiler.StartFastProfile(2); float sMin = vCell[1]; float sMax = vCell[1]; for (int q = 1; q < ncell; q++) { float val = vCell[q * 3 + 1]; sMin = System.Math.Min(sMin, val); sMax = System.Math.Max(sMax, val); } //AstarProfiler.EndFastProfile(2); int maxi = (int)System.Math.Ceiling(sMax); // Skip span if below or above the bounding box if (maxi >= 0 && sMin <= maximumVoxelYCoord) { // Make sure mini >= 0 int mini = System.Math.Max(0, (int)sMin); // Make sure the span is at least 1 voxel high maxi = System.Math.Max(mini + 1, maxi); voxelArea.AddLinkedSpan(z * voxelArea.width + x, (uint)mini, (uint)maxi, area, voxelWalkableClimb); } } } } //AstarProfiler.EndFastProfile(0); //AstarProfiler.EndProfile ("Rasterize..."); } AstarProfiler.EndProfile("Voxelizing - Step 2"); }
private float BrightnessToMorphValue(float brightness) { return(-1 * Math.Clamp(PupilNeutralValue + Math.Lerp(-1.0f, 1.5f, brightness), -1.0f, 1.5f)); }
public static Color HSVToRGB(float H, float S, float V, bool hdr) { Color white = Color.white; if (S == 0f) { white.r = V; white.g = V; white.b = V; } else if (V == 0f) { white.r = 0f; white.g = 0f; white.b = 0f; } else { white.r = 0f; white.g = 0f; white.b = 0f; float num = H * 6f; int num2 = (int)Mathf.Floor(num); float num3 = num - (float)num2; float num4 = V * (1f - S); float num5 = V * (1f - S * num3); float num6 = V * (1f - S * (1f - num3)); int num7 = num2; switch (num7 + 1) { case 0: white.r = V; white.g = num4; white.b = num5; break; case 1: white.r = V; white.g = num6; white.b = num4; break; case 2: white.r = num5; white.g = V; white.b = num4; break; case 3: white.r = num4; white.g = V; white.b = num6; break; case 4: white.r = num4; white.g = num5; white.b = V; break; case 5: white.r = num6; white.g = num4; white.b = V; break; case 6: white.r = V; white.g = num4; white.b = num5; break; case 7: white.r = V; white.g = num6; white.b = num4; break; } if (!hdr) { white.r = Mathf.Clamp(white.r, 0f, 1f); white.g = Mathf.Clamp(white.g, 0f, 1f); white.b = Mathf.Clamp(white.b, 0f, 1f); } } return(white); }