public void AddLapTimer(LapTimer t, tk.JsonTcpClient client) { if (raceStatusPrefab == null) { return; } Debug.Log("Adding lap timer."); GameObject go = Instantiate(raceStatusPrefab) as GameObject; RaceStatus rs = go.GetComponent <RaceStatus>(); rs.Init(t, client); go.transform.SetParent(raceStatusPanel.transform); float height = raceStatusPanel.transform.childCount * raceStatusHeight; raceStatusPanel.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height); raceStatusPanel.anchoredPosition = new Vector3(8.0f, -1 * height, 0.0f); }
// Find the car for the given JsonTcpClient and remove it from the scene. public bool RemoveCar(tk.JsonTcpClient client) { GameObject toRemove = null; foreach (GameObject go in cars) { GameObject TcpClientObj = getChildGameObject(go, "TCPClient"); if (TcpClientObj) { tk.TcpCarHandler handler = TcpClientObj.GetComponent <tk.TcpCarHandler>(); if (handler != null && handler.GetClient() == client) { toRemove = go; } } } if (toRemove != null) { RemoveLapTimer(toRemove); cars.Remove(toRemove); GameObject.Destroy(toRemove); if (cars.Count < 2) { DeactivateSplitScreen(); } return(true); } Debug.LogError("failed to remove car"); return(false); }
public GameObject Spawn(tk.JsonTcpClient client) { if (carPrefab == null) { Debug.LogError("No carPrefab set in CarSpawner!"); return(null); } // Create a car object, and also hook up all the connections // to various places in game that need to hook into the car. GameObject go = GameObject.Instantiate(carPrefab) as GameObject; if (go == null) { Debug.LogError("CarSpawner failed to instantiate prefab!"); return(null); } cars.Add(go); (Vector3 startPos, Quaternion startRot) = GetCarStartPosRot(); go.transform.position = startPos; go.transform.rotation = startRot; go.GetComponent <Car>().SavePosRot(); UpdateSplitScreenCams(); GameObject TcpClientObj = getChildGameObject(go, "TCPClient"); // CarTextFacecamera(go, cam.transform); if (TcpClientObj != null) { // without this it will not connect. TcpClientObj.SetActive(true); // now set the connection settings. TcpCarHandler carHandler = TcpClientObj.GetComponent <TcpCarHandler>(); if (carHandler != null) { carHandler.Init(client); } } if (OnNewCarCB != null) { OnNewCarCB.Invoke(go); } /////////////////////////////////////////////// // Search scene to find these. MenuHandler menuHandler = GameObject.FindObjectOfType <MenuHandler>(); Canvas canvas = GameObject.FindObjectOfType <Canvas>(); GameObject panelMenu = getChildGameObject(canvas.gameObject, "Panel Menu"); PID_UI pid_ui = null; GameObject pidPanel = getChildGameObject(canvas.gameObject, "PIDPanel"); /////////////////////////////////////////////// if (pidPanel) { pid_ui = pidPanel.GetComponent <PID_UI>(); } // set camera target follow tm // Set menu handler hooks if (menuHandler != null) { menuHandler.PIDContoller = getChildGameObject(go, "PIDController"); menuHandler.Logger = getChildGameObject(go, "Logger"); menuHandler.NetworkSteering = getChildGameObject(go, "TCPClient"); menuHandler.carJSControl = getChildGameObject(go, "JoyStickCarContoller"); menuHandler.trainingManager = getChildGameObject(go, "TrainingManager").GetComponent <TrainingManager>(); menuHandler.trainingManager.carObj = go; if (EnableTrainingManager) { menuHandler.trainingManager.gameObject.SetActive(true); getChildGameObject(go, "OverheadViewSphere").SetActive(true); } if (GlobalState.bAutoHideSceneMenu && panelMenu != null) { panelMenu.SetActive(false); } } // Set the PID ui hooks if (pid_ui != null) { pid_ui.pid = getChildGameObject(go, "PIDController").GetComponent <PIDController>(); pid_ui.logger = getChildGameObject(go, "Logger").GetComponent <Logger>(); } else { Debug.LogError("failed to find PID_UI"); } // Add race status, if possible. GameObject to = getChildGameObject(go, "Timer"); if (to != null) { AddTimer(to.GetComponent <Timer>(), client); } else { Debug.LogError("failed to find Timer"); } return(go); }
public void Init(tk.JsonTcpClient _client, string _playerName) { client = _client; playerName.text = _playerName; this.panelDisplay.SetActive(true); }
public GameObject Spawn(tk.JsonTcpClient client) { if (carPrefab == null) { Debug.LogError("No carPrefab set in CarSpawner!"); return(null); } //Create a car object, and also hook up all the connections //to various places in game that need to hook into the car. GameObject go = GameObject.Instantiate(carPrefab) as GameObject; if (go == null) { Debug.LogError("CarSpawner failed to instantiate prefab!"); return(null); } cars.Add(go); Vector3 offset = Vector3.zero; //just stack more cars after the second. Not pretty. int iRow = (cars.Count - 1) / 2; offset = Vector3.forward * (-5f * iRow); if (cars.Count % 2 == 0) { offset += Vector3.left * 4.5f; } go.transform.rotation = startTm.rotation; go.transform.position = startTm.position + offset; go.GetComponent <Car>().SavePosRot(); GameObject TcpClientObj = getChildGameObject(go, "TCPClient"); Camera cam = Camera.main; //Detect that we have the second car. Doesn't really handle more than 2 right now. if (cars.Count > 1) { cam = ActivateSplitScreen(); } // CarTextFacecamera(go, cam.transform); if (TcpClientObj != null) { //without this it will not connect. TcpClientObj.SetActive(true); //now set the connection settings. TcpCarHandler carHandler = TcpClientObj.GetComponent <TcpCarHandler>(); if (carHandler != null) { carHandler.Init(client); } } if (OnNewCarCB != null) { OnNewCarCB.Invoke(go); } /////////////////////////////////////////////// //Search scene to find these. CameraFollow cameraFollow = cam.transform.GetComponent <CameraFollow>(); MenuHandler menuHandler = GameObject.FindObjectOfType <MenuHandler>(); Canvas canvas = GameObject.FindObjectOfType <Canvas>(); GameObject panelMenu = getChildGameObject(canvas.gameObject, "Panel Menu"); PID_UI pid_ui = null; GameObject pidPanel = getChildGameObject(canvas.gameObject, "PIDPanel"); /////////////////////////////////////////////// if (pidPanel) { pid_ui = pidPanel.GetComponent <PID_UI>(); } //set camera target follow tm if (cameraFollow != null) { cameraFollow.target = getChildGameObject(go, "CameraFollowTm").transform; } //Set menu handler hooks if (menuHandler != null) { menuHandler.PIDContoller = getChildGameObject(go, "PIDController"); menuHandler.Logger = getChildGameObject(go, "Logger"); menuHandler.NetworkSteering = getChildGameObject(go, "TCPClient"); menuHandler.carJSControl = getChildGameObject(go, "JoyStickCarContoller"); menuHandler.trainingManager = getChildGameObject(go, "TrainingManager").GetComponent <TrainingManager>(); menuHandler.trainingManager.carObj = go; if (EnableTrainingManager) { menuHandler.trainingManager.gameObject.SetActive(true); getChildGameObject(go, "OverheadViewSphere").SetActive(true); } if (GlobalState.bAutoHideSceneMenu && panelMenu != null) { panelMenu.SetActive(false); } } //Set the PID ui hooks if (pid_ui != null) { pid_ui.pid = getChildGameObject(go, "PIDController").GetComponent <PIDController>(); pid_ui.logger = getChildGameObject(go, "Logger").GetComponent <Logger>(); } else { Debug.LogError("failed to find PID_UI"); } return(go); }
public GameObject Spawn(tk.JsonTcpClient client) { if (carPrefab == null) { Debug.LogError("No carPrefab set in CarSpawner!"); return(null); } //Create a car object, and also hook up all the connections //to various places in game that need to hook into the car. GameObject go = GameObject.Instantiate(carPrefab) as GameObject; if (go == null) { Debug.LogError("CarSpawner failed to instantiate prefab!"); return(null); } cars.Add(go); Vector3 startPos = GetCarStartPos(cars.Count - 1, true); go.transform.rotation = startTm.rotation; go.transform.position = startPos; go.GetComponent <Car>().SavePosRot(); GameObject TcpClientObj = getChildGameObject(go, "TCPClient"); Camera cam = Camera.main; bool bRaceActive = false; RaceManager raceMan = GameObject.FindObjectOfType <RaceManager>(); if (raceMan) { bRaceActive = raceMan.bRaceActive; } GenPathFromDriving pathGen = GameObject.FindObjectOfType <GenPathFromDriving>(); if (pathGen) { pathGen.Init(go); } //Detect that we have the second car. Doesn't really handle more than 2 right now. if (cars.Count > 1 && !bRaceActive) { cam = ActivateSplitScreen(); } // CarTextFacecamera(go, cam.transform); if (TcpClientObj != null) { //without this it will not connect. TcpClientObj.SetActive(true); //now set the connection settings. TcpCarHandler carHandler = TcpClientObj.GetComponent <TcpCarHandler>(); if (carHandler != null) { carHandler.Init(client); } } if (OnNewCarCB != null) { OnNewCarCB.Invoke(go); } /////////////////////////////////////////////// //Search scene to find these. CameraFollow cameraFollow = null; if (cam != null) { cameraFollow = cam.transform.GetComponent <CameraFollow>(); } MenuHandler menuHandler = GameObject.FindObjectOfType <MenuHandler>(); Canvas canvas = GameObject.FindObjectOfType <Canvas>(); GameObject panelMenu = getChildGameObject(canvas.gameObject, "Panel Menu"); PID_UI pid_ui = null; GameObject pidPanel = getChildGameObject(canvas.gameObject, "PIDPanel"); /////////////////////////////////////////////// if (pidPanel) { pid_ui = pidPanel.GetComponent <PID_UI>(); } //set camera target follow tm if (cameraFollow != null) { cameraFollow.target = getChildGameObject(go, "CameraFollowTm").transform; } //Set menu handler hooks if (menuHandler != null) { menuHandler.PIDContoller = getChildGameObject(go, "PIDController"); menuHandler.Logger = getChildGameObject(go, "Logger"); menuHandler.NetworkSteering = getChildGameObject(go, "TCPClient"); menuHandler.carJSControl = getChildGameObject(go, "JoyStickCarContoller"); menuHandler.trainingManager = getChildGameObject(go, "TrainingManager").GetComponent <TrainingManager>(); menuHandler.trainingManager.carObj = go; if (EnableTrainingManager) { menuHandler.trainingManager.gameObject.SetActive(true); getChildGameObject(go, "OverheadViewSphere").SetActive(true); } if (GlobalState.bAutoHideSceneMenu && panelMenu != null) { panelMenu.SetActive(false); } } //Set the PID ui hooks if (pid_ui != null) { pid_ui.pid = getChildGameObject(go, "PIDController").GetComponent <PIDController>(); pid_ui.logger = getChildGameObject(go, "Logger").GetComponent <Logger>(); } else { Debug.LogError("failed to find PID_UI"); } //Add race status, if possible. if (raceMan != null) { GameObject to = getChildGameObject(go, "LapTimer"); if (to != null) { raceMan.AddLapTimer(to.GetComponent <LapTimer>(), client); } } return(go); }
public void Init(tk.JsonTcpClient _client) { tk.TcpPrivateAPIHandler tcpPrivateAPIHandler = gameObject.AddComponent <tk.TcpPrivateAPIHandler>(); tcpPrivateAPIHandler.Init(_client); clients.Add(tcpPrivateAPIHandler); }
public void Init(Timer _timer, tk.JsonTcpClient _client) { timer = _timer; client = _client; }
public void Init(LapTimer _timer, tk.JsonTcpClient _client) { timer = _timer; dqNot.gameObject.SetActive(false); client = _client; }