public void CopyFrom(DMKBulletInfo prototype, float speedMultiplier = 1f) { this.bulletSprite = prototype.bulletSprite; this.damage = prototype.damage; this.speed = DMKCurveProperty.Copy(prototype.speed, speedMultiplier); this.accel = DMKCurveProperty.Copy(prototype.accel); this.angularAccel = DMKCurveProperty.Copy(prototype.angularAccel); this.bulletColor = prototype.bulletColor; this.died = false; this.useScaleCurve = prototype.useScaleCurve; this.scaleCurveX = DMKUtil.CopyCurve(prototype.scaleCurveX); this.scaleCurveY = DMKUtil.CopyCurve(prototype.scaleCurveY); this.collisionRect = prototype.collisionRect; this.maxLifetime = prototype.maxLifetime; this.lifeFrame = 0; }
void DMKUpdate() { if (!paused && enabled && currentAttackIndex != -1) { Rect cameraRect = DMKSettings.instance.GetCameraRect(); List <DMKBullet> diedBullets = new List <DMKBullet>(); // to do, put bullet update in another thread foreach (DMKBullet bullet in this.bulletContainer) { if (bullet == null) { diedBullets.Add(bullet); continue; } DMKBulletInfo info = bullet.bulletInfo; if (!info.died) { Vector3 prevPos = bullet.gameObject.transform.position; float dist = info.speed.get() * DMKSettings.instance.unitPerPixel; bullet.gameObject.transform.position = new Vector3(prevPos.x + (float)(dist * Mathf.Cos(info.direction)), prevPos.y + (float)(dist * Mathf.Sin(info.direction)), prevPos.z); float currentTime = (float)(info.lifeFrame) / 60; info.speed.Update(currentTime); info.speed.value += info.accel.Update(currentTime); float ang = info.angularAccel.Update(currentTime); if (ang != 0f) { info.direction += ang * Mathf.Deg2Rad; bullet.gameObject.transform.rotation = Quaternion.AngleAxis(info.direction * Mathf.Rad2Deg + 90, Vector3.forward); } if (info.useScaleCurve) { bullet.gameObject.transform.localScale = new Vector3(info.scaleCurveX.Evaluate(currentTime), info.scaleCurveY.Evaluate(currentTime), 1f); } if ((info.maxLifetime != 0 && info.maxLifetime <= info.lifeFrame) || !cameraRect.Contains(bullet.transform.position)) { info.died = true; diedBullets.Add(bullet); } info.lifeFrame++; } else { diedBullets.Add(bullet); } } foreach (DMKBullet bullet in diedBullets) { if (bullet != null) { DestroyImmediate(bullet.gameObject); } } this.bulletContainer.RemoveAll( b => { return(b == null || b.bulletInfo.died); } ); this.danmakus[currentAttackIndex].Update(); } }
static void ShooterGUILowerPart_BulletInfo(DMKBulletShooterController shooter) { Rect rr = GUILayoutUtility.GetLastRect(); GUI.Box(new Rect(0, rr.y + rr.height, rr.width, 2), ""); EditorGUILayout.BeginVertical(""); { EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginVertical(); string bulletInfoStr = "Bullet"; if (!shooter.editorBulletInfoExpanded) { bulletInfoStr = String.Format("Bullet Info (Speed = {0}, Accel = {1})", shooter.bulletInfo.speed.value, shooter.bulletInfo.accel.value, shooter.bulletInfo.maxLifetime); } shooter.editorBulletInfoExpanded = EditorGUILayout.Foldout(shooter.editorBulletInfoExpanded, bulletInfoStr); if (shooter.editorBulletInfoExpanded) { { EditorGUILayout.BeginVertical(); shooter.bulletInfo.bulletSprite = EditorGUILayout.ObjectField("Sprite", shooter.bulletInfo.bulletSprite, typeof(Sprite), false) as Sprite; shooter.bulletInfo.bulletColor = EditorGUILayout.ColorField("Color", shooter.bulletInfo.bulletColor); EditorGUILayout.EndVertical(); } EditorGUILayout.Separator(); DMKBulletInfo bulletInfo = shooter.bulletInfo; DMKGUIUtility.MakeCurveControl(ref bulletInfo.speed, "Speed"); DMKGUIUtility.MakeCurveControl(ref bulletInfo.accel, "Acceleration"); DMKGUIUtility.MakeCurveControl(ref bulletInfo.angularAccel, "Angular Accel"); GUILayout.BeginHorizontal(); { GUILayout.Label("Scale"); bulletInfo.useScaleCurve = DMKGUIUtility.MakeCurveToggle(bulletInfo.useScaleCurve); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Space(32); GUILayout.BeginVertical(); if (bulletInfo.useScaleCurve) { bulletInfo.scaleCurveX = EditorGUILayout.CurveField("Scale X", bulletInfo.scaleCurveX); bulletInfo.scaleCurveY = EditorGUILayout.CurveField("Scale Y", bulletInfo.scaleCurveY); } else { bulletInfo.scale = EditorGUILayout.Vector2Field("", bulletInfo.scale); } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); shooter.bulletInfo.damage = EditorGUILayout.IntField("Damage", shooter.bulletInfo.damage); shooter.bulletInfo.maxLifetime = EditorGUILayout.IntField("Lifetime (Frame)", shooter.bulletInfo.maxLifetime); } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); EditorGUILayout.EndVertical(); }