I use a third party dll which does not use namespace, it contains a enum named Speaker.
// Decompiled with JetBrains decompiler
// Type: Speaker
// Assembly: StreamSDK, Version=1.0.6782.19546, Culture=neutral,PublicKeyToken=null
// MVID: 82353EB3-505A-4A47-8EEB-ED74ED4FC9B9
// Assembly location: /Users/haha/test/Assets/_ThirdParty/SteamSDK/Core/XMLSerializer/StreamSDK.dll
public enum Speaker
{
remote,
local,
none,
}
My local project also has this class name under a specified namespace Photon.Voice.Unity;. After I import the dll, error happens because the compiler treats the local Speaker as the third party's Speaker.
I already use namespace in my local project:
using Photon.Voice.Unity;
Error happens in the following codes :
private void OnSpeakerCreated(Speaker speaker)
{
speaker.gameObject.transform.SetParent(this.RemoteVoicesPanel, false);
}
The error:
error CS1061: 'Speaker' does not contain a definition for 'gameObject' and no accessible extension method 'gameObject' accepting a first argument of type 'Speaker' could be found (are you missing a using directive or an assembly reference?)
After I add the full namespace, the codes are passed.
private void OnSpeakerCreated(Photon.Voice.Unity.Speaker speaker)
{
speaker.gameObject.transform.SetParent(this.RemoteVoicesPanel, false);
}
But I don't want to do that I just want to ban the use of the third party Speaker in the specified cs files or any other ways that I don't need to change the current codes.
If you are too lazy to write Photon.Voice.Unity.Speaker every time, you can create an alias for using a using alias directive:
using PhotonSpeaker = Photon.Voice.Unity.Speaker;
Now you can write:
private void OnSpeakerCreated(PhotonSpeaker speaker)
{
speaker.gameObject.transform.SetParent(this.RemoteVoicesPanel, false);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With