Untitled

 avatar
unknown
plain_text
3 years ago
1.1 kB
6
Indexable
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;
    }
}
Editor is loading...