Example #1
0
 private void Awake()
 {
     if (Object.op_Equality((Object)this.m_target, (Object)null))
     {
         this.m_target = ((Component)Camera.get_main()).get_gameObject();
     }
     try
     {
         if (Object.op_Inequality((Object)this.m_postFX, (Object)null))
         {
             Camera camera = Camera.get_main();
             if (Object.op_Equality((Object)camera, (Object)null))
             {
                 camera = (Camera)Object.FindObjectOfType <Camera>();
             }
             if (Object.op_Inequality((Object)camera, (Object)null))
             {
                 Type type = CTSDemoController.GetType("UnityEngine.PostProcessing.PostProcessingBehaviour");
                 if (type != (Type)null)
                 {
                     GameObject gameObject = ((Component)camera).get_gameObject();
                     this.m_postProcessingComponent = gameObject.GetComponent(type);
                     if (Object.op_Equality((Object)this.m_postProcessingComponent, (Object)null))
                     {
                         this.m_postProcessingComponent = gameObject.AddComponent(type);
                     }
                     if (Object.op_Inequality((Object)this.m_postProcessingComponent, (Object)null))
                     {
                         FieldInfo field = type.GetField("profile", BindingFlags.Instance | BindingFlags.Public);
                         if (field != (FieldInfo)null)
                         {
                             field.SetValue((object)this.m_postProcessingComponent, (object)this.m_postFX);
                         }
                         ((Behaviour)this.m_postProcessingComponent).set_enabled(false);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Debug.Log((object)"Failed to set up post fx.");
     }
     if (Object.op_Equality((Object)this.m_flyController, (Object)null))
     {
         this.m_flyController = (CTSFly)this.m_target.GetComponent <CTSFly>();
     }
     if (Object.op_Equality((Object)this.m_flyController, (Object)null))
     {
         this.m_flyController = (CTSFly)this.m_target.AddComponent <CTSFly>();
     }
     ((Behaviour)this.m_flyController).set_enabled(false);
     if (Object.op_Equality((Object)this.m_characterController, (Object)null))
     {
         this.m_characterController = (CharacterController)this.m_target.GetComponent <CharacterController>();
     }
     if (Object.op_Equality((Object)this.m_characterController, (Object)null))
     {
         this.m_characterController = (CharacterController)this.m_target.AddComponent <CharacterController>();
         this.m_characterController.set_height(4f);
     }
     ((Collider)this.m_characterController).set_enabled(false);
     if (Object.op_Equality((Object)this.m_walkController, (Object)null))
     {
         this.m_walkController = (CTSWalk)this.m_target.GetComponent <CTSWalk>();
     }
     if (Object.op_Equality((Object)this.m_walkController, (Object)null))
     {
         this.m_walkController = (CTSWalk)this.m_target.AddComponent <CTSWalk>();
         this.m_walkController.m_controller = this.m_characterController;
     }
     ((Behaviour)this.m_walkController).set_enabled(false);
     if (Object.op_Equality((Object)this.m_lookController, (Object)null))
     {
         this.m_lookController = (CTSLook)this.m_target.GetComponent <CTSLook>();
     }
     if (Object.op_Equality((Object)this.m_lookController, (Object)null))
     {
         this.m_lookController = (CTSLook)this.m_target.AddComponent <CTSLook>();
         this.m_lookController._playerRootT = this.m_target.get_transform();
         this.m_lookController._cameraT     = this.m_target.get_transform();
     }
     ((Behaviour)this.m_lookController).set_enabled(false);
     if (Object.op_Inequality((Object)this.m_instructions, (Object)null))
     {
         string str = string.Empty;
         if (Object.op_Inequality((Object)this.m_unityProfile, (Object)null))
         {
             str += "Controls: 1. Unity";
         }
         if (Object.op_Inequality((Object)this.m_liteProfile, (Object)null))
         {
             str = str.Length <= 0 ? "Controls: 2. Lite" : str + ", 2. Lite";
         }
         if (Object.op_Inequality((Object)this.m_basicProfile, (Object)null))
         {
             str = str.Length <= 0 ? "Controls: 3. Basic" : str + ", 3. Basic";
         }
         if (Object.op_Inequality((Object)this.m_advancedProfile, (Object)null))
         {
             str = str.Length <= 0 ? "Controls: 4. Advanced" : str + ", 4. Advanced";
         }
         if (Object.op_Inequality((Object)this.m_tesselatedProfile, (Object)null))
         {
             str = str.Length <= 0 ? "Controls: 5. Tesselated" : str + ", 5. Tesselated";
         }
         if (Object.op_Inequality((Object)this.m_flyController, (Object)null))
         {
             str = str.Length <= 0 ? "Controls: 6. Fly" : str + ", 6. Fly";
         }
         if (Object.op_Inequality((Object)this.m_walkController, (Object)null))
         {
             str = str.Length <= 0 ? "Controls: 7. Walk" : str + ", 7. Walk";
         }
         if (Object.op_Inequality((Object)this.m_postProcessingComponent, (Object)null))
         {
             str = str.Length <= 0 ? "Controls: P. Post FX" : str + ", P. Post FX";
         }
         this.m_instructions.set_text(str.Length <= 0 ? "Controls: ESC. Exit." : str + ", ESC. Exit.");
     }
     this.SelectBasic();
     if (Object.op_Inequality((Object)this.m_flyController, (Object)null))
     {
         ((Behaviour)this.m_flyController).set_enabled(false);
     }
     if (Object.op_Inequality((Object)this.m_walkController, (Object)null))
     {
         ((Behaviour)this.m_walkController).set_enabled(false);
     }
     if (Object.op_Inequality((Object)this.m_characterController, (Object)null))
     {
         ((Collider)this.m_characterController).set_enabled(false);
     }
     if (!Object.op_Inequality((Object)this.m_lookController, (Object)null))
     {
         return;
     }
     ((Behaviour)this.m_lookController).set_enabled(false);
 }
        void Awake()
        {
            //Target
            if (m_target == null)
            {
                m_target = Camera.main.gameObject;
            }

            //Get initial location and rotation
            m_startPos      = m_target.transform.position;
            m_startRotation = m_target.transform.rotation;
            m_flyPos        = m_target.transform.position;
            m_flyRotation   = m_target.transform.rotation;
            m_walkPos       = m_target.transform.position;
            m_walkRotation  = m_target.transform.rotation;

            #region PostFX
            //See if we can set up post processing for better lighting
            try
            {
                if (m_postFX != null)
                {
                    Camera camera = Camera.main;
                    if (camera == null)
                    {
                        camera = FindObjectOfType <Camera>();
                    }
                    if (camera != null)
                    {
                        Type postProcessingType = GetType("UnityEngine.PostProcessing.PostProcessingBehaviour");
                        if (postProcessingType != null)
                        {
                            GameObject cameraObj = camera.gameObject;

                            m_postProcessingComponent = cameraObj.GetComponent(postProcessingType);
                            if (m_postProcessingComponent == null)
                            {
                                m_postProcessingComponent = cameraObj.AddComponent(postProcessingType);
                            }
                            if (m_postProcessingComponent != null)
                            {
                                FieldInfo fi = postProcessingType.GetField("profile", BindingFlags.Public | BindingFlags.Instance);
                                if (fi != null)
                                {
                                    fi.SetValue(m_postProcessingComponent, m_postFX);
                                }
                                ((MonoBehaviour)m_postProcessingComponent).enabled = false;
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                Debug.Log("Failed to set up post fx.");
            }
            #endregion

            #region Lighting check
            #if UNITY_EDITOR
            if (m_readme != null)
            {
                string readme             = "";
                bool   needLightingUpdate = false;

                if (PlayerSettings.colorSpace != ColorSpace.Linear)
                {
                    needLightingUpdate = true;
                }

                if (!needLightingUpdate)
                {
                    var tier1 = EditorGraphicsSettings.GetTierSettings(EditorUserBuildSettings.selectedBuildTargetGroup, GraphicsTier.Tier1);
                    if (tier1.renderingPath != RenderingPath.DeferredShading)
                    {
                        needLightingUpdate = true;
                    }
                }

                if (!needLightingUpdate)
                {
                    var tier2 = EditorGraphicsSettings.GetTierSettings(EditorUserBuildSettings.selectedBuildTargetGroup, GraphicsTier.Tier2);
                    if (tier2.renderingPath != RenderingPath.DeferredShading)
                    {
                        needLightingUpdate = true;
                    }
                }

                if (!needLightingUpdate)
                {
                    var tier3 = EditorGraphicsSettings.GetTierSettings(EditorUserBuildSettings.selectedBuildTargetGroup, GraphicsTier.Tier3);
                    if (tier3.renderingPath != RenderingPath.DeferredShading)
                    {
                        needLightingUpdate = true;
                    }
                }

                if (needLightingUpdate)
                {
                    readme = "Instructions : Lighting incorrect";
                }

                if (m_postProcessingComponent == null)
                {
                    if (readme.Length == 0)
                    {
                        readme = "Instructions : Post FX missing.";
                    }
                    else
                    {
                        readme += ", Post FX missing";
                    }
                }

                if (readme.Length > 0)
                {
                    readme += ". Please read CTS_Demo_ReadMe to fix!";
                }
                m_readme.text = readme;
            }
#endif
            #endregion

            #region Controller setup

            //Fly controller
            if (m_flyController == null)
            {
                m_flyController = m_target.GetComponent <CTSFly>();
            }
            if (m_flyController == null)
            {
                m_flyController = m_target.AddComponent <CTSFly>();
            }
            m_flyController.enabled = false;

            //Character controller
            if (m_characterController == null)
            {
                m_characterController = m_target.GetComponent <CharacterController>();
            }
            if (m_characterController == null)
            {
                m_characterController        = m_target.AddComponent <CharacterController>();
                m_characterController.height = 4f;
            }
            m_characterController.enabled = false;

            //Walk controller
            if (m_walkController == null)
            {
                m_walkController = m_target.GetComponent <CTSWalk>();
            }
            if (m_walkController == null)
            {
                m_walkController = m_target.AddComponent <CTSWalk>();
                m_walkController.m_controller = m_characterController;
            }
            m_walkController.enabled = false;

            //Look controller
            if (m_lookController == null)
            {
                m_lookController = m_target.GetComponent <CTSLook>();
            }
            if (m_lookController == null)
            {
                m_lookController = m_target.AddComponent <CTSLook>();
                m_lookController._playerRootT = m_target.transform;
                m_lookController._cameraT     = m_target.transform;
            }
            m_lookController.enabled = false;
            #endregion

            #region Instructions
            if (m_instructions != null)
            {
                string commands = "";
                if (m_unityProfile != null)
                {
                    commands += "Controls: 1. Unity";
                }
                if (m_basicProfile != null)
                {
                    if (commands.Length > 0)
                    {
                        commands += ", 2. Basic";
                    }
                    else
                    {
                        commands = "Controls: 2. Basic";
                    }
                }
                if (m_advancedProfile != null)
                {
                    if (commands.Length > 0)
                    {
                        commands += ", 3. Advanced";
                    }
                    else
                    {
                        commands = "Controls: 3. Advanced";
                    }
                }
                if (m_tesselatedProfile != null)
                {
                    if (commands.Length > 0)
                    {
                        commands += ", 4. Tesselated";
                    }
                    else
                    {
                        commands = "Controls: 4. Tesselated";
                    }
                }
                if (m_flyController != null)
                {
                    if (commands.Length > 0)
                    {
                        commands += ", 5. Fly";
                    }
                    else
                    {
                        commands = "Controls: 5. Fly";
                    }
                }
                if (m_walkController != null)
                {
                    if (commands.Length > 0)
                    {
                        commands += ", 6. Walk";
                    }
                    else
                    {
                        commands = "Controls: 6. Walk";
                    }
                }
                if (m_postProcessingComponent != null)
                {
                    if (commands.Length > 0)
                    {
                        commands += ", P. Post FX";
                    }
                    else
                    {
                        commands = "Controls: P. Post FX";
                    }
                }
                if (commands.Length > 0)
                {
                    commands += ", ESC. Exit.";
                }
                else
                {
                    commands = "Controls: ESC. Exit.";
                }
                m_instructions.text = commands;
            }
            #endregion

            //Start in basic mode
            SelectBasic();

            //At home
            Home();
        }