Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.1 kB
2
Indexable
Never
using FishNet.Object;
using FishNet.Object.Synchronizing;
using UnityEngine;

public class SyncGenericsTest : NetworkBehaviour
{
    [SyncVar]
    private GenericClassTest<string> syncGenericStringType;
    [SyncVar]
    private GenericClassTest<int> syncGenericIntType;

    public override void OnStartServer()
    {
        base.OnStartServer();
        syncGenericStringType = new GenericClassTest<string>("Testeito " + base.Owner.ClientId);
        syncGenericIntType = new GenericClassTest<int>(base.Owner.ClientId);
    }

    private void Update()
    {
        if (!base.IsOwner) return;
        if (Input.GetKeyDown(KeyCode.P))
        {
            Debug.Log("Test string class var value: " + syncGenericStringType.obj.ToString());
            Debug.Log("Test int class var value: " + syncGenericIntType.obj.ToString());
        }
    }
}

public class GenericClassTest<T>
{
    public T obj;

    public GenericClassTest() {}

    public GenericClassTest(T obj)
    {
        this.obj = obj;
    }
}