Example #1
0
    void Update()
    {
        if (Input.GetMouseButton(2))
        {
            if (grabZone.grabableItem != null)
            {
                if (buttonSwitch == null)
                {
                    buttonSwitch = grabZone.grabableItem.GetComponent <ButtonSwitch>();
                }
                if (buttonSwitch)
                {
                    buttonSwitch.interacting = true;
                    buttonSwitch.Switch();
                }
            }
            else
            {
                if (buttonSwitch)
                {
                    buttonSwitch.interacting = false;
                    buttonSwitch             = null;
                }
            }
        }

        if (Input.GetMouseButtonUp(2))
        {
            if (buttonSwitch)
            {
                buttonSwitch.interacting = false;
                buttonSwitch             = null;
            }
        }
    }
    void Awake()
    {
        if (switchBtn == null)
        {
            switchBtn = GetComponent <ButtonSwitch>();
        }
        render = GetComponent <MeshRenderer>();

        OnSwitchToggle(switchBtn, switchBtn.State);
    }
 void OnSwitchToggle(ButtonSwitch btn, ButtonSwitch.ButtonSwitchState newState)
 {
     if (newState == ButtonSwitch.ButtonSwitchState.ON)
     {
         render.material.color = Color.red;
     }
     else
     {
         render.material.color = Color.blue;
     }
 }
Example #4
0
        /// <summary>
        /// Clears generated button event
        /// </summary>
        /// <param name="button">Button to clear button event for</param>
        public void ClearButtonEvent(ButtonSwitch button)
        {
            byte[] array = button switch
            {
                ButtonSwitch.Switch1 => new byte[] { 0xF0, 0xFF },
                ButtonSwitch.Switch2 => new byte[] { 0x0F, 0xFF },
                ButtonSwitch.Switch3 => new byte[] { 0xFF, 0xF0 },
                _ => throw new NotImplementedException()
            };

            _piJuice.WriteCommand(PiJuiceCommand.ButtonEvent, array);
        }
Example #5
0
        public void SetupLiveCameraStream()
        {
            captureSession = new AVCaptureSession();

            var viewLayer = CameraView.Layer;

            videoPreviewLayer = new AVCaptureVideoPreviewLayer(captureSession)
            {
                Frame = this.View.Bounds
            };
            videoPreviewLayer.VideoGravity = AVLayerVideoGravity.ResizeAspectFill;
            CameraView.Layer.AddSublayer(videoPreviewLayer);

            var captureDevice = AVCaptureDevice.GetDefaultDevice(AVMediaType.Video);

            ConfigureCameraForDevice(captureDevice);
            captureDeviceInput = AVCaptureDeviceInput.FromDevice(captureDevice);
            captureSession.AddInput(captureDeviceInput);

            var dictionary = new NSMutableDictionary();

            dictionary[AVVideo.CodecKey] = new NSNumber((int)AVVideoCodec.JPEG);
            stillImageOutput             = new AVCaptureStillImageOutput()
            {
                OutputSettings = new NSDictionary()
            };

            captureSession.AddOutput(stillImageOutput);
            captureSession.StartRunning();


            ButtonBack.SetImage(UIImage.FromBundle("arrow_left").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal);
            ButtonFlash.SetImage(UIImage.FromBundle("flash_off").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal);
            ButtonSwitch.SetImage(UIImage.FromBundle("switch_camera").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal);
            ButtonCapture.SetImage(UIImage.FromBundle("capture_camera").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal);

            ButtonFlash.TouchUpInside   += BttFlash_TouchUpInside;
            ButtonCapture.TouchUpInside += BttCapture_TouchUpInside;
            ButtonBack.TouchUpInside    += BttBack_TouchUpInside;
            ButtonSwitch.TouchUpInside  += BttSwitch_TouchUpInside;
        }
Example #6
0
        void ReleaseDesignerOutlets()
        {
            if (ButtonBack != null)
            {
                ButtonBack.Dispose();
                ButtonBack = null;
            }

            if (ButtonCapture != null)
            {
                ButtonCapture.Dispose();
                ButtonCapture = null;
            }

            if (ButtonFlash != null)
            {
                ButtonFlash.Dispose();
                ButtonFlash = null;
            }

            if (ButtonSwitch != null)
            {
                ButtonSwitch.Dispose();
                ButtonSwitch = null;
            }

            if (CameraView != null)
            {
                CameraView.Dispose();
                CameraView = null;
            }

            if (ViewTop != null)
            {
                ViewTop.Dispose();
                ViewTop = null;
            }
        }
Example #7
0
    // Check all active and existing scripts on this gameObject that can be used and use them
    // Called by MouseLookScript.cs from a Use() raycast
    public void Use(UseData ud)
    {
        // ButtonSwitch - used by static switches and button panels
        bs = GetComponent <ButtonSwitch>();
        if (useButtonSwitch && bs != null)
        {
            bs.Use(ud);
        }

        cs = GetComponent <ChargeStation>();
        if (useChargeStation && cs != null)
        {
            cs.Use(ud);
        }

        dr = GetComponent <Door>();
        if (useDoor && dr != null)
        {
            dr.Use(ud);
        }

        hb = GetComponent <HealingBed>();
        if (useHealingBed && hb != null)
        {
            hb.Use(ud);
        }

        ke = GetComponent <KeypadElevator>();
        if (useKeypadElevator && ke != null)
        {
            ke.Use(ud);
        }

        kk = GetComponent <KeypadKeycode>();
        if (useKeypadKeycode && kk != null)
        {
            kk.Use(ud);
        }

        pl = GetComponent <PaperLog>();
        if (usePaperLog && pl != null)
        {
            pl.Use(ud);
        }

        pgp = GetComponent <PuzzleGridPuzzle>();
        if (usePuzzleGridPuzzle && pgp != null)
        {
            pgp.Use(ud);
        }

        uou = GetComponent <UseableObjectUse>();
        if (useUseableObjectUse && uou != null)
        {
            uou.Use(ud);
        }

        ua = GetComponent <UseableAttachment>();
        if (useUseableAttachment && ua != null)
        {
            ua.Use(ud);
        }
    }
    public IEnumerator ProcessTwitchCommand(string cmd)
    {
        cmd = cmd.ToLowerInvariant();
        if (cmd.Equals("toggle"))
        {
            yield return("Morsematics");

            ButtonSwitch.OnInteract();
            yield break;
        }
        if (cmd.Equals("lights on"))
        {
            if (!switchState)
            {
                yield return("Morsematics");

                ButtonSwitch.OnInteract();
            }
            yield break;
        }
        if (cmd.Equals("lights off"))
        {
            if (switchState)
            {
                yield return("Morsematics");

                ButtonSwitch.OnInteract();
            }
            yield break;
        }
        if (cmd.StartsWith("submit "))
        {
            cmd = cmd.Substring(7);
        }
        else if (cmd.StartsWith("transmit "))
        {
            cmd = cmd.Substring(9);
        }
        else if (cmd.StartsWith("tx "))
        {
            cmd = cmd.Substring(3);
        }
        else
        {
            yield return("sendtochaterror Valid commands are submit and toggle.");

            yield break;
        }

        int[] input = new int[cmd.Length];
        for (int a = 0; a < cmd.Length; a++)
        {
            if (cmd[a] == '.')
            {
                input[a] = 0;
            }
            else if (cmd[a] == '-')
            {
                input[a] = 1;
            }
            else
            {
                yield return("sendtochaterror Invalid morse character: '" + cmd[a] + "'");

                yield break;
            }
        }

        /*if(val.Length != 1) {
         *  yield return "sendtochaterror Solutions must be a single letter.";
         *  yield break;
         * }
         * int c = val[0] - 'a';
         * if(c < 0 || c > 25) {
         *  yield return "sendtochaterror Solutions must be a single letter.";
         *  yield break;
         * }
         *
         * int[] input = Morsify(val.ToUpperInvariant());*/
        yield return("Morsematics");

        foreach (int i in input)
        {
            yield return(ButtonTransmit);

            if (i == 1)
            {
                yield return(new WaitForSeconds(0.6f));
            }
            else
            {
                yield return(new WaitForSeconds(0.2f));
            }
            yield return(ButtonTransmit);

            yield return(new WaitForSeconds(0.2f));
        }
        yield return(new WaitForSeconds(2f)); //Allow answer to pass through before returning so that it's credited properly

        yield break;
    }
Example #9
0
    // SETUP PLANET
    public void PlanetSetup(PlanetStats thisPlanet)
    {
        // Initialize Variables

        // Set a reference to the child objects, Name and Image;
        planetNameObject  = gameObject.transform.Find("Name").gameObject;
        planetImageObject = gameObject.transform.Find("Image").gameObject;

        // Get the RectTransform of this planet and it's name object.
        planetRectTransform = GetComponent <RectTransform>();
        nameRectTransform   = planetNameObject.GetComponent <RectTransform>();

        // Get the starting versions of this Mode's co-ords and scale
        thisModeX = planetRectTransform.anchoredPosition.x;
        thisModeY = planetRectTransform.anchoredPosition.y;

        // Get the pixels per unit of the sprite being used
        ppu = planetImageObject.GetComponent <Image>().sprite.pixelsPerUnit;

        // Get reference to this planet's button
        planetButtonScript = gameObject.GetComponent <ButtonSwitch>();

        // Initialize audio controller reference
        audioObj = AudioController.Instance;

        // Setup the objects in accordance with the current mode
        currentMode = GameController.currentMode;
        if (currentMode == "ScaleMode")
        {
            // Set the scale of the planet relative to it's diameter
            diameterInPixels = thisPlanet.diameter * GameController.pixelsPerKm;
            thisModeScale    = diameterInPixels / ppu;
            planetImageObject.transform.localScale = new Vector2(thisModeScale, thisModeScale);

            // Keep the name above the scaled planet
            nameRectTransform = planetNameObject.GetComponent <RectTransform>();
            thisModeNameX     = nameRectTransform.anchoredPosition.x;
            thisModeNameY     = nameRectTransform.anchoredPosition.y;
            nameRectTransform.anchoredPosition = new Vector2(thisModeNameX, thisModeNameY + GameController.textScalar * diameterInPixels);
        }
        // Setup the distance mode planet to be standard size
        else if (gameObject.name == "Distance Planet")
        {
            // Reset planetIsMoving bool
            GameController.planetIsMoving = false;

            // Set this planet's name text position to the Planet Info version
            var nameX = nameRectTransform.anchoredPosition.x;
            nameRectTransform.anchoredPosition = new Vector2(nameX, GameController.infoNameY);

            // Set this planet's position and scale to the default version
            planetRectTransform.anchoredPosition   = new Vector2(GameController.defaultX, GameController.kmPlanetY);
            planetImageObject.transform.localScale = new Vector2(GameController.defaultScale, GameController.defaultScale);
        }
        else if (currentMode == "DistanceMode")
        {
            // Get the reference to the Distance Planet and it's import script
            distanceObj          = DistanceController.distanceObj;
            distanceImportScript = distanceObj.GetComponent <PlanetImport>();

            // Disable the button if this mini planet is the same as Distance Planet
            if (gameObject.name == distanceImportScript.planet.name)
            {
                planetButtonScript.ButtonDisable();
            }
        }

        // Save vector to variable for future use
        thisModeNameVector = nameRectTransform.anchoredPosition;
    }