Last active
October 16, 2021 15:05
-
-
Save shivaduke28/c42f4427e8694c5ae3a0b66d9e63c785 to your computer and use it in GitHub Desktop.
VRChat Global Fog Controller(全然ちゃんと動作確認してないよ!)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UdonSharp; | |
using UnityEngine; | |
using UnityEngine.UI; | |
using VRC.SDKBase; | |
using VRC.Udon; | |
namespace Tsukemonoya | |
{ | |
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)] | |
public class FogController : UdonSharpBehaviour | |
{ | |
[SerializeField] Slider densitySlider; | |
[SerializeField] Slider fogStartSlider; | |
[SerializeField] Slider fogEndSlider; | |
[UdonSynced, FieldChangeCallback(nameof(SyncedFog))] | |
bool syncedFog; | |
public bool SyncedFog | |
{ | |
get => syncedFog; | |
set | |
{ | |
syncedFog = value; | |
RenderSettings.fog = value; | |
} | |
} | |
[SerializeField, UdonSynced, FieldChangeCallback(nameof(SyncedColor))] | |
Color32 syncedColor; | |
public Color32 SyncedColor | |
{ | |
get => syncedColor; | |
set | |
{ | |
syncedColor = value; | |
RenderSettings.fogColor = value; | |
} | |
} | |
[UdonSynced, FieldChangeCallback(nameof(SyncedFogMode))] | |
int syncedFogMode; | |
public int SyncedFogMode | |
{ | |
get => syncedFogMode; | |
set | |
{ | |
syncedFogMode = value; | |
RenderSettings.fogMode = (FogMode)value; | |
} | |
} | |
[UdonSynced, FieldChangeCallback(nameof(SyncedDensity))] | |
float syncedDensity; | |
public float SyncedDensity | |
{ | |
get => syncedDensity; | |
set | |
{ | |
deserializing = true; | |
if (!Networking.IsOwner(gameObject)) | |
{ | |
densitySlider.value = value; | |
} | |
syncedDensity = value; | |
RenderSettings.fogDensity = value; | |
deserializing = false; | |
} | |
} | |
[UdonSynced, FieldChangeCallback(nameof(SyncedFogStart))] | |
float syncedFogStart; | |
public float SyncedFogStart | |
{ | |
get => syncedDensity; | |
set | |
{ | |
deserializing = true; | |
if (!Networking.IsOwner(gameObject)) | |
{ | |
fogStartSlider.value = value; | |
} | |
syncedFogStart = value; | |
RenderSettings.fogStartDistance = value; | |
deserializing = false; | |
} | |
} | |
[UdonSynced, FieldChangeCallback(nameof(SyncedFogEnd))] | |
float syncedFogEnd; | |
public float SyncedFogEnd | |
{ | |
get => syncedDensity; | |
set | |
{ | |
deserializing = true; | |
if (!Networking.IsOwner(gameObject)) | |
{ | |
fogEndSlider.value = value; | |
} | |
syncedFogEnd = value; | |
RenderSettings.fogEndDistance = value; | |
deserializing = false; | |
} | |
} | |
bool deserializing; | |
// call from densitySlider | |
public void OnDensityChanged() | |
{ | |
if (deserializing) return; | |
Networking.SetOwner(Networking.LocalPlayer, gameObject); | |
SyncedDensity = densitySlider.value; | |
RequestSerialization(); | |
} | |
// call from fogStartSlider | |
public void OnFogStartChanged() | |
{ | |
if (deserializing) return; | |
Networking.SetOwner(Networking.LocalPlayer, gameObject); | |
SyncedFogStart = fogStartSlider.value; | |
RequestSerialization(); | |
} | |
// call from fogEndSlider | |
public void OnFogEndChanged() | |
{ | |
if (deserializing) return; | |
Networking.SetOwner(Networking.LocalPlayer, gameObject); | |
SyncedFogEnd = fogEndSlider.value; | |
RequestSerialization(); | |
} | |
void Start() | |
{ | |
if (Networking.IsOwner(gameObject)) | |
{ | |
if (densitySlider != null) | |
{ | |
SyncedDensity = densitySlider.value; | |
} | |
if (fogStartSlider != null) | |
{ | |
SyncedFogStart = fogStartSlider.value; | |
} | |
if (fogEndSlider != null) | |
{ | |
SyncedFogStart = fogEndSlider.value; | |
} | |
RequestSerialization(); | |
} | |
RenderSettings.fogColor = SyncedColor; | |
} | |
public override void Interact() | |
{ | |
ToggleFog(); | |
} | |
// call from other scripts or UI | |
public void SetFogColor(Color32 color) | |
{ | |
Networking.SetOwner(Networking.LocalPlayer, gameObject); | |
SyncedColor = color; | |
RequestSerialization(); | |
} | |
// call from other scripts or UI | |
public void ToggleFog() | |
{ | |
Networking.SetOwner(Networking.LocalPlayer, gameObject); | |
SyncedFog = !SyncedFog; | |
RequestSerialization(); | |
} | |
// call from other scripts or UI | |
public void ToggleFogMode() | |
{ | |
switch (RenderSettings.fogMode) | |
{ | |
case FogMode.Linear: | |
SyncedFogMode = (int)FogMode.Exponential; | |
break; | |
case FogMode.Exponential: | |
SyncedFogMode = (int)FogMode.ExponentialSquared; | |
break; | |
case FogMode.ExponentialSquared: | |
SyncedFogMode = (int)FogMode.Linear; | |
break; | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UdonSharp; | |
using UnityEngine; | |
using VRC.SDKBase; | |
using VRC.Udon; | |
namespace Tsukemonoya | |
{ | |
// A simple UdonSharp script to call target's method on Interact. | |
[UdonBehaviourSyncMode(BehaviourSyncMode.NoVariableSync)] | |
public class InteractTrigger : UdonSharpBehaviour | |
{ | |
[SerializeField] | |
UdonBehaviour target; | |
[SerializeField] | |
string eventName; | |
public override void Interact() | |
{ | |
target.SendCustomEvent(eventName); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment