public Danmaku FireCurved(DanmakuPrefab prefab, Vector2 location, DynamicFloat rotation, DynamicFloat speed, DynamicFloat angularSpeed, CoordinateSystem coordSys = CoordinateSystem.View, DanmakuModifier modifier = null) { if (TargetField == null) { TargetField = this; } Vector2 position = TargetField.WorldPoint(location, coordSys); if (modifier == null) { Danmaku danmaku = Danmaku.GetInactive(prefab, position, rotation); danmaku.Field = this; danmaku.Activate(); danmaku.Speed = speed; danmaku.AngularSpeed = angularSpeed; return(danmaku); } else { FireData temp = new FireData(); temp.Prefab = prefab; temp.Speed = speed; temp.AngularSpeed = angularSpeed; temp.Field = this; modifier.Initialize(temp); modifier.OnFire(position, rotation); return(null); } }
public FireBuilder WithModifier(DanmakuModifier modifier) { if (modifier != null) { modifiers.Add(modifier); } return(this); }
public void Fire() { Vector2 actualPosition = Position; DynamicFloat actualRotation = Rotation; if (positionSource != null) { actualPosition = positionSource.position; } if (rotationSource != null) { actualRotation = rotationSource.Rotation2D(); } if (targeted) { if (targetPosition != null) { actualRotation += DanmakuUtil.AngleBetween2D(actualPosition, (Vector2)targetPosition); } else if (targetObject != null) { actualRotation += DanmakuUtil.AngleBetween2D(actualPosition, targetObject.position); } } Vector2 tempPos = Position; DynamicFloat tempRotation = Rotation; Position = actualPosition; Rotation = actualRotation; if (modifiers.Count <= 0) { data.Fire(); } else if (modifiers.Count == 1) { DanmakuModifier singleModifier = modifiers[0]; if (singleModifier == null) { data.Fire(); } else { singleModifier.Fire(data); } } else { DanmakuModifier[] oldSubModifiers = new DanmakuModifier[modifiers.Count]; DanmakuModifier previous = null, current, initial = null; for (int i = 0; i < oldSubModifiers.Length; i++) { current = modifiers[i]; if (current != null) { oldSubModifiers[i] = current.SubModifier; if (previous != null) { previous.SubModifier = current; } else { initial = current; } previous = current; } } if (initial != null) { initial.Fire(data); } else { data.Fire(); } for (int i = 0; i < oldSubModifiers.Length; i++) { current = modifiers[i]; if (current != null) { current.SubModifier = oldSubModifiers[i]; } } } data.Position = tempPos; data.Rotation = tempRotation; }