예제 #1
0
 /// <summary>
 /// If a lantern object is destroyed by the player unregister it from our list. Its gone.
 /// </summary>
 /// <param name="_lightSource">The light source which was destroyed</param>
 internal void UnregisterLightSource(SSceneLight _lightSource)
 {
     if (Get == null)
     {
         return;              //mod is being unloaded
     }
     if (mi_sceneLights?.Contains(_lightSource) ?? false)
     {
         mi_sceneLights.Remove(_lightSource);
     }
 }
예제 #2
0
 /// <summary>
 /// Tries to restore each light source to its original vanilla state.
 /// Used on mod unload to make sure the game state is cleaned if the mod is disabled through the manager
 /// </summary>
 /// <param name="_lightSource"></param>
 internal void RestoreLightSource(SSceneLight _lightSource)
 {
     if (_lightSource.LightComponent)
     {
         _lightSource.LightComponent.shadows = LightShadows.None;
     }
     if (_lightSource.LightSwitch)
     {
         _lightSource.LightSwitch.SetLightOn(true);
     }
     if (_lightSource.PreModColliderLayer != 0)
     {
         if (_lightSource.Raycastable)
         {
             _lightSource.Raycastable.gameObject.layer = _lightSource.PreModColliderLayer;
         }
     }
 }
예제 #3
0
        /// <summary>
        /// Initializes the lantern switch behaviour providing a mod handle and a scene light wrapper.
        /// </summary>
        /// <param name="_mod">A handle to the mod object initializing this switch.</param>
        /// <param name="_light">Contains references to the block and other components.</param>
        public void Load(CLanternShadows _mod, SSceneLight _light)
        {
            mi_mod                   = _mod;
            mi_sceneLight            = _light;
            mi_nlCntrl               = mi_sceneLight.LightComponent.GetComponent <NightLightController>();
            mi_setLightIntensityInfo = typeof(NightLightController).GetMethod("SetLightIntensity", BindingFlags.NonPublic | BindingFlags.Instance);
            mi_network               = ComponentManager <Semih_Network> .Value;

            //use our block objects index so we receive RPC calls
            //need to use an existing blockindex as clients/host need to be aware of it
            ObjectIndex = mi_sceneLight.BlockObject.ObjectIndex;
            NetworkIDManager.AddNetworkID(this);

            CheckLightState(true);

            mi_loaded = true;

            if (!Semih_Network.IsHost) //request lantern states from host after load
            {
                mi_network.SendP2P(
                    mi_network.HostID,
                    new Message_Battery_OnOff( //just use the battery message as it should never
                        Messages.Battery_OnOff,
                        mi_network.NetworkIDManager,
                        mi_network.LocalSteamID,
                        this.ObjectIndex,
                        (int)ELanternRequestType.REQUEST_STATE, //we use the battery uses int to pass our custom command type
                        IsOn),
                    EP2PSend.k_EP2PSendReliable,
                    NetworkChannel.Channel_Game);
            }
            else if (mi_mod.SavedLightData.ContainsKey(SaveAndLoad.CurrentGameFileName))
            {
                var data = mi_mod.SavedLightData[SaveAndLoad.CurrentGameFileName].FirstOrDefault(_o => _o.ObjectID == ObjectIndex);
                if (data != null)
                {
                    UserControlsState = true;
                    SetLightOn(data.IsOn);
                }
            }
        }
예제 #4
0
        //called when a light source is created or when reloading the mod
        private void RegisterLight(Light _light, GameObject _blockObject)
        {
            if (_light == null || _blockObject == null)
            {
                return;
            }

            if (mi_sceneLights == null)
            {
                mi_sceneLights = new List <SSceneLight>();
            }

            var block = _blockObject.GetComponent <Block>();

            if (!block)
            {
                return;
            }

            var sceneLight = new SSceneLight();

            sceneLight.BlockObject    = block;
            sceneLight.LightComponent = _light;

            if (Config.EnableLightToggle)
            {
                var col = _blockObject.GetComponentInChildren <Collider>();
                if (!col)
                {
                    return;
                }

                var raycastable = col.gameObject.GetComponent <RaycastInteractable>();
                if (!raycastable)
                {
                    raycastable = col.gameObject.AddComponent <RaycastInteractable>();
                }

                sceneLight.Raycastable = raycastable;

                if (col.gameObject.layer == 0)
                {
                    sceneLight.PreModColliderLayer = col.gameObject.layer;
                    col.gameObject.layer           = LayerMask.NameToLayer("Block");
                }

                sceneLight.LightSwitch = col.gameObject.AddComponent <CLanternSwitch>();
            }
            else
            {
                sceneLight.LightSwitch = _light.gameObject.AddComponent <CLanternSwitch>();
            }

            if (sceneLight.LightSwitch)
            {
                sceneLight.BlockObject.networkedIDBehaviour = sceneLight.LightSwitch;
                sceneLight.LightSwitch.Load(this, sceneLight);
            }

            _light.shadows = Config.EnableShadows ? LightShadowType : LightShadows.None;
            if (!mi_sceneLights.Any(_o => _o.LightComponent == _light))
            {
                mi_sceneLights.Add(sceneLight);
            }
        }