2021-02-06 22:03:10 +00:00
|
|
|
|
using OWML.Common;
|
|
|
|
|
using QSB.Player;
|
2021-01-26 14:07:17 +00:00
|
|
|
|
using QSB.TransformSync;
|
|
|
|
|
using QuantumUNET;
|
2021-02-06 22:03:10 +00:00
|
|
|
|
using System;
|
2021-01-26 14:07:17 +00:00
|
|
|
|
using UnityEngine;
|
2020-08-16 17:15:36 +02:00
|
|
|
|
|
|
|
|
|
namespace QSB.Utility
|
|
|
|
|
{
|
2021-01-26 14:07:17 +00:00
|
|
|
|
public static class Extensions
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2021-01-26 14:07:17 +00:00
|
|
|
|
// GAMEOBJECT
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public static void Show(this GameObject gameObject) => SetVisibility(gameObject, true);
|
2020-08-16 17:15:36 +02:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public static void Hide(this GameObject gameObject) => SetVisibility(gameObject, false);
|
2020-08-16 17:15:36 +02:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
private static void SetVisibility(GameObject gameObject, bool isVisible)
|
|
|
|
|
{
|
|
|
|
|
var renderers = gameObject.GetComponentsInChildren<SkinnedMeshRenderer>();
|
|
|
|
|
foreach (var renderer in renderers)
|
|
|
|
|
{
|
|
|
|
|
renderer.enabled = isVisible;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-23 09:54:55 +02:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public static GameObject InstantiateInactive(this GameObject original)
|
|
|
|
|
{
|
|
|
|
|
original.SetActive(false);
|
2021-02-06 22:03:10 +00:00
|
|
|
|
var copy = UnityEngine.Object.Instantiate(original);
|
2020-12-02 21:23:01 +00:00
|
|
|
|
original.SetActive(true);
|
|
|
|
|
return copy;
|
|
|
|
|
}
|
2020-08-23 09:54:55 +02:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
public static Transform InstantiateInactive(this Transform original) =>
|
|
|
|
|
original.gameObject.InstantiateInactive().transform;
|
2021-01-26 14:07:17 +00:00
|
|
|
|
|
|
|
|
|
// QNET
|
|
|
|
|
public static PlayerInfo GetPlayer(this QNetworkConnection connection)
|
|
|
|
|
{
|
|
|
|
|
var go = connection.PlayerControllers[0].Gameobject;
|
|
|
|
|
var controller = go.GetComponent<PlayerTransformSync>();
|
|
|
|
|
return QSBPlayerManager.GetPlayer(controller.NetId.Value);
|
|
|
|
|
}
|
2021-02-06 22:03:10 +00:00
|
|
|
|
|
|
|
|
|
// C#
|
|
|
|
|
public static void SafeInvoke(this MulticastDelegate multicast, params object[] args)
|
|
|
|
|
{
|
|
|
|
|
foreach (var del in multicast.GetInvocationList())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
del.DynamicInvoke(args);
|
|
|
|
|
}
|
2021-02-06 22:14:29 +00:00
|
|
|
|
catch (Exception ex)
|
2021-02-06 22:03:10 +00:00
|
|
|
|
{
|
2021-02-07 11:09:05 +00:00
|
|
|
|
DebugLog.DebugWrite($"Error invoking delegate! Message : {ex.Message} Stack Trace : {Environment.NewLine}{ex.StackTrace}", MessageType.Error);
|
2021-02-06 22:03:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-14 21:20:53 +00:00
|
|
|
|
}
|
2021-01-26 14:07:17 +00:00
|
|
|
|
}
|