Пример #1
0
 private void GenerateWeapon()
 {
     // Small catch for errors, should never reach this however
     if (!bGenerationSuccess)
     {
         Debug.Log("Error reached while generating gun!");
         return;
     }
     else
     {
         Debug.Log("No error found, have a nice day");
         // Creates new gameobject in scene
         GameObject NewWeapon = new GameObject(newWeapon_ID);
         // Creates child object for nonfunctional art
         GameObject BaseModel = GameObject.Instantiate(newWeapon_Model);
         BaseModel.transform.SetParent(NewWeapon.transform);
         BaseModel.name = "Weapon Model";
         // Creates child object for muzzle-point
         GameObject MuzzlePoint = new GameObject("GunMuzzle");
         MuzzlePoint.transform.SetParent(NewWeapon.transform);
         gunMasterScript NewScript = NewWeapon.AddComponent <gunMasterScript>();
         NewScript.SetInitValues(newWeapon_ID, newWeapon_Name, newWeapon_Damage, newWeapon_MaxClipSize, newWeapon_Spread, newWeapon_Range, newWeapon_ProjVelocity, newWeapon_ProjLife, newWeapon_FireRate, newWeapon_PelletAmount, newWeapon_ReloadTime, newWeapon_BurstAmount, newWeapon_ProjectileType, newWeapon_FiringMode);
         NewScript.goMuzzlePoint = MuzzlePoint;
     }
 }
Пример #2
0
    private void OnGUI()
    {
        GUILayout.Label("Character Editor", EditorStyles.boldLabel);

        newUnit_ID = EditorGUILayout.TextField("ID", newUnit_ID);
        var tt_ID = GUILayoutUtility.GetLastRect();

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

        newUnit_Name = EditorGUILayout.TextField("Display Name", newUnit_Name);
        var tt_Name = GUILayoutUtility.GetLastRect();

        GUI.Label(tt_Name, new GUIContent("", "Proper name in script, can be accessed by things such as UI that don't depend on uniqueness"));

        newUnit_HP = float.Parse(EditorGUILayout.TextField("Health", newUnit_HP.ToString()));
        var tt_HP = GUILayoutUtility.GetLastRect();

        GUI.Label(tt_HP, new GUIContent("", "Health of this character, tune it to match the weapons"));

        newUnit_HasShields = EditorGUILayout.Toggle("Has Shields", newUnit_HasShields);
        var tt_HasShields = GUILayoutUtility.GetLastRect();

        GUI.Label(tt_HasShields, new GUIContent("", "Shields take damage first and can regenerate"));
        if (newUnit_HasShields)
        {
            newUnit_ShieldNum = float.Parse(EditorGUILayout.TextField("Shield Hitpoints", newUnit_ShieldNum.ToString()));
            var tt_ShieldNum = GUILayoutUtility.GetLastRect();
            GUI.Label(tt_ShieldNum, new GUIContent("", "Shield hitpoints, takes damage before Health but otherwise identical purpose"));

            newUnit_ShieldRechargeRate = float.Parse(EditorGUILayout.TextField("Recharge Per Second", newUnit_ShieldRechargeRate.ToString()));
            var tt_ShieldRecharge = GUILayoutUtility.GetLastRect();
            GUI.Label(tt_ShieldRecharge, new GUIContent("", "Number of Shield hitpoints regenerated per second"));

            newUnit_ShieldWaitTime = float.Parse(EditorGUILayout.TextField("Charge Delay", newUnit_ShieldWaitTime.ToString()));
            var tt_ShieldWaitTime = GUILayoutUtility.GetLastRect();
            GUI.Label(tt_ShieldWaitTime, new GUIContent("", "Time after being attacked before shields start charging"));
        }

        newUnit_HasWeapon = EditorGUILayout.Toggle("Has Weapon", newUnit_HasWeapon);
        var tt_HasWeapon = GUILayoutUtility.GetLastRect();

        GUI.Label(tt_HasWeapon, new GUIContent("", "Determines if character has a weapon or not"));
        if (newUnit_HasWeapon)
        {
            newUnit_Weapon = (gunMasterScript)EditorGUILayout.ObjectField(("Weapon Prefab"), newUnit_Weapon, typeof(gunMasterScript), true);
            var tt_Weapon = GUILayoutUtility.GetLastRect();
            GUI.Label(tt_Weapon, new GUIContent("", "Weapon Asset used by this character, dependency injection"));
        }

        newUnit_Faction = int.Parse(EditorGUILayout.TextField("Team", newUnit_Faction.ToString()));
        var tt_Faction = GUILayoutUtility.GetLastRect();

        GUI.Label(tt_Faction, new GUIContent("", "Allegiance of this character, determines Friend or Foe"));

        newUnit_Model = (GameObject)EditorGUILayout.ObjectField("Base Object", newUnit_Model, typeof(GameObject), false);
        var tt_Model = GUILayoutUtility.GetLastRect();

        GUI.Label(tt_Model, new GUIContent("", "Model for this character, should be an existing prefab"));

        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 ((newUnit_ID == null) || (newUnit_ID == ""))
            {
                bGenerationSuccess = false;
                sGenerationMessage = "Error: Character ID";
            }
            else if (newUnit_HP <= 0)
            {
                bGenerationSuccess = false;
                sGenerationMessage = "Error: Health is 0 or negative";
            }
            else if ((newUnit_HasShields) && (newUnit_ShieldNum <= 0))
            {
                bGenerationSuccess = false;
                sGenerationMessage = "Error: Shield is 0 or negative";
            }
            else if (newUnit_Model == null)
            {
                bGenerationSuccess = false;
                sGenerationMessage = "Error: Base Object is null";
            }
            else if ((newUnit_HasWeapon) && (newUnit_Weapon == null))
            {
                bGenerationSuccess = false;
                sGenerationMessage = "Error: Weapon slot is empty";
            }

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

            GenerateCharacter();
        }
    }
Пример #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();
        }
    }