public static string Serialize <T> (SimpleValueSource <T> source) { if (source == null || string.IsNullOrEmpty(source.Identifier)) { return(null); } string variableID = source.Identifier; if (typeof(T) == typeof(bool)) { SimpleValueSource <bool> castSource = (SimpleValueSource <bool>)(object) source; return(SerializeInternal(variableID, (castSource.StoredValue ? "b1" : "b0"))); } else if (typeof(T) == typeof(int)) { SimpleValueSource <int> castSource = (SimpleValueSource <int>)(object) source; return(SerializeInternal(variableID, "i" + castSource.StoredValue.ToString())); } else if (typeof(T) == typeof(float)) { SimpleValueSource <float> castSource = (SimpleValueSource <float>)(object) source; return(SerializeInternal(variableID, "f" + castSource.StoredValue.ToString())); } else { throw new ArgumentException(ERR_UNSUPPORTED_DATA_TYPE); } }
public void RpcSignalVariableChange(string serializedVariable) { // Désérialisation IEventSource deserializedVariable = null; try { deserializedVariable = ValueSourceSerialization.Deserialize(serializedVariable); SimpleValueSource <bool> boolVar = (deserializedVariable as SimpleValueSource <bool>); SimpleValueSource <int> intVar = (deserializedVariable as SimpleValueSource <int>); SimpleValueSource <float> floatVar = (deserializedVariable as SimpleValueSource <float>); if (boolVar != null) { SignalVariableChangeToClient(boolVar); } else if (intVar != null) { SignalVariableChangeToClient(intVar); } else if (floatVar != null) { SignalVariableChangeToClient(floatVar); } else { throw new ArgumentException("Type de données non supporté"); } } catch (Exception e) { Debug.LogError(e.ToString()); } }
private void SignalVariableChangeToClient <T>(SimpleValueSource <T> variable) { if (variable == null) { return; } ValueReceivers.Instance.SendValueToReceivers(variable.Identifier, variable.StoredValue); }
public void SignalVariableChangeToServer <T>(SimpleValueSource <T> source) { if (source == null || string.IsNullOrEmpty(source.Identifier)) { return; } // En RPC, on ne peut pas passer n'importe quels paramètres, donc il faut ruser un peu CmdSignalVariableChange(ValueSourceSerialization.Serialize(source)); }