44using UnityEngine . UI ;
55using agora_utilities ;
66
7- public class AgoraScreenShare : MonoBehaviour
7+ public class AgoraScreenShare : MonoBehaviour
88{
99
1010 [ SerializeField ]
@@ -19,27 +19,27 @@ public class AgoraScreenShare : MonoBehaviour
1919 [ SerializeField ]
2020 Toggle ScreenToggle ;
2121
22- public Text logText ;
22+ public Text logText ;
2323 private Logger logger ;
24- public IRtcEngine mRtcEngine = null ;
25- private const float Offset = 100 ;
26- private Texture2D mTexture ;
27- private Rect mRect ;
24+ public IRtcEngine mRtcEngine = null ;
25+ private const float Offset = 100 ;
26+ private Texture2D mTexture ;
27+ private Rect mRect ;
2828 public RawImage rawImage ;
2929 public RawImage textureImage ;
30- public Vector2 cameraSize = new Vector2 ( 640 , 480 ) ;
31- public int cameraFPS = 15 ;
30+ public Vector2 cameraSize = new Vector2 ( 640 , 480 ) ;
31+ public int cameraFPS = 15 ;
3232 bool running = false ;
3333 int timestamp = 0 ;
3434 bool _sharingImage = false ;
3535
3636 // Use this for initialization
37- void Start ( )
38- {
37+ void Start ( )
38+ {
3939 bool appReady = CheckAppId ( ) ;
4040 if ( ! appReady ) return ;
4141
42- InitEngine ( ) ;
42+ InitEngine ( ) ;
4343 InitTexture ( ) ;
4444
4545#if ! UNITY_WEBGL || UNITY_EDITOR
@@ -86,7 +86,7 @@ public void WebShareScreen()
8686 mRtcEngine . StartScreenCaptureForWeb ( ) ;
8787 }
8888
89-
89+
9090 // On Native only, after stopping screenshare, you need to choose the
9191 // external source mode again before joining the channel.
9292 // On Web, it is preferred to enable external source while in the channel
@@ -128,8 +128,8 @@ void HandleToggleValueChange(bool isScreenOn)
128128 minBitrate = 1 ,
129129 orientationMode = ORIENTATION_MODE . ORIENTATION_MODE_ADAPTIVE ,
130130 degradationPreference = DEGRADATION_PREFERENCE . MAINTAIN_FRAMERATE ,
131- mirrorMode = VIDEO_MIRROR_MODE_TYPE . VIDEO_MIRROR_MODE_DISABLED
132- // note: mirrorMode is not effective for WebGL
131+ mirrorMode = VIDEO_MIRROR_MODE_TYPE . VIDEO_MIRROR_MODE_DISABLED
132+ // note: mirrorMode is not effective for WebGL
133133 } ;
134134 mRtcEngine . SetVideoEncoderConfiguration ( config ) ;
135135
@@ -199,18 +199,18 @@ void StopSharing()
199199 }
200200
201201 void InitEngine ( )
202- {
202+ {
203203 mRtcEngine = IRtcEngine . GetEngine ( APP_ID ) ;
204- mRtcEngine . SetLogFile ( "log.txt" ) ;
205- mRtcEngine . SetChannelProfile ( CHANNEL_PROFILE . CHANNEL_PROFILE_LIVE_BROADCASTING ) ;
206- mRtcEngine . SetClientRole ( CLIENT_ROLE_TYPE . CLIENT_ROLE_BROADCASTER ) ;
207- mRtcEngine . EnableAudio ( ) ;
208- mRtcEngine . EnableVideo ( ) ;
209- mRtcEngine . EnableVideoObserver ( ) ;
204+ mRtcEngine . SetLogFile ( "log.txt" ) ;
205+ mRtcEngine . SetChannelProfile ( CHANNEL_PROFILE . CHANNEL_PROFILE_LIVE_BROADCASTING ) ;
206+ mRtcEngine . SetClientRole ( CLIENT_ROLE_TYPE . CLIENT_ROLE_BROADCASTER ) ;
207+ mRtcEngine . EnableAudio ( ) ;
208+ mRtcEngine . EnableVideo ( ) ;
209+ mRtcEngine . EnableVideoObserver ( ) ;
210210
211211 // Web: calling this before joining creates publish error
212212 // as we publish new created canvas source
213- //mRtcEngine.SetExternalVideoSource(true, false);
213+ //mRtcEngine.SetExternalVideoSource(true, false);
214214
215215 mRtcEngine . OnJoinChannelSuccess += OnJoinChannelSuccessHandler ;
216216 mRtcEngine . OnLeaveChannel += OnLeaveChannelHandler ;
@@ -219,16 +219,16 @@ void InitEngine()
219219 mRtcEngine . OnConnectionLost += OnConnectionLostHandler ;
220220 mRtcEngine . OnUserJoined += OnUserJoinedHandler ;
221221 mRtcEngine . OnUserOffline += OnUserOfflineHandler ;
222- }
222+ }
223223
224- void JoinChannel ( )
225- {
224+ void JoinChannel ( )
225+ {
226226 int ret = mRtcEngine . JoinChannelByKey ( TOKEN , CHANNEL_NAME , "" , 0 ) ;
227227 // int ret = mRtcEngine.JoinChannel(CHANNEL_NAME, "", 0);
228228 Debug . Log ( string . Format ( "JoinChannel ret: ${0}" , ret ) ) ;
229- }
229+ }
230230
231- bool CheckAppId ( )
231+ bool CheckAppId ( )
232232 {
233233 logger = new Logger ( logText ) ;
234234 return logger . DebugAssert ( APP_ID . Length > 10 , "<color=red>[STOP] Please fill in your appId in Canvas!!!!</color>" ) ;
@@ -268,12 +268,12 @@ void OnSDKWarningHandler(int warn, string msg)
268268 {
269269 logger . UpdateLog ( string . Format ( "OnSDKWarning warn: {0}, msg: {1}" , warn , msg ) ) ;
270270 }
271-
271+
272272 void OnSDKErrorHandler ( int error , string msg )
273273 {
274274 logger . UpdateLog ( string . Format ( "OnSDKError error: {0}, msg: {1}" , error , msg ) ) ;
275275 }
276-
276+
277277 void OnConnectionLostHandler ( )
278278 {
279279 logger . UpdateLog ( string . Format ( "OnConnectionLost " ) ) ;
@@ -283,8 +283,8 @@ void OnApplicationQuit()
283283 {
284284 if ( mRtcEngine != null )
285285 {
286- mRtcEngine . LeaveChannel ( ) ;
287- mRtcEngine . DisableVideoObserver ( ) ;
286+ mRtcEngine . LeaveChannel ( ) ;
287+ mRtcEngine . DisableVideoObserver ( ) ;
288288 IRtcEngine . Destroy ( ) ;
289289 mRtcEngine = null ;
290290 }
@@ -309,7 +309,7 @@ private void makeVideoView(uint uid)
309309 {
310310 return ; // reuse
311311 }
312-
312+
313313 // create a GameObject and assign to this new user
314314 VideoSurface videoSurface = makeImageSurface ( uid . ToString ( ) ) ;
315315 if ( ! ReferenceEquals ( videoSurface , null ) )
@@ -339,7 +339,7 @@ public VideoSurface makeImageSurface(string goName)
339339 GameObject canvas = GameObject . Find ( "Canvas" ) ;
340340 if ( canvas != null )
341341 {
342- go . transform . parent = canvas . transform ;
342+ go . transform . SetParent ( canvas . transform ) ;
343343 Debug . Log ( "add video view" ) ;
344344 }
345345 else
@@ -353,7 +353,7 @@ public VideoSurface makeImageSurface(string goName)
353353 Debug . Log ( "position x " + xPos + " y: " + yPos ) ;
354354 go . transform . localPosition = new Vector3 ( xPos , yPos , 0f ) ;
355355 //go.transform.localPosition = new Vector3(10, 10, 0f);
356- go . transform . localScale = new Vector3 ( 3 * 1.6666f , 3f , 1f ) ;
356+ go . transform . localScale = new Vector3 ( 1 * 1.33333f , 1f , 1f ) ;
357357
358358 // configure videoSurface
359359 VideoSurface videoSurface = go . AddComponent < VideoSurface > ( ) ;
0 commit comments