void Update() { // // get all the objects that have Player and Input component // List <GameObject> goComps = ObjectTracker.Find <OpponentsComponent>(); foreach (GameObject goInput in goComps) { if (gameOver) { return; } SpeedComponent speed = goInput.GetComponent <SpeedComponent>(); if (speed == null) { continue; } //input.xAxis = player.speed * Input.GetAxis(input.HorizontalInput); //input.shoot = Input.GetButton(input.ShootInput); // // move the player vertically // Vector3 now = goInput.transform.position; goInput.transform.position = new Vector3(now.x, now.y + speed.speed, now.z); // // find out if player has crossed the finish line // EventManager.TriggerEvent("FinishLineEvent", goInput.name); } }
/// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> /// <msdn-id>ms682317</msdn-id> /// <unmanaged>IUnknown::Release</unmanaged> /// <unmanaged-short>IUnknown::Release</unmanaged-short> protected unsafe override void Dispose(bool disposing) { // Only dispose non-zero object if (NativePointer != IntPtr.Zero) { // If object is disposed by the finalizer, emits a warning if (!disposing && Configuration.EnableTrackingReleaseOnFinalizer) { if (!Configuration.EnableReleaseOnFinalizer) { var objectReference = ObjectTracker.Find(this); LogMemoryLeakWarning?.Invoke(string.Format("Warning: Live ComObject [0x{0:X}], potential memory leak: {1}", NativePointer.ToInt64(), objectReference)); } } // Release the object if (disposing || Configuration.EnableReleaseOnFinalizer) { ((IUnknown)this).Release(); } // Untrack the object if (Configuration.EnableObjectTracking) { ObjectTracker.UnTrack(this); } // Set pointer to null (using protected members in order to avoid NativePointerUpdat* callbacks. _nativePointer = (void *)0; } base.Dispose(disposing); }
/// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> /// <msdn-id>ms682317</msdn-id> /// <unmanaged>IUnknown::Release</unmanaged> /// <unmanaged-short>IUnknown::Release</unmanaged-short> protected unsafe override void Dispose(bool disposing) { // Only dispose non-zero object if (NativePointer != IntPtr.Zero) { // If object is disposed by the finalizer, emits a warning if (!disposing && Configuration.EnableTrackingReleaseOnFinalizer) { var objectReference = ObjectTracker.Find(this); var additionalMessage = Configuration.EnableReleaseOnFinalizer ? "will be released automatically" : "memory leak detected"; System.Diagnostics.Debug.WriteLine(string.Format("Warning: Live ComObject, {0}: {1}", additionalMessage, objectReference)); } // Release the object if (disposing || Configuration.EnableReleaseOnFinalizer) { ((IUnknown)this).Release(); } // Untrack the object if (Configuration.EnableObjectTracking) { ObjectTracker.UnTrack(this); } // Set pointer to null (using protected members in order to avoid NativePointerUpdat* callbacks. _nativePointer = (void *)0; } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (NativePointer != IntPtr.Zero) { // If object is disposed by the finalizer, emits a warning if (!disposing && Configuration.EnableTrackingReleaseOnFinalizer) { if (!Configuration.EnableReleaseOnFinalizer) { var objectReference = ObjectTracker.Find(this); LogMemoryLeakWarning?.Invoke(string.Format("Warning: Live CppObject released on finalizer [0x{0:X}], potential memory leak: {1}", NativePointer.ToInt64(), objectReference)); } } if (Configuration.EnableObjectTracking) { ObjectTracker.UnTrack(this); } unsafe { // Set pointer to null (using protected members in order to avoid callbacks. _nativePointer = (void *)0; } } }
void Handle(string value) { // // Make the panel visible again // GameObject go = GameObject.Find("GameOverCanvas"); go.GetComponent <CanvasGroup>().alpha = 1f; Text endtxt = GameObject.Find("GameOverTxt").GetComponent <Text>(); endtxt.text = "GameOver, " + value + " wins :-)"; if (endtxt == null) { return; } Application.Quit(); List <GameObject> goList = ObjectTracker.Find <UIEndComponent>(); // // Game object is a panel that has text for end of game // //foreach (GameObject mmGO in goList) //{ // // // // Get the component so we can have the data we need // // // //Text endTxt = mmGO.GetComponent<Text>(); // //endTxt.text = "GameOver, " + value + " wins :-)"; // //mmGO.gameObject.SetActive(true); // Application.Quit(); //} }
private void Update() { List <GameObject> goComps = ObjectTracker.Find <InputComponent>(); foreach (GameObject opInput in goComps) { // // Get the component so we can have the data we need // InputComponent ocComp = opInput.GetComponent <InputComponent>(); if (Input.GetAxisRaw(ocComp.VerticalInput) != 0) { if (!isVerticalUsed) { EventManager.TriggerEvent("PlayerMoveEvent", ""); isVerticalUsed = true; } } else { isVerticalUsed = false; } if (Input.GetAxisRaw(ocComp.HorizontalInput) != 0) { if (!isHorizontalUsed) { EventManager.TriggerEvent("PlayerMoveEvent", ""); isHorizontalUsed = true; } } else { isHorizontalUsed = false; } } }
void Handle(string value) { List <GameObject> goList = ObjectTracker.Find <EndOfGameComponent>(); foreach (GameObject mmGO in goList) { // // We have an object with EndOfGameComponent // then it is done, stop the game // EventManager.TriggerEvent("EndOfGameEvent", "GameEnds"); return; } // // Not end of game yet. Find the car object and see if it crossed the line // GameObject car = GameObject.Find(value); goList = ObjectTracker.Find <FinishLineComponent>(); foreach (GameObject mmFinishLine in goList) { if (car.transform.position.y > mmFinishLine.transform.position.y) { // // Someone has crossed the finish line, add component // with winner's name // var eofg = mmFinishLine.AddComponent <EndOfGameComponent>(); eofg.WinnerName = car.name; // // This will stop the game // EventManager.TriggerEvent("EndOfGameEvent", car.name); } } }
void Handle(string value) { // // Find the OpponentsContainer object. It has an "OpponentValues" component // List <GameObject> goComps = ObjectTracker.Find <OpponentValues>(); foreach (GameObject opContainer in goComps) { // // Get the component so we can have the data we need // OpponentValues ocComp = opContainer.GetComponent <OpponentValues>(); // // Player's car is the origin of the spawn point for all others // The opponents use the Player's car as offset to place themselves // var spawnX = ocComp.spawnOrigin.position.x + Mathf.Abs(ocComp.spawnOrigin.position.x / 2.0f); var spawnY = ocComp.spawnOrigin.position.y; // // Setup of opponent cars as children // for (int cnt = 0; cnt < ocComp.maxCars; cnt++) { // // create object from prefabs in Assets/Resources folder // Give it a name starting with "Opps_" plust a number // Give it a sprite renderer so it can be displayed // Give it a position offset on x-axis from the player car // GameObject oppsObj = GameObject.Instantiate(Resources.Load("Opponent", typeof(GameObject))) as GameObject; oppsObj.name = "Opps_" + cnt.ToString(); // // This objects' parent is the "OpponentContainer" // oppsObj.transform.parent = opContainer.transform; // // Get the sprite renderer component & change the location // SpriteRenderer oppsRender = oppsObj.GetComponent <Renderer>() as SpriteRenderer; // // Add spawn X to width of the car multiply by count // var x = (spawnX) + ((oppsRender.bounds.extents.x * 3.0f) * cnt); var y = spawnY; oppsRender.transform.localPosition = new Vector2(x, y); // // Add OpponentCarComponent & SpeedComponent to this GameObject // oppsObj.AddComponent <OpponentsComponent>(); var sc = oppsObj.AddComponent <SpeedComponent>(); // // Get the SpeedComponent // //var sc = oppsObj.GetComponent<SpeedComponent>(); sc.speed = (Random.value * 0.02f); // // Tell ObjectTracker about this GameObject // ObjectTracker.Register(sc.GetType(), oppsObj); } } }