mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-04 23:39:22 +00:00
[RelativeSync] add support for YouAreMyPropNowWeAreHavingSoftTacosLaterMod
This commit is contained in:
parent
63948ddf69
commit
47b69dfbc7
1 changed files with 32 additions and 22 deletions
|
@ -12,18 +12,35 @@ public class RelativeSyncMarker : MonoBehaviour
|
||||||
|
|
||||||
public bool IsComponentActive
|
public bool IsComponentActive
|
||||||
=> _component.isActiveAndEnabled;
|
=> _component.isActiveAndEnabled;
|
||||||
|
|
||||||
public bool ApplyRelativePosition = true;
|
public bool ApplyRelativePosition = true;
|
||||||
public bool ApplyRelativeRotation = true;
|
public bool ApplyRelativeRotation = true;
|
||||||
public bool OnlyApplyRelativeHeading;
|
public bool OnlyApplyRelativeHeading;
|
||||||
|
|
||||||
private MonoBehaviour _component;
|
private MonoBehaviour _component;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
|
RegisterWithManager();
|
||||||
|
ConfigureForPotentialMovementParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
RelativeSyncManager.RelativeSyncTransforms.Remove(pathHash);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnHavingSoftTacosNow()
|
||||||
|
=> RegisterWithManager();
|
||||||
|
|
||||||
|
private void RegisterWithManager()
|
||||||
|
{
|
||||||
|
// Remove old hash in case this is a re-registration
|
||||||
|
RelativeSyncManager.RelativeSyncTransforms.Remove(pathHash);
|
||||||
|
|
||||||
string path = GetGameObjectPath(transform);
|
string path = GetGameObjectPath(transform);
|
||||||
int hash = path.GetHashCode();
|
int hash = path.GetHashCode();
|
||||||
|
|
||||||
// check if it already exists (this **should** only matter in worlds)
|
// check if it already exists (this **should** only matter in worlds)
|
||||||
if (RelativeSyncManager.RelativeSyncTransforms.ContainsKey(hash))
|
if (RelativeSyncManager.RelativeSyncTransforms.ContainsKey(hash))
|
||||||
{
|
{
|
||||||
|
@ -34,18 +51,11 @@ public class RelativeSyncMarker : MonoBehaviour
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pathHash = hash;
|
pathHash = hash;
|
||||||
RelativeSyncManager.RelativeSyncTransforms.Add(hash, this);
|
RelativeSyncManager.RelativeSyncTransforms.Add(hash, this);
|
||||||
|
|
||||||
ConfigureForPotentialMovementParent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
|
||||||
{
|
|
||||||
RelativeSyncManager.RelativeSyncTransforms.Remove(pathHash);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ConfigureForPotentialMovementParent()
|
private void ConfigureForPotentialMovementParent()
|
||||||
{
|
{
|
||||||
if (!gameObject.TryGetComponent(out CVRMovementParent movementParent))
|
if (!gameObject.TryGetComponent(out CVRMovementParent movementParent))
|
||||||
|
@ -54,20 +64,20 @@ public class RelativeSyncMarker : MonoBehaviour
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_component = movementParent;
|
_component = movementParent;
|
||||||
|
|
||||||
// TODO: a refactor may be needed to handle the orientation mode being animated
|
// TODO: a refactor may be needed to handle the orientation mode being animated
|
||||||
|
|
||||||
// respect orientation mode & gravity zone
|
// respect orientation mode & gravity zone
|
||||||
ApplyRelativeRotation = movementParent.orientationMode == CVRMovementParent.OrientationMode.RotateWithParent;
|
ApplyRelativeRotation = movementParent.orientationMode == CVRMovementParent.OrientationMode.RotateWithParent;
|
||||||
OnlyApplyRelativeHeading = movementParent.GetComponent<GravityZone>() == null;
|
OnlyApplyRelativeHeading = movementParent.GetComponent<GravityZone>() == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetGameObjectPath(Transform transform)
|
private static string GetGameObjectPath(Transform transform)
|
||||||
{
|
{
|
||||||
// props already have a unique instance identifier at root
|
// props already have a unique instance identifier at root
|
||||||
// worlds uhhhh, dont duplicate the same thing over and over thx
|
// worlds uhhhh, dont duplicate the same thing over and over thx
|
||||||
// avatars on remote/local client have diff path, we need to account for it -_-
|
// avatars on remote/local client have diff path, we need to account for it -_-
|
||||||
|
|
||||||
string path = transform.name;
|
string path = transform.name;
|
||||||
while (transform.parent != null)
|
while (transform.parent != null)
|
||||||
{
|
{
|
||||||
|
@ -79,22 +89,22 @@ public class RelativeSyncMarker : MonoBehaviour
|
||||||
path = MetaPort.Instance.ownerId + "/" + path;
|
path = MetaPort.Instance.ownerId + "/" + path;
|
||||||
break;
|
break;
|
||||||
} // remote player object root is already player guid
|
} // remote player object root is already player guid
|
||||||
|
|
||||||
path = transform.name + "/" + path;
|
path = transform.name + "/" + path;
|
||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool FindAvailableHash(ref int hash)
|
private static bool FindAvailableHash(ref int hash)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 16; i++)
|
for (int i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
hash += 1;
|
hash += 1;
|
||||||
if (!RelativeSyncManager.RelativeSyncTransforms.ContainsKey(hash)) return true;
|
if (!RelativeSyncManager.RelativeSyncTransforms.ContainsKey(hash)) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// failed to find a hash in 16 tries, dont care
|
// failed to find a hash in 16 tries, dont care
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue