일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- 빅데이터
- node.js
- WebGL
- 빅 데이터
- Machine Learning
- 김양재
- probability
- 통계
- 인공지능
- No SQL
- 빅 데이타
- 김양재 목사님
- 딥러닝
- 김양재 목사
- R
- data science
- 데이터 과학
- 우리들교회
- nodeJS
- MongoDB
- 확률
- Statistics
- Big Data
- Artificial Intelligence
- 몽고디비
- 주일설교
- openCV
- c++
- 빅데이타
- Deep learning
- Today
- Total
Scientific Computing & Data Science
Rendering with Different Cameras 본문
- Scene에 두 개의 카메라 설정
- 각 Camera 당 각각 AudioListener가 있으니 둘 중 하나는 삭제
- 씬에 GameObject를 하나 설정
- 이 오브젝트의 이름을 "Camera Controller"라 명명
- 두 개의 씬 Camera를 Camera Controller의 자식 오브젝트로 설정
- 왼쪽의 "CameraConnection" 스크립트를 Camera Controller에 부착
- Camera Controller를 클릭하여 선택하고 Component viewer에서 각 카메라를 드래그하여 넣는다.
using UnityEngine;
using System.Collections;
public class CameraConnection : MonoBehaviour {
public GameObject gameCam0;
public GameObject gameCam1;
private Camera camera0;
private Camera camera1;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
camera0 = gameCam0.GetComponent<Camera>();
camera1 = gameCam1.GetComponent<Camera>();
if(Network.isServer)
{
camera0.depth = 1;
camera1.depth = 0;
}
if(Network.isClient)
{
camera0.depth = 0;
camera1.depth = 1;
}
}
}
==============================================================================
private var connectToIP : String = "129.254.74.228";
//private var connectToIP : String = "127.0.0.1";
private var connectPort : int = 25001;
private var serverInitialized = false;
private var camParent : GameObject;
private var gameCam1 : GameObject;
private var gameCam2 : GameObject;
private var gameCam3 : GameObject;
private var gameCam4 : GameObject;
private var gameCam5 : GameObject;
private var gameCam6 : GameObject;
private var gameCam7 : GameObject;
private var gameCam8 : GameObject;
private var gameCam9 : GameObject;
private var camera1 : Camera;
private var camera2 : Camera;
private var camera3 : Camera;
private var camera4 : Camera;
private var camera5 : Camera;
private var camera6 : Camera;
private var camera7 : Camera;
private var camera8 : Camera;
private var camera9 : Camera;
private var str : String = "";
function Update()
{
if(Input.GetKeyDown("s"))
{
Network.InitializeServer(32, connectPort, false);
serverInitialized = true;
}
if(Input.GetKeyDown("c"))
{
Network.Connect(connectToIP, connectPort);
serverInitialized = false;
}
}
function OnGUI ()
{
if (Network.peerType == NetworkPeerType.Disconnected)
{
GUILayout.Label("Connection status: Disconnected");
connectToIP = GUILayout.TextField(connectToIP, GUILayout.MinWidth(100));
connectPort = parseInt(GUILayout.TextField(connectPort.ToString()));
GUILayout.BeginVertical();
if (GUILayout.Button ("Connect as client"))
{
Network.Connect(connectToIP, connectPort);
serverInitialized = false;
}
if (GUILayout.Button ("Start Server"))
{
Network.InitializeServer(32, connectPort, false);
serverInitialized = true;
}
GUILayout.EndVertical();
}
else
{
if (Network.peerType == NetworkPeerType.Connecting)
{
GUILayout.Label("Connection status: Connecting");
}
else if (Network.peerType == NetworkPeerType.Client)
{
//GUILayout.Label("Connection status: Client!");
//GUILayout.Label("Ping to server: " + Network.GetAveragePing( Network.connections[0] ) );
//GUILayout.Label("Network Player# " + Network.player.ToString());
}
else if (Network.peerType == NetworkPeerType.Server)
{
GUILayout.Label("Connection status: Server!");
GUILayout.Label("Connections: " + Network.connections.length);
if(Network.connections.length >= 1)
{
GUILayout.Label("Ping to first player: " + Network.GetAveragePing( Network.connections[0] ) );
}
}
/*if (GUILayout.Button ("Disconnect"))
{
Network.Disconnect();
}
*/
}
}
function OnConnectedToServer()
{
Debug.Log("This CLIENT has connected to a server");
gameCam1 = GameObject.FindWithTag("cam1");
camera1 = gameCam1.GetComponent(Camera);
gameCam2 = GameObject.FindWithTag("cam2");
camera2 = gameCam2.GetComponent(Camera);
gameCam3 = GameObject.FindWithTag("cam3");
camera3 = gameCam3.GetComponent(Camera);
gameCam4 = GameObject.FindWithTag("cam4");
camera4 = gameCam4.GetComponent(Camera);
gameCam5 = GameObject.FindWithTag("cam5");
camera5 = gameCam5.GetComponent(Camera);
gameCam6 = GameObject.FindWithTag("cam6");
camera6 = gameCam6.GetComponent(Camera);
gameCam7 = GameObject.FindWithTag("cam7");
camera7 = gameCam7.GetComponent(Camera);
gameCam8 = GameObject.FindWithTag("cam8");
camera8 = gameCam8.GetComponent(Camera);
gameCam9 = GameObject.FindWithTag("cam9");
camera9 = gameCam9.GetComponent(Camera);
switch(parseInt(Network.player.ToString()))
{
case 0:
Debug.Log("Camera #0");
camera1.depth = 0;
camera2.depth = 0;
camera3.depth = 0;
camera4.depth = 0;
camera5.depth = 0;
camera6.depth = 2;
camera7.depth = 0;
camera8.depth = 0;
camera9.depth = 0;
break;
case 1:
Debug.Log("Camera #1");
camera1.depth = 0;
camera2.depth = 2;
camera3.depth = 2;
camera4.depth = 0;
camera5.depth = 0;
camera6.depth = 0;
camera7.depth = 0;
camera8.depth = 0;
camera9.depth = 0;
break;
case 2:
Debug.Log("Camera #2");
camera1.depth = 0;
camera2.depth = 0;
camera3.depth = 0;
camera4.depth = 2;
camera5.depth = 2;
camera6.depth = 0;
camera7.depth = 0;
camera8.depth = 0;
camera9.depth = 0;
break;
case 3:
Debug.Log("Camera #3");
camera1.depth = 0;
camera2.depth = 0;
camera3.depth = 0;
camera4.depth = 0;
camera5.depth = 0;
camera6.depth = 0;
camera7.depth = 2;
camera8.depth = 0;
camera9.depth = 0;
break;
case 4:
Debug.Log("Camera #4");
camera1.depth = 2;
camera2.depth = 0;
camera3.depth = 0;
camera4.depth = 0;
camera5.depth = 0;
camera6.depth = 0;
camera7.depth = 0;
camera8.depth = 0;
camera9.depth = 0;
break;
case 5:
Debug.Log("Camera #5");
camera1.depth = 0;
camera2.depth = 0;
camera3.depth = 0;
camera4.depth = 0;
camera5.depth = 0;
camera6.depth = 0;
camera7.depth = 0;
camera8.depth = 3;
camera9.depth = 3;
break;
default:
Debug.Log("ERROR: Cannot find gamePlayer");
break;
}
}
// Called on client during disconnection from server, but also on the server when the connection has disconnected.
function OnDisconnectedFromServer(info : NetworkDisconnection)
{
Debug.Log("This CLIENT has disconnected from a server OR this SERVER was just shut down");
}
// Called on the client when a connection attempt fails for some reason.
function OnFailedToConnect(error: NetworkConnectionError)
{
Debug.Log("Could not connect to server: " + error);
}
//Server functions called by Unity
// Called on the server whenever a new player has successfully connected.
function OnPlayerConnected(player: NetworkPlayer)
{
Debug.Log("Player connected from: " + player.ipAddress + ":" + player.port);
}
// Called on the server whenever a Network.InitializeServer was invoked and has completed.
function OnServerInitialized()
{
serverInitialized = true;
gameCam1 = GameObject.FindWithTag("cam1");
camera1 = gameCam1.GetComponent(Camera);
gameCam2 = GameObject.FindWithTag("cam2");
camera2 = gameCam2.GetComponent(Camera);
gameCam3 = GameObject.FindWithTag("cam3");
camera3 = gameCam3.GetComponent(Camera);
gameCam4 = GameObject.FindWithTag("cam4");
camera4 = gameCam4.GetComponent(Camera);
gameCam5 = GameObject.FindWithTag("cam5");
camera5 = gameCam5.GetComponent(Camera);
gameCam6 = GameObject.FindWithTag("cam6");
camera6 = gameCam6.GetComponent(Camera);
gameCam7 = GameObject.FindWithTag("cam7");
camera7 = gameCam7.GetComponent(Camera);
gameCam8 = GameObject.FindWithTag("cam8");
camera8 = gameCam8.GetComponent(Camera);
gameCam9 = GameObject.FindWithTag("cam9");
camera9 = gameCam9.GetComponent(Camera);
camera1.depth = 0;
camera2.depth = 0;
camera3.depth = 0;
camera4.depth = 0;
camera5.depth = 0;
camera6.depth = 2;
camera7.depth = 0;
camera8.depth = 0;
camera9.depth = 0;
Debug.Log("Server initialized and ready");
// Camera Initialization
}
// Called on the server whenever a player is disconnected from the server
function OnPlayerDisconnected(player: NetworkPlayer)
{
Debug.Log("Player disconnected from: " + player.ipAddress + ":" + player.port);
}
// OTHERS:
// To have a full overview of all network functions called by unity
// the next four have been added here too, but they can be ignored for now
function OnFailedToConnectToMasterServer(info: NetworkConnectionError)
{
Debug.Log("Could not connect to master server: " + info);
}
function OnNetworkInstantiate (info : NetworkMessageInfo)
{
Debug.Log("New object instantiated by " + info.sender);
}
function OnSerializeNetworkView(stream : BitStream, info : NetworkMessageInfo)
{
//Custom code here
}
'CG & Video Games > Unity 3D' 카테고리의 다른 글
VertextLit Shader (0) | 2013.05.26 |
---|---|
Display Normal Shader (0) | 2013.05.26 |
Movie Texture Script (0) | 2013.05.26 |
Random Number Generation in C# (0) | 2013.05.25 |
Line Rendering Script (0) | 2013.05.25 |