public static WeaponParameters CreateWeaponSetInFolder(string folderPath, string weaponName, WeaponScript linkedWeapon)
    {
        WeaponParameters     weaponParams     = ScriptableObject.CreateInstance <WeaponParameters>();
        ShootParameters      shootParams      = ScriptableObject.CreateInstance <ShootParameters>();
        ProjectileParameters projectileParams = ScriptableObject.CreateInstance <ProjectileParameters>();

        weaponParams.weaponName = weaponName;

        weaponParams.SetWeaponPrefab(linkedWeapon);

        weaponParams.SetShootParameters(shootParams);

        ProjectileScript baseProjectilePrefab = AssetDatabase.LoadAssetAtPath <ProjectileScript>("Assets/Weapons/BaseProjectile.prefab");

        shootParams.SetProjectilePrefab(baseProjectilePrefab);

        shootParams.SetProjectileParameters(projectileParams);

        string weaponPath     = AssetDatabase.GenerateUniqueAssetPath(folderPath + "/" + weaponName + " Weapon Parameters.asset");
        string shootPath      = AssetDatabase.GenerateUniqueAssetPath(folderPath + "/" + weaponName + " Shoot Parameters.asset");
        string projectilePath = AssetDatabase.GenerateUniqueAssetPath(folderPath + "/" + weaponName + " Projectiles Parameters.asset");

        AssetDatabase.CreateAsset(weaponParams, weaponPath);
        AssetDatabase.CreateAsset(shootParams, shootPath);
        AssetDatabase.CreateAsset(projectileParams, projectilePath);

        EditorUtility.SetDirty(weaponParams);
        EditorUtility.SetDirty(shootParams);
        EditorUtility.SetDirty(projectileParams);

        return(weaponParams);
    }
    /// <summary>
    /// Tire le projectile en lui appliquant différents paramètres
    /// </summary>
    /// <param name="newParam">Paramètres de tirs appliqués à ce projectile</param>
    /// <param name="startPosition">Position depuis laquelle ce projectile sera tiré</param>
    /// <param name="endPosition">Position visée par ce projectile</param>
    public override void ShootProjectile(ProjectileParameters newParam, Vector3 startPosition, Vector3 endPosition)
    {
        gameObject.SetActive(true);

        projectileParameters = newParam;
        boulderStartPosition = startPosition;
        boulderEndPosition   = endPosition;

        projectileParameters.SetUpParameters();
        projectileBody.velocity         = Vector3.zero;
        projectileSizeParent.localScale = Vector3.one * projectileParameters.GetCurrentProjectileSize;
        lifetimeEnded = false;

        projectileParameters.SetLifeTime(GetLifeTimeWithDistance(Vector3.Distance(startPosition, endPosition)));

        relatedHitbox.SetUp(this);
        relatedHitbox.gameObject.SetActive(false);

        projectileRenderer.gameObject.SetActive(true);

        startedFall             = false;
        projectileFunctionEnded = false;
        persistingPlaced        = false;
        projectileReturned      = false;
        explodedOnContact       = false;

        ResetAllSpecialEffects();
        SetUpAirRotation();
    }
    void FireProjectile()
    {
        GameObject           projectileSpawnObject = gameObject.transform.Find("ProjectileSpawn").gameObject;
        ProjectileParameters projectileParams      = gunParameters.projectileParameters;

        if (projectileSpawnObject != null)
        {
            Vector3    spawn      = projectileSpawnObject.transform.position;
            GameObject projectile = Instantiate(projectileParams.GetProjectile(), spawn, Quaternion.Euler(Camera.main.transform.forward));
            projectile.transform.rotation = Quaternion.Euler(Camera.main.transform.forward);
            Rigidbody rb = projectile.gameObject.GetComponent <Rigidbody>();

            if (rb != null)
            {
                rb.AddForce(transform.forward * projectileParams.speed);
                ProjectileScript projectileScript = projectile.GetComponent <ProjectileScript>();
                if (projectileScript != null)
                {
                    projectileScript.SetParameters(projectileParams.type, projectileParams.fuse, projectileParams.detonationForce, projectileParams.radius, projectileParams.damage);
                }
                else
                {
                    Destroy(projectile);
                    Debug.Log("No projectile script attached, destroying projectile");
                }
            }
        }
    }
Beispiel #4
0
 public static void Initialize(this IProjectile projectile, Vector2 gridVelocity, ProjectileParameters projectileParameters, DamageTypes damageParameters, Vector3 targetPosition, Quaternion targetRotation, Transform projectileTransform, int sourceGridID)
 {
     projectileTransform.position = targetPosition;
     projectileTransform.rotation = targetRotation;
     projectile.damageTypes       = damageParameters;
     projectile.projectileReferences.rb2d.AddForce(gridVelocity.ToVector3() + (projectileTransform.right * projectileParameters.speed));
     projectile.sourceGridID = sourceGridID;
 }
Beispiel #5
0
 private void Start()
 {
     projectileParameters = GetComponent <ProjectileParameters>();
     distanceOnPath       = projectileParameters.initialDistanceOnPath;
     speed += projectileParameters.initialSpeed;
     if (projectileParameters.direction == -1)
     {
         speed = -speed;
     }
 }
Beispiel #6
0
 public GunParameters(GunType _type, int _damage, int _maxAmmo, float _rateOfFire, float _reloadSpeed, float _hitscanRange, GameObject _object, ProjectileParameters _projectile)
 {
     gunType              = _type;
     damage               = _damage;
     maxAmmo              = _maxAmmo;
     rateOfFire           = _rateOfFire;
     reloadSpeed          = _reloadSpeed;
     hitscanRange         = _hitscanRange;
     currentGunObject     = _object;
     projectileParameters = _projectile;
 }
    public static void ShowProjectileParameters(ProjectileParameters projParameters, float indentValue)
    {
        SerializedObject serializedParameters = new SerializedObject(projParameters);

        serializedParameters.Update();

        SerializedProperty speedAttribute    = serializedParameters.FindProperty("projectileSpeed");
        SerializedProperty lifetimeAttribute = serializedParameters.FindProperty("projectileLifetime");
        SerializedProperty sizeAttribute     = serializedParameters.FindProperty("projectileSize");
        SerializedProperty damagesAttribute  = serializedParameters.FindProperty("projectileDamages");

        EditorGUI.PropertyField(EditorStaticMethods.GetIndentedControlRect(indentValue), speedAttribute,
                                new GUIContent(projParameters.GetProjectileSpeed.mode == MinMaxMode.Constant ? "Projectile Speed" : "Random Projectile Speed",
                                               projParameters.GetProjectileSpeed.mode == MinMaxMode.Constant ? "The speed of the projectile" : "The speed of the projectile, randomly picked between the two Values"));

        if (projParameters.GetProjectileSpeed.minValue < 0)
        {
            projParameters.ChangeProjectileMinSpeed(0);
        }

        if (projParameters.GetProjectileSpeed.maxValue < 0)
        {
            projParameters.ChangeProjectileMaxSpeed(0);
        }

        EditorGUI.PropertyField(EditorStaticMethods.GetIndentedControlRect(indentValue), lifetimeAttribute,
                                new GUIContent(projParameters.GetProjectileLifetime.mode == MinMaxMode.Constant ? "Projectile Lifetime" : "Random Projectile Lifetime",
                                               projParameters.GetProjectileLifetime.mode == MinMaxMode.Constant ? "The lifeTime of the projectile" : "The lifeTime of the projectile, randomly picked between the two Values"));

        if (projParameters.GetProjectileLifetime.minValue < 0.01f)
        {
            projParameters.ChangeProjectileMinLifetime(0.01f);
        }

        if (projParameters.GetProjectileLifetime.maxValue < 0.01f)
        {
            projParameters.ChangeProjectileMaxLifetime(0.01f);
        }

        EditorGUI.PropertyField(EditorStaticMethods.GetIndentedControlRect(indentValue), sizeAttribute);
        if (projParameters.GetProjectileSize < 0.01f)
        {
            projParameters.ChangeSize(0.01f);
        }

        EditorGUI.PropertyField(EditorStaticMethods.GetIndentedControlRect(indentValue), damagesAttribute);
        if (projParameters.GetProjectileDamages < 1)
        {
            projParameters.ChangeDamages(1);
        }

        serializedParameters.ApplyModifiedProperties();
    }
Beispiel #8
0
    GunParameters GenerateNewGunParameters()
    {
        GameObject    inventoryObject = GameObject.FindGameObjectWithTag("Inventory");
        GunParameters gunParameters1;
        GunParameters gunParameters2;
        GunParameters newParameters = null;

        if (inventoryObject != null)
        {
            InventoryScript      inventory           = inventoryObject.GetComponent <InventoryScript>();
            List <GunParameters> listOfGunParameters = inventory.GetWeaponsInInventory();
            int numOfEquippedGuns = 0;

            foreach (GunParameters gp in listOfGunParameters)
            {
                if (gp != null)
                {
                    numOfEquippedGuns += 1;
                }
            }

            if (numOfEquippedGuns >= 2)
            {
                gunParameters1 = listOfGunParameters[0];
                gunParameters2 = listOfGunParameters[1];

                GunType              newGunType          = GenerateNewGunType();
                int                  newDamage           = GenerateNewGunDamage(gunParameters1.damage, gunParameters2.damage);
                int                  newMaxAmmo          = GenerateNewGunMaxAmmo(gunParameters1.maxAmmo, gunParameters2.maxAmmo);
                float                newRateOfFire       = GenerateNewGunRateOfFire(gunParameters1.rateOfFire, gunParameters2.rateOfFire);
                float                newReloadSpeed      = GenerateNewGunReloadSpeed(gunParameters1.reloadSpeed, gunParameters2.reloadSpeed);
                float                newHitscanRange     = GenerateNewGunHitscanRange(gunParameters1.hitscanRange, gunParameters2.hitscanRange);
                GameObject           newGameObject       = GenerateNewGameObject(gunParameters1.currentGunObject, gunParameters2.currentGunObject);
                ProjectileParameters newProjectileParams = GenerateNewProjectileParameters(gunParameters1.projectileParameters, gunParameters2.projectileParameters);
                newParameters = new GunParameters(newGunType, newDamage, newMaxAmmo, newRateOfFire, newReloadSpeed, newHitscanRange, newGameObject, newProjectileParams);
            }
            else if (numOfEquippedGuns == 1)
            {
                foreach (GunParameters gp in listOfGunParameters)
                {
                    if (gp != null)
                    {
                        newParameters = gp;
                    }
                }
            }
        }

        return(newParameters);
    }
Beispiel #9
0
    ProjectileParameters GenerateNewProjectileParameters(ProjectileParameters pp1, ProjectileParameters pp2)
    {
        ProjectileParameters newParams;
        ProjectileType       newType = GenerateNewProjectileType();
        float newFuse   = GenerateNewProjectileFuse(pp1.fuse, pp2.fuse);
        float newSpeed  = GenerateNewProjectileSpeed(pp1.speed, pp2.speed);
        float newForce  = GenerateNewProjectileForce(pp1.detonationForce, pp2.detonationForce);
        float newRadius = GenerateNewProjectileRadius(pp1.radius, pp2.radius);
        int   newDamage = GenerateNewProjectileDamage(pp1.damage, pp2.damage);

        newParams = new ProjectileParameters(newType, newFuse, newSpeed, newForce, newRadius, newDamage);

        return(newParams);
    }
Beispiel #10
0
    /// <summary>
    /// Tire le projectile en lui appliquant différents paramètres
    /// </summary>
    /// <param name="newParam">Paramètres de tirs appliqués à ce projectile</param>
    /// <param name="direction">Direction appliquée à ce projectile</param>
    /// <param name="currentShipVelocity">Vélocité actuelle su tireur</param>
    public virtual void ShootProjectile(ProjectileParameters newParam, Vector3 direction, Vector3 currentShipVelocity)
    {
        gameObject.SetActive(true);
        projectileParameters = newParam;
        projectileParameters.SetProjectileDirection(direction, currentShipVelocity);
        projectileParameters.SetUpParameters();
        projectileBody.velocity         = projectileParameters.GetCurrentProjectileVelocity;
        projectileSizeParent.localScale = Vector3.one * projectileParameters.GetCurrentProjectileSize;
        lifetimeEnded = false;

        relatedHitbox.gameObject.SetActive(true);
        relatedHitbox.SetUp(this);

        projectileRenderer.gameObject.SetActive(true);

        projectileFunctionEnded = false;
        projectileReturned      = false;

        ResetAllSpecialEffects();


        if (endLifeTimeHeightCurve == null)
        {
            endLifeTimeHeightCurve = endLifeTimeHeightCurve.SetAsSlowInFastOutDecreasingCurve();
        }
        else if (endLifeTimeHeightCurve.length == 0)
        {
            endLifeTimeHeightCurve = endLifeTimeHeightCurve.SetAsSlowInFastOutDecreasingCurve();
        }

        if (projectileParameters.GetTotalLifeTime < normalFallDuration)
        {
            thisFallDuration = projectileParameters.GetTotalLifeTime;
        }
        else
        {
            thisFallDuration = normalFallDuration;
        }

        startedFall       = false;
        persistingPlaced  = false;
        explodedOnContact = false;

        SetUpAirRotation();
    }
 private void OnEnable()
 {
     targetProjectileParameters = target as ProjectileParameters;
 }
Beispiel #12
0
 public void SetProjectileParameters(ProjectileParameters projParams)
 {
     projectileParameters = projParams;
 }
Beispiel #13
0
    public static void ShowShootParameters(ShootParameters shootParameters, float indentValue, ref bool showProjectileParameters)
    {
        SerializedObject serializedParameters = new SerializedObject(shootParameters);

        serializedParameters.Update();

        #region Base Parameters
        GUI.Label(EditorStaticMethods.GetIndentedControlRect(indentValue), "Base Parameters", EditorStyles.boldLabel);

        SerializedProperty projectilePrefabAttribute = serializedParameters.FindProperty("projectilePrefab");
        EditorGUI.PropertyField(EditorStaticMethods.GetIndentedControlRect(indentValue), projectilePrefabAttribute);

        SerializedProperty cadenceProperty = serializedParameters.FindProperty("shootCadence");
        EditorGUI.PropertyField(EditorStaticMethods.GetIndentedControlRect(indentValue), cadenceProperty, new GUIContent("Shoot Cadence", "The reloading time needed after a shot to be able to shoot again"));
        if (cadenceProperty.floatValue < 0)
        {
            cadenceProperty.floatValue = 0;
        }

        SerializedProperty numberOfProjectilesPerShotProperty = serializedParameters.FindProperty("numberOfProjectilesPerShot");
        EditorGUI.PropertyField(EditorStaticMethods.GetIndentedControlRect(indentValue), numberOfProjectilesPerShotProperty, new GUIContent("Number of Projectiles per Shot", "The number of projectile that will be instantiated on shot by each shoot origins of the weapon. Generaly of one except for shotguns"));
        if (numberOfProjectilesPerShotProperty.intValue < 1)
        {
            numberOfProjectilesPerShotProperty.intValue = 1;
        }

        SerializedProperty imprecisionAngleProperty = serializedParameters.FindProperty("imprecisionAngle");
        EditorGUI.PropertyField(EditorStaticMethods.GetIndentedControlRect(indentValue), imprecisionAngleProperty, new GUIContent("Imprecision Angle", "The angle of the cone in which the projectile direction will be randomly picked on shot. Set low for precise shots, set high for spray"));
        if (imprecisionAngleProperty.floatValue < 0)
        {
            imprecisionAngleProperty.floatValue = 0;
        }
        #endregion

        #region Serial Shots
        GUILayout.Space(20);
        GUI.Label(EditorStaticMethods.GetIndentedControlRect(indentValue), "Serial Shots", EditorStyles.boldLabel);

        SerializedProperty numberOfSerialShotsProperty = serializedParameters.FindProperty("numberOfSerialShots");
        bool isSerialShot = EditorGUI.Toggle(EditorStaticMethods.GetIndentedControlRect(indentValue), new GUIContent("Is Serial Shots", "Set true if you want a burst shot"), numberOfSerialShotsProperty.intValue > 1);

        if (isSerialShot)
        {
            if (numberOfSerialShotsProperty.intValue < 2)
            {
                numberOfSerialShotsProperty.intValue = 3;
            }

            EditorGUI.PropertyField(EditorStaticMethods.GetIndentedControlRect(indentValue), numberOfSerialShotsProperty, new GUIContent("Number of Shots", "The number of shots that will be done through the burst shot"));

            SerializedProperty timeBetweenEachSerialShotProperty = serializedParameters.FindProperty("timeBetweenEachSerialShot");
            EditorGUI.PropertyField(EditorStaticMethods.GetIndentedControlRect(indentValue), timeBetweenEachSerialShotProperty, new GUIContent("Time between each Shot", "The time between two shots of the burst shot"));

            if (numberOfSerialShotsProperty.intValue < 2)
            {
                numberOfSerialShotsProperty.intValue = 2;
            }

            if (timeBetweenEachSerialShotProperty.floatValue < 0)
            {
                timeBetweenEachSerialShotProperty.floatValue = 0;
            }
        }
        else
        {
            if (numberOfSerialShotsProperty.intValue != 1)
            {
                numberOfSerialShotsProperty.intValue = 1;
            }
        }
        #endregion

        #region Projectile Parameters
        GUILayout.Space(20);

        GUI.Label(EditorStaticMethods.GetIndentedControlRect(indentValue), "Projectiles Parameters", EditorStyles.boldLabel);

        SerializedProperty projParamsAttribute = serializedParameters.FindProperty("projectileParameters");
        EditorGUI.PropertyField(EditorStaticMethods.GetIndentedControlRect(indentValue), projParamsAttribute);

        serializedParameters.ApplyModifiedProperties();

        ProjectileParameters projParams = shootParameters.GetProjectileParameters;
        if (projParams != null)
        {
            showProjectileParameters = EditorGUI.BeginFoldoutHeaderGroup(EditorStaticMethods.GetIndentedControlRect(indentValue), showProjectileParameters, (showProjectileParameters ? "Close" : "Open") + " Projectile Parameters", showProjectileParameters ? EditorStyles.boldLabel : null);
            EditorGUI.EndFoldoutHeaderGroup();

            if (showProjectileParameters)
            {
                EditorGUILayout.BeginVertical("box");
                ProjectileParametersInspector.ShowProjectileParameters(projParams, indentValue + 15);
                EditorGUILayout.EndVertical();
            }
        }
        #endregion
    }