Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions Assets/AvatarFaceControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using Photon.Pun;
using Photon.Realtime;

public class AvatarFaceControl : MonoBehaviour
{
[SerializeField] Material _avatarFace;
[SerializeField] Texture _defaultTexture;

bool _crRunning = false;
IEnumerator _coroutine;
// Start is called before the first frame update
void Start()
{
_avatarFace.SetTexture("_MainTex", _defaultTexture);
}

// Update is called once per frame
void Update()
{
if (!PhotonView.Get(this).IsMine) return;
if (Input.GetKey(KeyCode.Alpha1))
PhotonView.Get(this).RPC("ShowFace", RpcTarget.All, (byte)QuickSlotManager_Sol.s_quickSlots[0].fid);
if (Input.GetKey(KeyCode.Alpha2))
PhotonView.Get(this).RPC("ShowFace", RpcTarget.All, (byte)QuickSlotManager_Sol.s_quickSlots[1].fid);
if (Input.GetKey(KeyCode.Alpha3))
PhotonView.Get(this).RPC("ShowFace", RpcTarget.All, (byte)QuickSlotManager_Sol.s_quickSlots[2].fid);
if (Input.GetKey(KeyCode.Alpha4))
PhotonView.Get(this).RPC("ShowFace", RpcTarget.All, (byte)QuickSlotManager_Sol.s_quickSlots[3].fid);
}

public void ChangeFace(int faceIndex)
{
_avatarFace.SetTexture("_MainTex", QuickSlotManager_Sol.s_faceTextures[faceIndex]);
}

[PunRPC]
void ShowFace(byte index)
{
if (_crRunning && _coroutine != null)
{
StopCoroutine(_coroutine);
}
//_coroutine = ShowFaceCoroutine(QuickSlotManager_Sol.s_quickSlots[(int)index].fid);
_coroutine = ShowFaceCoroutine(index);
StartCoroutine(_coroutine);
}

IEnumerator ShowFaceCoroutine(int index)
{
_crRunning = true;

ChangeFace(index);

yield return new WaitForSeconds(10f);

ChangeFace(11);

_crRunning = false;
}
}
11 changes: 11 additions & 0 deletions Assets/AvatarFaceControl.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

217 changes: 217 additions & 0 deletions Assets/ConnectToNetwork.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using Photon.Pun;
using Photon.Realtime;
using Cinemachine;
using StarterAssets;
using ExitGames.Client.Photon;
using DG.Tweening;
public class ConnectToNetwork : MonoBehaviourPunCallbacks
{
public enum ColorEnum
{
Red,
Green,
Blue
}
public static ConnectToNetwork Instance = null;
string nickname = "Player";
string gameVersion = "0.0.1";
bool isScene1;
bool hasCharacter;
static Color nowColor;
const string SUIT_COLOR_KEY = "SuitColor";
Renderer suitRenderer;

private void Awake()
{
if(Instance == null)
{
Instance = this;
}
else if(Instance != this)
{
Destroy(this.gameObject);
}
isScene1 = false;
DontDestroyOnLoad(this.gameObject);
}
// Start is called before the first frame update
void Start()
{
PhotonNetwork.AutomaticallySyncScene = true;
nickname += $"{Random.Range(1, 1000)}";
nowColor = Color.red;
hasCharacter = false;
PhotonNetwork.NickName = nickname;
PhotonNetwork.GameVersion = gameVersion;
PhotonNetwork.ConnectUsingSettings();
}

private void Update()
{
if (Input.GetKeyDown(KeyCode.Q) && isScene1)
{
isScene1 = false;
PhotonNetwork.LeaveRoom();
}
if (Input.GetKeyDown(KeyCode.E)&& !isScene1)
{
isScene1 = true;
PhotonNetwork.LeaveRoom();
}
if (Input.GetKeyDown(KeyCode.R)) SetColorProperty(ColorEnum.Red);
if (Input.GetKeyDown(KeyCode.G)) SetColorProperty(ColorEnum.Green);
if (Input.GetKeyDown(KeyCode.B)) SetColorProperty(ColorEnum.Blue);

}

public override void OnConnectedToMaster()
{
Debug.Log("Connected to Master");
PhotonNetwork.JoinLobby();
}

public override void OnJoinedLobby()
{
Debug.Log("Joined Lobby");
if (!isScene1)
{
PhotonNetwork.JoinOrCreateRoom("RoomQ", new RoomOptions(),TypedLobby.Default);
}
else
{
PhotonNetwork.JoinOrCreateRoom("RoomE", new RoomOptions(), TypedLobby.Default);
}
}

public override void OnJoinedRoom()
{
Debug.Log("PlayerManager/JoinedRoom as " + PhotonNetwork.LocalPlayer.NickName);
if (PhotonNetwork.CurrentRoom.PlayerCount == 1)
{
if(!isScene1)
{
PhotonNetwork.LoadLevel("SceneQ");
}
else
{
PhotonNetwork.LoadLevel("SceneE");
}
}
else
{
if(!hasCharacter)
{
hasCharacter = true;
InitializePlayer();
}
}
}

public override void OnJoinRandomFailed(short returnCode, string message)
{
PhotonNetwork.CreateRoom(null, new RoomOptions());
}

public override void OnPlayerEnteredRoom(Player newPlayer)
{
Debug.Log($"Player {newPlayer.NickName} joined");
}

public override void OnDisconnected(DisconnectCause cause)
{
Debug.Log("Disconnected from server: " + cause.ToString());
Application.Quit();
}

void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
if (PhotonNetwork.OfflineMode || PhotonNetwork.InRoom)
{
InitializePlayer();
}
}
public override void OnEnable()
{
base.OnEnable();
SceneManager.sceneLoaded += OnSceneLoaded;
}

public override void OnDisable()
{
base.OnDisable();
SceneManager.sceneLoaded -= OnSceneLoaded;
}

public override void OnPlayerPropertiesUpdate(Player targetPlayer, ExitGames.Client.Photon.Hashtable changedProps)
{
if(changedProps.ContainsKey(SUIT_COLOR_KEY))
{
SetSuitColor(targetPlayer, (ColorEnum)changedProps[SUIT_COLOR_KEY]);
}
}
void InitializePlayer()
{
//Resources.Load�� Resources���� �ȿ��� �־��� ����� prefab�� ã�µ� �̿�
var prefab = (GameObject)Resources.Load("PhotonPrefab/PlayerFollowCamera");
var cam = Instantiate(prefab, Vector3.zero, Quaternion.identity);
cam.name = "PlayerFollowCamera";

// instantiate player and link camera
// PhotonNetwork.Instantiate �� �ٷ� ��θ� �ִ� ��쿡�� Resources ���� ��θ� ���.
var player = PhotonNetwork.Instantiate("PhotonPrefab/CharacterPrefab", Vector3.zero, Quaternion.identity);
MaterialPropertyBlock block = new MaterialPropertyBlock();
block.SetColor("_Color", nowColor);
suitRenderer = player.transform.Find("Space_Suit/Tpose_/Man_Suit/Body").GetComponent<Renderer>();
suitRenderer.SetPropertyBlock(block);
// �� ���� ���� �������� cam�� ��� �����ϼ̴����� ���� �ٸ� �� �ս��ϴ�.
if (cam != null && player != null)
{
cam.GetComponent<CinemachineVirtualCamera>().Follow = player.transform.Find("FollowTarget");
player.GetComponent<ThirdPersonControllerMulti>().CinemachineCameraTarget = cam;
}
}

public void SetSuitColor(Player player, ColorEnum col)
{
MaterialPropertyBlock block = new MaterialPropertyBlock();
block.SetColor("_Color", GetColor(col));


GameObject playerGo = (GameObject)player.TagObject;
suitRenderer = playerGo.transform.Find("Space_Suit/Tpose_/Man_Suit/Body").GetComponent<Renderer>();

suitRenderer.SetPropertyBlock(block);
}

private Color GetColor(ColorEnum col)
{
Color returnColor;
switch (col)
{
case ColorEnum.Red:
returnColor = Color.red;
break;
case ColorEnum.Green:
returnColor = Color.green;
break;
case ColorEnum.Blue:
returnColor = Color.blue;
break;
default:
returnColor = Color.black;
break;
}
nowColor = returnColor;
return returnColor;
}

public void SetColorProperty(ColorEnum col)
{
PhotonNetwork.LocalPlayer.SetCustomProperties(new ExitGames.Client.Photon.Hashtable { { SUIT_COLOR_KEY, col } });
}
}
11 changes: 11 additions & 0 deletions Assets/ConnectToNetwork.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions Assets/ConsoleToGUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using UnityEngine;
namespace DebugStuff
{
public class ConsoleToGUI : MonoBehaviour
{
//#if !UNITY_EDITOR
static string myLog = "";
private string output;
private string stack;

void OnEnable()
{
Application.logMessageReceived += Log;
}

void OnDisable()
{
Application.logMessageReceived -= Log;
}

public void Log(string logString, string stackTrace, LogType type)
{
output = logString;
stack = stackTrace;
myLog = output + "\n" + myLog;
if (myLog.Length > 5000)
{
myLog = myLog.Substring(0, 4000);
}
}

void OnGUI()
{
//if (!Application.isEditor) //Do not display in editor ( or you can use the UNITY_EDITOR macro to also disable the rest)
{
//myLog = GUI.TextArea(new Rect(10, 10, Screen.width - 10, Screen.height - 10), myLog);
myLog = GUI.TextArea(new Rect(10, 10, 310, 310), myLog);
}
}
//#endif
}
}
11 changes: 11 additions & 0 deletions Assets/ConsoleToGUI.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Assets/Photon/PhotonChat.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/Photon/PhotonChat/Code.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading