1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
using System;
using Sirenix.OdinInspector;
using UnityEngine;
[Serializable]
public class ObjectsToSpawn
{
public enum Direction
{
forward,
normal,
identity
}
public enum SpawnOn
{
all,
player,
notPlayer
}
[FoldoutGroup("OnHit", 0)]
public GameObject effect;
[FoldoutGroup("OnHit", 0)]
public Direction direction;
[FoldoutGroup("OnHit", 0)]
public SpawnOn spawnOn;
[FoldoutGroup("OnHit", 0)]
public bool spawnAsChild;
[FoldoutGroup("OnHit", 0)]
public int numberOfSpawns = 1;
[FoldoutGroup("OnHit", 0)]
public float normalOffset;
[FoldoutGroup("OnHit", 0)]
public bool stickToBigTargets;
[FoldoutGroup("OnHit", 0)]
public bool stickToAllTargets;
[FoldoutGroup("OnHit", 0)]
public bool zeroZ;
[FoldoutGroup("OnProjectile", 0)]
public GameObject AddToProjectile;
[FoldoutGroup("OnProjectile", 0)]
public bool removeScriptsFromProjectileObject;
[FoldoutGroup("Stacking", 0)]
public bool scaleStacks;
[FoldoutGroup("Stacking", 0)]
public float scaleStackM = 0.5f;
[FoldoutGroup("Scaling", 0)]
public float scaleFromDamage;
[HideInInspector]
public int stacks;
public static GameObject[] SpawnObject(Transform spawnerTransform, HitInfo hit, ObjectsToSpawn objectToSpawn, HealthHandler playerHealth, PlayerSkin playerSkins, float damage = 55f, SpawnedAttack spawnedAttack = null, bool wasBlocked = false)
{
GameObject[] array = new GameObject[objectToSpawn.numberOfSpawns];
for (int i = 0; i < objectToSpawn.numberOfSpawns; i++)
{
if (wasBlocked && objectToSpawn.stickToAllTargets)
{
continue;
}
Vector3 position = (Vector3)hit.point + (Vector3)hit.normal * objectToSpawn.normalOffset + (objectToSpawn.zeroZ ? Vector3.zero : (Vector3.forward * 5f));
Quaternion rotation = Quaternion.LookRotation(spawnerTransform.forward);
if (objectToSpawn.direction == Direction.normal)
{
rotation = Quaternion.LookRotation(hit.normal + Vector2.right * 0.005f);
}
if (objectToSpawn.direction == Direction.identity)
{
rotation = Quaternion.identity;
}
if ((objectToSpawn.spawnOn != SpawnOn.notPlayer || !playerHealth) && (objectToSpawn.spawnOn != SpawnOn.player || (bool)playerHealth) && (bool)objectToSpawn.effect)
{
GameObject gameObject = UnityEngine.Object.Instantiate(objectToSpawn.effect, position, rotation);
if (objectToSpawn.spawnAsChild && (bool)hit.transform)
{
gameObject.transform.SetParent(hit.transform, worldPositionStays: true);
}
if ((bool)spawnedAttack)
{
spawnedAttack.CopySpawnedAttackTo(gameObject);
}
array[i] = gameObject;
SetTeamColor.TeamColorThis(gameObject, playerSkins);
if ((objectToSpawn.stickToBigTargets && !playerHealth && (!hit.rigidbody || hit.rigidbody.mass > 500f)) || objectToSpawn.stickToAllTargets)
{
gameObject.AddComponent<FollowLocalPos>().Follow(hit.transform);
}
if (objectToSpawn.scaleFromDamage != 0f)
{
gameObject.transform.localScale *= 1f * (1f - objectToSpawn.scaleFromDamage) + damage / 55f * objectToSpawn.scaleFromDamage;
}
if (objectToSpawn.scaleStacks)
{
gameObject.transform.localScale *= 1f + (float)objectToSpawn.stacks * objectToSpawn.scaleStackM;
}
}
}
return array;
}
public static void SpawnObject(ObjectsToSpawn objectToSpawn, Vector3 position, Quaternion rotation)
{
for (int i = 0; i < objectToSpawn.numberOfSpawns; i++)
{
UnityEngine.Object.Instantiate(objectToSpawn.effect, position, rotation);
}
}
}
|