Everything working as intended (UI, ownership requests and globe rotation)
This commit is contained in:
parent
3553794f2f
commit
831dd10379
Assets
DCDC_Project_Files/CountryInfo and Slider/CountryInfoUI
OurScripts
SharedSpatialAnchors
Prefabs/Resources
Scenes
ThirdParty/Photon/PhotonUnityNetworking/Resources
@ -4,6 +4,7 @@ using UnityEngine;
|
||||
using TMPro;
|
||||
using Photon.Pun;
|
||||
using PhotonPun = Photon.Pun;
|
||||
using System;
|
||||
|
||||
public class CanvasCountryInfoManager : MonoBehaviour
|
||||
{
|
||||
@ -59,12 +60,19 @@ public class CanvasCountryInfoManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void showNewCountries(String countryName, String co2Emissions)
|
||||
{
|
||||
//CanvasCountryInfoManager.instance.ShowNewCountryInCanvas(countryName, co2Emissions);
|
||||
GetComponent<PhotonPun.PhotonView>().RPC("ShowNewCountryInCanvas", RpcTarget.AllViaServer, countryName, co2Emissions);
|
||||
}
|
||||
|
||||
[PunRPC]
|
||||
public void ShowNewCountryInCanvas(string countryName, string co2ratio)
|
||||
{
|
||||
if (numberOfCountriesDisplayed < maxNumberOfCountriesDisplayed)
|
||||
{
|
||||
GameObject go = Instantiate(prefabCountryContainer, countryInfoContainer);
|
||||
GameObject go = PhotonNetwork.Instantiate(prefabCountryContainer.name, Vector3.zero, Quaternion.identity, 0);
|
||||
go.transform.SetParent(countryInfoContainer, false);
|
||||
SingleCountryDataUI dataScript = go.GetComponent<SingleCountryDataUI>();
|
||||
|
||||
dataScript.SetData(countryName, co2ratio);
|
||||
@ -81,32 +89,21 @@ public class CanvasCountryInfoManager : MonoBehaviour
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using Photon.Pun;
|
||||
using PhotonPun = Photon.Pun;
|
||||
using WPM;
|
||||
using System;
|
||||
|
||||
public class CanvasCountryInfoManager : MonoBehaviour
|
||||
{
|
||||
public GameObject prefabCountryContainer;
|
||||
public Transform countryInfoContainer;
|
||||
|
||||
//public GameObject countryInfoObj;
|
||||
|
||||
//public GameObject country;
|
||||
public int maxNumberOfCountriesDisplayed = 3;
|
||||
public GameObject info;
|
||||
|
||||
|
||||
|
||||
private int numberOfCountriesDisplayed = 0;
|
||||
|
||||
// SINGLETON
|
||||
@ -125,73 +122,51 @@ public class CanvasCountryInfoManager : MonoBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(countryInfoContainer != null)
|
||||
if (countryInfoContainer != null)
|
||||
{
|
||||
numberOfCountriesDisplayed = countryInfoContainer.childCount;
|
||||
}
|
||||
|
||||
//NEEDS RPC
|
||||
|
||||
//Check if it should show description
|
||||
if(numberOfCountriesDisplayed ==0)
|
||||
if (numberOfCountriesDisplayed == 0)
|
||||
info.SetActive(true);
|
||||
else
|
||||
info.SetActive(false);
|
||||
|
||||
///// TESTING!!
|
||||
//if(Input.GetKeyDown(KeyCode.I))
|
||||
//{
|
||||
// ShowNewCountryInCanvas("Iran", "45.93");
|
||||
//}
|
||||
//if (Input.GetKeyDown(KeyCode.C))
|
||||
//{
|
||||
// ShowNewCountryInCanvas("China", "2784.444");
|
||||
//}
|
||||
//if (Input.GetKeyDown(KeyCode.S))
|
||||
//{
|
||||
// ShowNewCountryInCanvas("Sweden", "5.6");
|
||||
//}
|
||||
// Test Inputs
|
||||
if (Input.GetKeyDown(KeyCode.I))
|
||||
{
|
||||
int testYear = 2018;
|
||||
string testCountry = "Sweden";
|
||||
float testValueCo2 = DataManager.instance.GetCo2FromYearAndCountry(testYear, testCountry);
|
||||
ShowNewCountryInCanvas(testCountry, testValueCo2.ToString());
|
||||
gameObject.GetComponent<PhotonPun.PhotonView>().RPC("ShowNewCountryInCanvas", RpcTarget.All, testCountry, testValueCo2.ToString());
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.O))
|
||||
{
|
||||
ShowNewCountryInCanvas("Iran", "5.0");
|
||||
gameObject.GetComponent<PhotonPun.PhotonView>().RPC("ShowNewCountryInCanvas", RpcTarget.All, "Iran", "5.0");
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.P))
|
||||
{
|
||||
ShowNewCountryInCanvas("Sweden", "6.0");
|
||||
gameObject.GetComponent<PhotonPun.PhotonView>().RPC("ShowNewCountryInCanvas", RpcTarget.All, "Sweden", "6.0");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//[PunRPC]
|
||||
public void showNewCountries(String countryName, String co2Emissions)
|
||||
{
|
||||
//CanvasCountryInfoManager.instance.ShowNewCountryInCanvas(countryName, co2Emissions);
|
||||
GetComponent<PhotonPun.PhotonView>().RPC("ShowNewCountryInCanvas", RpcTarget.AllViaServer, countryName, co2Emissions);
|
||||
}
|
||||
|
||||
[PunRPC]
|
||||
public void ShowNewCountryInCanvas(string countryName, string co2ratio)
|
||||
{
|
||||
if(numberOfCountriesDisplayed < maxNumberOfCountriesDisplayed)
|
||||
if (numberOfCountriesDisplayed < maxNumberOfCountriesDisplayed)
|
||||
{
|
||||
//GameObject go = Instantiate(prefabCountryContainer, countryInfoContainer);
|
||||
//GameObject go = SpawnCountryAndInfoContainer();
|
||||
//SingleCountryDataUI dataScript = go.GetComponent<SingleCountryDataUI>();
|
||||
GameObject go = Instantiate(prefabCountryContainer, countryInfoContainer);
|
||||
SingleCountryDataUI dataScript = go.GetComponent<SingleCountryDataUI>();
|
||||
|
||||
var netCountryContainer = PhotonNetwork.Instantiate(prefabCountryContainer.name, new Vector3(countryInfoContainer.position.x, countryInfoContainer.position.y, countryInfoContainer.position.z) , Quaternion.identity);
|
||||
|
||||
|
||||
//SingleCountryDataUI dataScript = netCountryContainer.GetComponent<SingleCountryDataUI>();
|
||||
|
||||
//
|
||||
netCountryContainer.GetComponent<PhotonPun.PhotonView>().RPC("SetData", RpcTarget.All, countryName, co2ratio);
|
||||
|
||||
//dataScript.SetData(countryName, co2ratio);
|
||||
var photonGrabbable = netCountryContainer.GetComponent<PhotonGrabbableObject>();
|
||||
photonGrabbable.TransferOwnershipToLocalPlayer();
|
||||
dataScript.SetData(countryName, co2ratio);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}*/
|
||||
|
||||
|
@ -2,33 +2,26 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.UIElements;
|
||||
using Photon.Pun;
|
||||
using Photon.Realtime;
|
||||
using PhotonPun = Photon.Pun;
|
||||
using PhotonRealtime = Photon.Realtime;
|
||||
|
||||
|
||||
public class SingleCountryDataUI : MonoBehaviour
|
||||
public class SingleCountryDataUI : MonoBehaviourPunCallbacks
|
||||
{
|
||||
public TMP_Text countryName;
|
||||
public TMP_Text co2ratio;
|
||||
|
||||
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
// Ensure PhotonView is properly initialized and assigned a valid ViewID
|
||||
if (photonView == null)
|
||||
{
|
||||
PhotonView pv = gameObject.AddComponent<PhotonView>();
|
||||
pv.ViewID = PhotonNetwork.AllocateViewID(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
[PunRPC]
|
||||
public void SetData(string country, string co2)
|
||||
{
|
||||
@ -39,18 +32,20 @@ public class SingleCountryDataUI : MonoBehaviour
|
||||
|
||||
public void CloseThisCountry()
|
||||
{
|
||||
//Removes this object from the parent container
|
||||
// that has the Layout component
|
||||
gameObject.GetComponent<PhotonPun.PhotonView>().RPC("destroyObject", RpcTarget.All);
|
||||
if (photonView.IsMine)
|
||||
{
|
||||
photonView.RPC("DestroyObject", RpcTarget.AllBuffered);
|
||||
}
|
||||
else if (PhotonNetwork.IsMasterClient)
|
||||
{
|
||||
photonView.TransferOwnership(PhotonNetwork.LocalPlayer);
|
||||
photonView.RPC("DestroyObject", RpcTarget.AllBuffered);
|
||||
}
|
||||
}
|
||||
|
||||
[PunRPC]
|
||||
public void destroyObject()
|
||||
public void DestroyObject()
|
||||
{
|
||||
Destroy(gameObject);
|
||||
PhotonNetwork.Destroy(gameObject);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using Photon.Pun;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using WPM;
|
||||
using static UnityEditor.Experimental.AssetDatabaseExperimental.AssetDatabaseCounters;
|
||||
using PhotonPun = Photon.Pun;
|
||||
using PhotonRealtime = Photon.Realtime;
|
||||
|
||||
@ -38,6 +40,8 @@ public class GlobeControllerScript : MonoBehaviour
|
||||
public string highlightedCountryName;
|
||||
int targetCountryIndex, targetRegionIndex;
|
||||
|
||||
public CanvasCountryInfoManager canvasManagerScript;
|
||||
|
||||
void Start()
|
||||
{
|
||||
selectedYear = 2018;
|
||||
@ -170,7 +174,7 @@ public class GlobeControllerScript : MonoBehaviour
|
||||
}
|
||||
|
||||
step = rotateSpeed * direction * Time.deltaTime;
|
||||
globe.transform.Rotate(0, step, 0);
|
||||
globe.transform.Rotate(0, -step, 0);
|
||||
}
|
||||
|
||||
public void updateYearForAll(int year)
|
||||
@ -203,7 +207,7 @@ public class GlobeControllerScript : MonoBehaviour
|
||||
var countryData = dataForYear.Find(c => c.countryName == country.name);
|
||||
if (countryData != null)
|
||||
{
|
||||
CanvasCountryInfoManager.instance.ShowNewCountryInCanvas(country.name, countryData.co2emissions.ToString());
|
||||
canvasManagerScript.showNewCountries(country.name, countryData.co2emissions.ToString());
|
||||
|
||||
}
|
||||
else
|
||||
@ -218,6 +222,9 @@ public class GlobeControllerScript : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void OnTryCountrySelected()
|
||||
{
|
||||
if (itemsSpawned)
|
||||
|
@ -6,12 +6,12 @@ using Photon.Pun;
|
||||
public class TransferOwnership : MonoBehaviourPun
|
||||
{
|
||||
|
||||
private float thumbstickThreshold = 0.1f;
|
||||
public float thumbstickThreshold = 0.1f;
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
Vector2 thumbstickInput = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick);
|
||||
if (thumbstickInput.magnitude > thumbstickThreshold || OVRInput.Get(OVRInput.Button.SecondaryIndexTrigger) || OVRInput.Get(OVRInput.Button.SecondaryHandTrigger))
|
||||
if (OVRInput.Get(OVRInput.Button.SecondaryThumbstickLeft) || OVRInput.Get(OVRInput.Button.SecondaryThumbstickRight) || OVRInput.Get(OVRInput.Button.SecondaryIndexTrigger) || OVRInput.Get(OVRInput.Button.SecondaryHandTrigger))
|
||||
{
|
||||
base.photonView.RequestOwnership();
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ GameObject:
|
||||
- component: {fileID: 8433603336126311449}
|
||||
- component: {fileID: 814751981687686240}
|
||||
- component: {fileID: 1292532822530760652}
|
||||
- component: {fileID: 4597160036641987947}
|
||||
m_Layer: 0
|
||||
m_Name: SingleCountryData
|
||||
m_TagString: Untagged
|
||||
@ -276,6 +277,19 @@ MonoBehaviour:
|
||||
m_SynchronizeRotation: 1
|
||||
m_SynchronizeScale: 1
|
||||
m_UseLocal: 1
|
||||
--- !u!114 &4597160036641987947
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 258636511145112296}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: e8c12cf7ae58311499d554466ac125a6, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
thumbstickThreshold: 0.1
|
||||
--- !u!1 &1091630702237929119
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -368,12 +382,12 @@ MonoBehaviour:
|
||||
m_faceColor:
|
||||
serializedVersion: 2
|
||||
rgba: 4294967295
|
||||
m_fontSize: 60
|
||||
m_fontSize: 25.75
|
||||
m_fontSizeBase: 36
|
||||
m_fontWeight: 400
|
||||
m_enableAutoSizing: 1
|
||||
m_fontSizeMin: 30
|
||||
m_fontSizeMax: 60
|
||||
m_fontSizeMin: 15
|
||||
m_fontSizeMax: 30
|
||||
m_fontStyle: 16
|
||||
m_HorizontalAlignment: 2
|
||||
m_VerticalAlignment: 512
|
||||
|
@ -392,3 +392,4 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: e8c12cf7ae58311499d554466ac125a6, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
thumbstickThreshold: 0.1
|
||||
|
@ -3668,6 +3668,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: e8c12cf7ae58311499d554466ac125a6, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
thumbstickThreshold: 0.1
|
||||
--- !u!1 &8343160140384535678
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -560,6 +560,7 @@ MonoBehaviour:
|
||||
latestHighlightedCountryIndex: 0
|
||||
latestTargetRegionIndex: 0
|
||||
highlightedCountryName:
|
||||
canvasManagerScript: {fileID: 1531203684}
|
||||
--- !u!114 &174579753
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -594,6 +595,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: e8c12cf7ae58311499d554466ac125a6, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
thumbstickThreshold: 0.1
|
||||
--- !u!1 &199840686
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -845,31 +847,31 @@ PrefabInstance:
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6055830746814444891, guid: 66ffb155de7ac9441b9fb9790635558c, type: 3}
|
||||
propertyPath: m_LocalPosition.x
|
||||
value: 0
|
||||
value: -1.29
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6055830746814444891, guid: 66ffb155de7ac9441b9fb9790635558c, type: 3}
|
||||
propertyPath: m_LocalPosition.y
|
||||
value: 0.47
|
||||
value: 0.45
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6055830746814444891, guid: 66ffb155de7ac9441b9fb9790635558c, type: 3}
|
||||
propertyPath: m_LocalPosition.z
|
||||
value: 2.14
|
||||
value: 1.75
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6055830746814444891, guid: 66ffb155de7ac9441b9fb9790635558c, type: 3}
|
||||
propertyPath: m_LocalRotation.w
|
||||
value: 1
|
||||
value: 0.9513008
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6055830746814444891, guid: 66ffb155de7ac9441b9fb9790635558c, type: 3}
|
||||
propertyPath: m_LocalRotation.x
|
||||
value: 0
|
||||
value: -0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6055830746814444891, guid: 66ffb155de7ac9441b9fb9790635558c, type: 3}
|
||||
propertyPath: m_LocalRotation.y
|
||||
value: 0
|
||||
value: -0.30826432
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6055830746814444891, guid: 66ffb155de7ac9441b9fb9790635558c, type: 3}
|
||||
propertyPath: m_LocalRotation.z
|
||||
value: 0
|
||||
value: -0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6055830746814444891, guid: 66ffb155de7ac9441b9fb9790635558c, type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.x
|
||||
@ -877,7 +879,7 @@ PrefabInstance:
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6055830746814444891, guid: 66ffb155de7ac9441b9fb9790635558c, type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.y
|
||||
value: 0
|
||||
value: -35.909
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6055830746814444891, guid: 66ffb155de7ac9441b9fb9790635558c, type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
@ -5906,6 +5908,18 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: e8c12cf7ae58311499d554466ac125a6, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
thumbstickThreshold: 0.1
|
||||
--- !u!114 &1531203684 stripped
|
||||
MonoBehaviour:
|
||||
m_CorrespondingSourceObject: {fileID: 2354572584401757569, guid: 66ffb155de7ac9441b9fb9790635558c, type: 3}
|
||||
m_PrefabInstance: {fileID: 293667086}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1531203677}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 67b5ed0d58cef46fba04693bc0312516, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &1543775229
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -6928,6 +6942,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: e8c12cf7ae58311499d554466ac125a6, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
thumbstickThreshold: 0.1
|
||||
--- !u!1 &1734058905
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -7110,6 +7125,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: e8c12cf7ae58311499d554466ac125a6, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
thumbstickThreshold: 0.1
|
||||
--- !u!1 &1877275224
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -66,6 +66,8 @@ MonoBehaviour:
|
||||
- ShowNewCountryInCanvas
|
||||
- ChangeYearRPC
|
||||
- destroyObject
|
||||
- DestroyObject
|
||||
- showNewCountries
|
||||
DisableAutoOpenWizard: 1
|
||||
ShowSettings: 1
|
||||
DevRegionSetOnce: 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user