Skip to content

Instantly share code, notes, and snippets.

Avatar

Rick Cheng icywind

View GitHub Profile
@icywind
icywind / AgoraVideoController.cs
Created Oct 21, 2019
Interface to the Agora Video SDK to do join channel, show video, mute microphone, flip camera, etc.
View AgoraVideoController.cs
using UnityEngine;
using agora_gaming_rtc;
using Tanks.TankControllers;
#if (UNITY_ANDROID && UNITY_2018_3_OR_NEWER)
using UnityEngine.Android;
#endif
public class AgoraVideoController
@icywind
icywind / AgoraPlayerController.cs
Created Oct 21, 2019
Mapping from the Unity Multiplayer's id to Agora user's id
View AgoraPlayerController.cs
using System;
using System.Collections.Generic;
using UnityEngine;
using TankNt = Tanks.Networking;
public class AgoraPlayerController
{
private Dictionary<TankNt.NetworkPlayer, uint> NetworkToAgoraIDMap = new Dictionary<TankNt.NetworkPlayer, uint>();
private List<TankNt.NetworkPlayer> m_NetworkPlayers = new List<TankNt.NetworkPlayer>();
private List<uint> m_AgoraUserIds = new List<uint>();
@icywind
icywind / TankManager.cs
Last active Oct 21, 2019
Partial list of TankManager.cs
View TankManager.cs
// new code
GameManager.AddTank(this);
StartCoroutine(SetupVideoSurface(player));
} // end of Initialize(TanksNetworkPlayer player)
IEnumerator SetupVideoSurface(TanksNetworkPlayer player)
{
Debug.Log("Tank initializing player:" + player);
yield return new WaitForFixedUpdate();
View FixedRotation.cs
using UnityEngine;
namespace Tanks.Utilities {
public class FixedRotation : MonoBehaviour
{
// Plane facing front
readonly Quaternion m_Rotation = Quaternion.Euler(-45,45,0);
void LateUpdate()
{
View GameSettings.cs
using System;
using UnityEngine;
using Tanks.Map;
using Tanks.Rules;
using Tanks.Networking;
using Tanks.Utilities;
#if PLATFORM_ANDROID
using UnityEngine.Android;
#endif
@icywind
icywind / VideoSurface.cs
Created Dec 10, 2019
Updated version of VideoSurface to use RawImage for rendering.
View VideoSurface.cs
using UnityEngine;
using System.Runtime.InteropServices;
using UnityEngine.UI;
/**!! This version of the script is non-official. use it on your own risk! */
/*
* This example script demonstrates how to attachThis example
* video content to a 3D object (chenzhenyong@agora.io)
*
View HandleUserJoined.cs
// When a remote user joined, this delegate will be called. Typically
// create a GameObject to render video on it
private void onUserJoined(uint uid, int elapsed)
{
Debug.Log ("onUserJoined: uid = " + uid);
// this is called in main thread
// find a game object to render video stream from 'uid'
GameObject go = GameObject.Find (uid.ToString ());
if (!ReferenceEquals (go, null)) {
View RAAR_ShareRenderTexture.cs
private void ShareRenderTexture()
{
if (BufferTexture == null) // offlined
{
return;
}
Camera targetCamera = Camera.main; // AR Camera
RenderTexture.active = targetCamera.targetTexture; // the targetTexture holds render texture
Rect rect = new Rect(0, 0, targetCamera.targetTexture.width, targetCamera.targetTexture.height);
BufferTexture.ReadPixels(rect, 0, 0);
@icywind
icywind / RAAR_DrawmarkModel.cs
Created Mar 23, 2020
A model for drawing points
View RAAR_DrawmarkModel.cs
[Serializable]
public class DrawmarkModel
{
public Color color;
public List<Vector2> points;
}
@icywind
icywind / CoProcessDrawing.cs
Created Mar 23, 2020
Method to send the data
View CoProcessDrawing.cs
IEnumerator CoProcessDrawing(DrawmarkModel dm)
{
string json = JsonUtility.ToJson(dm);
if (dataStreamId > 0)
{
rtcEngine.SendStreamMessage(dataStreamId, json);
}
yield return null;
}
You can’t perform that action at this time.