Beispiel #1
0
    public void handleSpawn()
    {
        if (obj.objectType == BaseQTObject.type.SERVER)
        {
            serverComponent = new ServerQTObjectComponent(this);
            handleServerObjectSpawn();

            obj.onOwnerChanged += handleServerOwnerChange;

            InvokeRepeating("handleServerSync", 0f, ServerSettings.instance.syncRate);
        }
        else
        {
            clientComponent = new ClientQTObjectComponent(this);
            handleClientObjectSpawn();

            obj.onOwnerChanged += handleClientOwnerChange;
        }

        obj.onOwnerChanged += handleOwnerChange;
        handleObjectSpawn();
    }
Beispiel #2
0
    public static void setCorrectSyncedObject(ClientQTObjectComponent clientComponent, FieldInfo field, object newValue)
    {
        object currentValue = field.GetValue(clientComponent.component);

        if (isArray(currentValue))
        {
            IEnumerable oldArray = currentValue as IEnumerable;
            if (newValue == null)
            {
                return;
            }

            IEnumerable newArray = newValue as IEnumerable;
            oldArray = newArray;
        }
        else if (isDictionary(currentValue))
        {
            IDictionary oldDictionary = currentValue as IDictionary;
            oldDictionary.Clear();
            if (newValue == null)
            {
                return;
            }

            IDictionary newDictionary = newValue as IDictionary;
            foreach (object key in newDictionary.Keys)
            {
                object value = newDictionary[key];
                oldDictionary.Add(key, value);
            }
        }
        else
        {
            field.SetValue(clientComponent.component, newValue);
        }
    }