Ejemplo n.º 1
0
        protected virtual void OnEnable()
        {
            lastSettings = new CamSettings(this, cam)
            {
                screenSize = new [] { 0, 0 }
            };
            ForceRefresh();

            falseCamGO = new GameObject("False Camera")
            {
                hideFlags = HideFlags.HideAndDontSave
            };
            falseCam             = falseCamGO.AddComponent <Camera>();
            falseCam.cullingMask = LayerMask.GetMask();

            camDraw = falseCamGO.AddComponent <PixelCamDrawer>();
            camDraw.SourceCamera = this;

            fallbackShader = Shader.Find("Hidden/SubjectNerd/PixelCamFallback");
            if (fallbackShader != null)
            {
                fallbackMaterial = new Material(fallbackShader)
                {
                    hideFlags = HideFlags.DontSave
                };
            }
            else
            {
                Debug.Log("Couldn't find fall back shader, material not created");
                enabled = false;
            }
        }
Ejemplo n.º 2
0
        protected virtual void OnEnable()
        {
            lastSettings = new CamSettings(AspectStretch, 0, cam.fieldOfView, cam.orthographic);

            falseCamGO = new GameObject("False Camera")
            {
                hideFlags = HideFlags.HideAndDontSave
            };
            falseCam             = falseCamGO.AddComponent <Camera>();
            falseCam.cullingMask = LayerMask.GetMask();

            camDraw = falseCamGO.AddComponent <PixelCamDrawer>();
            camDraw.SourceCamera = this;

            fallbackShader = Shader.Find("Hidden/SubjectNerd/PixelCamFallback");
            if (fallbackShader != null)
            {
                fallbackMaterial = new Material(fallbackShader)
                {
                    hideFlags = HideFlags.DontSave
                };
            }
            else
            {
                Debug.Log("Couldn't find fall back shader, material not created");
                enabled = false;
            }
        }
Ejemplo n.º 3
0
    public void LoadParameters(CamSettings settings)
    {
        this.zoom = settings.zoom;
        Transform target = null;

        Camera.mainCamera.nearClipPlane = settings.nearClip;
        switch (settings.target)
        {
        case CameraTargetList.BALL:
        {
            target = game.Ball.transform;
            break;
        }

        case CameraTargetList.OWNER:
        {
            if (game.Ball.Owner == null)
            {
                target = game.Ball.PreviousOwner.transform;
            }
            else
            {
                target = game.Ball.Owner.transform;
            }
            break;
        }
        }

        this.setTarget(target);
    }
Ejemplo n.º 4
0
    public CamManager(CamSettings settings, FollowCam fCam, TrackingCam tCam)
    {
        _settings     = settings;
        _followMode   = fCam;
        _trackingMode = tCam;

        activeCamera = _settings.uiCam;
    }
Ejemplo n.º 5
0
        public void CheckCamera()
        {
            var  currentSettings = new CamSettings(AspectStretch, zoomLevel, cam.fieldOfView, cam.orthographic);
            bool didChange       = currentSettings.Equals(lastSettings) == false;

            if (didChange)
            {
                SetupCamera();
            }
        }
Ejemplo n.º 6
0
            public bool Equals(CamSettings other)
            {
                bool isEqual = other.screenSize[0] == screenSize[0] &&
                               other.screenSize[1] == screenSize[1] &&
                               other.aspect != aspect &&
                               Math.Abs(other.fieldOfView - fieldOfView) < float.Epsilon &&
                               Math.Abs(other.zoomLevel - zoomLevel) < float.Epsilon;

                return(isEqual);
            }
Ejemplo n.º 7
0
        public bool CheckCamera()
        {
            var  currentSettings = new CamSettings(this, cam);
            bool didChange       = currentSettings.Equals(lastSettings) == false;

            if (didChange)
            {
                SetupCamera(currentSettings);
            }
            return(didChange);
        }
Ejemplo n.º 8
0
            public bool Equals(CamSettings other)
            {
                bool equalScreen = other.screenSize[0] == screenSize[0] &&
                                   other.screenSize[1] == screenSize[1];
                bool equalAspect = other.aspect == aspect;

                bool isEqual = other.isOrtho == isOrtho &&
                               equalScreen &&
                               equalAspect &&
                               Mathf.Approximately(other.zoomLevel, zoomLevel) &&
                               Mathf.Approximately(other.pixelsPerUnit, pixelsPerUnit) &&
                               Mathf.Approximately(other.downsample, downsample);

                if (isEqual && isOrtho == false)
                {
                    isEqual &= Mathf.Approximately(other.zDistance, zDistance) &&
                               Mathf.Approximately(other.fieldOfView, fieldOfView) &&
                               Mathf.Approximately(other.farPlane, farPlane);
                }

                return(isEqual);
            }
Ejemplo n.º 9
0
        private void SetupCamera(CamSettings settings)
        {
            var aspect = settings.aspect;

            zoomLevel = Mathf.Max(0.05f, Mathf.Abs(zoomLevel)) * Math.Sign(zoomLevel);
            // "Physical" pixel render size
            Vector2 screenRenderSize = GetScreenRenderSize();

            // Pixel render size
            int[] pixelRenderSize = GetRenderTextureSize(screenRenderSize, settings.aspect);

            float targetAspect = (float)pixelRenderSize[0] / (float)pixelRenderSize[1];

            cam.aspect = targetAspect;

            if (cam.orthographic)
            {
                // Orthographic camera needs to use screen size when calculating quad offset
                screenRenderSize = new Vector2(Screen.width, Screen.height);

                // Set the camera's size, according to pixel size
                float targetHeight = pixelRenderSize[1];
                // Use pixel density to convert to world units
                targetHeight /= pixelsPerUnit;
                targetHeight /= 2f;
                // Change orthographic size so camera is sized to world unit
                cam.orthographicSize = targetHeight;
            }

            // Find the settings to be used for drawing the GL quad
            CalculateQuad(screenRenderSize, pixelRenderSize);

            // Important to release current render texture
            cam.targetTexture = null;
            fallbackMaterial.SetTexture("_MainTex", null);
            if (advancedSettings != null && advancedSettings.cameraMaterial != null)
            {
                advancedSettings.cameraMaterial.SetTexture("_MainTex", null);
            }
            if (renderTexture != null)
            {
                renderTexture.Release();
            }

            // Create new render texture
            Vector2 renderSize = new Vector2(pixelRenderSize[0], pixelRenderSize[1]) / settings.downsample;

            int[] actualRenderSize = GetRenderTextureSize(renderSize, Vector2.one);
            renderTexture = new RenderTexture(actualRenderSize[0], actualRenderSize[1], 0)
            {
                useMipMap  = true,
                filterMode = FilterMode.Point,
                wrapMode   = TextureWrapMode.Clamp
            };
            // Make main camera render into it
            cam.targetTexture = renderTexture;

            // Set render texture as _MainTex on materials
            fallbackMaterial.SetTexture("_MainTex", renderTexture);
            if (advancedSettings != null)
            {
                CameraMaterial = advancedSettings.cameraMaterial;
            }

            lastSettings = settings;

            cam.Render();
            camDraw.DrawQuad();
        }
Ejemplo n.º 10
0
        protected void SetupCamera()
        {
            var aspect = AspectStretch;

            zoomLevel = Mathf.Max(0.05f, Mathf.Abs(zoomLevel)) * Math.Sign(zoomLevel);
            // "Physical" render size
            Vector2 screenRenderSize = GetScreenRenderSize();

            // Pixel render size
            int[] pixelRenderSize = GetRenderTextureSize(screenRenderSize, aspect);

            // Find the settings to be used for drawing the GL quad
            Vector2 pixelSize = new Vector2(pixelRenderSize[0], pixelRenderSize[1]) * zoomLevel;

            if (cam.orthographic)
            {
                // Orthographic camera needs to use screen size when calculating quad offset
                screenRenderSize = new Vector2(Screen.width, Screen.height);

                // Set the camera's size, according to pixel size
                float targetHeight = pixelRenderSize[1];
                // Use pixel density to convert to world units
                targetHeight /= pixelsPerUnit;
                targetHeight /= 2f;
                // Change orthographic size so camera is sized to world unit
                cam.orthographicSize = targetHeight;
            }

            quadOffset    = pixelSize - screenRenderSize;
            quadOffset   /= 2;
            quadOffset.x /= Screen.width;
            quadOffset.y /= Screen.height;

            // Set camera aspect ratio, since pixel aspect ratio will be different from current aspect
            float targetAspect = (float)pixelRenderSize[0] / (float)pixelRenderSize[1];

            cam.aspect = targetAspect;

            // Important to release current render texture
            cam.targetTexture = null;
            fallbackMaterial.SetTexture("_MainTex", null);
            if (advancedSettings != null && advancedSettings.cameraMaterial != null)
            {
                advancedSettings.cameraMaterial.SetTexture("_MainTex", null);
            }
            if (renderTexture != null)
            {
                renderTexture.Release();
            }

            // Create new render texture
            renderTexture = new RenderTexture(pixelRenderSize[0], pixelRenderSize[1], 0)
            {
                useMipMap  = true,
                filterMode = FilterMode.Point,
                wrapMode   = TextureWrapMode.Clamp
            };
            // Make main camera render into it
            cam.targetTexture = renderTexture;

            // Set render texture as _MainTex on materials
            fallbackMaterial.SetTexture("_MainTex", renderTexture);
            if (advancedSettings != null)
            {
                CameraMaterial = advancedSettings.cameraMaterial;
            }

            lastSettings = new CamSettings(aspect, zoomLevel, cam.fieldOfView, cam.orthographic);

            cam.Render();
            camDraw.DrawQuad();
        }
Ejemplo n.º 11
0
	public void LoadParameters(CamSettings settings)
	{
		this.zoom = settings.zoom;
		Transform	target = null;
		Camera.mainCamera.nearClipPlane = settings.nearClip;
		switch (settings.target)
		{
			case CameraTargetList.BALL:
			{
				target = game.Ball.transform;
				break;
			}
			case CameraTargetList.OWNER:
			{
				if(game.Ball.Owner == null)
				{
					target = game.Ball.PreviousOwner.transform;
				}
				else
				{
					target = game.Ball.Owner.transform;
				}
				break;
			}
		}
		
		this.setTarget(target);
	}