Exemple #1
0
 void UpdateCameraModes(UnityEngine.Camera src, UnityEngine.Camera dest)
 {
     if (dest == null)
     {
         return;
     }
     // set water camera to clear the same way as current camera
     dest.clearFlags      = src.clearFlags;
     dest.backgroundColor = src.backgroundColor;
     if (src.clearFlags == CameraClearFlags.Skybox)
     {
         Skybox sky   = src.GetComponent <Skybox>();
         Skybox mysky = dest.GetComponent <Skybox>();
         if (!sky || !sky.material)
         {
             mysky.enabled = false;
         }
         else
         {
             mysky.enabled  = true;
             mysky.material = sky.material;
         }
     }
     // update other values to match current camera.
     // even if we are supplying custom camera&projection matrices,
     // some of values are used elsewhere (e.g. skybox uses far plane)
     dest.farClipPlane     = src.farClipPlane;
     dest.nearClipPlane    = src.nearClipPlane;
     dest.orthographic     = src.orthographic;
     dest.fieldOfView      = src.fieldOfView;
     dest.aspect           = src.aspect;
     dest.orthographicSize = src.orthographicSize;
 }
Exemple #2
0
        public void DragSelectionBox(Camera main, CursorPanGroup group, CursorButton button, TutorialAIManager manager, float delayTime, string methodName)
        {
            BoxSelector selector = main.GetComponent<BoxSelector>();
            if (selector == null) {
                Debug.LogError("Cannot find Box Selector component from camera, " + main.ToString() + ".");
                return;
            }

            if (button != CursorButton.Left_Click) {
                Debug.LogError("Selection box only works with left mouse button.");
                return;
            }

            selector.StartBoxSelection(group, 0.5f);
            this.icon.SetButton(button);
            this.buttonPressedElapsedTime = 0f;
            this.isButtonPressed = true;
            this.isButtonHeld = true;
            this.isAppearing = true;
            this.panningElapsedTime = 0f;
            this.startingPosition = group.start;
            this.endingPosition = group.end;
            this.rectTransform.position = group.start;

            manager.Invoke(methodName, delayTime);
            this.Invoke("HeldButtonRelease", delayTime);
        }
Exemple #3
0
        /// <summary>
        /// Attaches the monitor to the specified character.
        /// </summary>
        /// <param name="character">The character to attach the monitor to.</param>
        protected override void OnAttachCharacter(GameObject character)
        {
            if (m_Character != null)
            {
                EventHandler.UnregisterEvent <Item, int>(m_Character, "OnAbilityWillEquipItem", OnEquipItem);
                EventHandler.UnregisterEvent <Item, bool>(m_Character, "OnItemUpdateDominantItem", OnUpdateDominantItem);
                EventHandler.UnregisterEvent <Item, int>(m_Character, "OnAbilityUnequipItemComplete", OnUnequipItem);
                EventHandler.UnregisterEvent <Item, int>(m_Character, "OnInventoryRemoveItem", OnUnequipItem);
                EventHandler.UnregisterEvent <bool, bool>(m_Character, "OnAddCrosshairsSpread", OnAddCrosshairsSpread);
                EventHandler.UnregisterEvent <bool, bool>(m_Character, "OnAimAbilityStart", OnAim);
                EventHandler.UnregisterEvent <Vector3, Vector3, GameObject>(m_Character, "OnDeath", OnDeath);
                EventHandler.UnregisterEvent(m_Character, "OnRespawn", OnRespawn);
                ResetMonitor();
            }

            base.OnAttachCharacter(character);

            if (m_Character == null)
            {
                return;
            }

            m_Camera           = Shared.Camera.CameraUtility.FindCamera(m_Character);
            m_CameraController = m_Camera.gameObject.GetCachedComponent <CameraController>();
            m_CameraController.SetCrosshairs(transform);

            m_AimAssist             = m_Camera.GetComponent <AimAssist>();
            m_CharacterTransform    = m_Character.transform;
            m_CharacterLayerManager = m_Character.GetCachedComponent <CharacterLayerManager>();
            m_CharacterLocomotion   = m_Character.GetCachedComponent <UltimateCharacterLocomotion>();
            m_PlayerInput           = m_Character.GetCachedComponent <Shared.Input.PlayerInput>();
            m_EnableImage           = false;
            gameObject.SetActive(CanShowUI());

            EventHandler.RegisterEvent <Item, int>(m_Character, "OnAbilityWillEquipItem", OnEquipItem);
            EventHandler.RegisterEvent <Item, bool>(m_Character, "OnItemUpdateDominantItem", OnUpdateDominantItem);
            EventHandler.RegisterEvent <Item, int>(m_Character, "OnAbilityUnequipItemComplete", OnUnequipItem);
            EventHandler.RegisterEvent <Item, int>(m_Character, "OnInventoryRemoveItem", OnUnequipItem);
            EventHandler.RegisterEvent <bool, bool>(m_Character, "OnAddCrosshairsSpread", OnAddCrosshairsSpread);
            EventHandler.RegisterEvent <bool, bool>(m_Character, "OnAimAbilityStart", OnAim);
            EventHandler.RegisterEvent <Vector3, Vector3, GameObject>(m_Character, "OnDeath", OnDeath);
            EventHandler.RegisterEvent(m_Character, "OnRespawn", OnRespawn);

            // An item may already be equipped.
            var inventory = m_Character.GetCachedComponent <Inventory.InventoryBase>();

            if (inventory != null)
            {
                for (int i = 0; i < inventory.SlotCount; ++i)
                {
                    var item = inventory.GetActiveItem(i);
                    if (item != null)
                    {
                        OnEquipItem(item, i);
                    }
                }
            }
        }
Exemple #4
0
        public static void setEnable(UnityEngine.Camera camera, bool value)
        {
            camera.enabled = value;

            AudioListener audioListener = camera.GetComponent <AudioListener> ();

            if (audioListener != null)
            {
                audioListener.enabled = value;
            }
        }
Exemple #5
0
 void Start()
 {
     {
         var pos            = new Vector3(0f, 0f, 0f);
         var rot            = Quaternion.identity;
         var float_resource = SystemManagerSystem.FloatResource;
         primary_player_entity_ = ECSPlayerManager.Instance.spawn(ref pos, ref rot, ref float_resource);
     }
     {
         var game_camera = main_camera_.GetComponent <GameCameraComponent>();
         game_camera.setup(primary_player_entity_);
     }
 }
Exemple #6
0
        IEnumerator FadeOut()
        {
            cutoff = 0.0f;
            for (int i = 0; i < 30; i++)
            {
                Debug.LogWarning("Fading");
                cutoff += 0.034f;
                cam.GetComponent <GJ_CameraController>().transitionMat.SetFloat("_Cutoff", cutoff);
                yield return(new WaitForSeconds(0.0125f));
            }
            cutoff = 1.0f;
            yield return(new WaitForSeconds(0.05f));

            for (int i = 0; i < 30; i++)
            {
                Debug.LogWarning("Fading");
                cutoff -= 0.034f;
                cam.GetComponent <GJ_CameraController>().transitionMat.SetFloat("_Cutoff", cutoff);
                yield return(new WaitForSeconds(0.0125f));
            }
            cutoff = 0.0f;
            yield return(new WaitForSeconds(0.01f));
        }
Exemple #7
0
    public override void OnUpdate()
    {
        // 每帧检查main camera, 把自己办
        if (audioLisnterTransform != null)
        {
            // 若camera 改变,更新缓存transform, 检查删除重复lisnter
            UnityEngine.Camera cam = UnityEngine.Camera.main;
            if (currentAttatchedCamera != cam)
            {
                currentAttatchedCamera = cam;
                if (currentAttatchedCamera != null)
                {
                    // upgrade
                    currentAttachedCameraTransform = currentAttatchedCamera.transform;

                    // del
                    var camLisnter = currentAttatchedCamera.GetComponent <AudioListener>();
                    if (camLisnter != null)
                    {
                        UnityEngine.GameObject.Destroy(camLisnter);
                    }
                }
            }

            if (currentAttatchedCamera != null)
            {
                audioLisnterTransform.transform.position = currentAttachedCameraTransform.position;
            }
        }
        base.OnUpdate();
        //if (!NeedPlayMusic)
        //    return;

        // Update
        for (int i = 0; i < spawnedAudio.Count; ++i)
        {
            var audioData = spawnedAudio[i];
            if (audioData.IsMusic)
            {
                UpdateMusic(audioData);
            }
            else
            {
                UpdateSound(audioData);
            }
        }

        // Destroy end music
        DespawnEndAudios();
    }
Exemple #8
0
        public void PushCamera()
        {
            if (_cameraStack.Count > 0)
            {
                UnityEngine.Camera camera = _cameraStack.Peek();
                camera.enabled = false;
                camera.GetComponent <AudioListener>().enabled = false;
            }

            GameObject newCameraObject = new GameObject("Stack Camera " + _cameraStack.Count);

            UnityEngine.Camera newCamera = newCameraObject.AddComponent <UnityEngine.Camera>();
            newCameraObject.AddComponent <AudioListener>();
            _cameraStack.Push(newCamera);
        }
        public void Initialize()
        {
            if (m_initialized)
            {
                return;
            }

            m_initialized            = true;
            m_camera                 = UnityEngine.Camera.main;
            m_hiZBuffer              = m_camera.GetComponent <HiZBuffer>();
            m_supportsComputeShaders = SystemInfo.supportsComputeShaders;
            if (m_supportsComputeShaders)
            {
                ResourceManager.Instance.LoadAsync <ComputeShader>(COMPUTE_SHADER_NAME, OnComputeShaderLoaded);
            }
        }
Exemple #10
0
        public void PopCamera()
        {
            if (_cameraStack.Count == 0)
            {
                return;
            }

            UnityEngine.Camera stackCamera = _cameraStack.Pop();
            Object.Destroy(stackCamera.gameObject);

            if (_cameraStack.Count > 0)
            {
                UnityEngine.Camera camera = _cameraStack.Peek();
                camera.enabled = true;
                camera.GetComponent <AudioListener>().enabled = _audioEnabled;
            }
        }
Exemple #11
0
        public void Execute(Camera cam, Vector3 targetPos, Vector3 targetLookat)
        {
            // Lerp and somesuch
            Vector3 oldPos = cam.transform.position;
            //Vector3 oldLookat = cam.transform.forward;


            Vector3 cameraOffset = cam.GetComponent<CameraController>().CameraOffset;

            Vector3 newPos = Vector3.Lerp(oldPos, targetLookat + cameraOffset, .1f); // hard coded .1f
            Vector3 newTarget = Vector3.Lerp(previousLookat, targetLookat, .1f);

            cam.transform.position = newPos;
            cam.transform.LookAt(newTarget);

            previousLookat = newTarget;

        }
Exemple #12
0
        /// <summary>
        /// Configure the mini camera for use
        /// </summary>
        private void InitMiniCamera()
        {
            try
            {
                miniCamera = Instantiate(UnityEngine.Camera.main, miniCameraView.transform); // Clone main camera
                foreach (Transform child in miniCamera.transform)
                {
                    Destroy(child.gameObject);
                }

                Destroy(miniCamera.GetComponent <DynamicCamera>()); // Shouldn't handle it's own position, so copy from main camera instead
            }
            catch (Exception)
            {
                miniCamera = null;
                throw;
            }
        }
    private void OnCollisionEnter(Collision land)
    {
        if (land.gameObject.tag == "overworld")
        {
            onOverWorld     = true;
            camera1.enabled = true;
            camera1.GetComponent <AudioListener>();
            camera2.enabled = false;
        }

        else

        {
            onOverWorld     = false;
            camera1.enabled = false;
            camera2.enabled = true;
        }
    }
 /**
  * Creates a new orthographic camera
  * <p>
  * Notice that you must 'enable' this camera by setting
  * 'Active' to true, and 'Audio' to true if you want it to
  * be the primary audio listener.
  * <p>
  * The camera is placed at (0, 0, -1) looking down the Z-axis.
  * <p>
  * There MUST be a camera on the scene already to be able create
  * this type of camera, and it inherits all the properties of the
  * main camera; although some of them are reset.
  */
 public nCamera(double height)
 {
     var original = GameObject.FindWithTag("MainCamera");
       _cam = (Camera) UnityEngine.Camera.Instantiate(
     original.camera,
     new Vector3(0, 0, -1),
     Quaternion.FromToRotation(
       new Vector3(0, 0, 0),
       new Vector3(0, 0, 1)
     )
       );
       _cam.orthographicSize = (float) height / 2;
       _cam.orthographic = true;
       _cam.backgroundColor = Color.black;
       _cam.depth = 0;
       _cam.enabled = false;
       _cam.GetComponent<AudioListener>().enabled = false;
       original.camera.enabled = false;
 }
        private void DrawCameraStage()
        {
            EditorGUILayout.LabelField("Camera", EditorStyles.boldLabel);
            EditorWindowTools.StartIndentedSection();
            UnityEngine.Camera     playerCamera = pcObject.GetComponentInChildren <UnityEngine.Camera>() ?? UnityEngine.Camera.main;
            SmoothCameraWithBumper smoothCamera = (playerCamera != null) ? playerCamera.GetComponent <SmoothCameraWithBumper>() : null;

            EditorGUILayout.BeginHorizontal();
            bool useSmoothCamera = EditorGUILayout.Toggle((smoothCamera != null), GUILayout.Width(ToggleWidth));

            EditorGUILayout.LabelField("Use Smooth Follow Camera", EditorStyles.boldLabel);
            EditorGUILayout.EndHorizontal();
            if (useSmoothCamera)
            {
                if (playerCamera == null)
                {
                    GameObject playerCameraObject = new GameObject("Player Camera");
                    playerCameraObject.transform.parent = pcObject.transform;
                    playerCamera     = playerCameraObject.AddComponent <UnityEngine.Camera>();
                    playerCamera.tag = "MainCamera";
                }
                smoothCamera = playerCamera.GetComponentInChildren <SmoothCameraWithBumper>() ?? playerCamera.gameObject.AddComponent <SmoothCameraWithBumper>();
                EditorWindowTools.StartIndentedSection();
                if (smoothCamera.target == null)
                {
                    EditorGUILayout.HelpBox("Specify the transform (usually the head) that the camera should follow.", MessageType.Info);
                }
                smoothCamera.target = EditorGUILayout.ObjectField("Target", smoothCamera.target, typeof(Transform), true) as Transform;
                EditorWindowTools.EndIndentedSection();
            }
            else
            {
                DestroyImmediate(smoothCamera);
            }
            if (GUILayout.Button("Select Camera", GUILayout.Width(100)))
            {
                Selection.activeObject = playerCamera;
            }
            EditorWindowTools.EndIndentedSection();
            DrawNavigationButtons(true, true, false);
        }
        // Update is called once per frame
        private void Update()
        {
            NodeLock.WaitLockEdit();

            ProcessPendingUpdates();

            // Transfer camera parameters

            PerspCamera perspCamera = _native_camera as PerspCamera;

            if (perspCamera != null)
            {
                perspCamera.VerticalFOV   = UnityCamera.fieldOfView;
                perspCamera.HorizontalFOV = 2 * Mathf.Atan(Mathf.Tan(UnityCamera.fieldOfView * Mathf.Deg2Rad / 2) * UnityCamera.aspect) * Mathf.Rad2Deg;;
                perspCamera.NearClipPlane = UnityCamera.nearClipPlane;
                perspCamera.FarClipPlane  = UnityCamera.farClipPlane;
            }

            Matrix4x4 unity_camera_transform = UnityCamera.transform.worldToLocalMatrix;

            Matrix4x4 gz_transform = _zflipMatrix * unity_camera_transform * _zflipMatrix;

            _native_camera.Transform = gz_transform.ToMatrix4();

            IWorldCoord ctrl = UnityCamera.GetComponent <IWorldCoord>();

            if (ctrl != null)
            {
                _native_camera.Position = ctrl.Position;
            }

            NodeLock.UnLock();

            NodeLock.WaitLockRender();
            _native_camera.Render(_native_context, 1000, 1000, 1000, _native_traverse_action);
            //native_camera.DebugRefresh();
            NodeLock.UnLock();
        }
Exemple #17
0
        protected void UpdateCameraModes(Camera src, Camera dest)
        {
            if (!dest)
            return;

            //set portal camera to act like the current camera

            // This doesn't fully work in all Unity versions work for some reason (I haven't had a good reason to figure out why, either)
            // So we'll start with that, and then make sure things actually work.
            dest.CopyFrom(src);

            //NB: Render to the full frame, irrespective of what the source camera does:
            dest.rect = new Rect(0, 0, 1, 1);

            dest.clearFlags = src.clearFlags;
            dest.backgroundColor = src.backgroundColor;
            if (src.clearFlags == CameraClearFlags.Skybox) {
            Skybox sky = src.GetComponent<Skybox>();
            Skybox mysky = dest.GetComponent<Skybox>();
            if (!sky || !sky.material) {
                mysky.enabled = false;
            } else {
                mysky.enabled = true;
                mysky.material = sky.material;
            }
            }

            // update other values to match current camera.
            // even if we are supplying custom camera & projection matrices,
            // some of values are used elsewhere (e.g. sky box uses far plane)
            dest.farClipPlane = src.farClipPlane;
            dest.nearClipPlane = src.nearClipPlane;
            dest.orthographic = src.orthographic;
            dest.fieldOfView = src.fieldOfView;
            dest.aspect = src.aspect;
            dest.orthographicSize = src.orthographicSize;
        }
        public static void ApplyConfig(Camera cam, Profile prof)
        {
            if(cam==null) { return; }

            var ssao = cam.GetComponent<UnityStandardAssets.ImageEffects.ScreenSpaceAmbientOcclusion>();
            if(ssao!=null)
            {
                switch(prof)
                {
                    case Profile.Fastest:
                        ssao.enabled = false;
                        break;
                    case Profile.Fast:
                        ssao.enabled = true;
                        ssao.m_SampleCount = UnityStandardAssets.ImageEffects.ScreenSpaceAmbientOcclusion.SSAOSamples.Low;
                        ssao.m_Downsampling = 4;
                        break;
                    case Profile.Medium:
                        ssao.enabled = true;
                        ssao.m_SampleCount = UnityStandardAssets.ImageEffects.ScreenSpaceAmbientOcclusion.SSAOSamples.Low;
                        ssao.m_Downsampling = 2;
                        break;
                    case Profile.High:
                        ssao.enabled = true;
                        ssao.m_SampleCount = UnityStandardAssets.ImageEffects.ScreenSpaceAmbientOcclusion.SSAOSamples.Medium;
                        ssao.m_Downsampling = 2;
                        break;
                    case Profile.VeryHigh:
                        ssao.enabled = true;
                        ssao.m_SampleCount = UnityStandardAssets.ImageEffects.ScreenSpaceAmbientOcclusion.SSAOSamples.High;
                        ssao.m_Downsampling = 2;
                        break;
                }
            }

            var ssr = cam.GetComponent<ScreenSpaceReflections>();
            if (ssr != null)
            {
                switch (prof)
                {
                    case Profile.Fastest:
                    case Profile.Fast:
                        ssr.enabled = false;
                        break;
                    case Profile.Medium:
                        ssr.enabled = true;
                        ssr.m_sample_count = ScreenSpaceReflections.SampleCount.Low;
                        ssr.m_downsampling = 2;
                        break;
                    case Profile.High:
                        ssr.enabled = true;
                        ssr.m_sample_count = ScreenSpaceReflections.SampleCount.Medium;
                        ssr.m_downsampling = 2;
                        break;
                    case Profile.VeryHigh:
                        ssr.enabled = true;
                        ssr.m_sample_count = ScreenSpaceReflections.SampleCount.High;
                        ssr.m_downsampling = 2;
                        break;
                }
            }

            var bloom = cam.GetComponent<UnityStandardAssets.ImageEffects.Bloom>();
            if (bloom != null)
            {
                switch (prof)
                {
                    case Profile.Fastest:
                    case Profile.Fast:
                        bloom.enabled = true;
                        bloom.quality = UnityStandardAssets.ImageEffects.Bloom.BloomQuality.Cheap;
                        break;
                    case Profile.Medium:
                    case Profile.High:
                    case Profile.VeryHigh:
                        bloom.enabled = true;
                        bloom.quality = UnityStandardAssets.ImageEffects.Bloom.BloomQuality.High;
                        break;
                }
            }

            var dof = cam.GetComponent<UnityStandardAssets.ImageEffects.DepthOfField>();
            if (dof != null)
            {
                switch (prof)
                {
                    case Profile.Fastest:
                    case Profile.Fast:
                    case Profile.Medium:
                        dof.enabled = false;
                        break;
                    case Profile.High:
                    case Profile.VeryHigh:
                        dof.enabled = true;
                        break;
                }
            }
        }
Exemple #19
0
 void UpdateCameraModes(Camera src, Camera dest)
 {
     if (dest == null)
     {
         return;
     }
     // set water camera to clear the same way as current camera
     dest.clearFlags = src.clearFlags;
     dest.backgroundColor = src.backgroundColor;
     if (src.clearFlags == CameraClearFlags.Skybox)
     {
         Skybox sky = src.GetComponent<Skybox>();
         Skybox mysky = dest.GetComponent<Skybox>();
         if (!sky || !sky.material)
         {
             mysky.enabled = false;
         }
         else
         {
             mysky.enabled = true;
             mysky.material = sky.material;
         }
     }
     // update other values to match current camera.
     // even if we are supplying custom camera&projection matrices,
     // some of values are used elsewhere (e.g. skybox uses far plane)
     dest.farClipPlane = src.farClipPlane;
     dest.nearClipPlane = src.nearClipPlane;
     dest.orthographic = src.orthographic;
     dest.fieldOfView = src.fieldOfView;
     dest.aspect = src.aspect;
     dest.orthographicSize = src.orthographicSize;
 }
Exemple #20
0
        /// <summary>
        /// Remove all the post processes from the scene camera
        /// </summary>
        private void CleanSceneCamera(Camera sceneCamera)
        {
            if(sceneCamera == null) return;

            CleanMissingPostEffects(sceneCamera);

            foreach(Component postEffect in PostEffects)
            {
                if(postEffect == null) continue;

                Type effectType = postEffect.GetType();
                Component cameraComponent = sceneCamera.GetComponent(effectType);

                if(Utilities.IsForbiddenComponent(sceneCamera, cameraComponent)) continue;

                DestroyImmediate(cameraComponent);
            }
        }
        // Use this for initialization
        void Start()
        {
            //initialize the player character
            Vector3 charPos = new Vector3(25.5f, -1.8f, 2.0f);
            characters.Add((GameObject)Instantiate(Character, charPos, Quaternion.identity));

            //set camera to follow the Camera Target
            Vector3 camPos = new Vector3(25.5f, -1.8f, 0.0f);
            cameraTargets.Add((GameObject)Instantiate(CamTarget, camPos, Quaternion.identity));

            Transform targetTransform = cameraTargets[0].transform;
            mainCam = Camera.allCameras[0];
            mainCam.GetComponent<SmoothFollow>().target = targetTransform;

            //Find the light
            light = GameObject.Find("Directional Light");

            //initialize the front wall
            Vector3 wallPos = mainCam.ViewportToWorldPoint(new Vector3(1.0f, 0.0f, 0.0f));
            wallPos.z = 2.0f; // resets to platform Z
            wallPos.y = -3.0f; // brings wall to ground
            wallPos.x *= 1.6f; // moves wall half of screen width away from camera
            frontWalls.Add((GameObject)Instantiate(FrontWall, wallPos, Quaternion.identity));
            frontWalls[0].transform.Rotate(0.0f, 0.0f, 90.0f);

            //initialize the kill zone
            Vector3 killZonePos = mainCam.ScreenToViewportPoint(new Vector3(0.0f, 0.0f, 2.0f));
            killZonePos.x += 7.0f; // move slightly right from current lock location
            KillZones.Add((GameObject)Instantiate(KillZone, killZonePos, Quaternion.identity));
            killZones[0].transform.Rotate(0.0f, 0.0f, 90.0f);

            // create bottom killzone
            Vector3 underworld = new Vector3(0.0f, -11.5f, 2.0f);
            killZones.Add((GameObject)Instantiate(KillZone, underworld, Quaternion.identity));

            // create knife
            knifeSpawn = new Vector3(killZonePos.x, killZonePos.y, killZonePos.z);
            knifeSpawn.x += 2.0f; // move slightly right from current lock location
            knife = (GameObject)Instantiate(Knife, knifeSpawn, Quaternion.identity);
            knife.transform.localScale = new Vector3(0.6f, 0.6f, 0.6f);
            thrown = false;

            // create chef
            chefSpawn = new Vector3(killZonePos.x, killZonePos.y, killZonePos.z);
            chefSpawn.x += 2.0f; // move slightly right from current lock location
            Chef = (GameObject)Instantiate(Chef, chefSpawn, Quaternion.identity);
            chefOnScreen = false;
            chefMovingOut = false;

            mainCam.aspect = (1920f / 910f);

            //initialize the game fragments
            for (int i = 0; i < numFrags; i++)
            {
                Vector3 fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                //make the first two fragments flat
                if (i == 0 || i == 1) fragments.Add((GameObject)Instantiate(GameFragments[0], fragPos, Quaternion.identity));
                else
                {
                    float fragType = Random.Range(0.0f, (float)GameFragments.Count);
                    if (fragType >= 0 && fragType < 1)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[0], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 1 && fragType < 2)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[1], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 2 && fragType < 3)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[2], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 3 && fragType < 4)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[3], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 4 && fragType < 5)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[4], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 5 && fragType < 6)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[5], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 6 && fragType < 7)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[6], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 7 && fragType < 8)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[7], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 8 && fragType < 9)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[8], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 9 && fragType <= 10)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[9], fragPos, Quaternion.identity));
                    }
                }
            }
        }
        public void RenderBlob(Camera blobCam, BlobSizeComputation ComputeBlobSize, float falloff, float blurFactor, float textureSize)
        {
            // Resize blob, remember to counter root scale
            Vector2 blobSize = ComputeBlobSize(ModelBounds);
            Vector3 rootScale = transform.localScale;
            BlobRenderer.transform.localScale = new Vector3(blobSize.x / rootScale.x, 1.0f / rootScale.y, blobSize.y / rootScale.z);

            // Resize blob texture
            int width, height; float textureDownScale;
            CalcTextureSize(blobSize, textureSize, out width, out height, out textureDownScale);
            if (BlobShadow == null || BlobShadow.width != width || BlobShadow.height != height) {
            if (BlobShadow != null) Texture2D.DestroyImmediate(BlobShadow);
            BlobShadow = new Texture2D(width, height);
            BlobShadow.filterMode = FilterMode.Trilinear;
            BlobShadow.hideFlags = HideFlags.HideInInspector | HideFlags.DontSave;
            BlobRenderer.sharedMaterial.mainTexture = BlobShadow;
            }

            // Setup blob camera
            RenderTexture targetTex = blobCam.targetTexture;
            Vector2 blobTexScale = new Vector2((float)targetTex.width / (float)BlobShadow.width,
                                           (float)targetTex.height / (float)BlobShadow.height);

            // Magic! Can't remember whats gaoing on here anymore. The margin start
            // copmutes the distance to where the margin should start (I think!) but
            // I've no idea what margin end is. An inverse lerp is used in the
            // shader to compute the intensity.
            Vector2 marginEnd =
            new Vector2(1.0f - (float)(targetTex.width  - BlobShadow.width)  / (float)targetTex.width,
                        1.0f - (float)(targetTex.height - BlobShadow.height) / (float)targetTex.height);

            Vector2 marginStart = blobCam.GetComponent<BlobBlur>().MarginStart =
            new Vector2(marginEnd.x / blobSize.x * ModelBounds.size.x,
                        marginEnd.y / blobSize.y * ModelBounds.size.z);

            blobCam.GetComponent<BlobBlur>().MarginEnd = new Vector2(Mathf.Max(marginEnd.x, marginStart.x),
                                                                 Mathf.Max(marginEnd.y, marginStart.y));

            // Place camera so it can see the model
            blobCam.transform.position = new Vector3(ModelBounds.center.x, ModelBounds.min.y - 0.01f * ModelBounds.size.y, ModelBounds.center.z);
            blobCam.orthographicSize = blobSize.y * 0.5f * blobTexScale.y;
            blobCam.aspect = 1.0f;

            // Convert texture size to mipmap max offset.
            // If the texture size had to be scaled due to originally exceeding 4096 pixels,
            // the scale is also applied to the texture size to keep the shadow relatively consistent.
            float modelSize = textureSize * Mathf.Max(ModelBounds.size.x, ModelBounds.size.z);
            blobCam.GetComponent<BlobBlur>().MipOffset = Mathf.Log(blurFactor * modelSize * textureDownScale, 2.0f);

            // Render blob
            Shader.SetGlobalFloat("_BlobFalloffExponent", falloff);
            blobCam.Render();

            // Copy from target tex to BlobShadow
            RenderTexture oldActive = RenderTexture.active;
            RenderTexture.active = targetTex;
            BlobShadow.ReadPixels(new Rect((targetTex.width - BlobShadow.width) / 2, (targetTex.height - BlobShadow.height) / 2,
                                       BlobShadow.width, BlobShadow.height), 0, 0);
            BlobShadow.Apply();
            RenderTexture.active = oldActive;
        }
Exemple #23
0
        public void setUp(Actions             actions,
							  MouseLook           mouseLook,
							  FOVKick             fovKick,
							  CurveControlledBob  headBob,
							  LerpControlledBob   jumpBob,
							  AttackController    attackController)
        {
            this.actions=actions;
                this.mouseLook=mouseLook;
                this.fovKick=fovKick;
                this.headBob=headBob;
                this.jumpBob=jumpBob;
                this.attackController=attackController;

                this.mainCameraObject    = SingletonNames.getMainCamera();
                this.playerObject        = SingletonNames.getPlayer();
                this.audioSource         = playerObject.gameObject.AddComponent<AudioSource>();
                this.audioData           = playerObject.GetComponent<MovementAudioData>();
                this.characterController = playerObject.GetComponent<CharacterController>();

                objectsSelector = mainCameraObject.GetComponent<ObjectsSelector>();

                originalCameraPosition = mainCameraObject.transform.localPosition;

                fovKick.Setup(mainCameraObject);
                headBob.Setup(mainCameraObject, stepInterval);
                mouseLook.Init(playerObject.transform, mainCameraObject.transform);

                stepCycle = 0f;
                nextStep = stepCycle / 2f;
                isJumping = false;
        }
 /**
  * <summary>Checks if a supplied Camera has the vp_FPCamera component attached.</summary>
  * <returns>Checks if a supplied Camera has the vp_FPCamera component attached.</returns>
  */
 public static bool IsUFPSCamera(Camera camera)
 {
     #if UltimateFPSIsPresent
     if (camera != null && camera.GetComponent <vp_FPCamera>())
     {
         return true;
     }
     #endif
     return false;
 }
Exemple #25
0
        internal void Init()
        {
            teacherInputsRemaining = 4;
                studentInputsRemaining = 5;
                maxInputs = 4;
                roundWins = 0;
                currentState = GameStates.START;
                ArrayList teacherPicks = new ArrayList();
                ArrayList studentPicks = new ArrayList();
                simonSaysSpotlight = GameObject.Find("SimonSaysLight");
                simonRedGameLight = GameObject.Find("SimonSaysLightRed");
                simonBlueGameLight = GameObject.Find("SimonSaysLightBlue");
                simonYellowGameLight = GameObject.Find("SimonSaysLightYellow");
                simonGreenGameLight = GameObject.Find("SimonSaysLightGreen");
                texts = GameObject.Find ("texts");
                tsquare = GameObject.Find ("tsquare");
                facebook = GameObject.Find ("facebook");
                studentCamera = GameObject.Find ("Student Camera").GetComponent<Camera>() as Camera;
                pinkEle = GameObject.Find ("PinkElephant");
                teacherTextNumbers = GameObject.Find("teacherInputsRemaining").GetComponent<TextMesh>();
                teacherNotifications = GameObject.Find("teacherNotifications").GetComponent<TextMesh>();
                studentNotifications = GameObject.Find("studentNotifications").GetComponent<TextMesh>();
                success = GameObject.Find("successNotification").GetComponent<TextMesh>();
                failure = GameObject.Find("failureNotification").GetComponent<TextMesh>();
                texts.SetActive(false);
                tsquare.SetActive(false);
                facebook.SetActive(false);
                s = studentCamera.GetComponent<sleep>();
                d = studentCamera.GetComponent<dream>();
                txts = texts.GetComponent<drift>();
                t2 = tsquare.GetComponent<drift>();
                fb = facebook.GetComponent<drift>();
                roundNum = 1;
                teacherSelections = new ArrayList();
                studentSelections = new ArrayList();
                redScreen = GameObject.Find("redScreen");
                redScreen.SetActive(false);
                greenScreen = GameObject.Find("greenScreen");
                greenScreen.SetActive(false);
                yellowScreen = GameObject.Find("yellowScreen");
                yellowScreen.SetActive(false);
                blueScreen = GameObject.Find("blueScreen");
                blueScreen.SetActive(false);
                //pinkEle.SetActive(false);

                startCam = GameObject.Find("StartCamera");
                switchScript = startCam.GetComponent<CameraSwitch>();

                /*Erin*/
                //startCam = GameObject.Find ("StartCamera").GetComponent<Camera>() as Camera;
                //endCam = GameObject.Find ("EndCamera").GetComponent<Camera>() as Camera;

                //snapeSound = GameObject.Find ("snapeSound");
                //peanutsSound = GameObject.Find ("peanutsSound");
                //anyoneSound = GameObject.Find ("anyoneSound");

                //startCam.enabled = true;
                //endCam.enabled = false;
                //studentCamera.enabled = false;
                //startCam.gameObject.camera.enabled = true;
                //endCam.gameObject.camera.enabled = false;
                //studentCamera.gameObject.camera.enabled = false;

                //snapeSound.gameObject.audio.enabled = false;
                //peanutsSound.gameObject.audio.enabled = false;
                //anyoneSound.gameObject.audio.enabled = true;
                /*Erin*/
        }
        protected override IEnumerator workerMethod()
        {
			var textureMerge = umaGenerator.textureMerge;
			for (int atlasIndex = umaData.generatedMaterials.materials.Count-1; atlasIndex >= 0; atlasIndex--)
            {
                var atlas = umaData.generatedMaterials.materials[atlasIndex];

                //Rendering Atlas
                int moduleCount = 0;

                //Process all necessary TextureModules
                for (int i = 0; i < atlas.materialFragments.Count; i++)
                {
                    if (!atlas.materialFragments[i].isRectShared)
                    {
                        moduleCount++;
                        moduleCount = moduleCount + atlas.materialFragments[i].overlays.Length;
                    }
                }
				textureMerge.EnsureCapacity(moduleCount);

                var slotData = atlas.materialFragments[0].slotData;
				resultingTextures = new Texture[slotData.asset.material.channels.Length];
				for (int textureType = slotData.asset.material.channels.Length - 1; textureType >= 0; textureType--)
                {
					switch(slotData.asset.material.channels[textureType].channelType )
					{
						case UMAMaterial.ChannelType.Texture:
						case UMAMaterial.ChannelType.NormalMap:
						{
							textureMerge.Reset();
							for (int i = 0; i < atlas.materialFragments.Count; i++)
							{
								textureMerge.SetupModule(atlas, i, textureType);
							}

							//last element for this textureType
							moduleCount = 0;

							umaGenerator.textureMerge.gameObject.SetActive(true);

							int width = Mathf.FloorToInt(atlas.cropResolution.x);
							int height = Mathf.FloorToInt(atlas.cropResolution.y);
							destinationTexture = new RenderTexture(Mathf.FloorToInt(atlas.cropResolution.x * umaData.atlasResolutionScale), Mathf.FloorToInt(atlas.cropResolution.y * umaData.atlasResolutionScale), 0, slotData.asset.material.channels[textureType].textureFormat, RenderTextureReadWrite.Linear);
							destinationTexture.filterMode = FilterMode.Point;
							destinationTexture.useMipMap = umaGenerator.convertMipMaps && !umaGenerator.convertRenderTexture;
							renderCamera = umaGenerator.textureMerge.myCamera;
							renderCamera.targetTexture = destinationTexture;
							renderCamera.orthographicSize = height >> 1;
							var camTransform = renderCamera.GetComponent<Transform>();
							camTransform.localPosition = new Vector3(width >> 1, height >> 1, 3);
							camTransform.localRotation = Quaternion.Euler(0, 180, 180);
							renderCamera.Render();
							renderCamera.gameObject.SetActive(false);
							renderCamera.targetTexture = null;

							if (umaGenerator.convertRenderTexture)
							{
								#region Convert Render Textures
								yield return 25;
								Texture2D tempTexture;
								tempTexture = new Texture2D(destinationTexture.width, destinationTexture.height, TextureFormat.ARGB32, umaGenerator.convertMipMaps);
								int xblocks = destinationTexture.width / 512;
								int yblocks = destinationTexture.height / 512;
								if (xblocks == 0 || yblocks == 0)
								{
									RenderTexture.active = destinationTexture;
									tempTexture.ReadPixels(new Rect(0, 0, destinationTexture.width, destinationTexture.height), 0, 0, umaGenerator.convertMipMaps);
									RenderTexture.active = null;
								}
								else
								{
									// figures that ReadPixels works differently on OpenGL and DirectX, someday this code will break because Unity fixes this bug!
									if (IsOpenGL())
									{
										for (int x = 0; x < xblocks; x++)
										{
											for (int y = 0; y < yblocks; y++)
											{
												RenderTexture.active = destinationTexture;
												tempTexture.ReadPixels(new Rect(x * 512, y * 512, 512, 512), x * 512, y * 512, umaGenerator.convertMipMaps);
												RenderTexture.active = null;
												yield return 8;
											}
										}
									}
									else
									{
										for (int x = 0; x < xblocks; x++)
										{
											for (int y = 0; y < yblocks; y++)
											{
												RenderTexture.active = destinationTexture;
												tempTexture.ReadPixels(new Rect(x * 512, destinationTexture.height - 512 - y * 512, 512, 512), x * 512, y * 512, umaGenerator.convertMipMaps);
												RenderTexture.active = null;
												yield return 8;
											}
										}
									}
								}
								resultingTextures[textureType] = tempTexture as Texture;

								renderCamera.targetTexture = null;
								RenderTexture.active = null;

								destinationTexture.Release();
								UnityEngine.GameObject.DestroyImmediate(destinationTexture);
								umaGenerator.textureMerge.gameObject.SetActive(false);
								yield return 6;
								tempTexture = resultingTextures[textureType] as Texture2D;
								tempTexture.Apply();
								tempTexture.wrapMode = TextureWrapMode.Repeat;
								tempTexture.filterMode = FilterMode.Bilinear;
								resultingTextures[textureType] = tempTexture;
								atlas.material.SetTexture(slotData.asset.material.channels[textureType].materialPropertyName, tempTexture);
							#endregion
							}
							else
							{
								destinationTexture.filterMode = FilterMode.Bilinear;
								destinationTexture.wrapMode = TextureWrapMode.Repeat;
								resultingTextures[textureType] = destinationTexture;
								atlas.material.SetTexture(slotData.asset.material.channels[textureType].materialPropertyName, destinationTexture);
							}
							umaGenerator.textureMerge.gameObject.SetActive(false);
							break;
						}
						case UMAMaterial.ChannelType.MaterialColor:
						{
							atlas.material.SetColor(slotData.asset.material.channels[textureType].materialPropertyName, atlas.materialFragments[0].baseColor);
							break;
						}
						case UMAMaterial.ChannelType.TintedTexture:
						{
							for (int i = 0; i < atlas.materialFragments.Count; i++)
							{
								var fragment = atlas.materialFragments[i];
								if (fragment.isRectShared) continue;
								for (int j = 0; j < fragment.baseTexture.Length; j++)
								{
									if (fragment.baseTexture[j] != null)
									{
										atlas.material.SetTexture(slotData.asset.material.channels[j].materialPropertyName, fragment.baseTexture[j]);
										if (j == 0)
										{
											atlas.material.color = fragment.baseColor;
										}
									}
								}
								foreach (var overlay in fragment.overlays)
								{
									for (int j = 0; j < overlay.textureList.Length; j++)
									{
										if (overlay.textureList[j] != null)
										{
											atlas.material.SetTexture(slotData.asset.material.channels[j].materialPropertyName, overlay.textureList[j]);
										}
									}
								}
							}
							break;
						}
					}
                }
                atlas.resultingAtlasList = resultingTextures;
            }
        }
Exemple #27
0
        /// <summary>
        /// Finds the camera data for this camera.
        /// If no data exists then create new data
        /// object and return it.
        /// </summary>
		public CameraData FindCameraData(Camera cam)
		{

            if (cam == null)
                throw new InvalidOperationException("Can not find camera data for null camera");

            if (!m_cameraData.ContainsKey(cam))
                m_cameraData.Add(cam, new CameraData());

            CameraData data = m_cameraData[cam];

            data.settings = cam.GetComponent<OceanCameraSettings>();

            return data;
		}
        void RenderReflectionFor(Camera cam, Camera reflectCamera)
        {
            if (!reflectCamera)
            {
                return;
            }

            if (m_SharedMaterial && !m_SharedMaterial.HasProperty(reflectionSampler))
            {
                return;
            }

            reflectCamera.cullingMask = reflectionMask & ~(1 << LayerMask.NameToLayer("Water"));

            SaneCameraSettings(reflectCamera);

            reflectCamera.backgroundColor = clearColor;
            reflectCamera.clearFlags = reflectSkybox ? CameraClearFlags.Skybox : CameraClearFlags.SolidColor;
            if (reflectSkybox)
            {
                if (cam.gameObject.GetComponent(typeof(Skybox)))
                {
                    Skybox sb = (Skybox)reflectCamera.gameObject.GetComponent(typeof(Skybox));
                    if (!sb)
                    {
                        sb = (Skybox)reflectCamera.gameObject.AddComponent(typeof(Skybox));
                    }
                    sb.material = ((Skybox)cam.GetComponent(typeof(Skybox))).material;
                }
            }

            GL.invertCulling = true;

            Transform reflectiveSurface = transform; //waterHeight;

            Vector3 eulerA = cam.transform.eulerAngles;

            reflectCamera.transform.eulerAngles = new Vector3(-eulerA.x, eulerA.y, eulerA.z);
            reflectCamera.transform.position = cam.transform.position;

            Vector3 pos = reflectiveSurface.transform.position;
            pos.y = reflectiveSurface.position.y;
            Vector3 normal = reflectiveSurface.transform.up;
            float d = -Vector3.Dot(normal, pos) - clipPlaneOffset;
            Vector4 reflectionPlane = new Vector4(normal.x, normal.y, normal.z, d);

            Matrix4x4 reflection = Matrix4x4.zero;
            reflection = CalculateReflectionMatrix(reflection, reflectionPlane);
            m_Oldpos = cam.transform.position;
            Vector3 newpos = reflection.MultiplyPoint(m_Oldpos);

            reflectCamera.worldToCameraMatrix = cam.worldToCameraMatrix * reflection;

            Vector4 clipPlane = CameraSpacePlane(reflectCamera, pos, normal, 1.0f);

            Matrix4x4 projection = cam.projectionMatrix;
            projection = CalculateObliqueMatrix(projection, clipPlane);
            reflectCamera.projectionMatrix = projection;

            reflectCamera.transform.position = newpos;
            Vector3 euler = cam.transform.eulerAngles;
            reflectCamera.transform.eulerAngles = new Vector3(-euler.x, euler.y, euler.z);

            reflectCamera.Render();

            GL.invertCulling = false;
        }
Exemple #29
0
		/// <summary>
		/// Called after the camera renders the ocean.
		/// </summary>
		void OceanOnPostRender(Camera cam)
		{

			if(cam.GetComponent<IgnoreOceanEvents>() != null) return;

            CameraData data = FindCameraData(cam);

			if(Grid != null)
				Grid.OceanOnPostRender(cam, data);
			
			if(Spectrum != null)
				Spectrum.OceanOnPostRender(cam, data);
			
			if(Reflection != null)
				Reflection.OceanOnPostRender(cam, data);
			
			if(UnderWater != null)
				UnderWater.OceanOnPostRender(cam, data);
		}
        private void UpdateCameraModes( Camera src, Camera dest )
        {
            if( dest == null )
                return;
            // set camera to clear the same way as current camera
            CameraClearFlags clearFlags = CameraClearFlags.Skybox;
            dest.clearFlags = clearFlags;
            dest.backgroundColor = src.backgroundColor;
            if( clearFlags == CameraClearFlags.Skybox )
            {
                Skybox sky = src.GetComponent(typeof(Skybox)) as Skybox;
                Skybox mysky = dest.GetComponent(typeof(Skybox)) as Skybox;
                if( !sky || !sky.material )
                {
                    mysky.enabled = false;
                }
                else
                {
                    mysky.enabled = true;
                    mysky.material = sky.material;
                }
            }
            // update other values to match current camera.
            // even if we are supplying custom camera&projection matrices,
            // some of values are used elsewhere (e.g. skybox uses far plane)

            // get near clipping plane from main camera
            dest.renderingPath = src.renderingPath;

            dest.farClipPlane = src.farClipPlane;

            dest.nearClipPlane = 0.03f; //src.nearClipPlane;
            dest.orthographic = src.orthographic;
            dest.fieldOfView = src.fieldOfView;
            dest.aspect = src.aspect;
            dest.orthographicSize = src.orthographicSize;
        }
        void Awake()
        {
            playerEnterExit = GetComponent<PlayerEnterExit>();
            if (!playerEnterExit)
                throw new Exception("PlayerEnterExit not found.");

            playerCamera = GetComponentInChildren<Camera>();
            if (!playerCamera)
                throw new Exception("Player Camera not found.");

            playerMouseLook = playerCamera.GetComponent<PlayerMouseLook>();
            if (!playerMouseLook)
                throw new Exception("PlayerMouseLook not found.");

            playerMotor = GetComponent<PlayerMotor>();
            if (!playerMotor)
                throw new Exception("PlayerMotor not found.");

            playerEntityBehaviour = GetComponent<DaggerfallEntityBehaviour>();
            if (!playerEntityBehaviour)
                throw new Exception("PlayerEntityBehaviour not found.");

            SaveLoadManager.RegisterSerializableGameObject(this);
        }