private void Start() { if (!SS_GUILayout.IsRuntimePlatformMobile()) { SS_Extensions.SetActive(gameObject, false); } }
private void Start() { if (!SS_GUILayout.IsRuntimePlatformMobile()) { gameObject.SetActive(false); } }
private void Update() { if ((SS_GUILayout.IsRuntimePlatformMobile() && Input.touchCount < 2) || !Input.GetMouseButton(1)) { return; } if (axes == RotationAxes.MouseXAndY) { float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX; rotationY += Input.GetAxis("Mouse Y") * sensitivityY; rotationY = Mathf.Clamp(rotationY, minimumY, maximumY); transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0); } else if (axes == RotationAxes.MouseX) { transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0); } else { rotationY += Input.GetAxis("Mouse Y") * sensitivityY; rotationY = Mathf.Clamp(rotationY, minimumY, maximumY); transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0); } }
protected override void Start() { base.Start(); Application.targetFrameRate = 2000; if (SS_GUILayout.IsRuntimePlatformMobile()) Shader.globalMaximumLOD = 150; if (TerrainDemoPrimaryCamera != null) _terrainDemoPrimaryCameraLayersDefault = TerrainDemoPrimaryCamera.cullingMask; }
private void OnGUI() { if (!visible) { return; } const float initWidth = 275f; float initHeight = 70f; const float initItemHeight = 30f; SS_GUILayout.itemWidth = initWidth - 20f; SS_GUILayout.itemHeight = initItemHeight; SS_GUILayout.yPos = 0f; SS_GUILayout.hovered = false; if (SS_GUILayout.IsRuntimePlatformMobile()) { SS_GUILayout.UpdateScaleMobile(); } else { SS_GUILayout.UpdateScaleDesktop(initHeight + 30f); } string levelName = Application.loadedLevelName; string sceneName = string.Empty; string text = string.Empty; switch (levelName) { case "SS_DiscoLights": sceneName = "Disco Lights Scene"; text = " This is an example of a more creative use of Swift Shadows, with hundreds " + "of shadow objects calculated and drawn at the same. All light spots " + "use a special \"light\" material and are rendered within a single draw call."; break; case "SS_Helicopter": sceneName = "Animated Shadows Scene"; text = " This scene demonstrates shadows following the transform of object they " + "are attached to. In this scene, the blades and body of helicopter, as " + "well as the platform and dish of the radar station, are actually two " + "different overlayed shadows. Nevertheless, the shadows are still drawn in a single " + "draw call by using a texture atlas."; break; case "SS_MovingCubes": sceneName = "Moving Cubes Scene"; text = " This is a generic demonstration of what Swift Shadows can do.\n" + " A raycast from the light source to the cubes determines the position of shadow, " + "and a projected quad is rendered in place. All shadows are drawn with a single " + "draw call, which is especially useful for mobile devices.\n" + " You can also notice the limitation: shadows are casted on one surface at time and " + "can extend beyond the surface they are projected on. Shadows can be set to fade away " + "as they fall at extreme angles to make this effect less noticeable."; break; case "SS_MultipleShadows": sceneName = "Multiple Shadows Demo"; text = " Multiple shadows components can be set for a single object. " + "There are 4 light sources in this scene, each resulting in a separate shadow of the object."; break; case "SS_TerrainInteraction": initHeight += 25f; sceneName = "Terrain Interaction Demo"; text = " This demonstrates how Swift Shadows can be used on uneven surfaces like terrain.\n" + " \"Use two cameras\" enables drawing the character and shadow on a separate pass, " + "which eliminates the effect of shadow being clipped with terrain. This comes with the cost " + "of some possible artifacts that aren't noticeable for most situations.\n"; break; } if (levelName != "SS_TerrainInteraction") { if (SS_GUILayout.IsRuntimePlatformMobile()) { text += "\n You can rotate the camera with two fingers.\n"; } else { if (levelName == "SS_DiscoLights") { text += "\n You can rotate the camera by holding the right mouse button.\n"; } else { text += "\n You can rotate the camera by holding the right mouse button and zoom with mouse wheel.\n"; } } } foreach (SS_ShadowMeshManager meshManager in SS_ShadowManager.Instance.ShadowManagers) { text += string.Format((meshManager.IsStatic ? "\nTotal shadows (static): " : "\nTotal shadows: ") + "{0}, drawn: {1}", meshManager.ShadowsCount, meshManager.VisibleShadowsCount); } var centeredStyle = GUI.skin.label; centeredStyle.alignment = TextAnchor.MiddleLeft; float textHeight = centeredStyle.CalcHeight(new GUIContent(text, ""), SS_GUILayout.itemWidth); initHeight += textHeight; GUI.BeginGroup(new Rect(15f, 15f, initWidth, initHeight), sceneName, GUI.skin.window); SS_GUILayout.yPos = 20f; SS_GUILayout.itemHeight = centeredStyle.CalcHeight(new GUIContent(text, ""), SS_GUILayout.itemWidth); SS_GUILayout.Label(text); SS_GUILayout.itemHeight = initItemHeight; if (levelName == "SS_TerrainInteraction" && TerrainDemoPrimaryCamera != null) { bool changed; _terrainDemoSecondaryCameraOn = SS_GUILayout.Toggle(_terrainDemoSecondaryCameraOn, "Use two cameras", out changed); if (changed) { if (_terrainDemoSecondaryCameraOn) { SS_Extensions.SetActive(TerrainDemoSecondaryCamera.gameObject, true); TerrainDemoPrimaryCamera.cullingMask = _terrainDemoPrimaryCameraLayersDefault; } else { SS_Extensions.SetActive(TerrainDemoSecondaryCamera.gameObject, false); TerrainDemoPrimaryCamera.cullingMask = TerrainDemoPrimaryCameraLayers; } SS_ShadowManager.Instance.UpdateCameraEvents(TerrainDemoSecondaryCamera); } } GUI.color = new Color(1f, 0.6f, 0.6f, 1f); if (GUI.Button(new Rect(SS_GUILayout.paddingLeft, initHeight - 40f, SS_GUILayout.itemWidth, 30f), "Back to Main Menu")) { SS_CameraFade.StartAlphaFade(Color.black, false, 0.5f, 0f, () => Application.LoadLevel("SS_Menu")); } GUI.EndGroup(); GUI.color = Color.white; SS_GUILayout.DrawLogo(Logo); }
/** * Camera logic on LateUpdate to only update after all character movement logic has been handled. */ private void UpdatePlayerFollow() { // If either mouse buttons are down, let the mouse govern camera position if (GUIUtility.hotControl == 0) { if (SS_GUILayout.IsRuntimePlatformMobile() && Input.touchCount >= 2) { Touch touch = Input.touches[0]; if (touch.phase == TouchPhase.Moved) { _xDeg += touch.deltaPosition.x * XSpeed * 0.0065f; _yDeg -= touch.deltaPosition.y * YSpeed * 0.0065f; } } else if (Input.GetMouseButton(1)) { _xDeg += Input.GetAxis("Mouse X") * XSpeed * 0.02f; _yDeg -= Input.GetAxis("Mouse Y") * YSpeed * 0.02f; } // otherwise, ease behind the target if any of the directional keys are pressed else if (RotateToTarget) { float targetRotationAngle = Target.eulerAngles.y; float currentRotationAngle = transform.eulerAngles.y; _xDeg = Mathf.LerpAngle(currentRotationAngle, targetRotationAngle, RotationDampening * Time.deltaTime); } } //_targetPos = Vector3.Lerp(_targetPos, Target.position, Time.deltaTime * PositionDampening); _targetPos = Target.position; // calculate the desired distance _desiredDistance -= Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * ZoomRate * Mathf.Abs(_desiredDistance) * SpeedDistance; _desiredDistance = Mathf.Clamp(_desiredDistance, MinDistance, MaxDistance); _yDeg = ClampAngle(_yDeg, YMinLimit, YMaxLimit); // set camera rotation Quaternion rotation = Quaternion.Euler(_yDeg, _xDeg, 0); _correctedDistance = _desiredDistance; // calculate desired camera position Vector3 vTargetOffset = new Vector3(0, -TargetHeight, 0); Vector3 position = _targetPos - (rotation * Vector3.forward * _desiredDistance + vTargetOffset); // check for collision using the true target's desired registration point as set by user using height RaycastHit collisionHit; Vector3 trueTargetPosition = new Vector3(_targetPos.x, _targetPos.y, _targetPos.z) - vTargetOffset; // if there was a collision, correct the camera position and calculate the corrected distance bool isCorrected = false; if (Physics.Linecast(trueTargetPosition, position, out collisionHit, CollisionLayers.value)) { // calculate the distance from the original estimated position to the collision location, // subtracting out a safety "offset" distance from the object we hit. The offset will help // keep the camera from being right on top of the surface we hit, which usually shows up as // the surface geometry getting partially clipped by the camera's front clipping plane. _correctedDistance = Vector3.Distance(trueTargetPosition, collisionHit.point) - OffsetFromWall; isCorrected = true; } // For smoothing, lerp distance only if either distance wasn't corrected, or correctedDistance is more than currentDistance _currentDistance = !isCorrected || _correctedDistance > _currentDistance?Mathf.Lerp(_currentDistance, _correctedDistance, Time.deltaTime *ZoomDampening) : _correctedDistance; // keep within legal limits _currentDistance = Mathf.Clamp(_currentDistance, MinDistance, MaxDistance); // recalculate position based on the new currentDistance position = _targetPos - (rotation * Vector3.forward * _currentDistance + vTargetOffset); //position = Vector3.Lerp(transform.position, Target.position, Time.deltaTime * PositionDampening) - (rotation * Vector3.forward * _currentDistance + vTargetOffset); //Debug.Log(Vector3.Lerp(transform.position, Target.position, Time.deltaTime * PositionDampening)); transform.rotation = rotation; transform.position = position; //transform.position = isCorrected ? position : position; // Vector3.Lerp(transform.position, position, Time.deltaTime * PositionDampening); }
private void OnGUI() { var centeredStyle = GUI.skin.label; const float width = 250f; const float buttonHeight = 35f; float height = 155f + buttonHeight * 3f; float logoHeight = Logo.height; if (Application.isWebPlayer) { height -= 25f + buttonHeight; } float totalHeight = height + logoHeight; if (SS_GUILayout.IsRuntimePlatformMobile()) { SS_GUILayout.UpdateScaleMobile(); } else { SS_GUILayout.UpdateScaleDesktop(totalHeight); } Rect totalRect = new Rect( Screen.width / 2f / SS_GUILayout.scaleFactor - width / 2f, Screen.height / 2f / SS_GUILayout.scaleFactor - totalHeight / 2f, width, totalHeight ); Rect logoRect = totalRect; logoRect.height = logoHeight; Rect rect = totalRect; rect.yMin += logoHeight; GUILayout.BeginArea( logoRect, "", "" ); GUILayout.Label(Logo); GUILayout.EndArea(); GUILayout.BeginArea( rect, "", GUI.skin.textArea ); GUILayout.BeginVertical(); if (GUILayout.Button("Moving cubes", GUILayout.Height(buttonHeight))) { SS_CameraFade.StartAlphaFade(Color.black, false, 0.5f, 0f, () => Application.LoadLevel("SS_MovingCubes")); } if (GUILayout.Button("Animated shadows", GUILayout.Height(buttonHeight))) { SS_CameraFade.StartAlphaFade(Color.black, false, 0.5f, 0f, () => Application.LoadLevel("SS_Helicopter")); } if (GUILayout.Button("Terrain interaction", GUILayout.Height(buttonHeight))) { SS_CameraFade.StartAlphaFade(Color.black, false, 0.5f, 0f, () => Application.LoadLevel("SS_TerrainInteraction")); } if (GUILayout.Button("Disco lights", GUILayout.Height(buttonHeight))) { SS_CameraFade.StartAlphaFade(Color.black, false, 0.5f, 0f, () => Application.LoadLevel("SS_DiscoLights")); } if (GUILayout.Button("Multiple shadows", GUILayout.Height(buttonHeight))) { SS_CameraFade.StartAlphaFade(Color.black, false, 0.5f, 0f, () => Application.LoadLevel("SS_MultipleShadows")); } if (!Application.isWebPlayer) { GUILayout.Space(20); GUI.color = new Color(1f, 0.6f, 0.6f, 1f); if (GUILayout.Button("Quit", GUILayout.Height(buttonHeight))) { SS_CameraFade.StartAlphaFade(Color.black, false, 0.5f, 0f, Application.Quit); } } GUILayout.EndVertical(); GUILayout.EndArea(); GUI.color = Color.black; centeredStyle.alignment = TextAnchor.UpperLeft; if (!SS_GUILayout.IsRuntimePlatformMobile() && !Application.isEditor) { Screen.fullScreen = GUI.Toggle( new Rect(rect.xMin - 90f, rect.yMin, 100f, 400f), Screen.fullScreen, " Fullscreen"); } //GUI.Label(new Rect(rect.xMax + 10f, // rect.yMin, Mathf.Min(200f, Screen.width - rect.xMax - 10f), 400f), // "You can press Enter/Menu button to disable GUI (as Unity GUI may cause slowdown, especially on mobile)"); }