Пример #1
0
    public AltUnityObject GameObjectToAltUnityObject(UnityEngine.GameObject altGameObject, UnityEngine.Camera camera = null)
    {
        int cameraId = -1;

        //if no camera is given it will iterate through all cameras until  found one that sees the object if no camera sees the object it will return the position from the last camera
        //if there is no camera in the scene it will return as scren position x:-1 y=-1, z=-1 and cameraId=-1
        if (camera == null)
        {
            _position = new UnityEngine.Vector3(-1, -1, -1);
            foreach (var camera1 in UnityEngine.Camera.allCameras)
            {
                _position = getObjectScreePosition(altGameObject, camera1);
                cameraId  = camera1.GetInstanceID();
                if (_position.x > 0 && _position.y > 0 && _position.x < UnityEngine.Screen.width && _position.y < UnityEngine.Screen.height && _position.z >= 0)//Check if camera sees the object
                {
                    break;
                }
            }
        }
        else
        {
            _position = getObjectScreePosition(altGameObject, camera);
            cameraId  = camera.GetInstanceID();
        }
        int parentId = 0;

        if (altGameObject.transform.parent != null)
        {
            parentId = altGameObject.transform.parent.GetInstanceID();
        }


        AltUnityObject altObject = new AltUnityObject(name: altGameObject.name,
                                                      id: altGameObject.GetInstanceID(),
                                                      x: System.Convert.ToInt32(UnityEngine.Mathf.Round(_position.x)),
                                                      y: System.Convert.ToInt32(UnityEngine.Mathf.Round(_position.y)),
                                                      z: System.Convert.ToInt32(UnityEngine.Mathf.Round(_position.z)),//if z is negative object is behind the camera
                                                      mobileY: System.Convert.ToInt32(UnityEngine.Mathf.Round(UnityEngine.Screen.height - _position.y)),
                                                      type: "",
                                                      enabled: altGameObject.activeSelf,
                                                      worldX: altGameObject.transform.position.x,
                                                      worldY: altGameObject.transform.position.y,
                                                      worldZ: altGameObject.transform.position.z,
                                                      idCamera: cameraId,
                                                      transformId: altGameObject.transform.GetInstanceID(),
                                                      parentId: parentId);

        return(altObject);
    }
Пример #2
0
        // On-demand create any objects we need
        private void CreateMirrorObjects( Camera currentCamera, out Camera reflectionCamera )
        {
            reflectionCamera = null;

            // Reflection render texture
            if( !m_ReflectionTexture || m_OldReflectionTextureSize != m_TextureSize )
            {
                if( m_ReflectionTexture )
                    DestroyImmediate( m_ReflectionTexture );
                m_ReflectionTexture = new RenderTexture(m_TextureSize, m_TextureSize, 16); //, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);

                m_ReflectionTexture.name = "__MirrorReflection" + GetInstanceID();
                m_ReflectionTexture.isPowerOfTwo = true;

                //m_ReflectionTexture.generateMips = true;
                m_ReflectionTexture.useMipMap = true;
                m_ReflectionTexture.wrapMode = TextureWrapMode.Clamp;

                //m_ReflectionTexture.hideFlags = HideFlags.DontSave;
                m_OldReflectionTextureSize = m_TextureSize;
            }

            // Camera for reflection
            reflectionCamera = m_ReflectionCameras[currentCamera] as Camera;
            if( !reflectionCamera ) // catch both not-in-dictionary and in-dictionary-but-deleted-GO
            {
                GameObject go = new GameObject( "Mirror Refl Camera id" + GetInstanceID() + " for " + currentCamera.GetInstanceID(), typeof(Camera), typeof(Skybox) );
                reflectionCamera = go.GetComponent<Camera>();
                reflectionCamera.enabled = false;
                reflectionCamera.transform.position = currentCamera.transform.position;
                reflectionCamera.transform.rotation = currentCamera.transform.rotation;
                reflectionCamera.gameObject.AddComponent<FlareLayer>();
                //go.hideFlags = HideFlags.HideAndDontSave;
                m_ReflectionCameras[currentCamera] = reflectionCamera;

                go.transform.SetParent(GameObject.Find("ReflectionsMod").transform);
            }
        }
Пример #3
0
        /** Creates the objects we need, as needed. */
        protected CameraInfo CreateCameraObjects(Camera currentCamera)
        {
            //get the state for this particular camera
            CameraInfo camInfo;
            if (!cameraInfo.TryGetValue(currentCamera, out camInfo)) {
            //Debug.Log("Creating objects for camera " + currentCamera.GetInstanceID());
            camInfo = new CameraInfo();
            camInfo.srcCamera = currentCamera;
            cameraInfo[currentCamera] = camInfo;
            }

            //Camera for seeing through the portal
            if (!camInfo.portalCamera) {
            GameObject cameraObject = new GameObject("Portal Camera id" + GetInstanceID() + " for " + currentCamera.GetInstanceID(), typeof(Camera), typeof(Skybox));
            cameraObject.hideFlags = Portal.hideObjects ? HideFlags.HideAndDontSave : HideFlags.DontSave;
            camInfo.portalCamera = cameraObject.GetComponent<Camera>();
            camInfo.portalCamera.enabled = false;
            camInfo.portalCamera.transform.position = transform.position;
            camInfo.portalCamera.transform.rotation = transform.rotation;
            camInfo.portalCamera.useOcclusionCulling = false;//occlusion culling in Unity is broken, much more visibly so with a nonstandard near plane
            #if UNITY_5
            camInfo.portalCamera.gameObject.AddComponent<FlareLayer>();
            #endif
            }

            if (!portalMaterial) {
            SetupMaterial();
            }

            return camInfo;
        }
Пример #4
0
        // On-demand create any objects we need for water
        void CreateWaterObjects(Camera currentCamera, out Camera reflectionCamera, out Camera refractionCamera)
        {
            WaterMode mode = GetWaterMode();

            reflectionCamera = null;
            refractionCamera = null;

            if (mode >= WaterMode.Reflective)
            {
                // Reflection render texture
                if (!m_ReflectionTexture || m_OldReflectionTextureSize != textureSize)
                {
                    if (m_ReflectionTexture)
                    {
                        DestroyImmediate(m_ReflectionTexture);
                    }
                    m_ReflectionTexture = new RenderTexture(textureSize, textureSize, 16);
                    m_ReflectionTexture.name = "__WaterReflection" + GetInstanceID();
                    m_ReflectionTexture.isPowerOfTwo = true;
                    m_ReflectionTexture.hideFlags = HideFlags.DontSave;
                    m_OldReflectionTextureSize = textureSize;
                }

                // Camera for reflection
                m_ReflectionCameras.TryGetValue(currentCamera, out reflectionCamera);
                if (!reflectionCamera) // catch both not-in-dictionary and in-dictionary-but-deleted-GO
                {
                    GameObject go = new GameObject("Water Refl Camera id" + GetInstanceID() + " for " + currentCamera.GetInstanceID(), typeof(Camera), typeof(Skybox));
                    reflectionCamera = go.GetComponent<Camera>();
                    reflectionCamera.enabled = false;
                    reflectionCamera.transform.position = transform.position;
                    reflectionCamera.transform.rotation = transform.rotation;
                    reflectionCamera.gameObject.AddComponent<FlareLayer>();
                    go.hideFlags = HideFlags.HideAndDontSave;
                    m_ReflectionCameras[currentCamera] = reflectionCamera;
                }
            }

            if (mode >= WaterMode.Refractive)
            {
                // Refraction render texture
                if (!m_RefractionTexture || m_OldRefractionTextureSize != textureSize)
                {
                    if (m_RefractionTexture)
                    {
                        DestroyImmediate(m_RefractionTexture);
                    }
                    m_RefractionTexture = new RenderTexture(textureSize, textureSize, 16);
                    m_RefractionTexture.name = "__WaterRefraction" + GetInstanceID();
                    m_RefractionTexture.isPowerOfTwo = true;
                    m_RefractionTexture.hideFlags = HideFlags.DontSave;
                    m_OldRefractionTextureSize = textureSize;
                }

                // Camera for refraction
                m_RefractionCameras.TryGetValue(currentCamera, out refractionCamera);
                if (!refractionCamera) // catch both not-in-dictionary and in-dictionary-but-deleted-GO
                {
                    GameObject go =
                        new GameObject("Water Refr Camera id" + GetInstanceID() + " for " + currentCamera.GetInstanceID(),
                            typeof(Camera), typeof(Skybox));
                    refractionCamera = go.GetComponent<Camera>();
                    refractionCamera.enabled = false;
                    refractionCamera.transform.position = transform.position;
                    refractionCamera.transform.rotation = transform.rotation;
                    refractionCamera.gameObject.AddComponent<FlareLayer>();
                    go.hideFlags = HideFlags.HideAndDontSave;
                    m_RefractionCameras[currentCamera] = refractionCamera;
                }
            }
        }
Пример #5
0
        // On-demand create any objects we need for water
        void CreateWaterObjects(UnityEngine.Camera currentCamera, out UnityEngine.Camera reflectionCamera, out UnityEngine.Camera refractionCamera)
        {
            WaterMode mode = GetWaterMode();

            reflectionCamera = null;
            refractionCamera = null;

            if (mode >= WaterMode.Reflective)
            {
                // Reflection render texture
                if (!m_ReflectionTexture || m_OldReflectionTextureSize != textureSize)
                {
                    if (m_ReflectionTexture)
                    {
                        DestroyImmediate(m_ReflectionTexture);
                    }
                    m_ReflectionTexture              = new RenderTexture(textureSize, textureSize, 16);
                    m_ReflectionTexture.name         = "__WaterReflection" + GetInstanceID();
                    m_ReflectionTexture.isPowerOfTwo = true;
                    m_ReflectionTexture.hideFlags    = HideFlags.DontSave;
                    m_OldReflectionTextureSize       = textureSize;
                }

                // Camera for reflection
                m_ReflectionCameras.TryGetValue(currentCamera, out reflectionCamera);
                if (!reflectionCamera) // catch both not-in-dictionary and in-dictionary-but-deleted-GO
                {
                    GameObject go = new GameObject("Water Refl Camera id" + GetInstanceID() + " for " + currentCamera.GetInstanceID(), typeof(UnityEngine.Camera), typeof(Skybox));
                    reflectionCamera                    = go.GetComponent <UnityEngine.Camera>();
                    reflectionCamera.enabled            = false;
                    reflectionCamera.transform.position = transform.position;
                    reflectionCamera.transform.rotation = transform.rotation;
                    reflectionCamera.gameObject.AddComponent <FlareLayer>();
                    go.hideFlags = HideFlags.HideAndDontSave;
                    m_ReflectionCameras[currentCamera] = reflectionCamera;
                }
            }

            if (mode >= WaterMode.Refractive)
            {
                // Refraction render texture
                if (!m_RefractionTexture || m_OldRefractionTextureSize != textureSize)
                {
                    if (m_RefractionTexture)
                    {
                        DestroyImmediate(m_RefractionTexture);
                    }
                    m_RefractionTexture              = new RenderTexture(textureSize, textureSize, 16);
                    m_RefractionTexture.name         = "__WaterRefraction" + GetInstanceID();
                    m_RefractionTexture.isPowerOfTwo = true;
                    m_RefractionTexture.hideFlags    = HideFlags.DontSave;
                    m_OldRefractionTextureSize       = textureSize;
                }

                // Camera for refraction
                m_RefractionCameras.TryGetValue(currentCamera, out refractionCamera);
                if (!refractionCamera) // catch both not-in-dictionary and in-dictionary-but-deleted-GO
                {
                    GameObject go =
                        new GameObject("Water Refr Camera id" + GetInstanceID() + " for " + currentCamera.GetInstanceID(),
                                       typeof(UnityEngine.Camera), typeof(Skybox));
                    refractionCamera                    = go.GetComponent <UnityEngine.Camera>();
                    refractionCamera.enabled            = false;
                    refractionCamera.transform.position = transform.position;
                    refractionCamera.transform.rotation = transform.rotation;
                    refractionCamera.gameObject.AddComponent <FlareLayer>();
                    go.hideFlags = HideFlags.HideAndDontSave;
                    m_RefractionCameras[currentCamera] = refractionCamera;
                }
            }
        }
Пример #6
0
        //On-demand create any objects we need
        private void CreateSurfaceObjects(Camera currentCamera, out Camera reflectionCamera)
        {
            reflectionCamera = null;

            //Reflection render texture
            if (!m_ReflectionTexture || m_OldReflectionTextureSize != m_TextureResolution)
            {
                if (m_ReflectionTexture)
                    DestroyImmediate (m_ReflectionTexture);
                m_ReflectionTexture = new RenderTexture (m_TextureResolution, m_TextureResolution, 16);
                m_ReflectionTexture.name = "__PlanarReflection" + GetInstanceID ();
                m_ReflectionTexture.isPowerOfTwo = true;
                m_ReflectionTexture.hideFlags = HideFlags.DontSave;
                m_OldReflectionTextureSize = m_TextureResolution;
            }

            //Camera for reflection
            reflectionCamera = m_ReflectionCameras [currentCamera] as Camera;
            if (!reflectionCamera) //catch both not-in-dictionary and in-dictionary-but-deleted-GO
            {
                GameObject go = new GameObject ("PlanarReflectionCamera" + GetInstanceID () + " for " + currentCamera.GetInstanceID (), typeof(Camera), typeof(Skybox));
                reflectionCamera = go.GetComponent<Camera> ();
                reflectionCamera.enabled = false;
                reflectionCamera.transform.position = transform.position;
                reflectionCamera.transform.rotation = transform.rotation;
                reflectionCamera.gameObject.AddComponent<FlareLayer> ();
                go.hideFlags = HideFlags.HideAndDontSave;
                m_ReflectionCameras [currentCamera] = reflectionCamera;
            }
        }
        // On-demand create any objects we need
        private void CreateMirrorObjects( Camera currentCamera, out Camera reflectionCamera )
        {
            reflectionCamera = null;

            // Reflection render texture
            if( !m_ReflectionTexture || m_OldReflectionTextureSize != m_TextureSize )
            {
                if( m_ReflectionTexture )
                    Destroy( m_ReflectionTexture );
                m_ReflectionTexture = new RenderTexture(m_TextureSize, m_TextureSize, 16); //, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);

                m_ReflectionTexture.name = "__MirrorReflection" + GetInstanceID();
                m_ReflectionTexture.isPowerOfTwo = true;

                //m_ReflectionTexture.generateMips = true;
                m_ReflectionTexture.useMipMap = true;
                m_ReflectionTexture.wrapMode = TextureWrapMode.Clamp;

                //m_ReflectionTexture.hideFlags = HideFlags.DontSave;
                m_OldReflectionTextureSize = m_TextureSize;
            }

            // Camera for reflection
            reflectionCamera = m_ReflectionCameras[currentCamera] as Camera;
            if( !reflectionCamera ) // catch both not-in-dictionary and in-dictionary-but-deleted-GO
            {
                GameObject go = new GameObject( "Mirror Refl Camera id" + GetInstanceID() + " for " + currentCamera.GetInstanceID(), typeof(Camera), typeof(Skybox) );
                reflectionCamera = go.GetComponent<Camera>();
                reflectionCamera.enabled = false;
                reflectionCamera.transform.position = currentCamera.transform.position;
                reflectionCamera.transform.rotation = currentCamera.transform.rotation;
                reflectionCamera.gameObject.AddComponent<FlareLayer>();
                //go.hideFlags = HideFlags.HideAndDontSave;
                m_ReflectionCameras[currentCamera] = reflectionCamera;

                if (currentBackgroundSettings == EnvironmentSetting.OutdoorSetting)
                {
                    // attach global fog to camera - this is important to get the same reflections like on normal terrain when deferred rendering is used
                    if ((reflectionCamera.renderingPath == RenderingPath.DeferredShading) || (reflectionCamera.renderingPath == RenderingPath.UsePlayerSettings))
                    {
                        UnityStandardAssets.ImageEffects.GlobalFog scriptGlobalFog = go.AddComponent<UnityStandardAssets.ImageEffects.GlobalFog>();
                        UnityStandardAssets.ImageEffects.GlobalFog globalFogMainCamera = Camera.main.gameObject.GetComponent<UnityStandardAssets.ImageEffects.GlobalFog>();
                        scriptGlobalFog.distanceFog = globalFogMainCamera.distanceFog;
                        scriptGlobalFog.excludeFarPixels = globalFogMainCamera.excludeFarPixels; // false
                        scriptGlobalFog.useRadialDistance = globalFogMainCamera.useRadialDistance;
                        scriptGlobalFog.heightFog = globalFogMainCamera.heightFog;
                        scriptGlobalFog.height = globalFogMainCamera.height;
                        scriptGlobalFog.heightDensity = globalFogMainCamera.heightDensity;
                        scriptGlobalFog.startDistance = globalFogMainCamera.startDistance;
                    }
                }

                go.transform.SetParent(GameObject.Find("ReflectionsMod").transform);
            }
        }