SCRtcPeers.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class SCRtcPeers
  5. {
  6. private Dictionary<string, SCRtcPeer> mSCRtcPeers = new Dictionary<string, SCRtcPeer>();
  7. public virtual SCRtcPeer addPeers(string pid)
  8. {
  9. if (!mSCRtcPeers.ContainsKey(pid))
  10. {
  11. SCRtcPeer sp = new SCRtcPeer();
  12. sp.peerId = pid;
  13. mSCRtcPeers.Add(pid, sp);
  14. return sp;
  15. }
  16. return null;
  17. }
  18. public virtual SCRtcPeer addPeers(SCRtcPeer scp)
  19. {
  20. if (!mSCRtcPeers.ContainsKey(scp.peerId))
  21. {
  22. SCRtcPeer sp = scp;
  23. mSCRtcPeers.Add(scp.peerId, sp);
  24. return sp;
  25. }
  26. return null;
  27. }
  28. public void updateTextures()
  29. {
  30. foreach (SCRtcPeer value in getPeers().Values)
  31. {
  32. value.updateTexture();
  33. }
  34. }
  35. public virtual void removePeers(string name)
  36. {
  37. if (mSCRtcPeers.ContainsKey(name))
  38. {
  39. mSCRtcPeers.Remove(name);
  40. }
  41. }
  42. public virtual Dictionary<string, SCRtcPeer> getPeers()
  43. {
  44. return mSCRtcPeers;
  45. }
  46. public virtual SCRtcPeer getPeerName(string name)
  47. {
  48. foreach(SCRtcPeer v in mSCRtcPeers.Values)
  49. {
  50. if(v.name==name)
  51. {
  52. Debug.Log("查找到===>" + name);
  53. return v;
  54. }
  55. }
  56. return null;
  57. }
  58. public virtual SCRtcPeer getPeer(string name)
  59. {
  60. if (mSCRtcPeers.ContainsKey(name))
  61. {
  62. return mSCRtcPeers[name];
  63. }
  64. return null;
  65. }
  66. public void initPeers()
  67. {
  68. mSCRtcPeers = new Dictionary<string, SCRtcPeer>();
  69. }
  70. }