Ejemplo n.º 1
0
 // CONSTRUCTOR
 public void SetInitValues(string newID, string newName, float newDamage, int newClip, float newSpread, float newRange, float newSpeed, float newLife, float newRate, int newPellet, float newReloadTime, int newBurst, enumProjectileType newProjType, enumFiringMode newFiringMode)
 {
     sGunID        = newID;
     sGunName      = newName;
     iClipMax      = newClip;
     fFireSpread   = newSpread;
     fFireRange    = newRange;
     fProjSpeed    = newSpeed;
     fProjLife     = newLife;
     fFireRate     = newRate;
     iPelletAmount = newPellet;
     iClipCur      = iClipMax;
     eProjType     = newProjType;
     eFireMode     = newFiringMode;
     fDamage       = newDamage;
     fReloadTime   = newReloadTime;
     iBurstAmount  = newBurst;
 }
Ejemplo n.º 2
0
    private void OnGUI()
    {
        GUILayout.Label("Weapon Editor", EditorStyles.boldLabel);


        // Mostly relating to identification
        newWeapon_ID = EditorGUILayout.TextField("Weapon ID", newWeapon_ID);
        var tt_ID = GUILayoutUtility.GetLastRect();

        GUI.Label(tt_ID, new GUIContent("", "The name that will appear in the hierarchy"));

        newWeapon_Name = EditorGUILayout.TextField("Weapon Name", newWeapon_Name);
        var tt_Name = GUILayoutUtility.GetLastRect();

        GUI.Label(tt_Name, new GUIContent("", "Proper name in script, this can be used for ingame purposes"));

        newWeapon_Model = (GameObject)EditorGUILayout.ObjectField("Mesh", newWeapon_Model, typeof(GameObject), false);
        var tt_Model = GUILayoutUtility.GetLastRect();

        GUI.Label(tt_Model, new GUIContent("", "Pre-existing model of the weapon goes here"));

        newWeapon_Damage = float.Parse(EditorGUILayout.TextField("Damage", newWeapon_Damage.ToString()));
        var tt_Damage = GUILayoutUtility.GetLastRect();

        GUI.Label(tt_Damage, new GUIContent("", "How much damage the weapon does"));

        // Weapons ammunition info
        newWeapon_MaxClipSize = int.Parse(EditorGUILayout.TextField("Clip Size", newWeapon_MaxClipSize.ToString()));
        var tt_Clip = GUILayoutUtility.GetLastRect();

        GUI.Label(tt_Clip, new GUIContent("", "Amount of shots before reloading, leave 0 for infinite"));

        newWeapon_FireRate = float.Parse(EditorGUILayout.TextField("Rate of Fire", newWeapon_FireRate.ToString()));
        var tt_FireRate = GUILayoutUtility.GetLastRect();

        GUI.Label(tt_FireRate, new GUIContent("", "Cooldown between each shot"));


        // Weapons range/spread and what type of projectile it uses
        newWeapon_Spread = float.Parse(EditorGUILayout.TextField("Fire Spread", newWeapon_Spread.ToString()));
        var tt_Spread = GUILayoutUtility.GetLastRect();

        GUI.Label(tt_Spread, new GUIContent("", "Firing arc of the weapon, higher value = less accurate"));

        newWeapon_ProjectileType = (enumProjectileType)EditorGUILayout.EnumPopup("Projectile Style", newWeapon_ProjectileType);
        var tt_ProjectileType = GUILayoutUtility.GetLastRect();

        GUI.Label(tt_ProjectileType, new GUIContent("", "Invisible Hitscan vs Physical Projectile"));

        if (newWeapon_ProjectileType == enumProjectileType.Raycast)
        {
            newWeapon_Range = float.Parse(EditorGUILayout.TextField("Weapon Range", newWeapon_Range.ToString()));
            var tt_Range = GUILayoutUtility.GetLastRect();
            GUI.Label(tt_Range, new GUIContent("", "If hitscan, how far away can it hit?"));
        }
        else
        {
            newWeapon_ProjLife = float.Parse(EditorGUILayout.TextField("Projectile Life", newWeapon_ProjLife.ToString()));
            var tt_Life = GUILayoutUtility.GetLastRect();
            GUI.Label(tt_Life, new GUIContent("", "If Projectile, how long does the bullet live?"));

            newWeapon_ProjVelocity = float.Parse(EditorGUILayout.TextField("Projectile Speed", newWeapon_ProjVelocity.ToString()));
            var tt_Velocity = GUILayoutUtility.GetLastRect();
            GUI.Label(tt_Velocity, new GUIContent("", "If Projectile, how fast does the bullet move?"));
        }

        newWeapon_PelletAmount = int.Parse(EditorGUILayout.TextField("Pellet Amount", newWeapon_PelletAmount.ToString()));
        var tt_Pellet = GUILayoutUtility.GetLastRect();

        GUI.Label(tt_Pellet, new GUIContent("", "For shotgun-like guns, how many pellets are fired per shot"));

        newWeapon_ReloadTime = float.Parse(EditorGUILayout.TextField("Reload Time", newWeapon_ReloadTime.ToString()));
        var tt_Reload = GUILayoutUtility.GetLastRect();

        GUI.Label(tt_Reload, new GUIContent("", "How long it takes for the gun to reload"));


        // The way the gun fires (affects what happens when the "fire" signal is given)
        newWeapon_FiringMode = (enumFiringMode)EditorGUILayout.EnumPopup("Firing Style", newWeapon_FiringMode);
        var tt_FiringMode = GUILayoutUtility.GetLastRect();

        GUI.Label(tt_FiringMode, new GUIContent("", "How the weapon acts when fired, can it continue firing if the trigger is held?"));

        if (newWeapon_FiringMode == enumFiringMode.BurstShot)
        {
            newWeapon_BurstAmount = int.Parse(EditorGUILayout.TextField("Burst-fire Amount", newWeapon_BurstAmount.ToString()));
            var tt_BurstAmount = GUILayoutUtility.GetLastRect();
            GUI.Label(tt_BurstAmount, new GUIContent("", "How many shots are fired from a single click"));
        }

        if (GUILayout.Button(sGenerationMessage))
        {
            // Runs a series of tests to ensure all data needed for generation is there
            // Each field is tested for success and an error message is written over the button if failure is found
            // Some fields don't need to be tested however
            if ((newWeapon_ID == null) || (newWeapon_ID == ""))
            {
                bGenerationSuccess = false;
                sGenerationMessage = "Error: Weapon ID";
            }
            else if ((newWeapon_Name == null) || (newWeapon_Name == ""))
            {
                bGenerationSuccess = false;
                sGenerationMessage = "Error: Weapon Name";
            }
            else if ((newWeapon_Model == null))
            {
                bGenerationSuccess = false;
                sGenerationMessage = "Error: Weapon Model";
            }
            else if (newWeapon_Damage < 0)
            {
                bGenerationSuccess = false;
                sGenerationMessage = "Error: Damage is negative";
            }
            else if ((newWeapon_FireRate <= 0))
            {
                bGenerationSuccess = false;
                sGenerationMessage = "Error: Firerate is 0 or negative";
            }
            else if ((newWeapon_MaxClipSize < 0))
            {
                bGenerationSuccess = false;
                sGenerationMessage = "Error: Clip size is negative";
            }
            else if ((newWeapon_Spread < 0))
            {
                bGenerationSuccess = false;
                sGenerationMessage = "Error: Spread is negative";
            }
            else if ((newWeapon_ProjectileType == enumProjectileType.Raycast) && (newWeapon_Range <= 0))
            {
                bGenerationSuccess = false;
                sGenerationMessage = "Error: Range is 0 or negative";
            }
            else if ((newWeapon_ProjectileType == enumProjectileType.Projectile) && (newWeapon_ProjVelocity <= 0))
            {
                bGenerationSuccess = false;
                sGenerationMessage = "Error: Projectile Speed is 0 or negative";
            }
            else if ((newWeapon_ProjectileType == enumProjectileType.Projectile) && (newWeapon_ProjLife <= 0))
            {
                bGenerationSuccess = false;
                sGenerationMessage = "Error: Projectile Life is 0 or negative";
            }
            else if (newWeapon_PelletAmount <= 0)
            {
                bGenerationSuccess = false;
                sGenerationMessage = "Error: Pellets are either 0 or negative";
            }
            else if (newWeapon_ReloadTime <= 0)
            {
                bGenerationSuccess = false;
                sGenerationMessage = "Error: Reload Time is either 0 or negative";
            }
            else if ((newWeapon_FiringMode == enumFiringMode.BurstShot) && (newWeapon_BurstAmount <= 0))
            {
                bGenerationSuccess = false;
                sGenerationMessage = "Error: Burst amount is either 0 or negative";
            }

            // All fields are passed, therefore gun can be generated properly
            else
            {
                bGenerationSuccess = true;
                sGenerationMessage = "Success!";
            }

            GenerateWeapon();
        }
        var tt_Generate = GUILayoutUtility.GetLastRect();

        GUI.Label(tt_Generate, new GUIContent("", "Create weapon using these parameters"));
    }
Ejemplo n.º 3
0
    // Tells gun to fire, behaviour varies based on firingmode
    private IEnumerator FireWeaponLoop()
    {
        // Conditions: character must have a gun, gun must have the right script, character must be willing to fire
        if ((characterHasWeapon) && (characterWeapon.GetComponent <gunMasterScript>() != null) && (willFire))
        {
            navAgent.isStopped = true;

            gunMasterScript gunScript = characterWeapon.GetComponent <gunMasterScript>(); // Will work due to middle condition above
            enumFiringMode  gunMode   = gunScript.eFireMode;
            float           fireRate  = (1 / gunScript.fFireRate);
            willFire = false;                 // Prevents this function being called repeatedly
            switch (gunMode)                  // Behaviour is different depending on firing style
            {
            case (enumFiringMode.Singleshot): // Fires single shots repeatedly for a while, then wait
            {
                // Fires a random number of times, waiting 1 second between each shot
                int fireAmount = Random.Range(1, gunScript.iClipCur);
                for (int i = 0; i < fireAmount; i++)
                {
                    gunScript.BeginFiring();
                    yield return(new WaitForSeconds(fireRate + 1f));
                }
                // Makes character reload before firing again
                gunScript.Reloading();
                yield return(new WaitForSeconds(gunScript.fReloadTime + 1f));

                break;
            }

            case (enumFiringMode.BurstShot):     // Similar to single, except it considers number of rounds used in burst
            {
                // Fires a random number of times, waiting 1 second between each shot
                int fireAmount = Random.Range(1, (gunScript.iClipCur / gunScript.iBurstAmount));
                for (int i = 0; i < fireAmount; i++)
                {
                    gunScript.BeginFiring();
                    yield return(new WaitForSeconds(fireRate + 1f));
                }
                // Makes character reload before firing again
                gunScript.Reloading();
                yield return(new WaitForSeconds(gunScript.fReloadTime + 1f));

                break;
            }

            case (enumFiringMode.AutomaticFire):     // Fires long burst then reloads
            {
                // Begins firing, waits random time between 2 and 10 seconds, then stops
                gunScript.BeginFiring();
                yield return(new WaitForSeconds(Random.Range(2, 10)));

                gunScript.EndFiring();

                // Makes character reload before firing again
                gunScript.Reloading();
                yield return(new WaitForSeconds(gunScript.fReloadTime + 1f));

                break;
            }
            }
            yield return(new WaitForSeconds(0.5f));

            willFire = true;
            // Resets moving/rotation behaviour
            navAgent.updateRotation = true;
            navAgent.isStopped      = false;
            // Checks if there are any new targets in the area
            AcquireTarget();
        }
    }