// Update is called once per frame void Update() { int countLightsOn = 0; // Add up all the lights that are turned on. foreach (GameObject lightObject in lightSwitchObjects) { LightSwitch lightSwitch = lightObject.GetComponent <LightSwitch> (); // Notice that this is retrieving the script's class. bool lightOn = lightSwitch.lightSwitch; // Retrieve the variable state from the other object's script. if (lightOn) { countLightsOn++; } } int numLights = lightSwitchObjects.Length; float percentOn = (float)countLightsOn / (float)numLights; // Cast the ints as floats so that you get floating point averages. // Most lights are off. if (percentOn < 0.5f) { thisLight.color = Color.red; } // Most lights are on else { thisLight.color = Color.green; } }
public static Task<bool> SetSwitch(LightSwitch ls, bool on) { var urlBuilder = new StringBuilder(BaseUrl + "wemo/"); var action = on ? "on/" : "off/"; urlBuilder.Append(action); urlBuilder.Append(ls.Name); urlBuilder.Append("?nocache=" + Environment.TickCount.ToString()); TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(); WebClient wc = new WebClient(); wc.DownloadStringCompleted += (s, args) => { if (args.Error != null) { tcs.TrySetResult(false); } else { if (string.Compare(args.Result, "OK", StringComparison.InvariantCultureIgnoreCase) == 0) { tcs.TrySetResult(true); } else { tcs.TrySetResult(false); } } }; wc.DownloadStringAsync(new Uri(urlBuilder.ToString(), UriKind.Absolute)); return tcs.Task; }
// Use this for initialization void Start() { if(nivel){ codigo = nivel.GetComponent<LightSwitch>(); } }
private void Start() { parentSwitch = GetComponentInParent <LightSwitch>(); lightObject = this.GetComponent <Light>(); defaultIntensity = lightObject.intensity; UpdateLightState(parentSwitch.flipped); }
private static void AssertSwitchesCount(int numSwitches, LightSwitch lightSwitchStateMachine) { var output = Substitute.For <Output>(); lightSwitchStateMachine.ShowSwitchesCountOn(output); output.Received(1).Show(numSwitches); }
public MsgLightSwitchConfig_YC001(byte ctrlBoardNO, LightSwitch lightSwitch) { msgBody = new byte[3]; msgBody[0] = 0; msgBody[1] = ctrlBoardNO; msgBody[2] = lightSwitch.GetParambyte(); }
public void TestDeviceTimeInit() { var input = new ServerInput("http://serverapi1.azurewebsites.net"); var device = new LightSwitch(input, null, null); Assert.AreEqual(device.LastUpdate, DateTime.MinValue); }
// Use this for initialization void Start() { HandRight = GameObject.Find("DistanceHandRight"); if (!HandRight) { Debug.Log("Can't find DistanceHandRight"); } HandLeft = GameObject.Find("DistanceHandLeft"); if (!HandLeft) { Debug.Log("Can't find DistanceHandLeft"); } highlightCollided = GetComponent <HighlightCollided>(); if (!highlightCollided) { Debug.Log("Script HighlightSelected not attached"); } lightSwitch = OtherLightSwitch.GetComponent <LightSwitch>(); if (!lightSwitch) { Debug.Log("Script LightSwitch not attached to other lightswitch"); } collider = GetComponent <BoxCollider>(); if (!collider) { Debug.Log("No Box Collider attached"); } //BoxCollider [] triggers = gameObject.GetComponentsInChildren<BoxCollider>(); //Trigger1 = triggers[0]; //Trigger2 = triggers[1]; //TODO find all colliders from HandRight, save them in list. Check for these colliders in OnCollisionEnter }
public static void Main() { ILightState lightOn = new LightOn(); LightSwitch lightSwitch = new LightSwitch(lightOn); lightSwitch.onPress(); }
public void CmdToggleLightSwitch(GameObject switchObj) { if (!Validations.CanApply(playerScript, switchObj, NetworkSide.Server)) { return; } if (CanInteractWallmount(switchObj.GetComponent <WallmountBehavior>())) { if (!Cooldowns.TryStartServer(playerScript, CommonCooldowns.Instance.Interaction)) { return; } LightSwitch s = switchObj.GetComponent <LightSwitch>(); if (s.isOn == LightSwitch.States.On) { s.isOn = LightSwitch.States.Off; } else if (s.isOn == LightSwitch.States.Off) { s.isOn = LightSwitch.States.On; } } else { Logger.LogWarningFormat("Player {0} attempted to interact with light switch through wall," + " this could indicate a hacked client.", Category.Exploits, this.gameObject.name); } }
// Use this for initialization void Start() { if (nivel) { codigo = nivel.GetComponent <LightSwitch>(); } }
/// <summary> /// Adds light switches by GameObject /// </summary> /// <param name="lightGO">LightSwitch GameObject.</param> public void AddLightSwitch(GameObject lightGO) { PlayMakerFSM playMakerFsm = Utils.GetPlaymakerScriptByName(lightGO, "Use"); if (playMakerFsm == null) { return; } bool isValid = false; if (playMakerFsm.FsmVariables.FindFsmBool("Switch") != null) { isValid = true; } if (isValid) { LightSwitch light = new LightSwitch(lightGO); lightSwitches.Add(light); Logger.Log($"Registered new light switch: {lightGO.name}"); light.onLightSwitchUse = (lightObj, turnedOn) => { onLightSwitchUsed(lightGO, !light.SwitchStatus); }; } }
public void TestDeviceTimeUpdate() { var input = new ServerInput("http://serverapi1.azurewebsites.net"); var device = new LightSwitch(input, null, null); device.LastUpdate = DateTime.Now.ToUniversalTime(); Assert.AreNotEqual(device.LastUpdate, DateTime.MinValue); }
private void OnEnable() { laserPoint = m_laserPoint; laserSource = gameObject.transform; AdjustDirection(); switchRoom = roomLayer.GetComponent <SwitchRoom> (); lightSwitch = roomLayer.GetComponent <LightSwitch> (); }
// Use this for initialization void Start() { isOn = true; backgroundPlayer = GetComponent <MediaPlayerCtrl> (); lightSwitch = GameObject.Find("Lever").GetComponent <LightSwitch> (); Debug.Log("init lightSwitch state: " + lightSwitch.isOn); GameObject.Find("Theater").transform.localScale = new Vector3(0, 0, 0); }
public void ServerPerformInteraction(HandApply interaction) { if (interaction.HandObject == null) { if (state == LightMountState.On) { Spawn.ServerPrefab(appliableItem, interaction.Performer.WorldPosServer()); Chat.AddExamineMsg(interaction.Performer, "You took the light tube out!"); ServerChangeLightState(LightMountState.MissingBulb); } else if (state == LightMountState.Off) { Spawn.ServerPrefab(appliableItem, interaction.Performer.WorldPosServer()); Chat.AddExamineMsg(interaction.Performer, "You took the light tube out!"); ServerChangeLightState(LightMountState.MissingBulb); } else if (state == LightMountState.Broken) { Spawn.ServerPrefab(appliableBrokenItem, interaction.Performer.WorldPosServer()); Chat.AddExamineMsg(interaction.Performer, "You took the broken light tube out!"); ServerChangeLightState(LightMountState.MissingBulb); } } else if (Validations.HasItemTrait(interaction.HandObject, traitRequired) && state == LightMountState.MissingBulb) { if (Validations.HasItemTrait(interaction.HandObject, CommonTraits.Instance.Broken)) { Despawn.ServerSingle(interaction.HandObject); Chat.AddExamineMsg(interaction.Performer, "You put broken light tube in!"); ServerChangeLightState(LightMountState.Broken); } else { if (lightSwitch == null) { lightSwitch = lightSource.relatedLightSwitch; } if (lightSwitch == null) { return; } if (lightSwitch.isOn == LightSwitch.States.On) { Despawn.ServerSingle(interaction.HandObject); Chat.AddExamineMsg(interaction.Performer, "You put light tube in!"); ServerChangeLightState(LightMountState.On); } else { Despawn.ServerSingle(interaction.HandObject); Chat.AddExamineMsg(interaction.Performer, "You put light tube in!"); ServerChangeLightState(LightMountState.Off); } } } }
void OnTriggerEnter(Collider collision) { if (collision.tag == "nivel") { nivelActual = collision.gameObject; codigo = nivelActual.GetComponent <LightSwitch>(); MovObjetoPunto.Click = true; } }
void OnTriggerEnter(Collider collision) { if (collision.tag == "nivel") { nivelActual = collision.gameObject; codigo = nivelActual.GetComponent<LightSwitch>(); MovObjetoPunto.Click = true; } }
public virtual void GenerateLightSwitch() { Doorway target = doorways[0]; Vector2 position = new Vector2(target.x, target.y); if (target.roomOutDirection == Direction.North) { position.y += 1; if (Random.value > .5f || target.x == x) { position.x += target.breadth; } else { position.x -= 1; } } else if (target.roomOutDirection == Direction.South) { if (Random.value > .5f || target.x == x) { position.x += target.breadth; } else { position.x -= 1; } } else if (target.roomOutDirection == Direction.East) { if (Random.value > .5f || target.y == y) { position.y += target.breadth; } else { position.y -= 1; } } else if (target.roomOutDirection == Direction.West) { if (Random.value > .5f || target.y == y) { position.y += target.breadth; } else { position.y -= 1; } } lightSwitch = (LightSwitch)InstantiateFurniture(PrefabRegistry.I.lightSwitch.GetComponent <LightSwitch>(), position); if (lightSwitch) { lightSwitch.GetComponent <DoubleCardinalSprite>().UpdateDirection(DirectionUtil.Reverse(target.roomOutDirection)); } lightSwitch.gameObject.name = GetType().Name + " LightSwitch"; }
private void Awake() { lightBlue = new Color(0, 0.5f, 1); alpha_zero = new Color(1, 1, 1, 0); secretDoor_mat.color = alpha_zero; alpha_increment = new Color(0, 0, 0, Time.deltaTime / 2); lightSwitch = GetComponent <LightSwitch> (); secretDoor_col.SetActive(false); switchRoom = GetComponent <SwitchRoom> (); }
private void Reset() { this._randSeed = UnityEngine.Random.Range(0, 2147483647); if (this.stylists == null) { this.stylists = new LightStylist[0]; } LightSwitch.DefaultArray("on", ref this.randOn); LightSwitch.DefaultArray("off", ref this.randOff); }
public void TestHouseInput() { const string HouseString = "{\"house_url\":\"http://127.0.0.1:8081\"}"; const string DeviceString = "{\"ID\": 0, \"Class\": \"LightSwitch\"}"; var inp = new HouseInput(HouseString, DeviceString); var ls = new LightSwitch(inp, null, _frame); Assert.IsTrue(ls.update()); Assert.AreEqual(ls.Enabled, false); }
/// <summary> /// 設定光源開關 /// </summary> /// <param name="onOff"></param> /// <param name="channel"></param> /// <returns></returns> public string SetLightOnOff(LightSwitch onOff, string channel) { /* * On/Off : 1/0 */ var instruction = "L"; var command = header + channel + instruction + ((int)onOff).ToString(); var checksum = getCheckSum(command); return(sendData(command + checksum + delimiter)); }
public Task SwitchLightAsync(string id, bool switchOn, CancellationToken cancellationToken = default) { var model = new LightSwitch { On = new LightOnOff_OnModel { On = switchOn } }; return(_httpClient.PutAsJsonAsync($"/clip/v2/resource/light/{id}", model, cancellationToken)); }
public override IDriverNode CreateDriverNode(IDriverContext ctx) { IDriverNode driverNode = null; switch (ctx.NodeInstance.This2NodeTemplateNavigation.Key) { case "light-bulb-switch": driverNode = new SwitchNode(ctx, Accessory.Services[1].Characteristics.Single(a => a.Type == CharacteristicBase.OnType), Driver); break; case "light-bulb-brightness": var brigthness = Accessory.CreateBrightness(); driverNode = new LightSwitch(ctx, Driver, brigthness); break; case "light-bulb-hue": var hue = Accessory.CreateHue(); driverNode = new LightSwitch(ctx, Driver, hue); break; case "power-outlet-switch": driverNode = new SwitchNode(ctx, Accessory.Services[1].Characteristics.Single(a => a.Type == CharacteristicBase.OnType), Driver); break; case "contact-sensor": driverNode = new BaseNode(ctx, Accessory.Services[1].Characteristics .Single(a => a.Type == CharacteristicBase.ContactSensorStateType), Driver); break; case "switch": driverNode = new SwitchNode(ctx, Accessory.Services[1].Characteristics.Single(a => a.Type == CharacteristicBase.OnType), Driver); break; case "temperature-sensor": driverNode = new BaseNode(ctx, Accessory.Services[1].Characteristics .Single(a => a.Type == CharacteristicBase.CurrentTemperatureType), Driver); break; case "switch-status": case "power-outlet-status": case "light-bulb-status": driverNode = new StateNode(ctx, Accessory.Services[1].Characteristics.Single(a => a.Type == CharacteristicBase.OnType), Driver); break; } return(driverNode); }
public void Received(LightSwitchData Received) { //Logger.Log (Received.LightSwitchTrigger.ToString() + " < LightSwitchTrigger" + Received.RelatedAPC.ToString() + " < APC" + Received.state.ToString() + " < state" ); // Leo Note: Some sync magic happening here. Decided not to touch it. tempStateCache = Received.state; if (waitToCheckState) { return; } if (Received.LightSwitch == relatedLightSwitch || relatedLightSwitch == null) { if (relatedLightSwitch == null) { relatedLightSwitch = Received.LightSwitch; } if (Received.RelatedAPC != null) { RelatedAPC = Received.RelatedAPC; { if (State == LightState.On) { if (!RelatedAPC.ConnectedSwitchesAndLights[relatedLightSwitch].Contains(this)) { RelatedAPC.ConnectedSwitchesAndLights[relatedLightSwitch].Add(this); } } } } else if (relatedLightSwitch.SelfPowered) { if (State == LightState.On) { if (!relatedLightSwitch.SelfPowerLights.Contains(this)) { relatedLightSwitch.SelfPowerLights.Add(this); } } } if (Renderer == null) { waitToCheckState = true; StartCoroutine(WaitToTryAgain()); return; } else { State = Received.state ? LightState.On : LightState.Off; } } }
// Start is called before the first frame update void Start() { entitiesContainer = transform.Find("Entities").gameObject; propsContainer = transform.Find("Props").gameObject; avatar = entitiesContainer.transform.Find("Avatar").GetComponent <Avatar>(); lightSwitch = propsContainer.transform.Find("LightSwitch").GetComponent <LightSwitch>(); door.Add(propsContainer.transform.Find("Doors").Find("DoorLeft").GetComponent <Door>()); door.Add(propsContainer.transform.Find("Doors").Find("DoorRight").GetComponent <Door>()); ballSpawner = propsContainer.transform.Find("BallSpawner").GetComponent <BallSpawner>(); ballDestroyer = propsContainer.transform.Find("BallDestroyer").GetComponent <BallDestroyer>(); LeanTween.init(800); avatar.transform.position = Vector3.zero; }
public void SwitchDidSwitchState(LightSwitch toggle, LightSwitch.SwitchState state) { if (state == LightSwitch.SwitchState.On && switches.Contains(toggle)) { onSwitches += 1; if (onSwitches == switches.Count) { IncrementBumperMultiplier(); ResetSwitches(); onSwitches = 0; } } }
public void FlipUpCommandShouldSetLightStateToOn() { var expectedStatus = false; Light light = new Light(); InterpreterPattern.ICommand commandA = new FlipDownCommand(light); LightSwitch lightSwitch = new LightSwitch(); lightSwitch.SetAndExecuteCommand(commandA); light.State.Should().Be(expectedStatus); }
private static void Main() { LightSwitch ls = new LightSwitch(); ls.TransitionCompleted += HandleTransitionCompleted; ls.Send(EventID.TurnOn); ls.Send(EventID.TurnOff); ls.Send(EventID.TurnOn); ls.Send(EventID.TurnOff); Console.ReadLine(); ls.Execute(); Console.ReadLine(); }
private void Awake() { this.rand = new SeededRandom(this.randSeed); LightSwitch.MakeCTX(ref this.stylists, ref this.stylistCTX); if (this.stylists != null) { for (int i = 0; i < (int)this.stylists.Length; i++) { if (this.stylists[i]) { this.stylists[i] = this.stylists[i].ensuredAwake; } } } }
// Use this for initialization void Start() { lightSwitchUp = lightSwitchObjectUp.GetComponent <LightSwitch>(); if (!lightSwitchUp) { Debug.Log("no lightswitch1 component"); } lightSwitchDown = lightSwitchObjectDown.GetComponent <LightSwitch>(); if (!lightSwitchDown) { Debug.Log("no lightswitch2 component"); } MovingPart = transform.GetChild(0); }
private void bridgePatternBtn_Click(object sender, RoutedEventArgs e) { IDeviceBridge lightSwitch = new LightSwitch(); IDeviceBridge tvSwitch = new TVSwitch(); IDeviceBridge radioSwitch = new RadioSwitch(); DeviceBridge db = new DeviceBridge(lightSwitch); statusBarTB.Text = db.On() + ", "; db = new DeviceBridge(tvSwitch); statusBarTB.Text += db.Off() + ", "; db = new DeviceBridge(radioSwitch); statusBarTB.Text += db.On(); }
public static void Patch() { Config.Load(); Database.Load(); LightSwitch.Patch(); LightSource_1.Patch(); //CraftTreeHandler.AddCraftingNode(CraftTree.Type.Fabricator, DeepEngineKit.TechType, "Energy Solution"); //Add the databank entry. //LanguageHandler.SetLanguageLine($"Ency_{DeepEngine.ClassID}", DeepEngine.FriendlyName); //LanguageHandler.SetLanguageLine($"EncyDesc_{DeepEngine.ClassID}", DeepEngine.PDADescription(Config.MaxPowerAllowed)); AD3D_Common.Helper.Log($"Patched successfully [v1.0.0]"); }
private void setChannelOnOff(LightSwitch onOff, string channel) { var msg = _lightManager.SetLightOnOff(onOff, channel); updatePanel(msg); }
public void OnEvent(LightSwitch.LightStateChangedEvent e) { TurnOnOff(e.lightState); }
/// <summary> /// 設定光源開關 /// </summary> /// <param name="onOff"></param> /// <param name="channel"></param> /// <returns></returns> public string SetLightOnOff(LightSwitch onOff, string channel) { /* * On/Off : 1/0 */ var instruction = "L"; var command = header + channel + instruction + ((int)onOff).ToString(); var checksum = getCheckSum(command); return sendData(command + checksum + delimiter); }
/// <summary> /// 設定光源 on/off, 非同步方法 /// </summary> /// <param name="onOff"></param> /// <param name="channel"></param> public void SetLightOnOffAsync(LightSwitch onOff, string channel) { var instruction = "L"; var model = new CCSCommandModel() { ChannelCommands = new Dictionary<string, InstructionModel>() { {channel, new InstructionModel(){Instruction = instruction, Data = ((int)onOff).ToString()}} }, }; if (!_bgWorker.IsBusy) { _bgWorker.RunWorkerAsync(model); } }
public CCSCommandModel GetLightOnOffModel(LightSwitch onOff, string channel) { var instruction = "L"; var model = new CCSCommandModel() { ChannelCommands = new Dictionary<string, InstructionModel>() { {channel, new InstructionModel(){Instruction = instruction, Data = ((int)onOff).ToString()}} }, }; return model; }
public static Task<bool> FlipSwitch(LightSwitch ls) { return HomeControllerApi.SetSwitch(ls, !ls.State); }