static void SerializeComponentReference(Stream stream, Component value) { if (value == null) { Basic.WriteByte(stream, 0); return; } var prefabId = PrefabStorage.Current.GetIndex(value.gameObject); if (prefabId != -1) { Basic.WriteByte(stream, 1); Write(stream, prefabId); } else { Basic.WriteByte(stream, 2); int refId = value.GetOrAddComponent<FSReference>().GetPersistentId(); Write(stream, refId); } }