public override void OnPlayerJoined(VRCPlayerApi player) { if (!localPlayer.IsOwner(pen.gameObject)) { return; } if (pen.IsHeld()) { SendCustomNetworkEvent(NetworkEventTarget.All, nameof(StartUsing)); } }
private void Interact() { EngineControl.PassengerEnterPlaneLocal(); Seat.rotation = Quaternion.Euler(0, Seat.eulerAngles.y, 0);//fixes offset seated position when getting in a rolled/pitched vehicle localPlayer.UseAttachedStation(); Seat.localRotation = SeatStartRot; HUDControl.MySeat = ThisStationID; if (PassengerOnly != null) { PassengerOnly.SetActive(true); } if (SeatAdjuster != null) { SeatAdjuster.SetActive(true); } foreach (GameObject obj in SetOwnerObjects) { if (!localPlayer.IsOwner(obj.gameObject)) { Networking.SetOwner(localPlayer, obj); } } }
public override void OnPlayerLeft(VRCPlayerApi player) { if (player.IsOwner(gameObject)) { vrcObjectSync.Respawn(); } }
public void hitDamage() { if (localPlayer == null || localPlayer.IsOwner(gameObject)) { if (damageable) { Health += -1; } } }
private void Update() { if (follow) { if (!Utilities.IsValid(owner) || !owner.IsOwner(gameObject)) { owner = Networking.GetOwner(gameObject); } sign.SetPositionAndRotation(owner.GetTrackingData(VRCPlayerApi.TrackingDataType.Head).position + new Vector3(0, offset, 0), owner.GetRotation()); } }
public bool CheckPlayerForHandler(VRCPlayerApi player) { foreach (THH_ChatHandler handler in handlers) { if (player.IsOwner(handler.gameObject)) { return(true); } } return(false); }
// プレイヤーがOwnerかどうかをテキストで表示させる処理 public void SetOptionalText(VRCPlayerApi player) { if (player.IsOwner(this.gameObject)) { // Owner側の処理 OptionText.text = $"<color=red>{player.displayName} is Owner!</color>"; } else { // Owner以外の処理 OptionText.text = $"{player.displayName} isn't Owner"; } }
public void constupdate() { ismaster.text = "ismaster: " + PlayerApiref.isMaster.ToString(); playerid.text = "playerid: " + PlayerApiref.playerId.ToString(); playergrounded.text = "isplayergrounded: " + PlayerApiref.IsPlayerGrounded().ToString(); isowner.text = "isowner: " + PlayerApiref.IsOwner(ownercheck).ToString(); gravitystrength.text = "gravitystrength: " + PlayerApiref.GetGravityStrength().ToString(); if (!changeapi) { runspeed.text = "runspeed: " + PlayerApiref.GetRunSpeed().ToString(); walkspeed.text = "walkspeed: " + PlayerApiref.GetWalkSpeed().ToString(); jumpimpulse.text = "jumpimpulse: " + PlayerApiref.GetJumpImpulse().ToString(); } else { runspeed.text = "runspeed: NULL"; walkspeed.text = "walkspeed: NULL"; jumpimpulse.text = "jumpimpulse: NULL"; } velocity.text = "velocity: " + PlayerApiref.GetVelocity().ToString(); position.text = "position: " + PlayerApiref.GetPosition().ToString(); rotation.text = "rotation: " + PlayerApiref.GetRotation().ToString(); }
public void UpdateTrackValue() { if (trackType == 1) { VRCPlayerApi player = null; switch (targetPlayer) { case 0: player = Networking.LocalPlayer; break; case 1: player = Networking.GetOwner(gameObject); break; case 2: if (targetTrigger) { var playerField = (VRCPlayerApi)targetTrigger.GetProgramVariable("triggeredPlayer"); player = playerField; } break; case 3: VRCPlayerApi[] players = new VRCPlayerApi[VRCPlayerApi.GetPlayerCount()];; VRCPlayerApi.GetPlayers(players); if (index < players.Length) { player = players[index]; } else { player = Networking.LocalPlayer; } break; } if (player == null || !player.IsValid()) { return; } switch (spot) { case "IsUserInVR": value_b = player.IsUserInVR(); break; case "IsPlayerGrounded": value_b = player.IsPlayerGrounded(); break; case "IsMaster": value_b = player.isMaster; break; case "IsInstanceOwner": value_b = player.isInstanceOwner; break; case "IsGameObjectOwner": value_b = player.IsOwner(gameObject); break; case "Position": value_v3 = player.GetPosition(); if (positionTracking) { transform.position = player.GetPosition(); transform.rotation = player.GetRotation(); } break; case "Rotation": value_v3 = player.GetRotation().eulerAngles; break; case "HeadPosition": value_v3 = player.GetTrackingData(VRCPlayerApi.TrackingDataType.Head).position; if (positionTracking) { transform.position = player.GetTrackingData(VRCPlayerApi.TrackingDataType.Head).position; transform.rotation = player.GetTrackingData(VRCPlayerApi.TrackingDataType.Head).rotation; } break; case "HeadRotation": value_v3 = player.GetTrackingData(VRCPlayerApi.TrackingDataType.Head).rotation.eulerAngles; break; case "RightHandPosition": value_v3 = player.GetTrackingData(VRCPlayerApi.TrackingDataType.RightHand).position; if (positionTracking) { transform.position = player.GetTrackingData(VRCPlayerApi.TrackingDataType.RightHand).position; transform.rotation = player.GetTrackingData(VRCPlayerApi.TrackingDataType.RightHand).rotation; } break; case "RightHandRotation": value_v3 = player.GetTrackingData(VRCPlayerApi.TrackingDataType.RightHand).rotation.eulerAngles; break; case "LeftHandPosition": value_v3 = player.GetTrackingData(VRCPlayerApi.TrackingDataType.LeftHand).position; if (positionTracking) { transform.position = player.GetTrackingData(VRCPlayerApi.TrackingDataType.LeftHand).position; transform.rotation = player.GetTrackingData(VRCPlayerApi.TrackingDataType.LeftHand).rotation; } break; case "LeftHandRotation": value_v3 = player.GetTrackingData(VRCPlayerApi.TrackingDataType.LeftHand).rotation.eulerAngles; break; case "Velocity": value_v3 = player.GetVelocity(); break; case "DisplayName": value_s = player.displayName; break; } } if (trackType == 2) { if (!targetObject) { return; } switch (spot) { case "IsActive": value_b = targetObject.activeSelf; break; case "Position": value_v3 = targetObject.transform.position; if (positionTracking) { transform.position = targetObject.transform.position; transform.rotation = targetObject.transform.rotation; } break; case "Rotation": value_v3 = targetObject.transform.rotation.eulerAngles; break; case "LocalPosition": value_v3 = targetObject.transform.localPosition; if (positionTracking) { transform.position = targetObject.transform.position; transform.rotation = targetObject.transform.rotation; } break; case "LocalRotation": value_v3 = targetObject.transform.localRotation.eulerAngles; break; case "Velocity": value_v3 = targetObject.GetComponent <Rigidbody>().velocity; break; case "AngularVelocity": value_v3 = targetObject.GetComponent <Rigidbody>().angularVelocity; break; } } if (trackType == 3) { switch (spot) { case "PlayerCount": value_i = VRCPlayerApi.GetPlayerCount(); value_f = value_i; break; case "Year": value_i = System.DateTime.Now.Year; value_f = value_i; break; case "Month": value_i = System.DateTime.Now.Month; value_f = value_i; break; case "Day": value_i = System.DateTime.Now.Day; value_f = value_i; break; case "DayOfWeek": value_i = (int)System.DateTime.Now.DayOfWeek; value_f = value_i; break; case "Hour": value_i = System.DateTime.Now.Hour; value_f = value_i; break; case "Minute": value_i = System.DateTime.Now.Minute; value_f = value_i; break; case "Second": value_i = System.DateTime.Now.Second; value_f = value_i; break; case "JoinHours": value_f = (float)(System.DateTime.Now - startTime).TotalHours; value_i = (int)value_f; break; case "JoinMinutes": value_f = (float)(System.DateTime.Now - startTime).TotalMinutes; value_i = (int)value_f; break; case "JoinSeconds": value_f = (float)(System.DateTime.Now - startTime).TotalSeconds; value_i = (int)value_f; break; } } if (trackType == 4) { if (targetComponent) { if (valueType == 0) { if (spot == "Toggle") { var toggle = (Toggle)targetComponent; value_b = toggle.isOn; } } if (valueType == 1) { if (spot == "Text") { var text = (Text)targetComponent; int.TryParse(text.text, out value_i); } if (spot == "InputField") { var inputField = (InputField)targetComponent; int.TryParse(inputField.text, out value_i); } } if (valueType == 2) { if (spot == "Slider") { var slider = (Slider)targetComponent; value_f = slider.value; } if (spot == "Scrollbar") { var scrollbar = (Scrollbar)targetComponent; value_f = scrollbar.value; } if (spot == "Text") { var text = (Text)targetComponent; float.TryParse(text.text, out value_f); } if (spot == "InputField") { var inputField = (InputField)targetComponent; float.TryParse(inputField.text, out value_f); } } if (valueType == 4) { if (spot == "Text") { var text = (Text)targetComponent; value_s = text.text; } if (spot == "InputField") { var inputField = (InputField)targetComponent; value_s = inputField.text; } } } } if (trackType == 5) { if (targetComponent != null && spot != "") { Animator animator = (Animator)targetComponent; if (valueType == 0) { value_b = animator.GetBool(spot); } if (valueType == 1) { value_i = animator.GetInteger(spot); } if (valueType == 2) { value_f = animator.GetFloat(spot); } } } if (trackType == 6) { switch (spot) { case "RightIndexTrigger": value_f = Input.GetAxis("Oculus_CrossPlatform_SecondaryIndexTrigger"); break; case "LeftIndexTrigger": value_f = Input.GetAxis("Oculus_CrossPlatform_PrimaryIndexTrigger"); break; case "RightGrip": value_f = Input.GetAxis("Oculus_CrossPlatform_SecondaryHandTrigger"); break; case "LeftGrip": value_f = Input.GetAxis("Oculus_CrossPlatform_PrimaryHandTrigger"); break; } } UpdateSubValue(); }
void Update() { float DeltaTime = Time.deltaTime; if (!InEditor) { IsOwner = localPlayer.IsOwner(VehicleMainObj); } else { IsOwner = true; } if (IsOwner) { if (Health <= 0) { if (InEditor) { Explode(); } else { SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.All, "Explode"); } } if (Manning) { //get inputs int Wf = Input.GetKey(KeyCode.W) ? 1 : 0; //inputs as ints int Sf = Input.GetKey(KeyCode.S) ? -1 : 0; int Af = Input.GetKey(KeyCode.A) ? -1 : 0; int Df = Input.GetKey(KeyCode.D) ? 1 : 0; float RGrip = 0; float RTrigger = 0; float LTrigger = 0; if (!InEditor) { RTrigger = Input.GetAxisRaw("Oculus_CrossPlatform_SecondaryIndexTrigger"); LTrigger = Input.GetAxisRaw("Oculus_CrossPlatform_PrimaryIndexTrigger"); RGrip = Input.GetAxisRaw("Oculus_CrossPlatform_SecondaryHandTrigger"); } Vector3 JoystickPosYaw; Vector3 JoystickPos; //virtual joystick if (InVR) { if (RGrip > 0.75) { Quaternion RotDif = Rotator.transform.rotation * Quaternion.Inverse(AAGunRotLastFrame); //difference in vehicle's rotation since last frame JoystickZeroPoint = RotDif * JoystickZeroPoint; //zero point rotates with the plane so it appears still to the pilot if (!RGripLastFrame) //first frame you gripped joystick { RotDif = Quaternion.identity; JoystickZeroPoint = localPlayer.GetTrackingData(VRCPlayerApi.TrackingDataType.RightHand).rotation;//rotation of the controller relative to the plane when it was pressed } //difference between the plane and the hand's rotation, and then the difference between that and the JoystickZeroPoint Quaternion JoystickDifference = (Quaternion.Inverse(Rotator.transform.rotation) * localPlayer.GetTrackingData(VRCPlayerApi.TrackingDataType.RightHand).rotation) * Quaternion.Inverse(JoystickZeroPoint); JoystickPosYaw = (JoystickDifference * Rotator.transform.forward);//angles to vector JoystickPosYaw.y = 0; JoystickPos = (JoystickDifference * Rotator.transform.up); JoystickPos.y = 0; VRPitchYawInput = new Vector2(JoystickPos.z, JoystickPosYaw.x) * 1.41421f; RGripLastFrame = true; } else { JoystickPosYaw.x = 0; VRPitchYawInput = Vector3.zero; RGripLastFrame = false; } AAGunRotLastFrame = Rotator.transform.rotation; } int InX = (Wf + Sf); int InY = (Af + Df); if (InX > 0 && InputXKeyb < 0 || InX < 0 && InputXKeyb > 0) { InputXKeyb = 0; } if (InY > 0 && InputYKeyb < 0 || InY < 0 && InputYKeyb > 0) { InputYKeyb = 0; } InputXKeyb = Mathf.Lerp((InputXKeyb), InX, Mathf.Abs(InX) > 0 ? TurningResponseDesktop * DeltaTime : 1); InputYKeyb = Mathf.Lerp((InputYKeyb), InY, Mathf.Abs(InY) > 0 ? TurningResponseDesktop * DeltaTime : 1); float InputX = Mathf.Clamp((VRPitchYawInput.x + InputXKeyb), -1, 1); float InputY = Mathf.Clamp((VRPitchYawInput.y + InputYKeyb), -1, 1); //joystick model movement if (!JoyStickNull) { JoyStick.localRotation = Quaternion.Euler(new Vector3(InputX * 25f, InputY * 25f, 0)); } InputX *= TurnSpeedMulti; InputY *= TurnSpeedMulti; RotationSpeedX += -(RotationSpeedX * TurnFriction * DeltaTime) + InputX * DeltaTime; RotationSpeedY += -(RotationSpeedY * TurnFriction * DeltaTime) + InputY * DeltaTime; //rotate turret float temprot = Rotator.transform.localRotation.eulerAngles.x; temprot += RotationSpeedX; if (temprot > 180) { temprot -= 360; } if (temprot > DownAngleMax || temprot < -UpAngleMax) { RotationSpeedX = 0; } temprot = Mathf.Clamp(temprot, -UpAngleMax, DownAngleMax);//limit angles Rotator.transform.localRotation = Quaternion.Euler(new Vector3(temprot, Rotator.transform.localRotation.eulerAngles.y + (RotationSpeedY), 0)); //Firing the gun if ((RTrigger >= 0.75 || Input.GetKey(KeyCode.Space)) && MGAmmoSeconds > 0) { firing = true; MGAmmoSeconds -= DeltaTime; MGAmmoRecharge = MGAmmoSeconds - MGReloadDelay; } else//recharge the ammo { firing = false; MGAmmoRecharge = Mathf.Min(MGAmmoRecharge + (DeltaTime * MGReloadSpeed), MGAmmoFull); MGAmmoSeconds = Mathf.Max(MGAmmoRecharge, MGAmmoSeconds); } if (DoAAMTargeting) { if (AAMLockTimer > AAMLockTime && AAMHasTarget) { AAMLocked = true; } else { AAMLocked = false; } //firing AAM if (LTrigger > 0.75 || (Input.GetKey(KeyCode.C))) { if (!LTriggerLastFrame) { if (AAMLocked && Time.time - AAMLastFiredTime > AAMLaunchDelay) { AAMLastFiredTime = Time.time; if (InEditor) { LaunchAAM(); } else { SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.All, "LaunchAAM"); } if (NumAAM == 0) { AAMLockTimer = 0; AAMLocked = false; } } } LTriggerLastFrame = true; } else { LTriggerLastFrame = false; } } //reloading AAMs if (NumAAM == FullAAMs) { AAMReloadTimer = 0; } else { AAMReloadTimer += DeltaTime; } if (AAMReloadTimer > MissileReloadTime) { if (InEditor) { ReloadAAM(); } else { SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.All, "ReloadAAM"); } } //HP Repair if (Health == FullHealth) { HPRepairTimer = 0; } else { HPRepairTimer += DeltaTime; } if (HPRepairTimer > HPRepairDelay) { if (InEditor) { HPRepair(); } else { SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.All, "HPRepair"); } } } } if (firing) { AAGunAnimator.SetBool("firing", true); } else { AAGunAnimator.SetBool("firing", false); } //Sounds if (AAMLockTimer > 0 && !AAMLocked && NumAAM > 0) { AAMLocking.gameObject.SetActive(true); AAMLockedOn.gameObject.SetActive(false); } else if (AAMLocked) { AAMLocking.gameObject.SetActive(false); AAMLockedOn.gameObject.SetActive(true); } else { AAMLocking.gameObject.SetActive(false); AAMLockedOn.gameObject.SetActive(false); } }
void OnTriggerEnter(Collider other) { if (CurrentCourseSelection != -1 && (other != null && other.gameObject == CurrentCourse.RaceCheckpoints[NextCheckpoint])) { if (NextCheckpoint == FinalCheckpoint)//end of the race { RaceTime = 0; float subframetime = 0; //get world space position of the point that was closest to the checkpoint the frame before the race was finished Vector3 LastFrameClosestPosThisFrame = transform.TransformPoint(PlaneClosestPosInverseFromPlane); //get the speed of the plane by comparing the two float speed = Vector3.Distance(PlaneClosestPosLastFrame, LastFrameClosestPosThisFrame); //check if the plane is travelling further per frame than the distance to the checkpoint from the last frame, just incase the raycast somehow missed //(only do subframe time if it'll be valid) if (speed > PlaneDistanceFromCheckPointLastFrame) { //get the amount of time we need to remove from current time to make it sub-frame accurate float passedratio = PlaneDistanceFromCheckPointLastFrame / speed; subframetime = -Time.fixedDeltaTime * passedratio + Time.fixedDeltaTime; } //Debug.Log("Finish Race!"); RaceTime = LastTime = (Time.time - RaceStartTime - subframetime); RaceOn = false; NextCheckpoint = 0; FinishedRace = true; if (CurrentCheckPointAnimator != null) { CurrentCheckPointAnimator.SetBool("Current", false); } StartCheckPointAnims(); CurrentCourse.MyTime = RaceTime; CurrentCourse.MyPlaneType = PlaneName; CurrentCourse.UpdateMyLastTime(); if (RaceTime < CurrentCourse.MyRecordTime) { CurrentCourse.MyRecordTime = CurrentCourse.MyTime = RaceTime; CurrentCourse.UpdateMyRecord(); } if (!CheckRecordDisallowedRace() && RaceTime < CurrentCourse.BestTime) { if (!InEditor && !localPlayer.IsOwner(CurrentCourse.gameObject)) { Networking.SetOwner(localPlayer, CurrentCourse.gameObject); } CurrentCourse.BestTime = RaceTime; CurrentCourse.UpdateInstanceRecord(); } RaceTime = 0; } else if (NextCheckpoint == 0)//starting the race { //subframe accuracy is done on the first and last checkpoint, the code for the last checkpoint(above) is commented RaceTime = 0; float subframetime = 0; Vector3 LastFrameClosestPosThisFrame = transform.TransformPoint(PlaneClosestPosInverseFromPlane); float speed = Vector3.Distance(PlaneClosestPosLastFrame, LastFrameClosestPosThisFrame); if (speed > PlaneDistanceFromCheckPointLastFrame) { float passedratio = PlaneDistanceFromCheckPointLastFrame / speed; subframetime = -Time.fixedDeltaTime * passedratio + Time.fixedDeltaTime; } //Debug.Log("Start Race!"); RaceStartTime = Time.time - subframetime; FinishedRace = false; RaceOn = true; NextCheckpoint++; ProgressCheckPointAnims(); if (NextCheckpoint == FinalCheckpoint) { DoSubFrameTimeCheck = true;//in case the course only has check points } else { DoSubFrameTimeCheck = false;//we don't need to do subframe times for middle checkpoints } } else { //Debug.Log("CheckPoint!"); NextCheckpoint++; ProgressCheckPointAnims(); //check if the next checkpoint is the end of the race, because if it is we need to get subframe time if (NextCheckpoint == FinalCheckpoint) { DoSubFrameTimeCheck = true; } } } }