Exemplo n.º 1
0
 public void DisposeAuto()
 {
     if (autoAim != null)
     {
         autoAim.Dispose();
     }
     autoAim = null;
 }
Exemplo n.º 2
0
    static void EnsureInstance()
    {
        if (instance)
        {
            return;
        }

        GameObject instanceGO = new GameObject("GryoRotation");

        instance = instanceGO.AddComponent <GyroRotation>();
    }
Exemplo n.º 3
0
        public Program()
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update1;

            #region serializer
            nameSerializer.AddValue("MAINCAMERANAME", x => x, "AimCamera");
            nameSerializer.AddValue("PROJECTORNAME", x => x, "Proj");
            nameSerializer.AddValue("LEADPROJECTORNAME", x => x, "LeadProj");
            nameSerializer.AddValue("COCKPITNAME", x => x, "Cockpit");
            nameSerializer.AddValue("MISSILECONTROLLER", x => x, "MissileController");

            parameterSerializer.AddValue("detectionRange", x => double.Parse(x), 1000);
            parameterSerializer.AddValue("projectionDistanceFromCockpit", x => double.Parse(x), 30);

            parameterSerializer.AddValue("projectionOffsetX", x => int.Parse(x), 0);
            parameterSerializer.AddValue("projectionOffsetY", x => int.Parse(x), 0);
            parameterSerializer.AddValue("projectionOffsetZ", x => int.Parse(x), 0);

            string customDat = Me.CustomData;
            nameSerializer.FirstSerialization(ref customDat);
            parameterSerializer.FirstSerialization(ref customDat);
            Me.CustomData = customDat;
            nameSerializer.DeSerialize(Me.CustomData);
            parameterSerializer.DeSerialize(Me.CustomData);
            #endregion

            cameras = new List <IMyCameraBlock>();
            GridTerminalSystem.GetBlocksOfType(cameras);
            foreach (var cam in cameras)
            {
                cam.EnableRaycast = true;
            }

            mainCam = GridTerminalSystem.GetBlockWithName(MAINCAMERANAME) as IMyCameraBlock;
            if (mainCam == null)
            {
                throw new Exception($"No camerablock named \"{MAINCAMERANAME}\"");
            }

            cockpit = GridTerminalSystem.GetBlockWithName(COCKPITNAME) as IMyShipController;
            if (cockpit == null)
            {
                throw new Exception($"No cockpit named \"{COCKPITNAME}\"");
            }

            var proj     = GridTerminalSystem.GetBlockWithName(PROJECTORNAME) as IMyProjector;
            var leadproj = GridTerminalSystem.GetBlockWithName(LEADPROJECTORNAME) as IMyProjector;

            var gunList = new List <IMyUserControllableGun>();
            GridTerminalSystem.GetBlocksOfType(gunList, x => x is IMySmallGatlingGun);
            guns = new GunSequencer(gunList);

            if (proj != null)
            {
                projector = new ProjectorVisualization(proj, projectionOffset);
            }

            if (leadproj != null)
            {
                leadProjector = new ProjectorVisualization(leadproj, projectionOffset);
            }

            missileManager = GridTerminalSystem.GetBlockWithName(MISSILECONTROLLER) as IMyProgrammableBlock;

            autoAim = null;
            DisposeAuto();

            random = new Random();
        }
Exemplo n.º 4
0
        public void Main(string argument, UpdateType uType)
        {
            //MUST BE EXECUTED AT THE START OF EACH TICK!
            cockpitpos = cockpit.GetPosition() + cockpit.WorldMatrix.Backward * 0.8 - cockpit.WorldMatrix.Up * 0.5;

            if (argument.ToUpper() == "TARGET")
            {
                DisposeDetection();
                DisposeAuto();
                AquireTarget();
            }
            else if (argument.ToUpper() == "AUTOMATIC")
            {
                if (autoAim == null)
                {
                    autoAim = new GyroRotation(this, cockpit);
                }
                else
                {
                    DisposeAuto();
                }

                Echo("Automatic!");
            }
            else if (argument.ToUpper() == "HOLDFIRE")
            {
                if (!guns.firing)
                {
                    guns.Shoot();
                }
                else
                {
                    guns.StopShooting();
                }
            }
            else if (argument.ToUpper() == "FULLAUTOMATIC")
            {
                if (autoAim == null)
                {
                    autoAim = new GyroRotation(this, cockpit);
                    if (!guns.firing)
                    {
                        guns.Shoot();
                    }
                }
                else
                {
                    DisposeAuto();
                    guns.StopShooting();
                }
            }
            else if (argument.ToUpper() == "TRYLAUNCHMISSILE")
            {
                if (detection != null && missileManager != null)
                {
                    if (detection.hasTarget)
                    {
                        missileManager.TryRun($"DeployAtTarget|{detection.GetPredictedTargetLocation()}");
                    }
                }
            }

            //Eachtick
            if (detection != null)
            {
                if (detection.DoDetect())
                {
                    GetTargetInterception(detection.targetI);
                }

                if (!detection.hasTarget)
                {
                    DisposeDetection();
                    DisposeAuto();
                }
            }
            guns.Main();
        }
Exemplo n.º 5
0
    void Awake()
    {
        instance = this;

        // find the current parent of the camera's transform
        Transform currentParent = transform.parent;

        // instantiate a new transform
        GameObject camParent = new GameObject("camParent");

        // match the transform to the camera position
        camParent.transform.position = transform.position;

        // make the new transform the parent of the camera transform
        transform.parent = camParent.transform;

        // make the original parent the grandparent of the camera transform
        //camParent.transform.parent = currentParent;

        // instantiate a new transform
        GameObject camGrandparent = new GameObject("camGrandParent");

        // match the transform to the camera position
        camGrandparent.transform.position = transform.position;

        // make the new transform the parent of the camera transform
        camParent.transform.parent = camGrandparent.transform;

        // make the original parent the grandparent of the camera transform
        camGrandparent.transform.parent = currentParent;

        // check whether device supports gyroscope
        //Removed Unity version Checks to support unity 4 - dustin.hagen
        gyroBool = SystemInfo.supportsGyroscope;

        camParent.transform.eulerAngles = new Vector3(90, 90, 0);
        quatMult = new Quaternion(0, 0, 1, 0);

        if (gyroBool)
        {
            gyro         = Input.gyro;
            gyro.enabled = true;

            #if UNITY_IPHONE
            camParent.transform.eulerAngles = new Vector3(90, 90, 0);

            if (Screen.orientation == ScreenOrientation.LandscapeLeft)
            {
                quatMult = new Quaternion(0, 0, 1, 0);         //**
            }
            else if (Screen.orientation == ScreenOrientation.LandscapeRight)
            {
                quatMult = new Quaternion(0, 0, 1, 0);         //**
            }
            else if (Screen.orientation == ScreenOrientation.Portrait)
            {
                quatMult = new Quaternion(0, 0, 1, 0);         //**
            }
            else if (Screen.orientation == ScreenOrientation.PortraitUpsideDown)
            {
                quatMult = new Quaternion(0, 0, 1, 0);         // Unable to build package on upsidedown
            }
            #endif
            #if UNITY_ANDROID
            camParent.transform.eulerAngles = new Vector3(90, 90, 0);
            if (Screen.orientation == ScreenOrientation.LandscapeLeft)
            {
                quatMult = new Quaternion(0, 0, 1, 0);         //**
            }
            else if (Screen.orientation == ScreenOrientation.LandscapeRight)
            {
                quatMult = new Quaternion(0, 0, 1, 0);         //**
            }
            else if (Screen.orientation == ScreenOrientation.Portrait)
            {
                quatMult = new Quaternion(0, 0, 1, 0);         //**
            }
            else if (Screen.orientation == ScreenOrientation.PortraitUpsideDown)
            {
                quatMult = new Quaternion(0, 0, 1, 0);         // Unable to build package on upsidedown
            }
            #endif
            Screen.sleepTimeout = SleepTimeout.NeverSleep;
        }
        else
        {
            #if UNITY_EDITOR
            //print("NO GYRO");
            #endif
        }
    }