public void RemoveWaypointIndexAndUpdate(int waypointIndex) { int oldIndex = -1; if (waypointIndexes != null) { /*halmeida - we remove every occurrence of the index and update the bigger indexes to preserve path logic.*/ for (int i = 0; i < waypointIndexes.Length; i++) { oldIndex = waypointIndexes[i]; if (oldIndex == waypointIndex) { UsefulFunctions.DecreaseArray <int>(ref waypointIndexes, i); if (waypointIndexes == null) { break; } else { i--; } } else { if (oldIndex > waypointIndex) { waypointIndexes[i] = oldIndex - 1; } } } } }
private void RemoveCanvasText(int textIndex) { if (texts != null) { if ((textIndex > -1) && (textIndex < texts.Length)) { texts[textIndex].Clear(); texts[textIndex] = null; textOriginTransforms[textIndex] = null; textTransforms[textIndex] = null; Destroy(textObjects[textIndex]); textObjects[textIndex] = null; UsefulFunctions.DecreaseArray <bool>(ref textPauseds, textIndex); UsefulFunctions.DecreaseArray <float>(ref textElapseds, textIndex); UsefulFunctions.DecreaseArray <float>(ref textStageElapseds, textIndex); UsefulFunctions.DecreaseArray <int>(ref textStages, textIndex); UsefulFunctions.DecreaseArray <float>(ref textDurationsHide, textIndex); UsefulFunctions.DecreaseArray <float>(ref textDurationsPlain, textIndex); UsefulFunctions.DecreaseArray <float>(ref textDurationsShow, textIndex); UsefulFunctions.DecreaseArray <Vector2>(ref textIncreasedScales, textIndex); UsefulFunctions.DecreaseArray <Vector2>(ref textSpeeds, textIndex); UsefulFunctions.DecreaseArray <Vector2>(ref textOriginPositions, textIndex); UsefulFunctions.DecreaseArray <Transform>(ref textOriginTransforms, textIndex); UsefulFunctions.DecreaseArray <int>(ref textEvolutions, textIndex); UsefulFunctions.DecreaseArray <SpritedStringUI>(ref texts, textIndex); UsefulFunctions.DecreaseArray <RectTransform>(ref textTransforms, textIndex); UsefulFunctions.DecreaseArray <GameObject>(ref textObjects, textIndex); } } }
//LayerTile, Matrix4x4.identity, //Color.white public bool Initiate(TestRunSO TestRunSO) { var Magix = UsefulFunctions.GetCorrectMatrix(MatrixName, WorldPosition); if (NoTileAt == false) { var TileAt = Magix.Matrix.MetaTileMap.GetTile(WorldPosition.ToLocal(Magix).RoundToInt(), LayerTile.LayerType); if (TileAt != LayerTile) { TestRunSO.Report.AppendLine(CustomFailedText); TestRunSO.Report.AppendLine($"Tile does not match specified one at {WorldPosition} is {TileAt.OrNull()?.name} When it should be {LayerTile.name} "); return(false); } else { return(true); } } else { var TileAt = Magix.Matrix.MetaTileMap.GetTile(WorldPosition.ToLocal(Magix).RoundToInt(), LayerType); if (TileAt != null) { TestRunSO.Report.AppendLine(CustomFailedText); TestRunSO.Report.AppendLine($"A tile is present at {WorldPosition} it should not be, it is {TileAt.name} "); return(false); } else { return(true); } } }
public bool Initiate(TestRunSO TestRunSO) { var Magix = UsefulFunctions.GetCorrectMatrix(MatrixName, PositionToCheck); var List = Magix.Matrix.ServerObjects.Get(PositionToCheck.ToLocal(Magix).RoundToInt()); var OriginalID = Prefab.GetComponent <PrefabTracker>().ForeverID; foreach (var Object in List) { var PrefabTracker = Object.GetComponent <PrefabTracker>(); if (PrefabTracker != null) { if (PrefabTracker.ForeverID == OriginalID) { var mono = Object.GetComponent(ComponentName); if (string.IsNullOrEmpty(ComponentName)) { TestRunSO.Report.AppendLine(CustomFailedText); TestRunSO.Report.AppendLine($" ComponentName was not Set "); return(false); } ClassVariableWriter.SetValue(mono.GetType(), mono); return(true); } } } TestRunSO.Report.AppendLine(CustomFailedText); TestRunSO.Report.AppendLine($"Could not find prefab {Prefab}"); return(false); }
public void InterpretMovementDirection(Vector2 normalizedDirection) { float angleWithRight = 0f; bool newSide = SIDE_RIGHT; if (normalizedDirection != Vector2.zero) { angleWithRight = UsefulFunctions.GetDirectionAngle(normalizedDirection); if (angleWithRight > 90f) { angleWithRight = -(180f - angleWithRight); newSide = SIDE_LEFT; } else if (angleWithRight < -90f) { angleWithRight = 180f + angleWithRight; newSide = SIDE_LEFT; } else { newSide = SIDE_RIGHT; } SetSide(newSide); SetSpeedAngleBody(true, angleWithRight); } else { SetSide(side); SetSpeedAngleBody(false, 0f); } }
private void CreateDebris(float offsetX, float offsetY) { GameObject newDebrisObject = null; SimpleAnimator newDebrisAnimator = null; float originX = 0f; float originY = 0f; newDebrisObject = Instantiate(debrisModel, Vector3.zero, Quaternion.identity) as GameObject; if (newDebrisObject != null) { newDebrisAnimator = newDebrisObject.GetComponent <SimpleAnimator>(); if (newDebrisAnimator != null) { newDebrisObject.transform.SetParent(transform, false); originX = -1f * (colliderWidth / 2f); originY = colliderHeight / 2f; newDebrisObject.transform.localPosition = new Vector3(originX + offsetX, originY + offsetY, -debrisDepth); UsefulFunctions.IncreaseArray <GameObject>(ref debrisObjects, newDebrisObject); UsefulFunctions.IncreaseArray <SimpleAnimator>(ref debrisAnimators, newDebrisAnimator); Debug.Log("Debug : ObstacleController : created debris with offsets (" + offsetX + ", " + offsetY + ")."); } else { Destroy(newDebrisObject); } } }
public bool ChangeStateToHeal() { Robot_Status temptarget = null; foreach (GameObject go in UsefulFunctions.GetNearbyRobotWithBoxColliderArray(parent_object.transform.position, robot_local_sprite_size * 4)) { if (go != parent_object) { temptarget = go.GetComponent <Robot_Status>(); if (temptarget.GetHealthPoint() < temptarget.GetBaseHealthPoint() && (temptarget.state_manager.states_enum != ROBOT_STATES.DEAD && temptarget.state_manager.states_enum != ROBOT_STATES.OUTOFENERGY)) { ally_target = go; break; } else { ally_target = null; } } } if (ally_target != null && Random.Range(1, 101) < parent_object.GetComponent <Robot_Status>().GetChanceToHeal()) { SetCurrentState(ROBOT_STATES.HEAL); return(true); } return(false); }
//Object collision public void OnTriggerEnter(Collider col) { AudioSource audio = player.GetComponent <AudioSource>(); audio.Play(); score++; gems_info.text = "GEMS: " + score.ToString() + "/" + menu_score.ToString(); ShorterFunctions.SaveMainInfo(collectObj); collision_t = trial_t; collectObj.SetActive(false); if (score != menu_score) { //collectObj = UsefulFunctions.ChooseGem(gems); collectObj = UsefulFunctions.RandomizeGem(gems); } else { player.GetComponent <CharacterController>().enabled = false; tornado.SetActive(true); foreach (GameObject g in tornados) { g.SetActive(true); } tornadoFeedback.SetActive(true); StartCoroutine(WaitForIt(3.5f)); } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { UsefulFunctions.XSelectBreps("Select breps for meshing", out RhinoList <Brep> breps); for (var i = 0; i < breps.Count; i++) { //mesh create form brep method // https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Mesh_CreateFromBrep_1.htm //MeshingParameters mp = new MeshingParameters(); //mp.MinimumEdgeLength = 4; //mp.MaximumEdgeLength = 12; var meshes = Mesh.CreateFromBrep(breps[i], MeshingParameters.FastRenderMesh); var weldedmesh = new Mesh(); //just creates a new mesh object foreach (var mesh in meshes) // foreach is just a different type of iterator { weldedmesh.Append(mesh); //not a truly welded mesh, just joined together. } // we do this because the meshing of a brep may result in several //meshes. Here, we 'weld' them into one. doc.Objects.AddMesh(weldedmesh); } doc.Views.Redraw(); return(Result.Success); }
// Update is called once per frame void LateUpdate() { if (Input.GetKeyDown(KeyCode.P)) { piecesManager.PrintPieces(); } if (Input.GetKeyDown(KeyCode.Escape)) { piecesManager.DeselectPiece(); } Vector3 mousePos = UsefulFunctions.GetMouseWorldPosition(); if (Input.GetMouseButtonDown(0)) { piecesManager.GetXY(mousePos, out int x, out int y); if (x >= 0 && y >= 0 && x < boardWidth && y < boardHeight) { if (piecesManager.selectedPiece != null) { piecesManager.MovePiece(mousePos, piecesManager.selectedPiece); } else { piecesManager.SelectPiece(mousePos); } } } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { UsefulFunctions.XSelectPoints("Select points to make an arc and/or circles", out Point3dList pointer); /*if(pointer.Count == 3) * { * UsefulFunctions.XDrawArc(pointer[0], pointer[1], pointer[2], doc); * UsefulFunctions.XDrawCircle(pointer[0], 10, doc); * UsefulFunctions.XDrawCircle(pointer[1], 5, doc); * UsefulFunctions.XDrawCircle(pointer[2], 2, doc); * }*/ Random rnd = new Random(); for (var i = 0; i < pointer.Count; i++) { double rndnr = 10 * rnd.NextDouble(); UsefulFunctions.XDrawCircle(pointer[i], rndnr, doc); } doc.Views.Redraw(); return(Result.Success); }
protected virtual void ValidateVisualEffectModels() { GameObject effectModel = null; if (projectileLaunchEffectsFront != null) { for (int i = 0; i < projectileLaunchEffectsFront.Length; i++) { effectModel = projectileLaunchEffectsFront[i]; if (effectModel != null) { if (effectModel.GetComponent <SimpleAnimator>() != null) { UsefulFunctions.IncreaseArray <GameObject>(ref projectileLaunchFront, effectModel); } } } } if (projectileLaunchEffectsBack != null) { for (int i = 0; i < projectileLaunchEffectsBack.Length; i++) { effectModel = projectileLaunchEffectsBack[i]; if (effectModel != null) { if (effectModel.GetComponent <SimpleAnimator>() != null) { UsefulFunctions.IncreaseArray <GameObject>(ref projectileLaunchBack, effectModel); } } } } }
//methods public bool Rebuild() { if (cornerpts.Count != 4) { return(false); } CurveList edgecurves = new CurveList(); for (var i = 0; i < cornerpts.Count - 1; i++) { LineCurve edge = new LineCurve(cornerpts[i], cornerpts[(i + 1) % 4]); //modulo gives remainer after divided by set number if (edge.IsValid) { edgecurves.Add(edge); } } if (edgecurves.Count != 4) { return(false); } brep = UsefulFunctions.XCreateBrepFromEdgeCurves(edgecurves); if (brep == null || !brep.IsValid) { return(false); } return(true); }
public void RemoveWaypointIndexSetAndUpdate(int firstIndexToRemove, int totalIndexesToRemove) { int index = -1; if (waypointIndexes != null) { int lastIndexToRemove = firstIndexToRemove + totalIndexesToRemove - 1; for (int i = 0; i < waypointIndexes.Length; i++) { index = waypointIndexes[i]; if ((index >= firstIndexToRemove) && (index <= lastIndexToRemove)) { UsefulFunctions.DecreaseArray <int>(ref waypointIndexes, i); if (waypointIndexes == null) { break; } else { i--; } } else { if (index > lastIndexToRemove) { waypointIndexes[i] = index - totalIndexesToRemove; } } } } }
private void addRhinoMeshVertices(Rhino.Geometry.Collections.MeshTopologyVertexList meshVertexList, Rhino.Geometry.Collections.MeshVertexNormalList meshVertexNormalList) { for (int i = 0; i < meshVertexList.Count; i++) { addVertex(UsefulFunctions.convertPointToVector(meshVertexList[i])); } }
string Main() { // We can replace any number of digits int n = 250000; primes = UsefulFunctions.findPrimes(n); var primeValues = Enumerable.Range(0, (int)n).Where(i => primes[i]).ToList(); primes = UsefulFunctions.findPrimes(1000000); foreach (int prime in primeValues.Where(p => p > 1000)) { //List<List<int>> sets = FindTwos(prime); List <List <int> > sets = FindThrees(prime); foreach (List <int> primeList in sets) { if (primeList.Count() >= 8) { // Console.Write("This Prime: " + prime + ", Primes: "); // foreach (int i in primeList) // Console.Write(i + ", "); // Console.WriteLine(); return(primeList.First().ToString()); } } } return(""); }
private void addPolylineMeshVertices(List <Polyline> inputPolylines, List <int>[] faceVertRefs) { for (int i = 0; i < inputPolylines.Count; i++) { if (inputPolylines[i].IsClosed) { Point3d[] pointsForPolyline = inputPolylines[i].ToArray(); faceVertRefs[i] = new List <int>(); for (int j = 0; j < pointsForPolyline.Length - 1; j++) { int isNew = isVertexNew(pointsForPolyline[j], 0.01f); if (isNew == -1) { addVertex(UsefulFunctions.convertPoint3dToVector(pointsForPolyline[j])); faceVertRefs[i].Add(vertices.Count - 1); } else { faceVertRefs[i].Add(isNew); } } } else { //polyline not closed - not good! } } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { UsefulFunctions.XSelectPoints("Seleect points for enumeration", out Point3dList points); var format = string.Format("F{0}", doc.ModelDistanceDisplayPrecision); for (var i = 0; i < points.Count; i++) { var str = string.Format("Point {0} X:{1},Y:{2},Z:{3}", i.ToString(), points[i].X.ToString(format), points[i].Y.ToString(format), points[i].Z.ToString(format)); if (i == 0) { str = "First Point"; } else if (i == points.Count - 1) { str = "Last Point"; } var dot = new TextDot(str, points[i]); doc.Objects.AddTextDot(dot); } doc.Views.Redraw(); return(Result.Success); }
public bool ChangeStateToRescue() { State_Manager temptarget = null; foreach (GameObject go in UsefulFunctions.GetNearbyRobotWithBoxColliderArray(parent_object.transform.position, robot_local_sprite_size * 4)) { temptarget = go.GetComponent <Robot_Status>().GetStateManager(); if (temptarget == null) { ally_target = null; } else { if (temptarget.GetRobotCurrentState() == ROBOT_STATES.DEAD || temptarget.GetRobotCurrentState() == ROBOT_STATES.OUTOFENERGY) { ally_target = go; break; } else { ally_target = null; } } } if (ally_target != null && Random.Range(1, 101) < parent_object.GetComponent <Robot_Status>().GetChanceToRescue()) { SetCurrentState(ROBOT_STATES.RESCUE); return(true); } return(false); }
public virtual bool ReactToPointerDown(float worldPointX, float worldPointY) { bool react = false; Vector3 centerPosition = Vector3.zero; Vector2 topLeft = Vector2.zero; if (reactionType == ReactionType.NotReact) { return(false); } if (open && !autoClose) { if (reactionType == ReactionType.ReactPrecisely) { centerPosition = transform.position; /*halmeida - the boxArea is top-left anchored, so it already has the offsets from the center to the left and * from the center to the top.*/ topLeft.x = centerPosition.x + boxArea.x; topLeft.y = centerPosition.y + boxArea.y; react = UsefulFunctions.AreaContainsPoint(topLeft.x, topLeft.y, boxArea.width, boxArea.height, worldPointX, worldPointY); } else { react = true; } if (react) { ReactToInteraction(); return(true); } } return(false); }
// Update is called once per frame void Update() { current_state.gameObject.SetActive(true);// just to make sure the main state is active //current_state.Execute(); StateTransitions(); if (home_base == null) { home_base = GameObject.FindGameObjectWithTag("Base"); } if (max_bounds == null) { if (UsefulFunctions.GetNearbyRobotMaxAreaWithBoxCollider( parent_object.transform.position, robot_local_sprite_size) != null) { max_bounds = UsefulFunctions.GetNearbyRobotMaxAreaWithBoxCollider(parent_object.transform.position, robot_local_sprite_size).GetComponent <BoxCollider2D>(); } } else { Vector3 current_pos = parent_object.transform.position; Vector3 area_pos = max_bounds.transform.position; current_pos.x = Mathf.Clamp(current_pos.x, area_pos.x - max_bounds.bounds.size.x / 2, area_pos.x + max_bounds.bounds.size.x / 2); current_pos.y = Mathf.Clamp(current_pos.y, area_pos.y - max_bounds.bounds.size.y / 2, area_pos.y + max_bounds.bounds.size.y / 2); parent_object.transform.position = current_pos; } }
private void AddDisplayedLife() { int lifeIndex = -1; int row = -1; int column = -1; GameObject lifeObject = null; RectTransform rectTrans = null; Vector2 anchoredPosition = Vector2.zero; if ((lifeImageModel != null) && (canvasRectTrans != null)) { lifeIndex = (lifeImageObjects == null) ? 0 : lifeImageObjects.Length; row = lifeIndex / lifeImagesPerRow; column = lifeIndex % lifeImagesPerRow; lifeObject = Instantiate(lifeImageModel) as GameObject; rectTrans = lifeObject.GetComponent <RectTransform>(); if (rectTrans != null) { rectTrans.SetParent(canvasRectTrans, false); anchoredPosition = rectTrans.anchoredPosition; anchoredPosition.x += column * lifeImageWidth; anchoredPosition.y -= row * lifeImageHeight; rectTrans.anchoredPosition = anchoredPosition; UsefulFunctions.IncreaseArray <GameObject>(ref lifeImageObjects, lifeObject); } } }
public void QuitExp() { if (UsefulFunctions.current_trial > 0) { _FileLocation = Application.dataPath + "/SubTrialInfo"; try { isSaving = true; _data = UsefulFunctions.SerializeObject(Demo.trialInfo); UsefulFunctions.CreateXML(_FileLocation, _data); Debug.Log("Main trial data Saved"); _data = UsefulFunctions.SerializeObject(Demo.trialPath); UsefulFunctions.CreateXML(_FileLocation, _data); Debug.Log("Overall path data Saved"); _data = UsefulFunctions.SerializeObject(Demo.trialFeedback); UsefulFunctions.CreateXML(_FileLocation, _data); Debug.Log("Feedback data Saved"); } catch (System.Exception ex) { Debug.LogError(ex.ToString()); } finally { isSaving = false; } } Application.LoadLevel(6); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { UsefulFunctions.XSelectCurves("Select curves for brep creation", out CurveList curves); if (curves.Count >= 3 && curves.Count <= 4) { Brep brep = UsefulFunctions.XCreateBrepFromEdgeCurves(curves); RhinoApp.WriteLine("The user created the brep(s) successfully"); if (brep != null && brep.IsValid) { doc.Objects.AddBrep(brep); } } else { Brep[] breps = UsefulFunctions.XCreateBrepFromPlanarCurves(curves, doc); for (var i = 0; i < breps.Length; i++) { if (breps[i] != null && breps[i].IsValid) { doc.Objects.AddBrep(breps[i]); } } } return(Result.Success); }
string Main() { // Find the value of n ≤ 1,000,000 for which n/φ(n) is a maximum. // Find the prime factorization of each number // Answer is actually just 2*3*5*7*11*13*17 int m = 1000000; double maxRatio = 0; int finalN = 0; bool[] primes = UsefulFunctions.findPrimes(m); primeValues = Enumerable.Range(0, (int)m).Where(i => primes[i]).ToList(); for (int n = 2; n < m; n = n + 2) { int coprimes = PhiOf(n); double ratio = (double)n / coprimes; if (ratio > maxRatio) { maxRatio = ratio; finalN = n; //Console.WriteLine(n + ", " + coprimes + ", " + ratio); } } //Console.WriteLine("Ratio: " + maxRatio); //Console.WriteLine("n: " + finalN); return(finalN.ToString()); }
//Object collision public void OnTriggerEnter(Collider col) { AudioSource audio = player.GetComponent <AudioSource>(); audio.Play(); score++; gems_info.text = "GEMS: " + score.ToString() + "/" + menu_score.ToString(); collision_t = trial_t; collectObj.SetActive(false); if (score != menu_score) { //collectObj = UsefulFunctions.RandomizeGem(gems); collectObj = UsefulFunctions.RandomizeGem(gems); } else { if (PlayerPrefs.GetInt("isMapping") == 1) { player.GetComponent <CharacterController>().enabled = false; tornado.SetActive(true); foreach (GameObject g in tornados) { g.SetActive(true); } tornadoFeedback.SetActive(true); StartCoroutine(WaitForIt(3.5f)); } else { feedbackEndTrial.SetActive(true); showFeedback = true; checkForButton = true; } } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { UsefulFunctions.XSelectPoints("Select points to make CRAZY curves and lines", out Point3dList pointer); if (pointer.Count < 1) { return(Result.Failure); } // The declarations could be done like this too, but above is an 'inline declaration' // Point3dList pointer // // UsefulFunctions.XSelectPoints("Select points to make a curve", out pointer); //RhinoApp.WriteLine("The user selected {0} points successfully", pointer.Count.ToString()); UsefulFunctions.XCurveFromPoints(pointer, doc, true); UsefulFunctions.XCurveFromPoints(pointer, doc, false); UsefulFunctions.XLinesFromPoints(pointer, doc); UsefulFunctions.XPolylineFromPoints(pointer, doc); return(Result.Success); }
// Update is called once per frame void FixedUpdate() { trial_t += Time.deltaTime; //updates time if (score == menu_score && checkForButton) { if (time_anim == (trial_t + 5)) { foreach (GameObject g in tornados) { g.GetComponent <ParticleSystem>().enableEmission = false; } } feedbackEndTrial.GetComponent <Animator>().SetBool("hasToGoBack", showFeedback); if (UsefulFunctions.OnButtonPression() == true) { score_text = score_gained.text; UsefulFunctions.SetSkyIndex(UsefulFunctions.skyIndex); if (!UsefulFunctions.isShorterVersion) { Application.LoadLevel("Feedback"); //Feedback level } else { Application.LoadLevel("FeedbackShorter"); //Feedback level } } } //if (treasure.GetComponent<Animator>().isActiveAndEnabled) //{ // dummy++; // if (dummy == 80) // { // treasure.SetActive(false); // player.GetComponent<MouseLook>().enabled = true; // tilted = true; // player.GetComponent<Animator>().SetBool("Tilted", tilted); // startRot = true; // } //} //if (player.transform.rotation.eulerAngles.x == 0.0f && startRot) //{ // player.GetComponent<Animator>().enabled = false; // startRot = false; //} /*if (Input.GetButton("Y")) * UsefulFunctions.RndEnvironment(); * * if (Input.GetButton("Y")) * collectObj = UsefulFunctions.RandomizeGem(gems); * * if (Input.GetButton("X")) * player.transform.position = UsefulFunctions.RandomizingGameObject(player); * * if (Input.GetButton("Y")) * { * int index = UsefulFunctions.SetSkyIndex(UsefulFunctions.skyIndex); * Camera.main.GetComponent<Skybox>().material = skies[index]; * }*/ }
String Main() { long n = 250000; int factors = 4; bool[] primes = UsefulFunctions.findPrimes(n); // bool array of what numbers are prime up to n primeValues = Enumerable.Range(0, (int)n).Where(i => primes[i]).ToList(); // list of all primes less than n int count = 0; for (long i = 100; i <= n; i++) { if (HasUniquePrimeFactors(i, factors)) { count++; if (count == factors) { return((i - (factors - 1)).ToString()); } } else { count = 0; } } return(""); }
public void RemoveLastWaypointIndex() { if (waypointIndexes != null) { UsefulFunctions.DecreaseArray <int>(ref waypointIndexes, (waypointIndexes.Length - 1)); } }