Наследование: MonoBehaviour
Пример #1
0
 // Start is called before the first frame update
 void Start()
 {
     script  = player.GetComponent <FirstPersonController>();
     script2 = lights.GetComponent <TurnOnLights>();
 }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        //this method is called out by Azure Function.
        //1. Shelly Door/Gate sensor activates Azure Function
        //2. Shelly Garage Spotlight activates Azure Function (this doesnt work !??)
        private async Task <MethodResponse> SetLights(MethodRequest methodRequest, object userContext)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            try
            {
                JsonElement jsonElement = JsonDocument.Parse(methodRequest.DataAsJson).RootElement;
                jsonElement.TryGetProperty("LightName", out JsonElement lightName);
                jsonElement.TryGetProperty("TurnOnLights", out JsonElement TurnOnLights);

                if (lightName.GetString() == "garage")
                {
                    TelemetryDataClass.isGarageLightsOn = await Shelly.SetShellySwitch(TurnOnLights.GetBoolean(), Shelly.GarageLight, nameof(Shelly.GarageLight));
                }
                if (lightName.GetString() == "outside")
                {
                    TelemetryDataClass.isOutsideLightsOn = await Shelly.SetShellySwitch(TurnOnLights.GetBoolean(), Shelly.OutsideLight, nameof(Shelly.OutsideLight));

                    SomeoneAtHome.LightsManuallyOnOff = true; //force lights on/off for 30 minutes
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Garage Light: " + e.ToString());
            }
            var response = Encoding.ASCII.GetBytes("Ok");

            return(new MethodResponse(response, 200));
        }