void StateData(TPCameraState camState) { EditorGUILayout.Space(); camState.cameraMode = (TPCameraMode)EditorGUILayout.EnumPopup("Camera Mode", camState.cameraMode); camState.Name = EditorGUILayout.TextField("State Name", camState.Name); if (CheckName(camState.Name, tpCamera.indexList)) { EditorGUILayout.HelpBox("This name already exist, choose another one", MessageType.Error); } switch (camState.cameraMode) { case TPCameraMode.FreeDirectional: FreeDirectionalMode(camState); break; case TPCameraMode.FixedAngle: FixedAngleMode(camState); break; case TPCameraMode.FixedPoint: FixedPointMode(camState); break; } }
public static void CopyState(this TPCameraState to, TPCameraState from) { to.forward = from.forward; to.right = from.right; to.maxDistance = from.maxDistance; to.Height = from.Height; }
public static void Slerp(this TPCameraState to, TPCameraState from, float time) { to.forward = Mathf.Lerp(to.forward, from.forward, time); to.right = Mathf.Lerp(to.right, from.right, time); to.maxDistance = Mathf.Lerp(to.maxDistance, from.maxDistance, time); to.Height = Mathf.Lerp(to.Height, from.Height, time); }
public static void Slerp(this TPCameraState to, TPCameraState from, float time, TPCameraState cacha) { to.forward = Mathf.Lerp(cacha.forward, from.forward, time); to.right = Mathf.Lerp(cacha.right, from.right, time); to.minDistance = Mathf.Lerp(cacha.minDistance, from.minDistance, time); to.maxDistance = Mathf.Lerp(cacha.maxDistance, from.maxDistance, time); to.Height = Mathf.Lerp(cacha.Height, from.Height, time); }
void FixedPointMode(TPCameraState camState) { //camState.height = EditorGUILayout.FloatField("Height", camState.height); camState.smoothFollow = EditorGUILayout.FloatField("Smooth Follow", camState.smoothFollow); //camState.right = EditorGUILayout.Slider("Right", camState.right, -3f, 3f); camState.fixedAngle.x = 0; camState.fixedAngle.y = 0; DrawLookPoint(camState); }
void StateData(TPCameraState camState) { camState.Name = EditorGUILayout.TextField ("State Name", camState.Name); if (CheckName (camState.Name, tpCamera.index)) { EditorGUILayout.HelpBox("This name already exist, choose another one", MessageType.Error); } camState.forward = (float)((int)EditorGUILayout.Slider ("Forward", camState.forward, -1f, 1f)); camState.right = EditorGUILayout.Slider ("Right", camState.right, -3f, 3f); camState.maxDistance = EditorGUILayout.FloatField ("maxDistance", camState.maxDistance); camState.minDistance = EditorGUILayout.FloatField ("minDistance", camState.minDistance); camState.Height = EditorGUILayout.FloatField ("Height", camState.Height); }
/// Change CameraState /// <param name="stateName"></param> /// <param name="Use smoth"></param> public void ChangeState(string stateName, bool hasSmooth) { if (currentState != null && currentState.Name.Equals(stateName)) { return; } // search for the camera state string name var state = CameraStateList.tpCameraStates.Find(delegate(TPCameraState obj) { return(obj.Name.Equals(stateName)); }); if (state != null) { currentStateName = stateName; currentState.cameraMode = state.cameraMode; lerpState = state; // set the state of transition (lerpstate) to the state finded on the list // in case there is no smooth, a copy will be make without the transition values if (currentState != null && !hasSmooth) { currentState.CopyState(state); } } else { // if the state choosed if not real, the first state will be set up as default if (CameraStateList.tpCameraStates.Count > 0) { state = CameraStateList.tpCameraStates[0]; currentStateName = state.Name; currentState.cameraMode = state.cameraMode; lerpState = state; if (currentState != null && !hasSmooth) { currentState.CopyState(state); } } } // in case a list of states does not exist, a default state will be created if (currentState == null) { currentState = new TPCameraState("Null"); currentStateName = currentState.Name; } indexList = CameraStateList.tpCameraStates.IndexOf(state); currentZoom = state.defaultDistance; currentState.fixedAngle = new Vector3(mouseX, mouseY); useSmooth = hasSmooth; indexLookPoint = 0; }
void FixedAngleMode(TPCameraState camState) { camState.defaultDistance = EditorGUILayout.FloatField("Distance", camState.defaultDistance); camState.useZoom = EditorGUILayout.Toggle("Use Zoom", camState.useZoom); if (camState.useZoom) { camState.maxDistance = EditorGUILayout.FloatField("Max Distance", camState.maxDistance); camState.minDistance = EditorGUILayout.FloatField("Min Distance", camState.minDistance); } camState.height = EditorGUILayout.FloatField("Height", camState.height); camState.smoothFollow = EditorGUILayout.FloatField("Smooth Follow", camState.smoothFollow); camState.cullingHeight = EditorGUILayout.FloatField("Culling Height", camState.cullingHeight); //camState.cullingMinDist = EditorGUILayout.FloatField("Culling Min Dist", camState.cullingMinDist); camState.right = EditorGUILayout.Slider("Right", camState.right, -3f, 3f); camState.fixedAngle.x = EditorGUILayout.Slider("Angle X", camState.fixedAngle.x, -360, 360); camState.fixedAngle.y = EditorGUILayout.Slider("Angle Y", camState.fixedAngle.y, -360, 360); }
void FreeDirectionalMode(TPCameraState camState) { camState.forward = (float)((int)EditorGUILayout.Slider("Forward", camState.forward, -1f, 1f)); camState.right = EditorGUILayout.Slider("Right", camState.right, -3f, 3f); camState.defaultDistance = EditorGUILayout.FloatField("Distance", camState.defaultDistance); camState.useZoom = EditorGUILayout.Toggle("Use Zoom", camState.useZoom); if (camState.useZoom) { camState.maxDistance = EditorGUILayout.FloatField("Max Distance", camState.maxDistance); camState.minDistance = EditorGUILayout.FloatField("Min Distance", camState.minDistance); } camState.height = EditorGUILayout.FloatField("Height", camState.height); camState.smoothFollow = EditorGUILayout.FloatField("Smooth Follow", camState.smoothFollow); camState.cullingHeight = EditorGUILayout.FloatField("Culling Height", camState.cullingHeight); //camState.cullingMinDist = EditorGUILayout.FloatField("Culling Min Dist", camState.cullingMinDist); MinMaxSlider("Limit Angle X", ref camState.xMinLimit, ref camState.xMaxLimit, -360, 360); MinMaxSlider("Limit Angle Y", ref camState.yMinLimit, ref camState.yMaxLimit, -180, 180); }
public static void CopyState(this TPCameraState to, TPCameraState from) { to.forward = from.forward; to.right = from.right; to.mouseX = from.mouseX; to.mouseY = from.mouseY; to.distance = from.distance; to.fieldOfView = from.fieldOfView; to.maxDistance = from.maxDistance; to.minDistance = from.minDistance; to.Height = from.Height; to.startZoomAngle = from.startZoomAngle; to.endZoomAngle = from.endZoomAngle; to.zoomAngleAateX = from.zoomAngleAateX; to.zoomAngleAateY = from.zoomAngleAateY; to.startZoomDistance = from.startZoomDistance; to.endZoomDistance = from.endZoomDistance; to.zoomDistanceAate = from.zoomDistanceAate; }
/// <summary> /// Copy of CameraStates /// </summary> /// <param name="to"></param> /// <param name="from"></param> public static void CopyState(this TPCameraState to, TPCameraState from) { to.Name = from.Name; to.forward = from.forward; to.right = from.right; to.defaultDistance = from.defaultDistance; to.maxDistance = from.maxDistance; to.minDistance = from.minDistance; to.height = from.height; to.fixedAngle = from.fixedAngle; to.smoothFollow = from.smoothFollow; to.yMinLimit = from.yMinLimit; to.yMaxLimit = from.yMaxLimit; to.xMinLimit = from.xMinLimit; to.xMaxLimit = from.xMaxLimit; to.cullingHeight = from.cullingHeight; to.cullingMinDist = from.cullingMinDist; to.cameraMode = from.cameraMode; to.useZoom = from.useZoom; }
/// <summary> /// Copy of CameraStates /// </summary> /// <param name="to"></param> /// <param name="from"></param> public static void CopyState(this TPCameraState to, TPCameraState from) { to.Name = from.Name; to.forward = from.forward; to.right = from.right; to.defaultDistance = from.defaultDistance; to.maxDistance = from.maxDistance; to.minDistance = from.minDistance; to.height = from.height; to.fixedAngle = from.fixedAngle; to.lookPoints = from.lookPoints; to.smoothFollow = from.smoothFollow; to.yMinLimit = from.yMinLimit; to.yMaxLimit = from.yMaxLimit; to.xMinLimit = from.xMinLimit; to.xMaxLimit = from.xMaxLimit; to.cullingHeight = from.cullingHeight; to.cullingMinDist = from.cullingMinDist; to.cameraMode = from.cameraMode; to.useZoom = from.useZoom; }
/// <summary> /// Lerp between CameraStates /// </summary> /// <param name="to"></param> /// <param name="from"></param> /// <param name="time"></param> public static void Slerp(this TPCameraState to, TPCameraState from, float time) { to.Name = from.Name; to.forward = Mathf.Lerp(to.forward, from.forward, time); to.right = Mathf.Lerp(to.right, from.right, time); to.defaultDistance = Mathf.Lerp(to.defaultDistance, from.defaultDistance, time); to.maxDistance = Mathf.Lerp(to.maxDistance, from.maxDistance, time); to.minDistance = Mathf.Lerp(to.minDistance, from.minDistance, time); to.height = Mathf.Lerp(to.height, from.height, time); to.fixedAngle = Vector2.Lerp(to.fixedAngle, from.fixedAngle, time); to.smoothFollow = Mathf.Lerp(to.smoothFollow, from.smoothFollow, time); to.yMinLimit = Mathf.Lerp(to.yMinLimit, from.yMinLimit, time); to.yMaxLimit = Mathf.Lerp(to.yMaxLimit, from.yMaxLimit, time); to.xMinLimit = Mathf.Lerp(to.xMinLimit, from.xMinLimit, time); to.xMaxLimit = Mathf.Lerp(to.xMaxLimit, from.xMaxLimit, time); to.cullingHeight = Mathf.Lerp(to.cullingHeight, from.cullingHeight, time); to.cullingMinDist = Mathf.Lerp(to.cullingMinDist, from.cullingMinDist, time); to.cameraMode = from.cameraMode; to.useZoom = from.useZoom; to.lookPoints = from.lookPoints; }
void Init() { #if UNITY_EDITOR X_MouseSensitivity = 3; S_MouseSensitivity = 0.05f; #endif AudioListenerTransform = this.transform.parent.GetComponentInChildren <AudioListener>().transform; if (lerpState == null) { lerpState = new TPCameraState("lerp"); cacheLerpState = new TPCameraState("lerp"); } if (currentState == null) { currentState = new TPCameraState(""); } if (CameraStateList == null) { CameraStateList = Resources.Load <TPCameraListData>("Data/Camera/TPCameraListData"); if (CameraStateList == null) { Debug.LogError("TPCameraListData don't exist!!!"); return; } } mainCamera = this.GetComponentInChildren <Camera>(); TargetLookAt = new GameObject("targetLookAt").transform; //TargetLookAt.hideFlags = HideFlags.HideInHierarchy; TargetLookAt.position = Vector3.one; TargetLookAt.rotation = Quaternion.identity; DontDestroyOnLoad(TargetLookAt); DontDestroyOnLoad(this.gameObject); ChangeState("Lock2p5", false); }
/// <summary> /// Mudança de estado da camera /// </summary> /// <param name="stateName"></param> /// <param name="Use smoth"></param> public void ChangeState(string stateName, bool hasSmooth) { if (currentState.Name.Equals(stateName)) return; //busca pelo estado na lista por nome var state = CameraStateList.tpCameraStates.Find(delegate(TPCameraState obj) { return obj.Name.Equals(stateName); }); if (state != null) { currentStateName = stateName; lerpState = state;//seta o estado de transicação (lerpstate) para o estado encontrado na lista //caso nao haja smoth sera feito uma copia de valores sem transição if (currentState != null && !hasSmooth) currentState.CopyState(state); } else { //caso o estado não indicado por nome nao exista será setado o primeiro estado como padrão if (CameraStateList.tpCameraStates.Count > 0) { state = CameraStateList.tpCameraStates[0]; currentStateName = state.Name; lerpState = state; if (currentState != null && !hasSmooth) currentState.CopyState(state); } } //caso não exista uma lista de estado será criado um estado default; if (currentState == null) { currentState = new TPCameraState("Null"); currentStateName = currentState.Name; } index = CameraStateList.tpCameraStates.IndexOf(state); currentZoom = state.defaultDistance; }
public void ChangeState(string stateName, Transform scopeTarget, Sprite scopeImage) { var state = CameraStateList.tpCameraStates.Find(delegate(TPCameraState obj) { return obj.Name.Equals(stateName); }); if (scopeTarget != null) { transform.position = scopeTarget.position; } if (state != null) { currentStateName = stateName; lerpState = state; if(currentState != null) currentState.CopyState(state); if(scopeTarget != null) target = scopeTarget; else target = Player; } else { currentStateName = stateName; state = CameraStateList.tpCameraStates[0]; lerpState = state; if(currentState != null) currentState.CopyState(state); if(scopeTarget != null) target = scopeTarget; else target = Player; } if (currentState == null) currentState = new TPCameraState(""); index = CameraStateList.tpCameraStates.IndexOf (state); }
public void ChangeState(string stateName, bool hasSmooth) { var state = CameraStateList.tpCameraStates.Find(delegate(TPCameraState obj) { return obj.Name.Equals(stateName); }); if (state != null) { currentStateName = stateName; lerpState = state; if(currentState != null && !hasSmooth) currentState.CopyState(state); target = Player; } else { currentStateName = stateName; state = CameraStateList.tpCameraStates[0]; lerpState = state; if(currentState != null && !hasSmooth) currentState.CopyState(state); target = Player; } if (currentState == null) currentState = new TPCameraState(""); index = CameraStateList.tpCameraStates.IndexOf (state); }
void FixedAngleMode(TPCameraState camState) { camState.defaultDistance = EditorGUILayout.FloatField("Default Distance", camState.defaultDistance); camState.useZoom = EditorGUILayout.Toggle("Use Zoom", camState.useZoom); if (camState.useZoom) { camState.maxDistance = EditorGUILayout.FloatField("Max Distance", camState.maxDistance); camState.minDistance = EditorGUILayout.FloatField("Min Distance", camState.minDistance); } camState.height = EditorGUILayout.FloatField("Height", camState.height); camState.smoothFollow = EditorGUILayout.FloatField("Smooth Follow", camState.smoothFollow); camState.cullingHeight = EditorGUILayout.FloatField("Culling Height", camState.cullingHeight); camState.cullingMinDist = EditorGUILayout.FloatField("Culling Min Dist", camState.cullingMinDist); camState.right = EditorGUILayout.Slider("Right", camState.right, -3f, 3f); camState.fixedAngle.x = EditorGUILayout.Slider("Angle X", camState.fixedAngle.x, -360, 360); camState.fixedAngle.y = EditorGUILayout.Slider("Angle Y", camState.fixedAngle.y, -360, 360); }
void StateData(TPCameraState camState) { EditorGUILayout.Space(); camState.cameraMode = (TPCameraMode)EditorGUILayout.EnumPopup("Camera Mode", camState.cameraMode); camState.Name = EditorGUILayout.TextField ("State Name", camState.Name); if (CheckName (camState.Name, tpCamera.index)) { EditorGUILayout.HelpBox("This name already exist, choose another one", MessageType.Error); } switch (camState.cameraMode) { case TPCameraMode.FreeDirectional: FreeDirectionalMode(camState); break; case TPCameraMode.FixedAngle: FixedAngleMode(camState); break; } }
void FreeDirectionalMode(TPCameraState camState) { camState.forward = (float)((int)EditorGUILayout.Slider("Forward", camState.forward, -1f, 1f)); camState.right = EditorGUILayout.Slider("Right", camState.right, -3f, 3f); camState.defaultDistance = EditorGUILayout.FloatField("Default Distance", camState.defaultDistance); camState.useZoom = EditorGUILayout.Toggle("Use Zoom", camState.useZoom); if (camState.useZoom) { camState.maxDistance = EditorGUILayout.FloatField("Max Distance", camState.maxDistance); camState.minDistance = EditorGUILayout.FloatField("Min Distance", camState.minDistance); } camState.height = EditorGUILayout.FloatField("Height", camState.height); camState.smoothFollow = EditorGUILayout.FloatField("Smooth Follow", camState.smoothFollow); camState.cullingHeight = EditorGUILayout.FloatField("Culling Height", camState.cullingHeight); camState.cullingMinDist = EditorGUILayout.FloatField("Culling Min Dist", camState.cullingMinDist); MinMaxSlider("Limit Angle X", ref camState.xMinLimit, ref camState.xMaxLimit, -360, 360); MinMaxSlider("Limit Angle Y", ref camState.yMinLimit, ref camState.yMaxLimit, -180, 180); }
void DrawLookPoint(TPCameraState camState) { if (camState.lookPoints == null) { camState.lookPoints = new List <LookPoint>(); } //GUILayout.BeginVertical("window"); if (camState.lookPoints.Count > 0) { EditorGUILayout.HelpBox("You can create multiple camera points and change them using the TriggerChangeCameraState script.", MessageType.Info); if (tpCamera.indexLookPoint > camState.lookPoints.Count - 1) { tpCamera.indexLookPoint = 0; } if (tpCamera.indexLookPoint < 0) { tpCamera.indexLookPoint = camState.lookPoints.Count - 1; } GUILayout.BeginHorizontal("box"); GUILayout.Label("Fixed Points"); GUILayout.FlexibleSpace(); if (GUILayout.Button("<", GUILayout.Width(20))) { if (tpCamera.indexLookPoint - 1 < 0) { tpCamera.indexLookPoint = camState.lookPoints.Count - 1; } else { tpCamera.indexLookPoint--; } tpCamera.transform.position = camState.lookPoints[tpCamera.indexLookPoint].positionPoint; tpCamera.transform.rotation = Quaternion.Euler(camState.lookPoints[tpCamera.indexLookPoint].eulerAngle); indexSelected = tpCamera.indexLookPoint; } GUILayout.Box((tpCamera.indexLookPoint + 1).ToString("00") + "/" + camState.lookPoints.Count.ToString("00")); if (GUILayout.Button(">", GUILayout.Width(20))) { if (tpCamera.indexLookPoint + 1 > camState.lookPoints.Count - 1) { tpCamera.indexLookPoint = 0; } else { tpCamera.indexLookPoint++; } tpCamera.transform.position = camState.lookPoints[tpCamera.indexLookPoint].positionPoint; tpCamera.transform.rotation = Quaternion.Euler(camState.lookPoints[tpCamera.indexLookPoint].eulerAngle); indexSelected = tpCamera.indexLookPoint; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal("box"); GUILayout.Label("Point Name"); camState.lookPoints[tpCamera.indexLookPoint].pointName = GUILayout.TextField(camState.lookPoints[tpCamera.indexLookPoint].pointName, 100); GUILayout.EndHorizontal(); EditorGUILayout.HelpBox("Check 'Static Camera' to create a static point and leave uncheck to look at the Player.", MessageType.Info); camState.lookPoints[tpCamera.indexLookPoint].freeRotation = EditorGUILayout.Toggle("Static Camera", camState.lookPoints[tpCamera.indexLookPoint].freeRotation); EditorGUILayout.Space(); } GUILayout.BeginHorizontal("box"); if (GUILayout.Button("New Point")) { LookPoint p = new LookPoint(); p.pointName = "point_" + (camState.lookPoints.Count + 1).ToString("00"); p.positionPoint = tpCamera.transform.position; p.eulerAngle = (tpCamera.target) ? tpCamera.target.position : (tpCamera.transform.position + tpCamera.transform.forward); camState.lookPoints.Add(p); tpCamera.indexLookPoint = camState.lookPoints.Count - 1; tpCamera.transform.position = camState.lookPoints[tpCamera.indexLookPoint].positionPoint; indexSelected = tpCamera.indexLookPoint; } if (GUILayout.Button("Remove current point ")) { if (camState.lookPoints.Count > 0) { camState.lookPoints.RemoveAt(tpCamera.indexLookPoint); tpCamera.indexLookPoint--; if (tpCamera.indexLookPoint > camState.lookPoints.Count - 1) { tpCamera.indexLookPoint = 0; } if (tpCamera.indexLookPoint < 0) { tpCamera.indexLookPoint = camState.lookPoints.Count - 1; } if (camState.lookPoints.Count > 0) { tpCamera.transform.position = camState.lookPoints[tpCamera.indexLookPoint].positionPoint; } indexSelected = tpCamera.indexLookPoint; } } GUILayout.EndHorizontal(); EditorGUILayout.Space(); //GUILayout.EndVertical(); }
/// <summary> /// Lerp between CameraStates /// </summary> /// <param name="to"></param> /// <param name="from"></param> /// <param name="time"></param> public static void Slerp(this TPCameraState to, TPCameraState from, float time) { to.Name = from.Name; to.forward = Mathf.Lerp(to.forward, from.forward, time); to.right = Mathf.Lerp(to.right, from.right, time); to.defaultDistance = Mathf.Lerp(to.defaultDistance, from.defaultDistance, time); to.maxDistance = Mathf.Lerp(to.maxDistance, from.maxDistance, time); to.minDistance = Mathf.Lerp(to.minDistance, from.minDistance, time); to.height = Mathf.Lerp(to.height, from.height, time); to.fixedAngle = Vector2.Lerp(to.fixedAngle, from.fixedAngle, time); to.smoothFollow = Mathf.Lerp(to.smoothFollow, from.smoothFollow, time); to.yMinLimit = Mathf.Lerp(to.yMinLimit, from.yMinLimit, time); to.yMaxLimit = Mathf.Lerp(to.yMaxLimit, from.yMaxLimit, time); to.xMinLimit = Mathf.Lerp(to.xMinLimit, from.xMinLimit, time); to.xMaxLimit = Mathf.Lerp(to.xMaxLimit, from.xMaxLimit, time); to.cullingHeight = Mathf.Lerp(to.cullingHeight, from.cullingHeight, time); to.cullingMinDist = Mathf.Lerp(to.cullingMinDist, from.cullingMinDist, time); to.cameraMode = from.cameraMode; to.useZoom = from.useZoom; }