private void SetupSpotLight(VolumeLightManager renderer, Matrix4x4 viewProj) { commandBuffer.Clear(); int pass = 0; if (!IsCameraInSpotLightBounds()) { pass = 1; } float scale = thisLight.range; float angleScale = Mathf.Tan((thisLight.spotAngle + 1) * 0.5f * Mathf.Deg2Rad) * thisLight.range; Matrix4x4 world = Matrix4x4.TRS(transform.position, transform.rotation, new Vector3(angleScale, angleScale, scale)); Matrix4x4 view = Matrix4x4.TRS(thisLight.transform.position, thisLight.transform.rotation, Vector3.one).inverse; Matrix4x4 clip = Matrix4x4.TRS(new Vector3(0.5f, 0.5f, 0.0f), Quaternion.identity, new Vector3(-0.5f, -0.5f, 1.0f)); Matrix4x4 proj = Matrix4x4.Perspective(thisLight.spotAngle, 1, 0, 1); spotMaterial.SetMatrix("_MyLightMatrix0", clip * proj * view); spotMaterial.SetMatrix("_WorldViewProj", viewProj * world); spotMaterial.SetVector("_LightPos", new Vector4(thisLight.transform.position.x, thisLight.transform.position.y, thisLight.transform.position.z, 1.0f / (thisLight.range * thisLight.range))); spotMaterial.SetVector("_LightColor", thisLight.color * thisLight.intensity); Vector3 apex = transform.position; Vector3 axis = transform.forward; Vector3 center = apex + axis * thisLight.range; float d = -Vector3.Dot(center, axis); spotMaterial.SetFloat("_PlaneD", d); spotMaterial.SetFloat("_CosAngle", Mathf.Cos((thisLight.spotAngle + 1) * 0.5f * Mathf.Deg2Rad)); spotMaterial.SetVector("_ConeApex", new Vector4(apex.x, apex.y, apex.z)); spotMaterial.SetVector("_ConeAxis", new Vector4(axis.x, axis.y, axis.z)); spotMaterial.EnableKeyword("SPOT"); if (Noise) { spotMaterial.EnableKeyword("NOISE"); } else { spotMaterial.DisableKeyword("NOISE"); } spotMaterial.SetTexture("_LightTexture0", renderer.spotTexutre); bool forceShadowsOff = false; if ((thisLight.transform.position - Camera.current.transform.position).magnitude >= QualitySettings.shadowDistance) { forceShadowsOff = true; } if (thisLight.shadows != LightShadows.None && forceShadowsOff == false) { clip = Matrix4x4.TRS(new Vector3(0.5f, 0.5f, 0.5f), Quaternion.identity, new Vector3(0.5f, 0.5f, 0.5f)); if (_reversedZ) { proj = Matrix4x4.Perspective(thisLight.spotAngle, 1, thisLight.range, thisLight.shadowNearPlane); } else { proj = Matrix4x4.Perspective(thisLight.spotAngle, 1, thisLight.shadowNearPlane, thisLight.range); } Matrix4x4 m = clip * proj; m[0, 2] *= -1; m[1, 2] *= -1; m[2, 2] *= -1; m[3, 2] *= -1; spotMaterial.SetMatrix("_MyWorld2Shadow", m * view); spotMaterial.SetMatrix("_WorldView", m * view); spotMaterial.EnableKeyword("SHADOWS_DEPTH"); commandBuffer.SetGlobalTexture("_ShadowMapTexture", BuiltinRenderTextureType.CurrentActive); commandBuffer.SetRenderTarget(renderer.GetVolumeLightBuffer()); commandBuffer.DrawMesh(spotMesh, world, spotMaterial, 0, pass); renderer.commandBuffers[0].DrawMesh(spotMesh, world, spotMaterial, 0, pass); } else { spotMaterial.DisableKeyword("SHADOWS_DEPTH"); renderer.commandBuffers[0].DrawMesh(spotMesh, world, spotMaterial, 0, pass); } }
public void addButton(int cost, Sprite sprite, GameObject turret) { GameObject newButton = Instantiate(radialButton); newButton.transform.SetParent(buttonParent.transform, false); newButton.GetComponentsInChildren <Image>()[1].sprite = sprite; newButton.GetComponentInChildren <Text>().text = cost.ToString(); int count = buttons.Count; newButton.GetComponent <Button>().onClick.AddListener(delegate { buttonCall(count); }); buttons.Add(newButton); turrets.Add(turret); //update button positions float angleIncrement = 2 * Mathf.PI / buttons.Count; float angleCount = 0; foreach (GameObject button in buttons) { button.GetComponent <RectTransform>().localPosition = new Vector3(Mathf.Sin(angleCount) * 35, Mathf.Cos(angleCount) * 35, 0); button.GetComponent <RectTransform>().localScale = new Vector3(0.2f, 0.2f, 1); angleCount += angleIncrement; } }
// Update is called once per frame void FixedUpdate() { if (planetSpawnCount < 0) { planetSpawnCount = Mathf.RoundToInt(planetSpawnrate / Time.fixedDeltaTime); // Remove destroyed planets int j = 0; while (j < planets.Count) { if (planets[j] == null) { planets.RemoveAt(j); planetsDestroyed++; } else { j++; } } // Planet wrapping for (int i = 0; i < planets.Count; i++) { if (Vector2.Distance((Vector2)player.transform.position, (Vector2)planets[i].transform.position) > 100 + 5 * planetsDestroyed) { Destroy(planets[i]); planets.RemoveAt(i); } } // Spike wrapping for (int i = 0; i < spikeCircles.Count; i++) { if (Vector2.Distance((Vector2)player.transform.position, (Vector2)spikeCircles[i].transform.position) > 100 + 5 * planetsDestroyed) { spikeCircles[i].GetComponent <SpikeCircleSpawner_scr>().Destruct(); spikeCircles.RemoveAt(i); } } while (planets.Count < planetsDestroyed + 2) { GameObject a = Instantiate(planetPrefab); float angle = Random.Range(0, 360); Vector3 position = new Vector3(transform.position.x + Mathf.Cos(angle * Mathf.Deg2Rad) * 35 + 5 * planetsDestroyed, transform.position.y + Mathf.Sin(angle * Mathf.Deg2Rad) * 35 + 5 * planetsDestroyed, 0); a.transform.position = position; a.GetComponent <Planet_scr>().size = Random.Range(5, 35); a.GetComponent <Planet_scr>().Generate(); planets.Add(a); } while (spikeCircles.Count < 1) { GameObject a = Instantiate(spikeCirclePrefab); float angle = Random.Range(0, 360); Vector3 position = new Vector3(transform.position.x + Mathf.Cos(angle * Mathf.Deg2Rad) * 35 + 5 * planetsDestroyed, transform.position.y + Mathf.Sin(angle * Mathf.Deg2Rad) * 35 + 5 * planetsDestroyed, 0); a.transform.position = position; spikeCircles.Add(a); } } planetSpawnCount--; }
public override void ApplyToGrid(GridCell gCell, BoosterObjectData bData, Action completeCallBack) { if (!gCell.Overlay) { if (!gCell.Match && !gCell.StaticBlocker && !gCell.DynamicBlocker) { Booster.ActiveBooster.DeActivateBooster(); completeCallBack?.Invoke(); return; } } Booster b = Booster.ActiveBooster; b.AddCount(-1); ParallelTween par0 = new ParallelTween(); TweenSeq bTS = new TweenSeq(); //move activeBooster Vector3 pos = transform.position; float dist = Vector3.Distance(transform.position, gCell.transform.position); Vector3 rotPivot = Vector3.zero; float rotRad = 6f; bTS.Add((callBack) => { SetToFront(true); SimpleTween.Move(b.SceneObject, b.SceneObject.transform.position, gCell.transform.position, dist / speed).AddCompleteCallBack(() => { rotPivot = transform.position - new Vector3(0, rotRad, 0); callBack(); }).SetEase(EaseAnim.EaseInSine); }); // back move bTS.Add((callBack) => { SimpleTween.Value(gameObject, Mathf.Deg2Rad * 90f, Mathf.Deg2Rad * 180f, 0.25f).SetEase(EaseAnim.EaseInCubic). // SetOnUpdate((float val) => { transform.position = new Vector3(rotRad * Mathf.Cos(val), rotRad * Mathf.Sin(val), 0) + rotPivot; }). AddCompleteCallBack(() => { callBack(); }); }); //forward move bTS.Add((callBack) => { SimpleTween.Value(gameObject, Mathf.Deg2Rad * 180f, Mathf.Deg2Rad * 100f, 0.2f).SetEase(EaseAnim.EaseOutBounce). SetOnUpdate((float val) => { transform.position = new Vector3(rotRad * Mathf.Cos(val), rotRad * Mathf.Sin(val), 0) + rotPivot; }). AddCompleteCallBack(() => { MSound.PlayClip(0, bData.privateClip); Destroy(gameObject, 0.25f); Creator.InstantiateAnimPrefab(bData.animPrefab, gCell.transform, gCell.transform.position, SortingOrder.BoosterToFront + 2, true, callBack); }); }); // if (gCell.IsMatchable) { bTS.Add((callBack) => { GridCell.ExplodeCell(gCell, 0, true, false, true, callBack); // gCell.CollectMatch(0, true, false, true, true, callBack); }); } bTS.Add((callback) => { Booster.ActiveBooster.DeActivateBooster(); completeCallBack?.Invoke(); callback(); }); bTS.Start(); }
private void FixedUpdate() { if (!this.isServer) { return; } this.secondsTaken += Time.get_deltaTime(); float num1 = Mathf.InverseLerp(0.0f, this.secondsToTake, this.secondsTaken); if (!this.dropped && (double)num1 >= 0.5) { this.dropped = true; BaseEntity entity = GameManager.server.CreateEntity(this.prefabDrop.resourcePath, ((Component)this.dropOrigin).get_transform().get_position(), (Quaternion)null, true); if (Object.op_Implicit((Object)entity)) { entity.globalBroadcast = true; entity.Spawn(); } } ((Component)this).get_transform().set_position(Vector3.Lerp(this.startPos, this.endPos, num1)); Vector3 vector3_1 = Vector3.op_Subtraction(this.endPos, this.startPos); Vector3 normalized = ((Vector3) ref vector3_1).get_normalized(); Vector3 zero = Vector3.get_zero(); if (Vector3.op_Inequality(this.swimScale, Vector3.get_zero())) { if ((double)this.swimRandom == 0.0) { this.swimRandom = Random.Range(0.0f, 20f); } float num2 = Time.get_time() + this.swimRandom; ((Vector3) ref zero).\u002Ector(Mathf.Sin(num2 * (float)this.swimSpeed.x) * (float)this.swimScale.x, Mathf.Cos(num2 * (float)this.swimSpeed.y) * (float)this.swimScale.y, Mathf.Sin(num2 * (float)this.swimSpeed.z) * (float)this.swimScale.z); Vector3 vector3_2 = ((Component)this).get_transform().InverseTransformDirection(zero); Transform transform = ((Component)this).get_transform(); transform.set_position(Vector3.op_Addition(transform.get_position(), Vector3.op_Multiply(vector3_2, this.appliedSwimScale))); } ((Component)this).get_transform().set_rotation(Quaternion.op_Multiply(Quaternion.LookRotation(normalized), Quaternion.Euler(Mathf.Cos(Time.get_time() * (float)this.swimSpeed.y) * this.appliedSwimRotation, 0.0f, Mathf.Sin(Time.get_time() * (float)this.swimSpeed.x) * this.appliedSwimRotation))); Vector3 position = ((Component)this).get_transform().get_position(); float num3 = Mathf.Max(TerrainMeta.HeightMap.GetHeight(Vector3.op_Addition(((Component)this).get_transform().get_position(), Vector3.op_Multiply(((Component)this).get_transform().get_forward(), 30f))), TerrainMeta.HeightMap.GetHeight(((Component)this).get_transform().get_position())); position.y = (__Null)(double)Mathf.Max(SantaSleigh.desiredAltitude, num3 + SantaSleigh.altitudeAboveTerrain); ((Component)this).get_transform().set_position(position); ((Component)this).get_transform().set_hasChanged(true); if ((double)num1 < 1.0) { return; } this.Kill(BaseNetworkable.DestroyMode.None); }
//Calculates the area where the enemys can view public Vector2 GetDirectionVector2D(float angle) { return(new Vector2(Mathf.Cos(angle * Mathf.Deg2Rad), Mathf.Sin(angle * Mathf.Deg2Rad)).normalized); }
private HashSet <Instance> GetMarqueeList(Ray mouseRay) { HashSet <Instance> list = new HashSet <Instance>(); Building[] buildingBuffer = BuildingManager.instance.m_buildings.m_buffer; PropInstance[] propBuffer = PropManager.instance.m_props.m_buffer; NetNode[] nodeBuffer = NetManager.instance.m_nodes.m_buffer; NetSegment[] segmentBuffer = NetManager.instance.m_segments.m_buffer; TreeInstance[] treeBuffer = TreeManager.instance.m_trees.m_buffer; m_selection.a = m_mouseStartPosition; m_selection.c = RaycastMouseLocation(mouseRay); if (m_selection.a.x == m_selection.c.x && m_selection.a.z == m_selection.c.z) { m_selection = default(Quad3); } else { float angle = Camera.main.transform.localEulerAngles.y * Mathf.Deg2Rad; Vector3 down = new Vector3(Mathf.Cos(angle), 0, -Mathf.Sin(angle)); Vector3 right = new Vector3(-down.z, 0, down.x); Vector3 a = m_selection.c - m_selection.a; float dotDown = Vector3.Dot(a, down); float dotRight = Vector3.Dot(a, right); if ((dotDown > 0 && dotRight > 0) || (dotDown <= 0 && dotRight <= 0)) { m_selection.b = m_selection.a + dotDown * down; m_selection.d = m_selection.a + dotRight * right; } else { m_selection.b = m_selection.a + dotRight * right; m_selection.d = m_selection.a + dotDown * down; } // Disables select-during-drag //if (ToolState == ToolStates.DrawingSelection) //{ // return list; //} Vector3 min = m_selection.Min(); Vector3 max = m_selection.Max(); int gridMinX = Mathf.Max((int)((min.x - 16f) / 64f + 135f), 0); int gridMinZ = Mathf.Max((int)((min.z - 16f) / 64f + 135f), 0); int gridMaxX = Mathf.Min((int)((max.x + 16f) / 64f + 135f), 269); int gridMaxZ = Mathf.Min((int)((max.z + 16f) / 64f + 135f), 269); InstanceID id = new InstanceID(); ItemClass.Layer itemLayers = GetItemLayers(); if (!HidePO && PO.Active && filterProcs) { //string msg = ""; foreach (IPO_Object obj in PO.Objects) { if (PointInRectangle(m_selection, obj.Position)) { //msg += $"{obj.Id},"; id.NetLane = obj.Id; list.Add(id); } } //Debug.Log(msg); } for (int i = gridMinZ; i <= gridMaxZ; i++) { for (int j = gridMinX; j <= gridMaxX; j++) { if (filterBuildings || filterSurfaces || (filterPicker && Filters.Picker.IsBuilding)) { ushort building = BuildingManager.instance.m_buildingGrid[i * 270 + j]; int count = 0; while (building != 0u) { //Debug.Log($"Building:{building}"); if (IsBuildingValid(ref buildingBuffer[building], itemLayers) && PointInRectangle(m_selection, buildingBuffer[building].m_position)) { if (Filters.Filter(buildingBuffer[building].Info)) { id.Building = Building.FindParentBuilding(building); if (id.Building == 0) { id.Building = building; } list.Add(id); } } building = buildingBuffer[building].m_nextGridBuilding; if (++count > 49152) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Buildings: Invalid list detected!\n" + Environment.StackTrace); break; } } } if (filterProps || filterDecals || filterSurfaces || (filterPicker && Filters.Picker.IsProp)) { ushort prop = PropManager.instance.m_propGrid[i * 270 + j]; int count = 0; while (prop != 0u) { //Debug.Log($"Prop:{prop}"); if (Filters.Filter(propBuffer[prop].Info)) { if (PointInRectangle(m_selection, propBuffer[prop].Position)) { id.Prop = prop; list.Add(id); } } prop = propBuffer[prop].m_nextGridProp; if (++count > 65536) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Prop: Invalid list detected!\n" + Environment.StackTrace); } } } if (filterNodes || filterBuildings || (filterPicker && Filters.Picker.IsNode)) { ushort node = NetManager.instance.m_nodeGrid[i * 270 + j]; int count = 0; while (node != 0u) { //Debug.Log($"Node:{node}"); if (IsNodeValid(ref nodeBuffer[node], itemLayers) && PointInRectangle(m_selection, nodeBuffer[node].m_position)) { ushort building = NetNode.FindOwnerBuilding(node, 363f); if (building != 0) { if (filterBuildings) { id.Building = Building.FindParentBuilding(building); if (id.Building == 0) { id.Building = building; } list.Add(id); } } else if (filterNodes || (filterPicker && Filters.Picker.IsNode)) { if (Filters.Filter(nodeBuffer[node])) { //Debug.Log($"Node:{node}"); id.NetNode = node; list.Add(id); } } } node = nodeBuffer[node].m_nextGridNode; if (++count > 32768) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Nodes: Invalid list detected!\n" + Environment.StackTrace); } } } if (filterSegments || filterBuildings || (filterPicker && Filters.Picker.IsSegment)) { ushort segment = NetManager.instance.m_segmentGrid[i * 270 + j]; int count = 0; while (segment != 0u) { //Debug.Log($"Segment:{segment}"); if (IsSegmentValid(ref segmentBuffer[segment], itemLayers) && PointInRectangle(m_selection, segmentBuffer[segment].m_bounds.center)) { ushort building = FindOwnerBuilding(segment, 363f); if (building != 0) { if (filterBuildings) { id.Building = Building.FindParentBuilding(building); if (id.Building == 0) { id.Building = building; } list.Add(id); } } else if (filterSegments || (filterPicker && Filters.Picker.IsSegment)) { if (Filters.Filter(segmentBuffer[segment])) { id.NetSegment = segment; list.Add(id); } } } segment = segmentBuffer[segment].m_nextGridSegment; if (++count > 36864) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Segments: Invalid list detected!\n" + Environment.StackTrace); } } } } } if (filterTrees || (filterPicker && Filters.Picker.IsTree)) { gridMinX = Mathf.Max((int)((min.x - 8f) / 32f + 270f), 0); gridMinZ = Mathf.Max((int)((min.z - 8f) / 32f + 270f), 0); gridMaxX = Mathf.Min((int)((max.x + 8f) / 32f + 270f), 539); gridMaxZ = Mathf.Min((int)((max.z + 8f) / 32f + 270f), 539); for (int i = gridMinZ; i <= gridMaxZ; i++) { for (int j = gridMinX; j <= gridMaxX; j++) { uint tree = TreeManager.instance.m_treeGrid[i * 540 + j]; int count = 0; while (tree != 0) { //Debug.Log($"Tree:{tree}"); if (PointInRectangle(m_selection, treeBuffer[tree].Position)) { if (Filters.Filter(treeBuffer[tree].Info)) { id.Tree = tree; list.Add(id); } } tree = treeBuffer[tree].m_nextGridTree; if (++count > 262144) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Trees: Invalid list detected!\n" + Environment.StackTrace); } } } } } } return(list); }
void moveThermostatArmTo(float angle) { armHeight = thermostatArm.transform.localScale.y; thermostatArm.transform.eulerAngles = new Vector3(0.0f, 0.0f, -armRotation); thermostatArm.transform.position = new Vector3(armHeight * Mathf.Sin(armRotation * Mathf.PI / 180f) / 2, armHeight * Mathf.Cos(armRotation * Mathf.PI / 180f) / 2, thermostat.transform.position.z - 0.025f); }
void LateUpdate() { float angle = Mathf.PI * 2f * spinCurve.Evaluate(Time.time / Interval); transform.localPosition = new Vector3(Mathf.Sin(angle), Mathf.Cos(angle)) * radius + center; }
public override bool Calculate() { Texture tex = textureInputKnob.GetValue <Texture>(); if (!textureInputKnob.connected() || tex == null) { // Reset outputs if no texture is available textureOutputKnob.ResetValue(); outputSize = Vector2Int.zero; if (outputTex != null) { outputTex.Release(); } return(true); } var inputSize = new Vector2Int(tex.width, tex.height); if (inputSize != outputSize) { outputSize = inputSize; InitializeRenderTexture(); } speed = speedInputKnob.connected() ? speedInputKnob.GetValue <float>() : speed; angle = angleInputKnob.connected() ? angleInputKnob.GetValue <float>() : angle; // Keep offset bounded by (2x) dimensions so that floating point coverage doesn't decrease // over long pans. use 2x so that mirrored textures don't jump on resetting the offset var r = speed * tex.width * Time.deltaTime; offset += new Vector2(r * Mathf.Cos(angle), r * Mathf.Sin(angle)); Vector2 mirrorSafeBounds = 2 * new Vector2(tex.width - 1, tex.height - 1); if (offset.x > mirrorSafeBounds.x) { offset.x -= mirrorSafeBounds.x; } else if (offset.x < -mirrorSafeBounds.x) { offset.x += mirrorSafeBounds.x; } if (offset.y > mirrorSafeBounds.y) { offset.y -= mirrorSafeBounds.y; } else if (offset.y < -mirrorSafeBounds.y) { offset.y += mirrorSafeBounds.y; } int panKernel = 0; if (smoothTransitions && mirror) { panKernel = bilinearMirrorKernel; } else if (smoothTransitions && !mirror) { panKernel = bilinearRepeatKernel; } else if (!smoothTransitions && mirror) { panKernel = pointMirrorKernel; } else if (!smoothTransitions && !mirror) { panKernel = pointRepeatKernel; } panShader.SetInt("width", tex.width); panShader.SetInt("height", tex.height); panShader.SetFloats("offset", offset.x, offset.y); panShader.SetTexture(panKernel, "OutputTex", outputTex); panShader.SetTexture(panKernel, "InputTex", tex); var threadGroupX = Mathf.CeilToInt(tex.width / 16.0f); var threadGroupY = Mathf.CeilToInt(tex.height / 16.0f); panShader.Dispatch(panKernel, threadGroupX, threadGroupY, 1); // Assign output channels textureOutputKnob.SetValue(outputTex); return(true); }
private void BuildMeshes() { #if UNITY_EDITOR _InitialMeshComplexity = MeshComplexity; #endif int triangleCount = GetTriangleCount(); Vector3[] innerVerts = new Vector3[triangleCount]; Vector2[] innerUVs = new Vector2[triangleCount]; Vector3[] outerVerts = new Vector3[triangleCount]; Vector2[] outerUVs = new Vector2[triangleCount]; int[] tris = new int[triangleCount * 3]; for (int i = 0; i < triangleCount; i += 2) { float angle = 2 * i * Mathf.PI / triangleCount; float x = Mathf.Cos(angle); float y = Mathf.Sin(angle); outerVerts[i] = new Vector3(x, y, 0); outerVerts[i + 1] = new Vector3(x, y, 0); outerUVs[i] = new Vector2(0, 1); outerUVs[i + 1] = new Vector2(1, 1); innerVerts[i] = new Vector3(x, y, 0); innerVerts[i + 1] = new Vector3(x, y, 0); innerUVs[i] = new Vector2(0, 1); innerUVs[i + 1] = new Vector2(1, 0); int ti = i * 3; tris[ti] = i; tris[ti + 1] = i + 1; tris[ti + 2] = (i + 2) % triangleCount; tris[ti + 3] = i + 1; tris[ti + 4] = (i + 3) % triangleCount; tris[ti + 5] = (i + 2) % triangleCount; } if (_OpaqueMesh != null) { DestroyImmediate(_OpaqueMesh); } if (_TransparentMesh != null) { DestroyImmediate(_TransparentMesh); } _OpaqueMesh = new Mesh() { name = "Opaque Vignette Mesh", hideFlags = HideFlags.HideAndDontSave }; _TransparentMesh = new Mesh() { name = "Transparent Vignette Mesh", hideFlags = HideFlags.HideAndDontSave }; _OpaqueMesh.vertices = outerVerts; _OpaqueMesh.uv = outerUVs; _OpaqueMesh.triangles = tris; _OpaqueMesh.UploadMeshData(true); _OpaqueMesh.bounds = new Bounds(Vector3.zero, Vector3.one * 10000); _OpaqueMeshFilter.sharedMesh = _OpaqueMesh; _TransparentMesh.vertices = innerVerts; _TransparentMesh.uv = innerUVs; _TransparentMesh.triangles = tris; _TransparentMesh.UploadMeshData(true); _TransparentMesh.bounds = new Bounds(Vector3.zero, Vector3.one * 10000); _TransparentMeshFilter.sharedMesh = _TransparentMesh; }
void fireMakeing( ) { if (_anim_ctrl.getShakeFlag( )) { _fire_angle += _fire_angle_speed; } if (Mathf.Abs(_fire_angle) >= Mathf.Deg2Rad * 43) { _fire_angle_speed *= -1; } _fire.transform.position = transform.position + transform.right * (_fire_radius * Mathf.Cos(-_fire_angle + 90 * Mathf.Deg2Rad)) + transform.up * _fire_height + transform.forward * (_fire_radius * Mathf.Sin(-_fire_angle + 90 * Mathf.Deg2Rad)); if (Input.GetButtonUp("Fire1") || _fire_stamina <= 0) { _fire.Stop( ); } if (Input.GetButtonUp("Fire1")) { _fire_flag = false; _fire_angle = 0; _fire_angle_speed = Mathf.Abs(_fire_angle_speed); } }
void UpdateCamera() { var pos = new Vector3(Mathf.Sin(m_CameraPhi) * Mathf.Cos(m_CameraTheta), Mathf.Cos(m_CameraPhi), Mathf.Sin(m_CameraPhi) * Mathf.Sin(m_CameraTheta)) * m_CameraDistance; m_PreviewUtility.camera.transform.position = pos; m_PreviewUtility.camera.transform.LookAt(Vector3.zero); }
protected override Vector2 ExtrusionProfileFunction(float u, float v) { v = 0.15f + 0.06f * Mathf.Cos(3 * TAU * v); u *= TAU; return(new Vector2(v * Mathf.Cos(u), v * Mathf.Sin(u))); }
public static float InOut(float k) { return(0.5f * (1f - Mathf.Cos(Mathf.PI * k))); }
void ConfigureLights() { mainLightExists = false; bool shadowmaskExists = false; bool subtractiveLighting = false; shadowTileCount = 0; for (int i = 0; i < cull.visibleLights.Count; i++) { if (i == maxVisibleLights) { break; } VisibleLight light = cull.visibleLights[i]; visibleLightColors[i] = light.finalColor; Vector4 attenuation = Vector4.zero; attenuation.w = 1f; Vector4 shadow = Vector4.zero; LightBakingOutput baking = light.light.bakingOutput; visibleLightOcclusionMasks[i] = occlusionMasks[baking.occlusionMaskChannel + 1]; if (baking.lightmapBakeType == LightmapBakeType.Mixed) { shadowmaskExists |= baking.mixedLightingMode == MixedLightingMode.Shadowmask; if (baking.mixedLightingMode == MixedLightingMode.Subtractive) { subtractiveLighting = true; cameraBuffer.SetGlobalColor( subtractiveShadowColorId, RenderSettings.subtractiveShadowColor.linear ); } } if (light.lightType == LightType.Directional) { Vector4 v = light.localToWorld.GetColumn(2); v.x = -v.x; v.y = -v.y; v.z = -v.z; visibleLightDirectionsOrPositions[i] = v; shadow = ConfigureShadows(i, light.light); shadow.z = 1f; if (i == 0 && shadow.x > 0f && shadowCascades > 0) { mainLightExists = true; shadowTileCount -= 1; } } else { visibleLightDirectionsOrPositions[i] = light.localToWorld.GetColumn(3); attenuation.x = 1f / Mathf.Max(light.range * light.range, 0.00001f); if (light.lightType == LightType.Spot) { Vector4 v = light.localToWorld.GetColumn(2); v.x = -v.x; v.y = -v.y; v.z = -v.z; visibleLightSpotDirections[i] = v; float outerRad = Mathf.Deg2Rad * 0.5f * light.spotAngle; float outerCos = Mathf.Cos(outerRad); float outerTan = Mathf.Tan(outerRad); float innerCos = Mathf.Cos(Mathf.Atan((46f / 64f) * outerTan)); float angleRange = Mathf.Max(innerCos - outerCos, 0.001f); attenuation.z = 1f / angleRange; attenuation.w = -outerCos * attenuation.z; shadow = ConfigureShadows(i, light.light); } else { visibleLightSpotDirections[i] = Vector4.one; } } visibleLightAttenuations[i] = attenuation; shadowData[i] = shadow; } bool useDistanceShadowmask = QualitySettings.shadowmaskMode == ShadowmaskMode.DistanceShadowmask; CoreUtils.SetKeyword( cameraBuffer, shadowmaskKeyword, shadowmaskExists && !useDistanceShadowmask ); CoreUtils.SetKeyword( cameraBuffer, distanceShadowmaskKeyword, shadowmaskExists && useDistanceShadowmask ); CoreUtils.SetKeyword( cameraBuffer, subtractiveLightingKeyword, subtractiveLighting ); if (mainLightExists || cull.visibleLights.Count > maxVisibleLights) { int[] lightIndices = cull.GetLightIndexMap(); if (mainLightExists) { lightIndices[0] = -1; } for (int i = maxVisibleLights; i < cull.visibleLights.Count; i++) { lightIndices[i] = -1; } cull.SetLightIndexMap(lightIndices); } }
// Update is called once per frame void FixedUpdate() { if (waitTime <= 0) { if (state == 0) { waitTime = 61; state = 2; } else if (state == 1) { waitTime = idleTime; state = 0; Shoot(BlueBullet, 30, 0.0f, 2.35f); Shoot(RedBullet, 30, 6.0f, 2.25f); } else if (state == 2) { GameObject Player = GameObject.FindGameObjectWithTag("Player"); if (Player) { float x1 = gameObject.transform.position.x, y1 = gameObject.transform.position.y, x2 = Player.gameObject.transform.position.x, y2 = Player.gameObject.transform.position.y; float distance = Mathf.Sqrt(Mathf.Pow((y2 - y1), 2) + Mathf.Pow((x2 - x1), 2)) + 5.0f; moveAngle = Mathf.Atan2(y2 - y1, x2 - x1); waitTime = (int)(distance / BossSpeed); state = 1; } } } else { waitTime--; if (state == 1) { Vector3 pos = this.gameObject.transform.position; pos.x = pos.x + (Mathf.Cos(moveAngle) * BossSpeed); pos.y = pos.y + (Mathf.Sin(moveAngle) * BossSpeed); this.gameObject.transform.position = pos; } else if (state == 2) { if (waitTime == 60) { Shoot(RedBullet, 50, 0.0f, 4.5f); } else if (waitTime == 40) { Shoot(BlueBullet, 45, 0.0f, 4.0f); } else if (waitTime == 20) { Shoot(RedBullet, 40, 0.0f, 3.5f); } } } //Freeze the velocity this.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0); //Set orientation //gameObject.transform.rotation = Quaternion.Euler (new Vector3 (0, 0, (moveAngle - 90.0f))); }
public static Mesh CreateCircleSection(float angle, float range) { Mesh mesh = new Mesh(); float angle_fov = angle * 90 / Mathf.PI; int quality = 15; float angle_start = -angle_fov; float angle_end = angle_fov; float angle_delta = (angle_end - angle_start) / quality; float angle_curr = angle_start; float angle_next = angle_start + angle_delta; Vector3 pos_curr_min = Vector3.zero; Vector3 pos_curr_max = Vector3.zero; Vector3 pos_next_min = Vector3.zero; Vector3 pos_next_max = Vector3.zero; Vector3[] vertices = new Vector3[4 * quality]; int[] triangles = new int[3 * 2 * quality]; for (int i = 0; i < quality; i++) { Vector3 sphere_curr = new Vector3( Mathf.Sin(Mathf.Deg2Rad * (angle_curr)), 0, Mathf.Cos(Mathf.Deg2Rad * (angle_curr))); Vector3 sphere_next = new Vector3( Mathf.Sin(Mathf.Deg2Rad * (angle_next)), 0, Mathf.Cos(Mathf.Deg2Rad * (angle_next))); pos_curr_max = sphere_curr * range; pos_next_max = sphere_next * range; int a = 4 * i; int b = 4 * i + 1; int c = 4 * i + 2; int d = 4 * i + 3; vertices[a] = pos_curr_min; vertices[b] = pos_curr_max; vertices[c] = pos_next_max; vertices[d] = pos_next_min; triangles[6 * i] = a; triangles[6 * i + 1] = b; triangles[6 * i + 2] = c; triangles[6 * i + 3] = c; triangles[6 * i + 4] = d; triangles[6 * i + 5] = a; angle_curr += angle_delta; angle_next += angle_delta; } mesh.vertices = vertices; mesh.triangles = triangles; return(mesh); }
public void Shot() { float AngleInDegrees = 45f; const float g = 9.8f; Vector3 direction = PlayerMovement.instance.transform.position - transform.position; direction.z = 0; //Vector3 fromToXZ = new Vector3(fromTo.x, 0f, fromTo.z); //transform.rotation = Quaternion.LookRotation(fromToXZ, Vector3.up); float x = direction.magnitude; float y = direction.y; float AngleInRadians = AngleInDegrees * Mathf.PI / 180; float v2 = (g * x * x) / (2 * (y - Mathf.Tan(AngleInRadians) * x) * Mathf.Pow(Mathf.Cos(AngleInRadians), 2)); float v = Mathf.Sqrt(Mathf.Abs(v2)); // GetComponent<Rigidbody>().velocity = SpawnTransform.forward * v; }
private void Deform() { Vector3 vi = new Vector3(); Vector3 v1 = new Vector3(); Vector3 vo = new Vector3(); Vector3[] newVertices = new Vector3[mesh.vertices.Length]; ; float R, r, beta; for (int i = 0; i < mesh.vertices.Length; i++) { vi = vertices[i]; /* * * * Version A * * */ // R = Mathf.Sqrt(vi.x * vi.x + Mathf.Pow(vi.y - A.y ,2)); // // r = R * Mathf.Sin(theta); // // beta = Mathf.Asin(vi.x / R) / Mathf.Sin(theta); // // // v1.x = r * Mathf.Sin(beta); // v1.y = R + A.y - r* (1 - Mathf.Cos(beta))*Mathf.Sin(theta); // v1.z = r * (1-Mathf.Cos(beta)) * Mathf.Cos(theta); /* * * * VersionB * */ R = Mathf.Sqrt(Mathf.Pow(vi.x - B,2) + Mathf.Pow(vi.y - A.y ,2)); r = R * Mathf.Sin(theta); // beta = Mathf.Asin(vi.x / R) / Mathf.Sin(theta); if(vi.x < B) { beta = 0; }else { beta = Mathf.Asin((vi.x-B) / R) / Mathf.Sin(theta); } if(vi.x < B) { v1.x = vi.x; }else{ v1.x = B + r * Mathf.Sin(beta); } if(vi.x < B) { v1.y = vi.y; }else{ v1.y = R + A.y - r* (1 - Mathf.Cos(beta))*Mathf.Sin(theta); } v1.z = r * (1-Mathf.Cos(beta)) * Mathf.Cos(theta); newVertices[i].x = v1.x; newVertices[i].y = v1.y; newVertices[i].z = v1.z; vo.x = (v1.x * Mathf.Cos(rho) - v1.z * Mathf.Sin(rho)); vo.y = v1.y; vo.z = (v1.x * Mathf.Sin(rho) + v1.z * Mathf.Cos(rho)); } mesh.vertices = newVertices; mesh.RecalculateBounds (); mesh.RecalculateNormals (); }
private Debri addD(float sx, float sy, int n) { var vx = Mathf.Sin(degrees(n)) * 150; var vy = Mathf.Cos(degrees(n)) * 150; return new Debri(sx, sy, vx, vy, 10); }
// Update is called once per frame void Update() { if (skylight != null && parentBuilding != null && parentBuilding.building.isActive) { GetComponent <Renderer>().materials[0].SetColor("_EmissionColor", emissionColor * ((Mathf.Cos(skylight.currentTimeOfDay * 2 * Mathf.PI) * 0.5f + 0.5f) + (Mathf.Cos(skylight.currentTimeOfDay * 10.0f * Mathf.PI) * 0.05f - 0.05f))); } else { GetComponent <Renderer>().materials[0].SetColor("_EmissionColor", Color.black); } }
Mesh GenerateMesh(bool front, bool back, bool sides, float extrude, float elevate, bool useNormals, bool useUVS, Vector2 frontUVScale, Vector2 backUVScale, Vector2 sideUVScale) { Mesh mesh = new Mesh(); if (Points.Count == 0) { return(mesh); } int backStart = 0; int sidesStart = 0; Vector3 elevation = Vector3.back * elevate; // Vertices { List <Vector3> points = new List <Vector3>(); { // front if (front) { foreach (Vector3 point in Points) { points.Add(point + elevation); } } backStart = points.Count; // back if (back) { foreach (Vector3 point in Points) { points.Add(point + Vector3.forward * extrude + elevation); } } sidesStart = points.Count; if (sides) { //front side foreach (Vector3 point in Points) { points.Add(point + elevation); points.Add(point + elevation); } // back side); foreach (Vector3 point in Points) { points.Add(point + Vector3.forward * extrude + elevation); points.Add(point + Vector3.forward * extrude + elevation); } } } mesh.vertices = points.ToArray(); } // uvs if (useUVS) { List <Vector2> uvs = new List <Vector2>(); float totalLength = 0; // calculate total length { Vector2 previousPoint = Points[Points.Count - 1]; foreach (Vector2 point in Points) { totalLength += (point - previousPoint).magnitude; previousPoint = point; } } if (front) { for (int i = 0; i < Points.Count; i++) { Vector2 point = Points[i]; uvs.Add(new Vector2(point.x * frontUVScale.x, point.y * frontUVScale.y)); } } if (back) { for (int i = 0; i < Points.Count; i++) { Vector2 point = Points[i]; uvs.Add(new Vector2(point.x * backUVScale.x, point.y * backUVScale.y)); } } if (sides) { for (int z = 0; z < 2; z++) { Vector2 previousPoint = Points[0]; float length = 0; for (int i = 0; i < Points.Count; i++) { Vector2 point = Points[i]; length += (point - previousPoint).magnitude; uvs.Add(new Vector2(z * extrude * sideUVScale.x, (i == 0 ? totalLength : length) * sideUVScale.y)); uvs.Add(new Vector2(z * extrude * sideUVScale.x, length * sideUVScale.y)); previousPoint = point; } length += (Points[0] - previousPoint).magnitude; } } mesh.uv = uvs.ToArray(); } bool counterClockwise; // Triangles (the hard part) { List <Vector2> points2D = new List <Vector2>(); foreach (Vector3 point in Points) { points2D.Add(point); } List <int> indices = new List <int>(); Triangulate.Process(ref points2D, ref indices, out counterClockwise); List <int> triangles = new List <int>(); // front if (front) { triangles.AddRange(indices); } // back if (back) { for (int i = 0; i < indices.Count; i += 3) { triangles.Add(indices[i + 2] + backStart); triangles.Add(indices[i + 1] + backStart); triangles.Add(indices[i + 0] + backStart); } } if (sides) { // side int v1 = sidesStart + Points.Count * 0 + Points.Count * 2 - 1; int v2 = sidesStart + Points.Count * 2 + Points.Count * 2 - 1; for (int i = 0; i < Points.Count; i++) { int v3 = sidesStart + Points.Count * 0 + i * 2; int v4 = sidesStart + Points.Count * 2 + i * 2; if (counterClockwise) { triangles.Add(v1); triangles.Add(v3); triangles.Add(v2); triangles.Add(v3); triangles.Add(v4); triangles.Add(v2); } else { triangles.Add(v1); triangles.Add(v2); triangles.Add(v3); triangles.Add(v3); triangles.Add(v2); triangles.Add(v4); } v1 = v3 + 1; v2 = v4 + 1; } } mesh.triangles = triangles.ToArray(); } // normals if (useNormals) { List <Vector3> normals = new List <Vector3>(); if (front) { // front for (int i = 0; i < Points.Count; i++) { normals.Add(Vector3.back); } } if (back) { for (int i = 0; i < Points.Count; i++) { normals.Add(Vector3.forward); } } // the sides if (sides) { for (int repeat = 0; repeat < 2; repeat++) { for (int i = 0; i < Points.Count; i++) { Vector2 p1 = Points[(i + Points.Count - 1) % Points.Count]; Vector2 p2 = Points[i]; Vector2 p3 = Points[(i + 1) % Points.Count]; Vector2 diff1 = (p1 - p2).normalized; Vector2 diff2 = (p2 - p3).normalized; Vector2 normal1 = new Vector3(diff1.y, -diff1.x, 0).normalized; Vector2 normal2 = new Vector3(diff2.y, -diff2.x, 0).normalized; Vector2 smoothNormal = (normal1 + normal2).normalized; if (counterClockwise) { smoothNormal *= -1; normal1 *= -1; normal2 *= -1; } if (Vector2.Dot(normal1, normal2) > Mathf.Cos(Mathf.Deg2Rad * SmoothAngle)) { normals.Add(smoothNormal); normals.Add(smoothNormal); } else { normals.Add(normal1); normals.Add(normal2); } } } } mesh.normals = normals.ToArray(); } mesh.RecalculateBounds(); return(mesh); }
static Quaternion Q3(float k) { return(new Quaternion(0, 0, Mathf.Sin(k / 2), Mathf.Cos(k / 2))); }
// Start is called before the first frame update void Start() { float rad = angle * Mathf.Deg2Rad; velocity = new Vector2(Mathf.Cos(rad), Mathf.Sin(rad)) * speed; }
private void FindMetersPerLat(float lat) // Compute lengths of degrees { // Set up "Constants" float m1 = 111132.92f; // latitude calculation term 1 float m2 = -559.82f; // latitude calculation term 2 float m3 = 1.175f; // latitude calculation term 3 float m4 = -0.0023f; // latitude calculation term 4 float p1 = 111412.84f; // longitude calculation term 1 float p2 = -93.5f; // longitude calculation term 2 float p3 = 0.118f; // longitude calculation term 3 lat = lat * Mathf.Deg2Rad; // Calculate the length of a degree of latitude and longitude in meters metersPerLat = m1 + (m2 * Mathf.Cos(2 * (float)lat)) + (m3 * Mathf.Cos(4 * (float)lat)) + (m4 * Mathf.Cos(6 * (float)lat)); metersPerLon = (p1 * Mathf.Cos((float)lat)) + (p2 * Mathf.Cos(3 * (float)lat)) + (p3 * Mathf.Cos(5 * (float)lat)); }
public static Mesh CreateTorus(Single radius1 = 1, Single radius2 = 0.3f, Int32 radialSegments = 24, Int32 sides = 18) { // Generate vertices and normals var vertices = new Vector3[(radialSegments + 1) * (sides + 1)]; var normals = new Vector3[vertices.Length]; for (var seg = 0; seg <= radialSegments; seg++) { var currSeg = seg == radialSegments ? 0 : seg; var t1 = (Single)currSeg / radialSegments * TwoPI; var r1 = new Vector3(Mathf.Cos(t1) * radius1, 0f, Mathf.Sin(t1) * radius1); for (var side = 0; side <= sides; side++) { var currSide = side == sides ? 0 : side; var t2 = (Single)currSide / sides * TwoPI; var r2 = Quaternion.AngleAxis( -t1 * Mathf.Rad2Deg, Vector3.up) * new Vector3(Mathf.Sin(t2) * radius2, Mathf.Cos(t2) * radius2 ); vertices[side + seg * (sides + 1)] = r1 + r2; normals[side + seg * (sides + 1)] = (vertices[side + seg * (sides + 1)] - r1).normalized; } } // Create UVs var uvs = new Vector2[vertices.Length]; for (var seg = 0; seg <= radialSegments; seg++) { for (var side = 0; side <= sides; side++) { uvs[side + seg * (sides + 1)] = new Vector2((Single)seg / radialSegments, (Single)side / sides); } } // Create Triangles var nbFaces = vertices.Length; var nbTriangles = nbFaces * 2; var nbIndexes = nbTriangles * 3; var triangles = new int[nbIndexes]; var i = 0; for (var seg = 0; seg <= radialSegments; seg++) { for (var side = 0; side <= sides - 1; side++) { var current = side + seg * (sides + 1); var next = side + (seg < (radialSegments) ? (seg + 1) * (sides + 1) : 0); if (i < triangles.Length - 6) { triangles[i++] = current; triangles[i++] = next; triangles[i++] = next + 1; triangles[i++] = current; triangles[i++] = next + 1; triangles[i++] = current + 1; } } } // Create Mesh var mesh = new Mesh(); mesh.Clear(); mesh.vertices = vertices; mesh.normals = normals; mesh.uv = uvs; mesh.triangles = triangles; mesh.RecalculateBounds(); mesh.Optimize(); return(mesh); }
public static float In(float k) { return(1f - Mathf.Cos(k * Mathf.PI / 2f)); }
public float commandStep(Pose observedPose, Vector3 linearVel, float angularVel, float dt) { if (!goalReceived) { return(0f); } Debug.Log(string.Format("observedPose: {0}", observedPose)); float yaw = getYaw(observedPose.rotation.eulerAngles); Debug.Log(string.Format("yaw in command step: {0}", yaw)); float headingError = getYaw(goal.rotation.eulerAngles) - yaw; Debug.Log(string.Format("headingError: {0}", headingError)); float headingCorrection = kPHeading * headingError + kDHeading * ((headingError - prevHeadingError) / dt); Debug.Log(string.Format("headingCorrection: {0}", headingCorrection)); // Incoming pose and velocity - convert to front axle. Pose frontPose = new Pose(new Vector3(observedPose.position.x + wheelbase * Mathf.Cos(yaw), observedPose.position.y + wheelbase * Mathf.Sin(yaw), 0), observedPose.rotation); Debug.Log(string.Format("frontPose: {0}", frontPose)); Vector3 frontLinearVel = new Vector3(linearVel.x + angularVel * Mathf.Sin(yaw), linearVel.y + angularVel * Mathf.Cos(yaw), 0); Debug.Log(string.Format("frontLinearVel: {0}", frontLinearVel)); Vector3 intersection = findIntersection(frontPose.position, goal.position, getYaw(goal.rotation.eulerAngles)); Debug.Log(string.Format("intersection: {0}", intersection)); float crosstrackError = Vector3.Distance(intersection, frontPose.position); Debug.Log(string.Format("cross track error: {0}", crosstrackError)); // Goal line always points forward - so, if pose.y is bigger, pose is to the left. if (goal.position.y < frontPose.position.y) { crosstrackError *= -1; } float crosstrackCorrection = Mathf.Atan2(kCrosstrack * crosstrackError, velDamping + Vector3.Magnitude(frontLinearVel)); Debug.Log(string.Format("cross track correction: {0}", crosstrackCorrection)); prevHeadingError = headingError; cte.Add(crosstrackError.ToString()); time.Add(Time.time.ToString()); WriteToFile(); return(headingCorrection + crosstrackCorrection);; }
// Token: 0x06000474 RID: 1140 RVA: 0x00026AAC File Offset: 0x00024EAC public bool RecalculateCell(int x, int z, bool preserveExistingNodes) { LinkedLevelCell linkedLevelCell = new LinkedLevelCell(); Vector3 position = this.matrix.MultiplyPoint3x4(new Vector3((float)x + 0.5f, 0f, (float)z + 0.5f)); RaycastHit[] array = this.collision.CheckHeightAll(position); for (int i = 0; i < array.Length / 2; i++) { RaycastHit raycastHit = array[i]; array[i] = array[array.Length - 1 - i]; array[array.Length - 1 - i] = raycastHit; } bool result = false; if (array.Length > 0) { LinkedLevelNode linkedLevelNode = null; for (int j = 0; j < array.Length; j++) { LinkedLevelNode linkedLevelNode2 = new LinkedLevelNode(); linkedLevelNode2.position = array[j].point; if (linkedLevelNode != null && linkedLevelNode2.position.y - linkedLevelNode.position.y <= this.mergeSpanRange) { linkedLevelNode.position = linkedLevelNode2.position; linkedLevelNode.hit = array[j]; linkedLevelNode.walkable = this.collision.Check(linkedLevelNode2.position); } else { linkedLevelNode2.walkable = this.collision.Check(linkedLevelNode2.position); linkedLevelNode2.hit = array[j]; linkedLevelNode2.height = float.PositiveInfinity; if (linkedLevelCell.first == null) { linkedLevelCell.first = linkedLevelNode2; linkedLevelNode = linkedLevelNode2; } else { linkedLevelNode.next = linkedLevelNode2; linkedLevelNode.height = linkedLevelNode2.position.y - linkedLevelNode.position.y; linkedLevelNode = linkedLevelNode.next; } } } } else { linkedLevelCell.first = new LinkedLevelNode { position = position, height = float.PositiveInfinity, walkable = !this.collision.unwalkableWhenNoGround }; } uint graphIndex = (uint)this.active.astarData.GetGraphIndex(this); LinkedLevelNode linkedLevelNode3 = linkedLevelCell.first; int num = 0; int k = 0; for (;;) { if (k >= this.layerCount) { if (k + 1 > 255) { break; } this.AddLayers(1); result = true; } LevelGridNode levelGridNode = this.nodes[z * this.width + x + this.width * this.depth * k]; if (levelGridNode == null || !preserveExistingNodes) { this.nodes[z * this.width + x + this.width * this.depth * k] = new LevelGridNode(this.active); levelGridNode = this.nodes[z * this.width + x + this.width * this.depth * k]; levelGridNode.Penalty = this.initialPenalty; levelGridNode.GraphIndex = graphIndex; result = true; } levelGridNode.SetPosition((Int3)linkedLevelNode3.position); levelGridNode.Walkable = linkedLevelNode3.walkable; levelGridNode.WalkableErosion = levelGridNode.Walkable; if (linkedLevelNode3.hit.normal != Vector3.zero) { float num2 = Vector3.Dot(linkedLevelNode3.hit.normal.normalized, this.collision.up); if (this.penaltyAngle) { levelGridNode.Penalty += (uint)Mathf.RoundToInt((1f - num2) * this.penaltyAngleFactor); } float num3 = Mathf.Cos(this.maxSlope * 0.0174532924f); if (num2 < num3) { levelGridNode.Walkable = false; } } levelGridNode.NodeInGridIndex = z * this.width + x; if (linkedLevelNode3.height < this.characterHeight) { levelGridNode.Walkable = false; } num++; linkedLevelNode3 = linkedLevelNode3.next; k++; if (linkedLevelNode3 == null) { goto Block_14; } } Debug.LogError("Too many layers, a maximum of LevelGridNode.MaxLayerCount are allowed (required " + (k + 1) + ")"); return(result); Block_14: while (k < this.layerCount) { this.nodes[z * this.width + x + this.width * this.depth * k] = null; k++; } linkedLevelCell.count = num; return(result); }