using ShadowStudio.Model; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using XRTool.Util; using Newtonsoft.Json; using ShadowStudio.UI; using SC.XR.Unity.Module_InputSystem; using ShadowStudio.Tool; using XRTool.UI; public class TestArtCreate : MonoBehaviour { public ArtType artType; public int indexOfArt; public Transform left; public Transform right; public PlayerAnimatorController PlayerAnimator; public Renderer TestRender; // Start is called before the first frame update void Start() { ArtInfoMgr.Instance.OpenLocalData(); //TransferState state = (TransferState)10; //print(state.ToString()); //PlayerAnimator.SetHands(left,right); //DispatcherBase.KeyDownDelegateRegister(OnKeyDownAction); //DispatcherBase.KeyUpDelegateRegister(OnKeyUpAction); //if (DataConfMgr.Instance.TableHelper == null) //{ // DataConfMgr.Instance.OpenData(Application.persistentDataPath); //} //DataConfMgr.Instance.TableHelper.readConfComplete += OnReadConfComplete; //DataConfMgr.Instance.OpenTable("serverName"); } private void OnReadConfComplete() { if (DataConfMgr.Instance.TableHelper.DataList != null && DataConfMgr.Instance.TableHelper.DataList.Count > 0) { print(JsonConvert.SerializeObject( DataConfMgr.Instance.TableHelper.DataList)); } else { ServerConfig sc = new ServerConfig(); sc.serverName = "fat"; sc.loginUrl = "https://webapi-fat.shadowcreator.com/100009/index.php?s=index/command/gateway"; sc.lobbyUrl = "wss://studiosignaling.tech.shadowcreator.com/fatlobby/?appId=100009"; sc.roomUrl = "wss://studiosignaling.tech.shadowcreator.com/fatroom/?token="; sc.rtcUrl = "wss://studiosignaling.tech.shadowcreator.com/rtc/"; DataConfMgr.Instance.TableHelper.AddData(sc); } } private void OnKeyUpAction(InputKeyCode keyCode, InputDevicePartBase part) { if (part.PartType == InputDevicePartType.HandLeft) { if (PlayerAnimator) { PlayerAnimator.LeftHandState = 0; } } else if (part.PartType == InputDevicePartType.HandRight) { if (PlayerAnimator) { PlayerAnimator.RightHandState = 0; } } } private void OnKeyDownAction(InputKeyCode keyCode, InputDevicePartBase part) { if (part.PartType == InputDevicePartType.HandLeft) { if (PlayerAnimator) { PlayerAnimator.LeftHandState = 1; } } else if (part.PartType == InputDevicePartType.HandRight) { if (PlayerAnimator) { PlayerAnimator.RightHandState = 1; } } } private void GetAllInfo() { for (int i = 0; i < ArtInfoMgr.Instance.ArtInfoList.Count; i++) { print(ArtInfoMgr.Instance.ArtInfoList[i].ArtName); } } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Space)) { CreateUser(); } if (Input.GetKeyDown(KeyCode.C)) { CreateArt(artType, indexOfArt); } if (Input.GetKeyDown(KeyCode.F)) { for (int i = 0; i < ArtInfoMgr.Instance.ArtInfoList.Count; i++) { CreateArt(ArtInfoMgr.Instance.ArtInfoList[i]); } } PlayerAnimator.transform.position = GameSession.Instance.gameHead.position; PlayerAnimator.transform.forward = GameSession.Instance.BodyForward; PlayerAnimator.playerHead.rotation = GameSession.Instance.gameHead.rotation; Vector3 leftpos; Quaternion leftRot; if (GameSession.Instance.TryHandLeftPosition(out leftpos, out leftRot)) { if (!PlayerAnimator.HandLeft.gameObject.activeSelf) { PlayerAnimator.HandLeft.gameObject.SetActive(true); } PlayerAnimator.HandLeft.position = leftpos; PlayerAnimator.HandLeft.rotation = leftRot; } else { if (PlayerAnimator.HandLeft.gameObject.activeSelf) { PlayerAnimator.HandLeft.gameObject.SetActive(false); } } Vector3 rightpos; Quaternion rightRot; if (GameSession.Instance.TryHandRightPosition(out rightpos, out rightRot)) { if (!PlayerAnimator.HandRight.gameObject.activeSelf) { PlayerAnimator.HandRight.gameObject.SetActive(true); } PlayerAnimator.HandRight.position = rightpos; PlayerAnimator.HandRight.rotation = rightRot; } else { if (PlayerAnimator.HandRight.gameObject.activeSelf) PlayerAnimator.HandRight.gameObject.SetActive(false); } } /// /// 创建用户 /// public void CreateUser() { CommonMethod.MyPeer = new Peer(); CommonMethod.MyPeer.PeerId = "Test"; CommonMethod.MyPeer.NickName = "Test"; ArtInfoMgr.Instance.OnUserChange(new List() { CommonMethod.MyPeer }, true); } private void CreateArt(ArtInfo info) { ArtHandler handler = ArtInfoMgr.Instance.CreateArtHandler(info); handler.CreateArt(); } private void CreateArt(ArtType artType, int indexOfArt) { Debug.Log(artType); var list = ArtInfoMgr.Instance.GetArtInfoList(artType); if (list != null) { print(list.Count); if (indexOfArt >= 0 && indexOfArt < list.Count) { ArtInfo info = list[indexOfArt]; print(info.ArtName); ArtHandler handler = ArtInfoMgr.Instance.CreateArtHandler(info); print(handler.GetIcon()); var container = handler.CreateArt(); container.Position = GameSession.Instance.GetHeadForwadPos(1); //gameObject.hideFlags = HideFlags.HideAndDontSave; } } else { UnityLog.Instance.LogError(artType.ToString() + " is null list!"); } } }