示例#1
0
文件: Laser.cs 项目: EPKgit/2DTopDown
    public override bool AttemptUseAbility(InputAction.CallbackContext ctx, Vector2 inputDirection)
    {
        if (DEBUGFLAGS.ABILITY)
        {
            Debug.Log(string.Format("{0} ATTEMPT USE perf:{1} strt:{2} canc:{3}", name, ctx.performed, ctx.started, ctx.cancelled));
        }
        if (!IsCastable())
        {
            return(false);
        }
        if (!started)        //the first press of the button
        {
            started = true;
            temp    = PoolManager.instance.RequestObject(laserPrefab);

            BaseLaser laser = temp.GetComponent <BaseLaser>();
            // temp.transform.localScale = new Vector3(size, size, size);
            laser.Setup
            (
                playerAbilities.transform.position, inputDirection, playerAbilities.gameObject, laser.totalLength
            );
            temp.GetComponent <Poolable>().Reset();
            return(true);
        }
        started = false;
        UseAbility(ctx, inputDirection);
        return(false);
    }
示例#2
0
        /// <summary>
        /// Opens dialog to select laser executable manually.
        /// Gets the filename of selected executable and adds it to the list of sensors to be loaded.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLoadLaser_Click(object sender, EventArgs e)
        {
            DialogResult result = ofdSelectLaser.ShowDialog();

            if (result == DialogResult.OK)
            {
                // get sensor executable title and add it to list
                Assembly  laserAssembly = Assembly.LoadFrom(ofdSelectLaser.FileName);
                Type[]    types         = laserAssembly.GetExportedTypes();
                BaseLaser laser         = Activator.CreateInstance(types[0]) as BaseLaser;
                string    laserTitle    = laser.Title;
                if (cmbLasers.Items.Contains(laserTitle))
                {
                    int i = 1;
                    laserTitle = laserTitle + " (" + i.ToString() + ")";
                    while (true)
                    {
                        if (!cmbLasers.Items.Contains(laserTitle))
                        {
                            break;
                        }
                    }
                }

                cmbLasers.Items.Add(laserTitle);
                _laserPaths.Add(ofdSelectLaser.FileName);
                cmbLasers.SelectedIndex = cmbLasers.Items.Count - 1;
                EnableLaserRemoval();
            }
        }
示例#3
0
 /// <summary>
 /// When laser form is closed, the resources must be released.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void laser_FormClosed(object sender, FormClosedEventArgs e)
 {
     _laser.FormClosed -= laser_FormClosed;
     _laser.Dispose();
     _laser          = null;
     gbLaser.Enabled = true;
 }
示例#4
0
        /// <summary>
        /// Starts the selected laser.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStartLaser_Click(object sender, EventArgs e)
        {
            // check the sensor part to exists
            if (!File.Exists(_laserPaths[cmbLasers.SelectedIndex]))
            {
                MessageBox.Show("The laser part is not found on path " +
                                _laserPaths[cmbLasers.SelectedIndex] +
                                ". Check the config file or load the part manually using \"Load\" button.",
                                "Laser part not found.",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // load the sensor part
            Assembly laserAssembly = Assembly.LoadFrom(_laserPaths[cmbLasers.SelectedIndex]);

            Type[] types = laserAssembly.GetExportedTypes();
            _laser             = Activator.CreateInstance(types[0]) as BaseLaser;
            _laser.FormClosed += laser_FormClosed;
            _laser.Show();

            // Organize windows
            _laser.Location = new Point(Location.X + Size.Width + 10, 10);

            // Disable controls
            gbLaser.Enabled = false;
        }
示例#5
0
        public ZWPictureBox()
        {
            // enable double buffering
            this.SetStyle(ControlStyles.UserPaint |
                          ControlStyles.AllPaintingInWmPaint |
                          ControlStyles.OptimizedDoubleBuffer, true);
            this.laser        = new FixedLaser(this);
            rulers            = new Rulers(this);
            listViewItemArray = new ListViewItemArray();
            GraphicsList      = new GraphicsList();
            this.GraphicsList.DrawObjsChanged += GraphicsList_DrawObjsChanged;

            Initialize();
            InitializeControls();
            InitializeImageTracker();

            this.PictureBoxPaintedEvent += imageTracker.OnPicturePainted;
        }
示例#6
0
        /// <summary>
        /// Finds laser executables and populates the dropdown list.
        /// </summary>
        /// <param name="laserPath">Path to laser executables</param>
        /// <param name="selectedIndex">Selected index for dropdownlist</param>
        private void FindLasers(string laserPath, JArray userLasers, int selectedIndex)
        {
            if (!Path.IsPathRooted(laserPath))
            {
                laserPath = Path.GetFullPath(Path.Combine(BASE_DIR, laserPath));
            }
            ofdSelectLaser.InitialDirectory = laserPath;

            string[]      allLaserExes = Directory.GetFiles(laserPath, "*.exe", SearchOption.AllDirectories);
            List <string> laserTitles  = new List <string>();

            foreach (string laserExe in allLaserExes)
            {
                if (!laserExe.Contains("ref"))
                {
                    _laserPaths.Add(laserExe);
                    Assembly  laserAssembly = Assembly.LoadFrom(laserExe);
                    Type[]    types         = laserAssembly.GetExportedTypes();
                    BaseLaser laser         = Activator.CreateInstance(types[0]) as BaseLaser;
                    laserTitles.Add(laser.Title);
                }
            }

            cmbLasers.Items.AddRange(laserTitles.ToArray());
            _numInstalledLasers = laserTitles.Count;

            // Finally load the sensors added by user
            foreach (JToken laser in userLasers)
            {
                cmbLasers.Items.Add(laser["title"]);
                _laserPaths.Add(Path.GetFullPath((string)laser["path"]));
            }

            if (selectedIndex < cmbLasers.Items.Count)
            {
                cmbLasers.SelectedIndex = selectedIndex;
            }

            EnableLaserRemoval();
        }