public void OnStationExit(VRCStation station) { #if VRC_SDK_VRCSDK2 VRCSDK2.VRC_Station s = (VRCSDK2.VRC_Station)station; if (s.OnLocalPlayerExitStation.TriggerObject == null) { return; } VRC_Trigger trigger = s.OnLocalPlayerExitStation.TriggerObject.GetComponent <VRC_Trigger>(); if (trigger != null) { trigger.ExecuteCustomTrigger(s.OnLocalPlayerExitStation.CustomName); } #endif }
public static IEnumerator EnforceAvatarStationLimitsEnumerator(GameObject currentAvatar, System.Action <VRCSDK2.VRC_Station> onFound) { Queue <GameObject> children = new Queue <GameObject>(); children.Enqueue(currentAvatar.gameObject); int station_count = 0; while (children.Count > 0) { GameObject child = children.Dequeue(); if (child == null) { continue; } int childCount = child.transform.childCount; for (int idx = 0; idx < child.transform.childCount; ++idx) { children.Enqueue(child.transform.GetChild(idx).gameObject); } VRCSDK2.VRC_Station[] stations = child.transform.GetComponents <VRCSDK2.VRC_Station>(); if (stations != null && stations.Length > 0) { for (int i = 0; i < stations.Length; i++) { VRCSDK2.VRC_Station station = stations[i]; if (station == null) { continue; } #if VRC_CLIENT VRC_StationInternal station_internal = station.transform.GetComponent <VRC_StationInternal>(); #endif if (station_count < MAX_STATIONS_PER_AVATAR) { bool marked_for_destruction = false; // keep this station, but limit it if (station.disableStationExit) { Debug.LogError("[" + currentAvatar.name + "]==> Stations on avatars cannot disable station exit. Re-enabled."); station.disableStationExit = false; } if (station.stationEnterPlayerLocation != null) { if (Vector3.Distance(station.stationEnterPlayerLocation.position, station.transform.position) > MAX_STATION_LOCATION_DISTANCE) { #if VRC_CLIENT marked_for_destruction = true; Debug.LogError("[" + currentAvatar.name + "]==> Station enter location is too far from station (max dist=" + MAX_STATION_LOCATION_DISTANCE + "). Station disabled."); #else Debug.LogError("Station enter location is too far from station (max dist=" + MAX_STATION_LOCATION_DISTANCE + "). Station will be disabled at runtime."); #endif } if (Vector3.Distance(station.stationExitPlayerLocation.position, station.transform.position) > MAX_STATION_LOCATION_DISTANCE) { #if VRC_CLIENT marked_for_destruction = true; Debug.LogError("[" + currentAvatar.name + "]==> Station exit location is too far from station (max dist=" + MAX_STATION_LOCATION_DISTANCE + "). Station disabled."); #else Debug.LogError("Station exit location is too far from station (max dist=" + MAX_STATION_LOCATION_DISTANCE + "). Station will be disabled at runtime."); #endif } if (marked_for_destruction) { #if VRC_CLIENT Validation.RemoveComponent(station); if (station_internal != null) { Validation.RemoveComponent(station_internal); } #endif } else { if (onFound != null) { onFound(station); } } } } else { #if VRC_CLIENT Debug.LogError("[" + currentAvatar.name + "]==> Removing station over limit of " + MAX_STATIONS_PER_AVATAR); Validation.RemoveComponent(station); if (station_internal != null) { Validation.RemoveComponent(station_internal); } #else Debug.LogError("Too many stations on avatar(" + currentAvatar.name + "). Maximum allowed=" + MAX_STATIONS_PER_AVATAR + ". Extra stations will be removed at runtime."); #endif } station_count++; } } yield return(null); } }
void OnEnable() { if(myTarget == null) myTarget = (VRCSDK2.VRC_Station)target; }