public override void Initialize()
        {
            GameObject pt = ResourceManager.Instance.CurrentScene.GetObject("PlayerTime");

            if (pt == null)
            {
                throw new ArgumentNullException("AreaTransition: PlayerTime object does not exist!");
            }

            cTime = (PlayerTime)pt.GetComponent <PlayerTime>();

            GameObject player = ResourceManager.Instance.CurrentScene.GetObject(1);

            pController = (PlayerController)player.GetComponent <PlayerController>();
            stash       = (HideoutStash)player.GetComponent <HideoutStash>();
            equipment   = pController.Equipment;
            if ((player.GetComponent <PlayerHUD>() as PlayerHUD) != null)
            {
                music = (player.GetComponent <PlayerHUD>() as PlayerHUD).ExplorationCue;
            }

            if (cTime == null || pController == null || stash == null || equipment == null)
            {
                throw new ArgumentNullException("AreaTransition: some required components are inexistant!");
            }

            mBoxes[0]             = new MessageBox(messagePosition, messageDimenstions.X, messageDimenstions.Y);
            mBoxes[0].OptionCount = 3;
            mBoxes[0].Text        = MESSAGE_0;
            mBoxes[0].OptionTexts = new string[] { MESSAGE_0_0, MESSAGE_0_1, MESSAGE_0_2 };
            mBoxes[0].Initialize();

            mBoxes[1]             = new MessageBox(messagePosition, messageDimenstions.X * 0.8f, messageDimenstions.Y);
            mBoxes[1].OptionCount = 2;
            mBoxes[1].Text        = MESSAGE_1;
            mBoxes[1].OptionTexts = new string[] { MESSAGE_1_0, MESSAGE_1_1 };
            mBoxes[1].Initialize();

            mBoxes[2]             = new MessageBox(messagePosition, messageDimenstions.X, messageDimenstions.Y);
            mBoxes[2].OptionCount = 1;
            mBoxes[2].Text        = MESSAGE_2;
            mBoxes[2].OptionTexts = new string[] { MESSAGE_2_0 };
            mBoxes[2].Initialize();

            colliderHelper = new GameObject(MyObject.UniqueID + (uint)MyObject.Name.GetHashCode() + 1, MyObject.Name + "AreaTransitionHelper");
            MyObject.AddChild(colliderHelper);
            colliderHelper.MyTransform          = new Transform(colliderHelper, Vector3.Zero, Vector3.Up, Vector3.Zero, MyObject.MyTransform.Scale * 1.3f);
            colliderHelper.MyCollider           = new SphereCollider(colliderHelper, true);
            colliderHelper.OnTriggerEnterEvent += new GameObject.OnTriggerEnterEventHandler(HelperEnter);
            colliderHelper.OnTriggerExitEvent  += new GameObject.OnTriggerExitEventHandler(HelperExit);

            GameObject playerTimeObj = ResourceManager.Instance.CurrentScene.GetObject(355);

            if (playerTimeObj != null)
            {
                this.playerTime = (PlayerTime)playerTimeObj.GetComponent <PlayerTime>();
            }

            base.Initialize();
        }
Example #2
0
        public override void Initialize()
        {
            if (TextureNames == null)
            {
                throw new ArgumentNullException("DaytimeChange: Textures not set!");
            }
            if (TextureNames.Count() < TEXTURE_COUNT)
            {
                throw new ArgumentException("DaytimeChange: Texture count less than " + TEXTURE_COUNT.ToString() + "!");
            }

            sun        = ResourceManager.Instance.CurrentScene.GetObject(SunID);
            lightDay   = ResourceManager.Instance.CurrentScene.DirectionalLights[LightDayID];
            lightNight = ResourceManager.Instance.CurrentScene.DirectionalLights[LightNightID];
            ambient    = ResourceManager.Instance.CurrentScene.AmbientLight;

            foreach (ObjectComponent comp in this.MyObject.Components)
            {
                if (comp.GetType() == typeof(CustomModel))
                {
                    myModel = (CustomModel)comp;
                    if (myModel == null)
                    {
                        break;
                    }
                    if (myModel.Mat[0].GetType() != typeof(SkyboxMaterial))
                    {
                        throw new InvalidOperationException("DaytimeChange: Skybox's material is not SkyboxMaterial!");
                    }
                    myMaterial = (SkyboxMaterial)myModel.Mat[0];
                    break;
                }
            }

            if (sun == null || lightDay == null || lightNight == null || myModel == null || myMaterial == null || ambient == null)
            {
                throw new ArgumentNullException("DaytimeChange: Some of the objects do not exist!");
            }

            foreach (ObjectComponent comp in sun.Components)
            {
                if (comp.GetType() == typeof(Billboard))
                {
                    if (((Billboard)comp).Mat != null)
                    {
                        sunMaterial = ((Billboard)comp).Mat;
                    }
                }
            }

            startDaylightColor    = lightDay.LightColor;
            startDaylightSpecular = lightDay.LightSpecularColor;
            startNightColor       = lightNight.LightColor;
            startNightSpecular    = lightNight.LightSpecularColor;
            startAmbientColor     = ambient.LightColor;

            for (int i = 0; i < TEXTURE_COUNT; ++i)
            {
                if (TextureNames[i] != null)
                {
                    textures[i] = ResourceManager.Instance.LoadTextureCube(TextureNames[i]);
                }
            }

            if (textures[0] != null)
            {
                myMaterial.CubeMap = textures[0];
            }
            if (textures[1] != null)
            {
                myMaterial.CubeMap1 = textures[1];
            }
            if (textures[2] != null)
            {
                myMaterial.CubeMap2 = textures[2];
            }
            if (textures[3] != null)
            {
                myMaterial.CubeMap3 = textures[3];
            }

            GameObject pt = ResourceManager.Instance.CurrentScene.GetObject("PlayerTime");

            if (pt == null)
            {
                throw new ArgumentNullException("DaytimeChange: PlayerTime object does not exist!");
            }

            foreach (ObjectComponent comp in pt.Components)
            {
                if (comp.GetType() == typeof(PlayerTime))
                {
                    cTime = (PlayerTime)comp;
                }
            }

            if (cTime == null)
            {
                throw new ArgumentNullException("DaytimeChange: PlayerTime object has no PlayerTime component!");
            }

            long t = cTime.TotalMilliseconds;

            if (t >= SunriseMS - StateChangeMS && t <= SunsetMS + StateChangeMS)
            {
                switched = true;
            }
            else
            {
                switched = false;
            }

            startSunDiffuse = myMaterial.DiffuseColor;

            base.Initialize();
        }