Commit 20470ba4 authored by ATREVI Dieudonne's avatar ATREVI Dieudonne
Browse files

fix folloOnX and followY according to the config file

parents 8fe81c10 a562b86e
......@@ -65,7 +65,7 @@ public class LoadEnv : MonoBehaviour
cam_Movement.enabled = false;
menuM = gameObject.GetComponent<MenuManager>();
menuM.CheckCommandLine(); // The Command Line Checker works when it's called here not in MenuManager Start()
menuM.CheckCommandLine();
}
/// <summary>
......@@ -83,17 +83,17 @@ public class LoadEnv : MonoBehaviour
// -------------
// CAMERA CONFIG
cam_Rec.enabled = true;
cam_Movement.enabled = true;
cam.transform.position = ConfigReader.camPosition;
cam.transform.rotation = Quaternion.Euler(ConfigReader.camRotation);
cam_Movement.lookAt_Id = ConfigReader.camLookAtTarget;
cam_Movement.follow_Id = ConfigReader.camFollowTarget;
cam_Movement.activateLookAt = ConfigReader.lookAtAgent;
cam_Movement.activateFollow = ConfigReader.followAgent;
cam_Movement.follow_LockX = !ConfigReader.camFollowOnX;
cam_Movement.follow_LockZ = !ConfigReader.camFollowOnY;
cam_Movement.lockFirstPersonView = ConfigReader.camLockFirstPerson;
cam_Rec.enabled = true;
cam_Movement.enabled = true;
cam.transform.position = ConfigReader.camPosition;
cam.transform.rotation = Quaternion.Euler(ConfigReader.camRotation);
cam_Movement.lookAt_Id = ConfigReader.camLookAtTarget;
cam_Movement.follow_Id = ConfigReader.camFollowTarget;
cam_Movement.activateLookAt = ConfigReader.lookAtAgent;
cam_Movement.activateFollow = ConfigReader.followAgent;
cam_Movement.followOnX = ConfigReader.camFollowOnX;
cam_Movement.followOnY = ConfigReader.camFollowOnY;
cam_Movement.lockFirstPersonView = ConfigReader.camLockFirstPerson;
// -------------
......@@ -421,24 +421,24 @@ public class LoadEnv : MonoBehaviour
// -------------
// CAMERA CONFIG
cam_Rec.enabled = true;
cam_Movement.enabled = true;
cam.transform.position = ConfigReader.camPosition;
cam.transform.rotation = Quaternion.Euler(ConfigReader.camRotation);
cam_Movement.lookAt_Id = ConfigReader.camLookAtTarget;
cam_Movement.follow_Id = ConfigReader.camFollowTarget;
cam_Movement.activateLookAt = ConfigReader.lookAtAgent;
cam_Movement.activateFollow = ConfigReader.followAgent;
cam_Movement.follow_LockX = !ConfigReader.camFollowOnX;
cam_Movement.follow_LockZ = !ConfigReader.camFollowOnY;
cam_Rec.enabled = true;
cam_Movement.enabled = true;
cam.transform.position = ConfigReader.camPosition;
cam.transform.rotation = Quaternion.Euler(ConfigReader.camRotation);
cam_Movement.lookAt_Id = ConfigReader.camLookAtTarget;
cam_Movement.follow_Id = ConfigReader.camFollowTarget;
cam_Movement.activateLookAt = ConfigReader.lookAtAgent;
cam_Movement.activateFollow = ConfigReader.followAgent;
cam_Movement.followOnX = ConfigReader.camFollowOnX;
cam_Movement.followOnY = ConfigReader.camFollowOnY;
cam_Movement.lockFirstPersonView = ConfigReader.camLockFirstPerson;
// -------------
// RECORD CONFIG
cam_Rec.record = ConfigReader.recording;
cam_Rec.timeToStart = ConfigReader.recordingStart;
cam_Rec.timeToStop = ConfigReader.recordingEnd;
cam_Rec.framerate = ConfigReader.recordingFramerate;
cam_Rec.record = ConfigReader.recording;
cam_Rec.timeToStart = ConfigReader.recordingStart;
cam_Rec.timeToStop = ConfigReader.recordingEnd;
cam_Rec.framerate = ConfigReader.recordingFramerate;
cam_fc.init();
if (ConfigReader.recordingSaveDir[0] == '.')
......
......@@ -51,7 +51,7 @@ public class MenuManager : MonoBehaviour
public GameObject topMenuPanel; // the top menu panel
public GameObject slider; // Slider for the progress state bar
LoadEnv env; // Contain datas for the environnement
public InputField FollowAgentID, LookAgentID;
/// <summary>
/// initialize the menu
/// </summary>
......@@ -74,8 +74,6 @@ public class MenuManager : MonoBehaviour
topMenuPanel.SetActive(false);
cameraMovPanel = GameObject.Find("/controlCanvas/cameraMovPanel");
LookAgentID = cameraMovPanel.transform.Find("LookAgentID").GetComponent<InputField>();
FollowAgentID = cameraMovPanel.transform.Find("FollowAgentID").GetComponent<InputField>();
cameraMovPanel.SetActive(false);
......@@ -91,36 +89,33 @@ public class MenuManager : MonoBehaviour
}
/// <summary>
/// Update the active button on the control panel
/// Update the highlight active button on the control panel
/// </summary>
void Update()
{
if(controlPanel.activeSelf)
{
if(!cameraMovPanel.transform.Find("Lookat").GetComponent<Toggle>().isOn && !cameraMovPanel.transform.Find("Followat").GetComponent<Toggle>().isOn)
{
updateControlPanel();
}
else{
if(EventSystem.current.currentSelectedGameObject==null)
{
updateControlPanel();
}
if(!LookAgentID.isFocused && !FollowAgentID.isFocused)
{
updateControlPanel();
}
}
updateControlPanel();
}
}
public void updateControlPanel()
{
ColorBlock selectedColor, disableColor;
selectedColor = controlPanel.transform.Find("play").GetComponent<Button>().colors;
disableColor = controlPanel.transform.Find("play").GetComponent<Button>().colors;
selectedColor.normalColor = new Color32(212,61,61,255);
disableColor.normalColor = new Color32(200,200,200,255);
if(Time.timeScale == 1)
{
controlPanel.transform.Find("play").GetComponent<Button>().Select();
controlPanel.transform.Find("play").GetComponent<Button>().colors = selectedColor;
controlPanel.transform.Find("pause").GetComponent<Button>().colors = disableColor;
}
else{
controlPanel.transform.Find("pause").GetComponent<Button>().Select();
controlPanel.transform.Find("play").GetComponent<Button>().colors = disableColor;
controlPanel.transform.Find("pause").GetComponent<Button>().colors = selectedColor;
}
}
......@@ -275,6 +270,10 @@ public class MenuManager : MonoBehaviour
updateControlPanel();
}
/// <summary>
/// Check the toggle button on the camera movement panel
/// </summary>
public void checkLookatToggleOnScene(){
GameObject PanelMovCamera = GameObject.Find("/controlCanvas/cameraMovPanel");
GameObject LookAgentIDtxt = GameObject.Find("/controlCanvas/cameraMovPanel/LookAgentIDtxt");
......@@ -347,9 +346,8 @@ public class MenuManager : MonoBehaviour
cameraMovPanel.SetActive(true);
// Update Camera type on the screen
cameraMovPanel.transform.Find("cameraType").GetComponent<Dropdown>().value = ConfigReader.camType;
updateControlPanel();
if( cameraMovPanel.activeSelf)
cameraMovPanel.transform.Find("cameraType").GetComponent<Dropdown>().value = ConfigReader.camType;
}
/// <summary>
......@@ -363,8 +361,6 @@ public class MenuManager : MonoBehaviour
//slider.SetActive(!panel.activeSelf);
topMenuPanel.SetActive(true);
cameraMovPanel.SetActive(true);
updateControlPanel();
}
/// <summary>
......
......@@ -32,6 +32,9 @@ public class CamMvt : MonoBehaviour
[SerializeField()]
public Vector3 _default_position;
public Vector3 _default_rotation;
// Rotation - Looking at an agent
public bool activateLookAt = false; // if true: lock the view to look at the selected agent - else : free movment
public bool activateFollow = false; // if true: follow the selected agent
......@@ -45,8 +48,8 @@ public class CamMvt : MonoBehaviour
private int _previous_follow_Id; // Id of the previous agent to follow
private GameObject follow_Agent; // Agent to follow
private Vector3 follow_LastPosition; // Last position of the agent to follow
public bool follow_LockX; // Lock axe X of the camera during camera's translation
public bool follow_LockZ; // Lock axe Z of the camera during camera's translation
public bool followOnX; // Lock axe Y of the camera during camera's translation
public bool followOnY; // Lock axe X of the camera during camera's translation
// Head and Torsum references
private Transform agent_head_transform; // transform reference of the head of the current followID agent
......@@ -78,6 +81,10 @@ public class CamMvt : MonoBehaviour
/// </summary>
public void initializeTargetObjects()
{
//initial positions
_default_position = transform.position;
_default_rotation = transform.eulerAngles;
// initialize the look at and follow target
update_look_at_target();
update_follow_target();
......@@ -131,13 +138,13 @@ public class CamMvt : MonoBehaviour
public void readCameraMovParamOnScene()
{
activateLookAt = panelMovCamera.transform.Find("Lookat").GetComponent<Toggle>().isOn;
activateFollow = panelMovCamera.transform.Find("Followat").GetComponent<Toggle>().isOn;
lookAt_Id = int.Parse(panelMovCamera.transform.Find("LookAgentID").GetComponent<InputField>().text);
follow_Id = int.Parse(panelMovCamera.transform.Find("FollowAgentID").GetComponent<InputField>().text);
follow_LockX = panelMovCamera.transform.Find("FollowX").GetComponent<Toggle>().isOn;
follow_LockZ = panelMovCamera.transform.Find("FollowY").GetComponent<Toggle>().isOn;
lockFirstPersonView = panelMovCamera.transform.Find("LockPerson").GetComponent<Toggle>().isOn;
activateLookAt = panelMovCamera.transform.Find("Lookat").GetComponent<Toggle>().isOn;
activateFollow = panelMovCamera.transform.Find("Followat").GetComponent<Toggle>().isOn;
lookAt_Id = int.Parse(panelMovCamera.transform.Find("LookAgentID").GetComponent<InputField>().text);
follow_Id = int.Parse(panelMovCamera.transform.Find("FollowAgentID").GetComponent<InputField>().text);
followOnX = panelMovCamera.transform.Find("FollowX").GetComponent<Toggle>().isOn;
followOnY = panelMovCamera.transform.Find("FollowY").GetComponent<Toggle>().isOn;
lockFirstPersonView = panelMovCamera.transform.Find("LockPerson").GetComponent<Toggle>().isOn;
}
// Update is called once per frame
void Update()
......@@ -162,10 +169,6 @@ public class CamMvt : MonoBehaviour
// ------------------------------
// ROTATION - LOOKING AT AN AGENT
if (lookAt_Agent != null && activateLookAt)
{
transform.LookAt(lookAt_Agent.transform);
}
if (lockFirstPersonView)
{
if (camSelect.options[camSelect.value].text == "First_Person")
......@@ -177,6 +180,14 @@ public class CamMvt : MonoBehaviour
transform.forward = agent_reference_transform.forward;
}
}
if(camSelect.options[camSelect.value].text == "Default")
{
transform.eulerAngles = _default_rotation;
}
else if (lookAt_Agent != null && activateLookAt)
{
transform.LookAt(lookAt_Agent.transform);
}
#endregion
......@@ -185,10 +196,14 @@ public class CamMvt : MonoBehaviour
{
Vector3 delta = follow_Agent.transform.position - follow_LastPosition;
follow_LastPosition = follow_Agent.transform.position;
if (follow_LockX)
if (followOnX)
delta.z = 0;
if (followOnY)
delta.x = 0;
if(!followOnX && !followOnY){
delta.x = 0;
if (follow_LockZ)
delta.z = 0;
}
_position_follow = _position_follow + delta;
_position_first_person = agent_head_transform.position;
......@@ -197,8 +212,11 @@ public class CamMvt : MonoBehaviour
// --------------------------------
// TRANSLATION - FOLLOWING AN AGENT
if (camSelect.options[camSelect.value].text == "Default" || camSelect.options[camSelect.value].text == "Follow")
if (camSelect.options[camSelect.value].text == "Default")
{
transform.position = _default_position;
}
if (camSelect.options[camSelect.value].text == "Follow")
{
transform.position = _position_follow;
}
......@@ -292,69 +310,5 @@ public class CamMvt : MonoBehaviour
return null;
}
}
/*//CAMERA TYPE parser
/// <summary>
/// Get the camera Type from the string
/// </summary>
/// <param name="camera_type"> string defining the camera type </param>
/// <returns> correspondent CameraType </returns>
private CameraType get_CameraType(string camera_type)
{
CameraType returned_camera_type;
if (camera_type == "Default")
{
returned_camera_type = CameraType.Default;
}
else if (camera_type == "Follow")
{
returned_camera_type = CameraType.Follow;
}
else if (camera_type == "First_Person")
{
returned_camera_type = CameraType.First_Person;
}
else if (camera_type == "Torsum")
{
returned_camera_type = CameraType.Torsum;
}
else
{
returned_camera_type = CameraType.Default;
}
return returned_camera_type;
}
/// <summary>
/// Get the correspondent string from the camera type
/// </summary>
/// <param name="camera_type"> the selected camera type </param>
/// <returns> correspondent string </returns>
private string get_CameraType(CameraType camera_type)
{
string returned_camera_type;
if (camera_type == CameraType.Default)
{
returned_camera_type = "Default";
}
else if (camera_type == CameraType.Follow)
{
returned_camera_type = "Follow";
}
else if (camera_type == CameraType.First_Person)
{
returned_camera_type = "First_Person";
}
else if (camera_type == CameraType.Torsum)
{
returned_camera_type = "Torsum";
}
else
{
returned_camera_type = "Default";
}
return returned_camera_type;
}*/
#endregion
}
\ No newline at end of file
......@@ -8,7 +8,7 @@
<rotation x="0" y="0" z="0" />
</env_stageInfos>
<cam>
<cameraType typeID="4" />
<cameraType typeID="1" />
<position x="-30" y="-3" z="5" />
<rotation x="30" y="0" z="90.03349" />
<lookAtAgent agentID="-1" />
......
......@@ -8,11 +8,11 @@
<rotation x="0" y="0" z="0" />
</env_stageInfos>
<cam>
<cameraType typeID="1" />
<cameraType typeID="4" />
<position x="0" y="0" z="30" />
<rotation x="90" y="0" z="0" />
<lookAtAgent agentID="-1" />
<followAgent agentID="-1" followOnX="false" followOnY="false" lockFirstPerson="false"/>
<followAgent agentID="-1" followOnX="false" followOnY="false" lockFirstPerson="false" />
<CamResolution x="-1" y="-1" />
</cam>
<recording start="0" end="0" framerate="15" width="-1" height="-1">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment