Skip to content

Instantly share code, notes, and snippets.

@ZeredaGames
Last active December 27, 2015 06:24
Show Gist options
  • Save ZeredaGames/7f1704c1423e289c07bb to your computer and use it in GitHub Desktop.
Save ZeredaGames/7f1704c1423e289c07bb to your computer and use it in GitHub Desktop.
Make 6 avalable cameras and this changes via the Camera enums .CS remove all debug moad and general settings if you do not have the script or do not want to use a debug mode.
//
// CameraManager.cs
//
// Author:
// ${ZeredaGames-AKA Thamas Bell} <${thamasbell@hotmail.com}>
//
// Copyright (c) ${2015} ${Thamas Bell}
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using UnityEngine;
using System.Collections;
using UnityEngine.ZG.Scripts.Managers.GeneralSets;
namespace ZG.Managers.CameraSettings
{
public class CameraManager : MonoBehaviour
{
/// <summary>
/// The change array.
/// </summary>
public EnumCamera.CameraState[] ChangeArray;
/// <summary>
/// The altern key.
/// </summary>
public KeyCode AlternKey = KeyCode.LeftAlt;
/// <summary>
/// The conrtol key.
/// </summary>
public KeyCode ConrtolKey = KeyCode.LeftControl;
/// <summary>
/// The shift key.
/// </summary>
public KeyCode ShiftKey = KeyCode.LeftShift;
/// <summary>
/// The Cameras.
/// </summary>
public GameObject FirstPerson, LeftSholder, RightSholder, BehindPlayerView1, BehindPlayerView2, BehindPlayerView3;
/// <summary>
/// The changer.
/// </summary>
protected float Changer;
/// <summary>
/// Awake this instance.
/// </summary>
void Awake ()
{
Options = FindObjectOfType<OptionsController> ();
}
/// <summary>
/// Update this instance.
/// </summary>
void Update ()
{
Changer = Options.CameraSlider.value;
if (Options.CameraSlider.value == Changer) {
PlayerPrefs.GetFloat ("Camera Settings:");
ChangeCamera ((int)Changer);
ChangeCamera (Options.CameraSlider.value);
if (GeneralSettings.DebugMode) {
Debug.Log ("Camera Settings <float> and <int> Changer Value:" + Changer);
Debug.Log ("Camera Settings <int>[] Changer Array:" + ChangeArray);
}
}
}
/// <summary>
/// Changes the camera.
/// </summary>
/// <param name="value">Value.</param>
public void ChangeCamera (float value)
{
Options.CameraSlider.value = value;
CamSet = FindObjectOfType<CameraSettings> ();
GetBool (EnumCamera.CameraStates);
if (GetBool (EnumCamera.CameraStates)) {
if (value == 0 && value == 7) {
FirstPerson.gameObject.SetActive (false);
LeftSholder.gameObject.SetActive (false);
RightSholder.gameObject.SetActive (false);
BehindPlayerView1.gameObject.SetActive (false);
BehindPlayerView2.gameObject.SetActive (false);
BehindPlayerView3.gameObject.SetActive (false);
if (GeneralSettings.DebugMode) {
Debug.Log ("Camera Settings <float> - New Value:" + EnumCamera.CameraStates);
Debug.Log ("Camera Settings <float> - New Value:" + value + " This Is Not Acceptable");
Debug.LogError ("<color=red>Not a Viable value</color> <i>(if 0 then rise value,
if 7 then lower value)</i>");
}
return;
}
if (value == 1) {
EnumCamera.CameraStates = EnumCamera.CameraState.FirstPerson;
FirstPerson.gameObject.SetActive (true);
LeftSholder.gameObject.SetActive (false);
RightSholder.gameObject.SetActive (false);
BehindPlayerView1.gameObject.SetActive (false);
BehindPlayerView2.gameObject.SetActive (false);
BehindPlayerView3.gameObject.SetActive (false);
if (GeneralSettings.DebugMode) {
Debug.Log ("Camera Settings <float> - New Value:" + EnumCamera.CameraStates);
Debug.Log ("Camera Settings <float> - New Value:" + value);
}
PlayerPrefs.SetFloat ("Camera Settings:", value);
return;
}
if (value == 2) {
EnumCamera.CameraStates = EnumCamera.CameraState.LeftSholder;
FirstPerson.gameObject.SetActive (false);
LeftSholder.gameObject.SetActive (true);
RightSholder.gameObject.SetActive (false);
BehindPlayerView1.gameObject.SetActive (false);
BehindPlayerView2.gameObject.SetActive (false);
BehindPlayerView3.gameObject.SetActive (false);
if (GeneralSettings.DebugMode) {
Debug.Log ("Camera Settings <float> - New Value:" + EnumCamera.CameraStates);
Debug.Log ("Camera Settings <float> - New Value:" + value);
}
PlayerPrefs.SetFloat ("Camera Settings:", value);
return;
}
if (value == 3) {
EnumCamera.CameraStates = EnumCamera.CameraState.RightSholder;
FirstPerson.gameObject.SetActive (false);
LeftSholder.gameObject.SetActive (false);
RightSholder.gameObject.SetActive (true);
BehindPlayerView1.gameObject.SetActive (false);
BehindPlayerView2.gameObject.SetActive (false);
BehindPlayerView3.gameObject.SetActive (false);
if (GeneralSettings.DebugMode) {
Debug.Log ("Camera Settings <float> - New Value:" + EnumCamera.CameraStates);
Debug.Log ("Camera Settings <float> - New Value:" + value);
}
PlayerPrefs.SetFloat ("Camera Settings:", value);
return;
}
if (value == 4) {
EnumCamera.CameraStates = EnumCamera.CameraState.BehindPlayerView1;
FirstPerson.gameObject.SetActive (false);
LeftSholder.gameObject.SetActive (false);
RightSholder.gameObject.SetActive (false);
BehindPlayerView1.gameObject.SetActive (true);
BehindPlayerView2.gameObject.SetActive (false);
BehindPlayerView3.gameObject.SetActive (false);
if (GeneralSettings.DebugMode) {
Debug.Log ("Camera Settings <float> - New Value:" + EnumCamera.CameraStates);
Debug.Log ("Camera Settings <float> - New Value:" + value);
}
PlayerPrefs.SetFloat ("Camera Settings:", value);
return;
}
if (value == 5) {
EnumCamera.CameraStates = EnumCamera.CameraState.BehindPlayerView2;
FirstPerson.gameObject.SetActive (false);
LeftSholder.gameObject.SetActive (false);
RightSholder.gameObject.SetActive (false);
BehindPlayerView1.gameObject.SetActive (false);
BehindPlayerView2.gameObject.SetActive (true);
BehindPlayerView3.gameObject.SetActive (false);
if (GeneralSettings.DebugMode) {
Debug.Log ("Camera Settings <float> - New Value:" + EnumCamera.CameraStates);
Debug.Log ("Camera Settings <float> - New Value:" + value);
}
PlayerPrefs.SetFloat ("Camera Settings:", value);
return;
}
if (value == 6) {
EnumCamera.CameraStates = EnumCamera.CameraState.BehindPlayerView3;
FirstPerson.gameObject.SetActive (false);
LeftSholder.gameObject.SetActive (false);
RightSholder.gameObject.SetActive (false);
BehindPlayerView1.gameObject.SetActive (false);
BehindPlayerView2.gameObject.SetActive (false);
BehindPlayerView3.gameObject.SetActive (true);
if (GeneralSettings.DebugMode) {
Debug.Log ("Camera Settings <float> - New Value:" + EnumCamera.CameraStates);
Debug.Log ("Camera Settings <float> - New Value:" + value);
}
PlayerPrefs.SetFloat ("Camera Settings:", value);
return;
}
return;
}
return;
}
/// <summary>
/// Gets the bool.
/// </summary>
/// <returns><c>true</c>, if bool was gotten, <c>false</c> otherwise.</returns>
/// <param name="thisCameraSet">This camera set.</param>
bool GetBool (EnumCamera.CameraState thisCameraSet)
{
return true;
}
/// <summary>
/// The options.
/// </summary>
public OptionsController Options;
/// <summary>
/// The cam set.
/// </summary>
public static CameraSettings CamSet;
/// <summary>
/// Changes the camera.
/// </summary>
/// <param name="value">Value.</param>
public void ChangeCamera (int value)
{
CamSet = FindObjectOfType<CameraSettings> ();
EnumCamera.CameraStates = ChangeArray [value];
GetBool (EnumCamera.CameraStates);
if (GetBool (EnumCamera.CameraStates)) {
if (value == 0 && value == 7) {
FirstPerson.gameObject.SetActive (false);
LeftSholder.gameObject.SetActive (false);
RightSholder.gameObject.SetActive (false);
BehindPlayerView1.gameObject.SetActive (false);
BehindPlayerView2.gameObject.SetActive (false);
BehindPlayerView3.gameObject.SetActive (false);
if (GeneralSettings.DebugMode) {
Debug.Log ("Camera Settings <int> - New Value:" + EnumCamera.CameraStates);
Debug.Log ("Camera Settings <int> - New Value:" + value);
Debug.LogError ("<color=red>Not a Viable value</color> <i>(if 0 then rise value,
if 7 then lower value)</i>");
}
return;
}
if (value == 1) {
EnumCamera.CameraStates = EnumCamera.CameraState.FirstPerson;
FirstPerson.gameObject.SetActive (true);
LeftSholder.gameObject.SetActive (false);
RightSholder.gameObject.SetActive (false);
BehindPlayerView1.gameObject.SetActive (false);
BehindPlayerView2.gameObject.SetActive (false);
BehindPlayerView3.gameObject.SetActive (false);
if (GeneralSettings.DebugMode) {
Debug.Log ("Camera Settings <int> - New Value:" + EnumCamera.CameraStates);
Debug.Log ("Camera Settings <int> - New Value:" + value);
}
return;
}
if (value == 2) {
EnumCamera.CameraStates = EnumCamera.CameraState.LeftSholder;
FirstPerson.gameObject.SetActive (false);
LeftSholder.gameObject.SetActive (true);
RightSholder.gameObject.SetActive (false);
BehindPlayerView1.gameObject.SetActive (false);
BehindPlayerView2.gameObject.SetActive (false);
BehindPlayerView3.gameObject.SetActive (false);
if (GeneralSettings.DebugMode) {
Debug.Log ("Camera Settings <int> - New Value:" + EnumCamera.CameraStates);
Debug.Log ("Camera Settings <int> - New Value:" + value);
}
return;
}
if (value == 3) {
EnumCamera.CameraStates = EnumCamera.CameraState.RightSholder;
FirstPerson.gameObject.SetActive (false);
LeftSholder.gameObject.SetActive (false);
RightSholder.gameObject.SetActive (true);
BehindPlayerView1.gameObject.SetActive (false);
BehindPlayerView2.gameObject.SetActive (false);
BehindPlayerView3.gameObject.SetActive (false);
if (GeneralSettings.DebugMode) {
Debug.Log ("Camera Settings <int> - New Value:" + EnumCamera.CameraStates);
Debug.Log ("Camera Settings <int> - New Value:" + value);
}
return;
}
if (value == 4) {
EnumCamera.CameraStates = EnumCamera.CameraState.BehindPlayerView1;
FirstPerson.gameObject.SetActive (false);
LeftSholder.gameObject.SetActive (false);
RightSholder.gameObject.SetActive (false);
BehindPlayerView1.gameObject.SetActive (true);
BehindPlayerView2.gameObject.SetActive (false);
BehindPlayerView3.gameObject.SetActive (false);
if (GeneralSettings.DebugMode) {
Debug.Log ("Camera Settings <int> - New Value:" + EnumCamera.CameraStates);
Debug.Log ("Camera Settings <int> - New Value:" + value);
}
return;
}
if (value == 5) {
EnumCamera.CameraStates = EnumCamera.CameraState.BehindPlayerView2;
FirstPerson.gameObject.SetActive (false);
LeftSholder.gameObject.SetActive (false);
RightSholder.gameObject.SetActive (false);
BehindPlayerView1.gameObject.SetActive (false);
BehindPlayerView2.gameObject.SetActive (true);
BehindPlayerView3.gameObject.SetActive (false);
if (GeneralSettings.DebugMode) {
Debug.Log ("Camera Settings <int> - New Value:" + EnumCamera.CameraStates);
Debug.Log ("Camera Settings <int> - New Value:" + value);
}
return;
}
if (value == 6) {
EnumCamera.CameraStates = EnumCamera.CameraState.BehindPlayerView3;
FirstPerson.gameObject.SetActive (false);
LeftSholder.gameObject.SetActive (false);
RightSholder.gameObject.SetActive (false);
BehindPlayerView1.gameObject.SetActive (false);
BehindPlayerView2.gameObject.SetActive (false);
BehindPlayerView3.gameObject.SetActive (true);
if (GeneralSettings.DebugMode) {
Debug.Log ("Camera Settings <int> - New Value:" + EnumCamera.CameraStates);
Debug.Log ("Camera Settings <int> - New Value:" + value);
}
return;
}
return;
}
return;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment