public static Entity CreateEntity(EntityManager entity_manager, UnityEngine.Vector3 localPos, UnityEngine.Quaternion localRot, ref AtomicFloat life, Entity parent_entity, ref RandomLocal random) { var entity = entity_manager.CreateEntity(archetype_); entity_manager.SetComponentData(entity, LockTarget.Create(ref life)); entity_manager.SetComponentData(entity, new Position { Value = localPos, }); entity_manager.SetComponentData(entity, new Rotation { Value = localRot, }); entity_manager.SetComponentData(entity, random.create()); var attach_entity = entity_manager.CreateEntity(typeof(Attach)); entity_manager.SetComponentData(attach_entity, new Attach { Parent = parent_entity, Child = entity, }); return(entity); }
private void init(ref Vector3 position, ref Quaternion rotation, LockTarget lock_target) { // var rotation = Quaternion.identity; base.init(ref position, ref rotation); rigidbody_.init(); rigidbody_.transform_.position_ = position; float theta; if (MyRandom.Probability(0.5f)) { theta = (MyRandom.Range(-1f, 1f) * Mathf.PI * 0.125f) * Mathf.Rad2Deg; } else { theta = (MyRandom.Range(-1f, 1f) * Mathf.PI * 0.125f + Mathf.PI) * Mathf.Rad2Deg; } var rot = Quaternion.Euler(0f, 0f, theta) * rotation; var v = rot * new Vector3(20f, 0f, 0f); rigidbody_.setVelocity(ref v); lock_target_ = lock_target; trail_locator_ = new Vector3(0, 0, -1); // var col = new Color(0.1f, 1f, 0.5f); var pos = rigidbody_.transform_.transformPosition(ref trail_locator_); trail_id_ = Trail.Instance.spawn(ref pos, 0.2f /* width */, Trail.Type.Missile); arrival_time_ = MyRandom.Range(1.0f, 1.5f); destroy_start_ = 0f; }
void Update() { player_.rigidbody_.transform_.position_ = camera_.transform.position; player_.rigidbody_.transform_.rotation_ = camera_.transform.rotation; foreach (var t in list_) { t.update(1f / 60f, Time.time, 0f /* flow_speed */); } LockTarget.checkAll(player_, Time.time); var inv_mat = player_.rigidbody_.transform_.getInverseR(); foreach (var t in list_) { if (t.lock_target_.isEntering(ref inv_mat, ref player_.rigidbody_.transform_.position_, 1f /* ratio */, 1f /* dist_min */, 500f /* dist_max */)) { t.owner_.GetComponent <MeshRenderer>().material.color = Color.red; } else { t.owner_.GetComponent <MeshRenderer>().material.color = Color.white; } } }
void Update() { my_camera_.rigidbody_.transform_.position_ = camera_.transform.position; my_camera_.rigidbody_.transform_.rotation_ = camera_.transform.rotation; foreach (var t in list_) { t.update(1f / 60f, Time.time); // t.renderUpdate(0 /* front */, my_camera_, ref dummy_draw_buffer_); } LockTarget.checkAll(my_camera_); var inv_mat = my_camera_.rigidbody_.transform_.getInverseR(); foreach (var t in list_) { if (t.lock_target_.isEntering(ref inv_mat, ref my_camera_.rigidbody_.transform_.position_, 1f /* ratio */, 1f /* dist_min */, 500f /* dist_max */)) { t.owner_.GetComponent <MeshRenderer>().material.color = Color.red; } else { t.owner_.GetComponent <MeshRenderer>().material.color = Color.white; } } }
public void Execute(int i) { LockTarget lt = locktarget_list_[i]; if (lt.isLocked(time_)) { lockon_limit_.TryIncrement(LASER_MAX); } }
public override void destroy() { // type_ = Type.None; enumerator_ = null; lock_target_.destroy(); lock_target_ = null; MyCollider.destroyEnemy(collider_); base.destroy(); }
public static void createPool() { pool_ = new LockTarget[POOL_MAX]; for (var i = 0; i < POOL_MAX; ++i) { var obj = new LockTarget(); obj.alive_ = false; pool_[i] = obj; } pool_index_ = 0; }
public void zako2_init(ref Vector3 position, ref Quaternion rotation) { rigidbody_.init(ref position, ref rotation); collider_ = MyCollider.createEnemy(); MyCollider.initSphereEnemy(collider_, ref position, 1f /* radius */); lock_target_ = LockTarget.create(this, new LockTarget.CalcPosition(calc_lock_position_center)); enumerator_ = zako2_act(); // この瞬間は実行されない on_update_ = new OnUpdateFunc(zako2_update); on_render_update_ = new OnRenderUpdateFunc(zako2_render_update); life_ = 100f; }
public void renderUpdate(int front) { MySprite.Instance.put(front, ref location_rect_, MySprite.Kind.Location, MySprite.Type.Half); MySprite.Instance.put(front, ref maxlockon_rect_, MySprite.Kind.MaxLockon, MySprite.Type.Half); // lockon gauge int lock_num = LockTarget.getCurrentLockNum(); int fired_num = LockTarget.getCurrentFiredNum(); int charge_num = lock_num - fired_num; int idx = 0; for (var i = 0; i < gauge_rect_L_list_.Length; ++i) { MySprite.Kind kind = (idx < charge_num ? MySprite.Kind.GaugeRL : MySprite.Kind.GaugeBL); MySprite.Instance.put(front, ref gauge_rect_L_list_[i], kind, MySprite.Type.Half); ++idx; } for (var i = 0; i < gauge_rect_M_list_.Length; ++i) { MySprite.Kind kind = (idx < charge_num ? MySprite.Kind.GaugeRM : MySprite.Kind.GaugeBM); MySprite.Instance.put(front, ref gauge_rect_M_list_[i], kind, MySprite.Type.Half); ++idx; } for (var i = 0; i < gauge_rect_S_list_.Length; ++i) { MySprite.Kind kind = (idx < charge_num ? MySprite.Kind.GaugeRS : MySprite.Kind.GaugeBS); MySprite.Instance.put(front, ref gauge_rect_S_list_[i], kind, MySprite.Type.Half); ++idx; } // unitychan if (unitychan_width_ratio_ > 0f) { var rect = new Rect(unitychan_rect_.x, unitychan_rect_.y, unitychan_rect_.width * unitychan_width_ratio_, unitychan_rect_.height * unitychan_height_ratio_); MySprite.Instance.put(front, ref rect, unitychan_kind_, MySprite.Type.Full); } // weapon & damage MySprite.Instance.put(front, ref weapon_rect_, MySprite.Kind.Weapon, MySprite.Type.Half); if (damage_mark_on_) { var rect = weapon_rect_; rect.x += damage_mark_position_.x; rect.y += damage_mark_position_.y; rect.width = 32f; rect.height = 32f; MySprite.Instance.put(front, ref rect, MySprite.Kind.DamageMark, MySprite.Type.GuardMark); } }
public void spawn_internal(EntityCommandBuffer.Concurrent command_buffer, ref LockTarget lt, ref float3 position, ref quaternion rotation, ref RandomLocal random, int index, Entity target, float arrive_period, int job_index) { command_buffer.CreateEntity(job_index, archetype_); command_buffer.SetComponent(job_index, new Position { Value = position, }); command_buffer.SetComponent(job_index, new LaserData { end_time_ = CV.MaxValue, target_entity_ = target, arrive_period_ = arrive_period, lock_target_ = lt, }); var rb = new RigidbodyPosition(0f /* damper */); const float FIRE_VEL = 8f; var fire_velocity = new float3(index % 2 == 0 ? FIRE_VEL * 2f : -FIRE_VEL * 2f, random.range(-FIRE_VEL, FIRE_VEL), random.range(-FIRE_VEL, FIRE_VEL)); rb.velocity_ = math.mul(rotation, fire_velocity); command_buffer.SetComponent(job_index, rb); var td = new TrailData { color_type_ = (int)TrailManager.ColorType.Green, }; command_buffer.SetComponent(job_index, td); { var buffer = command_buffer.SetBuffer <TrailPoint>(job_index); for (var i = 0; i < buffer.Capacity; ++i) { buffer.Add(new TrailPoint { position_ = position, normal_ = new float3(0f, 0f, 1f), }); } } var material = TrailManager.Instance.getMaterial(); var renderer = new TrailRenderer { material_ = material, }; command_buffer.SetSharedComponent <TrailRenderer>(job_index, renderer); }
public void restart() { GameManager.Instance.restart(); TaskManager.Instance.restart(); MyCollider.restart(); LockTarget.restart(); TubeScroller.Instance.restart(); Beam.Instance.restart(); Trail.Instance.restart(); Sight.Instance.restart(); setBulletTime(false); flow_speed_target_ = 0f; flow_speed_ = 0f; }
public void dragon_init() { var position = new Vector3(-10f, -5f, 10f); rigidbody_.init(ref position, ref CV.QuaternionIdentity); rigidbody_.setDamper(2f); rigidbody_.setRotateDamper(20f); collider_ = MyCollider.createEnemy(); MyCollider.initSphereEnemy(collider_, ref position, 1f /* radius */); lock_target_ = LockTarget.create(this, new LockTarget.CalcPosition(calc_lock_position_dragon)); enumerator_ = dragon_act(); // この瞬間は実行されない on_update_ = new OnUpdateFunc(dragon_update); on_render_update_ = new OnRenderUpdateFunc(dragon_render_update); life_ = 10000000f; dragon_ = dragon_pool_; dragon_.init(this, ref rigidbody_.transform_.position_, ref rigidbody_.transform_.rotation_); }
public void init(Task task, int idx, ref Vector3 position, ref Quaternion rotation, DrawBuffer.Type draw_type) { rigidbody_.init(ref position, ref rotation); rigidbody_.setRotateDamper(8); collider_ = MyCollider.createEnemy(); MyCollider.initSphereEnemy(collider_, ref position, 1f /* radius */); idx_ = idx; lock_target_ = LockTarget.create(task, new LockTarget.CalcPosition(this.calc_lock_position)); locator_ = (idx_ == 0 ? new Vector3(0f, 0f, 0f) : new Vector3(0f, 0f, -3f)); draw_type_ = draw_type; }
void spawn(ref LockTarget lt, ref float3 pos, ref quaternion rot, ref RandomLocal random, int i, Entity entity, float arrive_period) { ECSLaserManager.spawn(command_buffer_, ref lt, ref pos, ref rot, ref random, i, entity, arrive_period); }
public static void spawn(EntityCommandBuffer.Concurrent command_buffer, ref LockTarget lt, ref float3 position, ref quaternion rotation, ref RandomLocal random, int index, Entity target, float arrive_period) { Instance.spawn_internal(command_buffer, ref lt, ref position, ref rotation, ref random, index, target, arrive_period); }
public void Execute(int i) { LockTarget lt = locktarget_list_[i]; if (!lt.isLocked(time_)) { bool can_lock = false; var locktarget_local_to_world = locktarget_local_to_world_list_[i].Value; var diff = locktarget_local_to_world.c3.xyz - player_position_.Value; float inner_product = math.dot(diff, player_normal_); if (inner_product > 0f) { float diffsqr = Vector3.Dot(diff, diff); if (inner_product * inner_product >= diffsqr * cone_cos_sqr_) { if (lt.has_direction_ != 0) { var fwd = new float4(0f, 0f, 1f, 0f); var vec = math.mul(locktarget_local_to_world, fwd).xyz; if (math.dot(diff, vec) < 0f) { can_lock = true; } } else { can_lock = true; } } } if (can_lock) { if (lockon_limit_.TryIncrement(LASER_MAX /* inclusive_limit */)) { lt.setLocked(time_); locktarget_list_[i] = lt; sight_spawner_.Enqueue(new SightSpawnData { target_entity_ = locktarget_entity_list_[i], }); } } } }
private void update_attack(double update_time, bool replay) { if (!replay) { fire_button_ = getButton(InputManager.Button.Fire) > 0; } bool fire_button_released = (!fire_button_ && prev_fire_button_); prev_fire_button_ = fire_button_; // fire bullets if (fire_button_) { if (can_fire_time_ - update_time > 0f && update_time - fire_time_ > 0f) { var lpos = rigidbody_.transform_.transformPosition(ref l_bullet_locator_); Bullet.create(ref lpos, ref rigidbody_.transform_.rotation_, 120f /* speed */, update_time); var rpos = rigidbody_.transform_.transformPosition(ref r_bullet_locator_); Bullet.create(ref rpos, ref rigidbody_.transform_.rotation_, 120f /* speed */, update_time); SystemManager.Instance.registSound(DrawBuffer.SE.Bullet); fire_time_ = update_time + 0.08f; arm_offset_ = 1f; } } else { can_fire_time_ = update_time + 2f; } // lockonrange display LockonRange.Instance.setOn(fire_button_); now_locking_ = fire_button_; // fire missiles if (fire_button_released) { bool fired = LockTarget.fireMissiles(this); if (fired) { SystemManager.Instance.registSound(DrawBuffer.SE.Missile); } } }
public void Execute(int i) { LockTarget lt = locktarget_list_[i]; if (lt.isLocked(time_)) { var screen_pos = screen_position_list_[i]; var spd = new SpriteData(); spd.setType(SpriteManager.Type.target); spd.setPosition(ref screen_pos.Value); if (lt.isFired(time_)) { spd.setColor(1f, 0.25f, 0.2f, 1f); } else { spd.setColor(0.1f, 1f, 0.5f, 1f); } sprite_data_list_.AddRef(ref spd); } }
void Start() { TaskManager.Instance.init(); // Sight.Instance.init(); LockTarget.createPool(); list_ = new List <TestTask>(); GameObject prefab = null; for (var i = 0; i < MAX; ++i) { GameObject go; if (prefab == null) { prefab = GameObject.Find("Cube"); go = prefab; } else { float range = 8; go = Instantiate(prefab, new Vector3(Random.Range(-range, range), Random.Range(-range, range), Random.Range(-range, range)), Quaternion.identity) as GameObject; } var task = new TestTask(); var pos = go.transform.position; var rot = go.transform.rotation; task.init(); task.rigidbody_.init(ref pos, ref rot); var lock_target = LockTarget.create(task, new LockTarget.CalcPosition(task.calc_position)); task.lock_target_ = lock_target; task.owner_ = go; list_.Add(task); } camera_ = Camera.main; player_ = Player.create(); }
// private DrawBuffer dummy_draw_buffer_; void Start() { TaskManager.Instance.init(); Sight.Instance.init(null /* material */); LockTarget.createPool(); list_ = new List <TestTask>(); GameObject prefab = null; for (var i = 0; i < MAX; ++i) { GameObject go; if (prefab == null) { prefab = GameObject.Find("Cube"); go = prefab; } else { float range = 8; go = Instantiate(prefab, new Vector3(Random.Range(-range, range), Random.Range(-range, range), Random.Range(-range, range)), Quaternion.identity) as GameObject; } var task = new TestTask(); var pos = go.transform.position; var rot = go.transform.rotation; task.init(ref pos, ref rot); var lock_target = LockTarget.create(task, ref CV.Vector3Zero); task.lock_target_ = lock_target; task.owner_ = go; list_.Add(task); } camera_ = Camera.main; my_camera_ = MyCamera.create(); // dummy_draw_buffer_ = new DrawBuffer(); }
public void init(ref Vector3 position, ref Quaternion rotation, Type type) { base.init(ref position, ref rotation); collider_ = MyCollider.createEnemy(); MyCollider.initSphereEnemy(collider_, ref position, 1f /* radius */); var lock_pos = new Vector3(0, 0, 0); lock_target_ = LockTarget.create(this, ref lock_pos); type_ = type; phase_ = Phase.Alive; switch (type_) { case Type.None: Debug.Assert(false); break; case Type.Zako: /* ここで GC.allocate が発生してしまう */ enumerator_ = zako_act(); // この瞬間は実行されない break; } }
public static Missile create(ref Vector3 position, ref Quaternion rotation, LockTarget lock_target) { int cnt = 0; while (pool_[pool_index_].alive_) { ++pool_index_; if (pool_index_ >= POOL_MAX) { pool_index_ = 0; } ++cnt; if (cnt >= POOL_MAX) { Debug.LogError("EXCEED Missile POOL!"); break; } } var obj = pool_[pool_index_]; obj.init(ref position, ref rotation, lock_target); return(obj); }
public override void update(float dt, float update_time) { update_time_ = update_time; if (MyCollider.getHitOpponentForPlayer(collider_) != MyCollider.Type.None) { var pos = new Vector3(MyRandom.Range(-2f, 2f), MyRandom.Range(-2f, 2f), MyRandom.Range(-2f, 2f)); HUD.Instance.setDamagePoint(ref pos); } if (Options.Instance.AutoPlay) { enumerator_.MoveNext(); } int hori = getButton(InputManager.Button.Horizontal); int vert = getButton(InputManager.Button.Vertical); bool fire_button = getButton(InputManager.Button.Fire) > 0; int lr = getButton(InputManager.Button.Roll); roll_target_ += (float)(lr) * 150f * dt; roll_ = Mathf.Lerp(roll_, roll_target_, 0.1f); const float MOVE_FORCE = 1f; const float CURSOR_FORCE = 6f; float sn = Mathf.Sin(roll_ * Mathf.Deg2Rad); float cs = Mathf.Cos(roll_ * Mathf.Deg2Rad); float vx = hori * cs - vert * sn; float vy = hori * sn + vert * cs; rigidbody_.addForceXY(vx * MOVE_FORCE, vy * MOVE_FORCE); target_cursor_.addForceXY(vx * CURSOR_FORCE, vy * CURSOR_FORCE); if (hori < 0) { pitch_acceleration_ += 2000f; } else if (hori > 0) { pitch_acceleration_ += -2000f; } // cursor update { // 外に向けさせない float x = rigidbody_.transform_.position_.x + target_cursor_.transform_.position_.x; float y = rigidbody_.transform_.position_.y + target_cursor_.transform_.position_.y; float len2 = x * x + y * y; float R = 64f; if (len2 > Tube.RADIUS_SQR) { R = 256f; } target_cursor_.addForceX(-target_cursor_.transform_.position_.x * R); target_cursor_.addForceY(-target_cursor_.transform_.position_.y * R); target_cursor_.update(dt); } // pitch pitch_acceleration_ += -pitch_ * 8f; // spring pitch_acceleration_ += -pitch_velocity_ * 4f; // friction pitch_velocity_ += pitch_acceleration_ * dt; pitch_ += pitch_velocity_ * dt; pitch_acceleration_ = 0f; // rotate rigidbody_.transform_.rotation_ = Quaternion.LookRotation(target_cursor_.transform_.position_) * Quaternion.Euler(0, 0, pitch_); // update rigidbody_.update(dt); float radius = Tube.RADIUS - PLAYER_WIDTH2; if (rigidbody_.transform_.position_.sqrMagnitude >= radius * radius) { hit_wall_ = true; rigidbody_.cancelUpdateForTube(dt); if (MyRandom.ProbabilityForSecond(60f, SystemManager.Instance.getDT())) { float x = rigidbody_.transform_.position_.x; float y = rigidbody_.transform_.position_.y; float z = rigidbody_.transform_.position_.z; float len = Mathf.Sqrt(x * x + y * y); float rlen = 1f / len; float r = rlen * Tube.RADIUS; var v = new Vector3(x * r, y * r, z); Spark.Instance.spawn(ref v, Spark.Type.Orange, update_time); } } else { hit_wall_ = false; } // collider MyCollider.updatePlayer(collider_, ref rigidbody_.transform_.position_); // fire bullets if (fire_button && update_time - fire_time_ > 0.06667f) { var lpos = rigidbody_.transform_.transformPosition(ref l_bullet_locator_); Bullet.create(ref lpos, ref rigidbody_.transform_.rotation_, 120f /* speed */, update_time); var rpos = rigidbody_.transform_.transformPosition(ref r_bullet_locator_); Bullet.create(ref rpos, ref rigidbody_.transform_.rotation_, 120f /* speed */, update_time); SystemManager.Instance.registSound(DrawBuffer.SE.Bullet); fire_time_ = update_time; } // fire missiles if (fire_button && !prev_fire_button_) // tmp { bool fired = LockTarget.fireMissiles(this); if (fired) { SystemManager.Instance.registSound(DrawBuffer.SE.Missile); } } prev_fire_button_ = fire_button; // trail { float flow_z = -30f * dt; var lpos = rigidbody_.transform_.transformPosition(ref l_trail_locator_); Trail.Instance.update(l_trail_, ref lpos, flow_z, update_time); var rpos = rigidbody_.transform_.transformPosition(ref r_trail_locator_); Trail.Instance.update(r_trail_, ref rpos, flow_z, update_time); } }
private void main_loop() { long begin_time = stopwatch_.ElapsedTicks; // flip int updating_front = 1 - rendering_front_; // begin Sight.Instance.begin(); MySprite.Instance.begin(); MyFont.Instance.begin(); Beam.Instance.begin(updating_front); Trail.Instance.begin(updating_front); Spark.Instance.begin(); Explosion.Instance.begin(); Hahen.Instance.begin(); // update bool locked = false; if (!pause_) { GameManager.Instance.update(dt_, update_time_); TaskManager.Instance.update(dt_, update_time_); // lockon locked = LockTarget.checkAll(player_); Sight.Instance.updateAll(dt_); // HUD HUD.Instance.update(dt_, update_time_); // collision MyCollider.calculate(); if (InputManager.Instance.getButton(InputManager.Button.Pause) > 0) { pause_ = true; } ++update_frame_; update_time_ += dt_; } else { if (InputManager.Instance.getButton(InputManager.Button.Pause) > 0) { pause_ = false; } } if (locked) { registSound(DrawBuffer.SE.Lockon); } update_tick_ = stopwatch_.ElapsedTicks - begin_time; begin_time = stopwatch_.ElapsedTicks; // renderUpdate draw_buffer_[updating_front].beginRender(); TaskManager.Instance.renderUpdate(updating_front, ref draw_buffer_[updating_front]); // HUD HUD.Instance.renderUpdate(updating_front); render_update_tick_ = stopwatch_.ElapsedTicks - begin_time; // debug info if (Options.Instance.PerformanceMeter) { { MyFont.Instance.putNumber(updating_front, (int)update_frame_, 8 /* keta */, 0.5f /* scale */, -440f, 270f, MyFont.Type.Green); } { int gc_count = System.GC.CollectionCount(0 /* generation */) - gc_start_count_; MyFont.Instance.putNumber(updating_front, gc_count, 8 /* keta */, 0.5f /* scale */, -440f, 254f, MyFont.Type.Red); } if (used_heap_size_ != 0) { int bytes = (int)used_heap_size_; MyFont.Instance.putNumber(updating_front, bytes, 9 /* keta */, 0.5f /* scale */, -340f, 254f, MyFont.Type.Red); } if (mono_heap_size_ != 0) { int bytes = (int)mono_heap_size_; MyFont.Instance.putNumber(updating_front, bytes, 9 /* keta */, 0.5f /* scale */, -240f, 254f, MyFont.Type.Red); } if (mono_used_size_ != 0) { int bytes = (int)mono_used_size_; MyFont.Instance.putNumber(updating_front, bytes, 9 /* keta */, 0.5f /* scale */, -140f, 254f, MyFont.Type.Red); } { int task_count = TaskManager.Instance.getCount(); MyFont.Instance.putNumber(updating_front, task_count, 8 /* keta */, 0.5f /* scale */, -440f, 238f, MyFont.Type.Blue); } var height = 5f; var length = 440f; var badget = 16.666f; var update_y = 262f; var render_y = 254f; { var rect0b = new Rect(-length * 0.5f, update_y, length, height); MySprite.Instance.put(updating_front, ref rect0b, MySprite.Kind.Square, MySprite.Type.Black); var update_ratio = (float)update_tick_ * 1000f / ((float)System.Diagnostics.Stopwatch.Frequency * badget); var rect1b = new Rect(length * (update_ratio * 0.5f - 1f), update_y, length * update_ratio, height); MySprite.Instance.put(updating_front, ref rect1b, MySprite.Kind.Square, MySprite.Type.Blue); var render_update_ratio = (float)render_update_tick_ * 1000f / ((float)System.Diagnostics.Stopwatch.Frequency * badget); var rect2b = new Rect(length * (update_ratio - 1f + render_update_ratio * 0.5f), update_y, length * update_ratio, height); MySprite.Instance.put(updating_front, ref rect2b, MySprite.Kind.Square, MySprite.Type.Green); } #if UNITY_PSP2 || UNITY_PS4 { var render_ratio = (float)render_tick_ * 1000f / ((float)System.Diagnostics.Stopwatch.Frequency * badget); var rect0b = new Rect(-length * 0.5f, render_y, length, height); MySprite.Instance.put(updating_front, ref rect0b, MySprite.Kind.Square, MySprite.Type.Black); var rect1b = new Rect(length * (render_ratio * 0.5f - 1f), render_y, length * render_ratio, height); MySprite.Instance.put(updating_front, ref rect1b, MySprite.Kind.Square, MySprite.Type.Red); var render_ratio_begin = (float)render_tick3_ * 1000f / ((float)System.Diagnostics.Stopwatch.Frequency * badget); var render_ratio_end = (float)render_tick4_ * 1000f / ((float)System.Diagnostics.Stopwatch.Frequency * badget); var render_ratio_len = render_ratio_end - render_ratio_begin; var rect2b = new Rect(length * (render_ratio_len * 0.5f - 1f + render_ratio_begin * 0.5f), render_y, length * (render_ratio_len), height); MySprite.Instance.put(updating_front, ref rect2b, MySprite.Kind.Square, MySprite.Type.Magenta); } #else { var render_ratio = (float)render_tick2_ * 1000f / ((float)System.Diagnostics.Stopwatch.Frequency * badget); var rect0b = new Rect(-length * 0.5f, render_y, length, height); MySprite.Instance.put(updating_front, ref rect0b, MySprite.Kind.Square, MySprite.Type.Black); var rect1b = new Rect(length * (render_ratio * 0.5f - 1f), render_y, length * render_ratio, height); MySprite.Instance.put(updating_front, ref rect1b, MySprite.Kind.Square, MySprite.Type.Red); } #endif } // end Hahen.Instance.end(updating_front); Explosion.Instance.end(updating_front); Spark.Instance.end(updating_front); Trail.Instance.end(); Beam.Instance.end(); MyFont.Instance.end(updating_front); MySprite.Instance.end(updating_front); Sight.Instance.end(updating_front); }
void Awake() { #if UNITY_PSP2 UnityEngine.PSVita.Diagnostics.enableHUD = true; #endif Application.targetFrameRate = 60; DontDestroyOnLoad(gameObject); stopwatch_ = new System.Diagnostics.Stopwatch(); stopwatch_.Start(); rendering_front_ = 0; Instance.init(); Options.Instance.init(); InputManager.Instance.init(); GameManager.Instance.init(); TaskManager.Instance.init(); MyCollider.createPool(); LockTarget.createPool(); Missile.createPool(); Bullet.createPool(); Enemy.createPool(); EnemyBullet.createPool(); Debris.Instance.init(debris_material_); Spark.Instance.init(spark_material_); Beam.Instance.init(beam_material_); Trail.Instance.init(trail_material_); Explosion.Instance.init(explosion_material_); Hahen.Instance.init(hahen_material_); HUD.Instance.init(); draw_buffer_ = new DrawBuffer[2]; for (int i = 0; i < 2; ++i) { draw_buffer_[i].init(); } manual_reset_event_ = new System.Threading.ManualResetEvent(false); setFPS(DefaultFps); update_frame_ = 0; update_sync_frame_ = 0; update_time_ = 0f; render_frame_ = 0; render_sync_frame_ = 0; pause_ = false; camera_ = GameObject.Find("MainCamera").GetComponent <Camera>(); // Camera.main; ProjectionMatrix = camera_.projectionMatrix; camera_.enabled = false; if (player_prefab_ != null) { player_go_ = Instantiate(player_prefab_) as GameObject; } if (zako_prefab_ != null) { zako_pool_ = new GameObject[ZAKO_MAX]; for (var i = 0; i < ZAKO_MAX; ++i) { zako_pool_[i] = Instantiate(zako_prefab_) as GameObject; zako_pool_[i].SetActive(false); } } uv_scroller_list_ = new UVScroller[8]; // pause menu pausemenu_canvas_go_ = GameObject.Find("Canvas"); if (pausemenu_canvas_go_ != null) { var go = GameObject.Find("FPSValue"); fps_text_ = go.GetComponent <UnityEngine.UI.Text>(); fps_text_.text = "1/" + fps_.ToString(); pausemenu_canvas_go_.SetActive(false); } // audio audio_sources_bullet_ = new AudioSource[AUDIOSOURCE_BULLET_MAX]; for (var i = 0; i < AUDIOSOURCE_BULLET_MAX; ++i) { audio_sources_bullet_[i] = gameObject.AddComponent <AudioSource>(); audio_sources_bullet_[i].clip = se_bullet_; audio_sources_bullet_[i].volume = 0.05f; } audio_source_bullet_index_ = 0; audio_sources_explosion_ = new AudioSource[AUDIOSOURCE_EXPLOSION_MAX]; for (var i = 0; i < AUDIOSOURCE_EXPLOSION_MAX; ++i) { audio_sources_explosion_[i] = gameObject.AddComponent <AudioSource>(); audio_sources_explosion_[i].clip = se_explosion_; audio_sources_explosion_[i].volume = 0.25f; } audio_source_explosion_index_ = 0; audio_sources_missile_ = new AudioSource[AUDIOSOURCE_MISSILE_MAX]; for (var i = 0; i < AUDIOSOURCE_MISSILE_MAX; ++i) { audio_sources_missile_[i] = gameObject.AddComponent <AudioSource>(); audio_sources_missile_[i].clip = se_missile_; audio_sources_missile_[i].volume = 0.25f; } audio_source_missile_index_ = 0; audio_sources_lockon_ = new AudioSource[AUDIOSOURCE_LOCKON_MAX]; for (var i = 0; i < AUDIOSOURCE_LOCKON_MAX; ++i) { audio_sources_lockon_[i] = gameObject.AddComponent <AudioSource>(); audio_sources_lockon_[i].clip = se_lockon_; audio_sources_lockon_[i].volume = 0.25f; } audio_source_lockon_index_ = 0; audio_sources_voice_ikuyo_ = gameObject.AddComponent <AudioSource>(); audio_sources_voice_ikuyo_.clip = se_voice_ikuyo_; audio_sources_voice_ikuyo_.volume = 0.75f; audio_sources_voice_uwaa_ = gameObject.AddComponent <AudioSource>(); audio_sources_voice_uwaa_.clip = se_voice_uwaa_; audio_sources_voice_uwaa_.volume = 0.75f; audio_sources_voice_sorosoro_ = gameObject.AddComponent <AudioSource>(); audio_sources_voice_sorosoro_.clip = se_voice_sorosoro_; audio_sources_voice_sorosoro_.volume = 0.75f; audio_sources_voice_ototo_ = gameObject.AddComponent <AudioSource>(); audio_sources_voice_ototo_.clip = se_voice_ototo_; audio_sources_voice_ototo_.volume = 0.75f; audio_sources_voice_yoshi_ = gameObject.AddComponent <AudioSource>(); audio_sources_voice_yoshi_.clip = se_voice_yoshi_; audio_sources_voice_yoshi_.volume = 0.75f; audio_sources_bgm_ = gameObject.AddComponent <AudioSource>(); audio_sources_bgm_.clip = bgm01_; audio_sources_bgm_.volume = 0.5f; audio_sources_bgm_.loop = true; gc_start_count_ = System.GC.CollectionCount(0 /* generation */); }
private void initialize() { #if UNITY_PSP2 UnityEngine.PSVita.Diagnostics.enableHUD = true; #endif DontDestroyOnLoad(gameObject); stopwatch_ = new System.Diagnostics.Stopwatch(); stopwatch_.Start(); rendering_front_ = 0; camera_ = GameObject.Find("MainCamera").GetComponent <Camera>(); // Camera.main; camera_.eventMask = 0; { player_go_ = Instantiate(player_prefab_) as GameObject; player_arm_transform_ = player_go_.transform.Find("fighter_arm"); { var go = new GameObject(); go.name = "LockonRangeRenderer"; go.transform.position = CV.Vector3Zero; go.transform.rotation = CV.QuaternionIdentity; var lr = go.AddComponent <LockonRangeRenderer>(); LockonRangeRenderer.setInstance(lr); go.transform.SetParent(player_go_.transform); go.transform.localPosition = new Vector3(0f, 0.5f, 0f); } { var go = new GameObject(); go.name = "ShieldRenderer"; go.transform.position = Vector3.zero; go.transform.rotation = Quaternion.identity; go.AddComponent <ShieldRenderer>(); go.transform.SetParent(player_go_.transform); go.transform.localPosition = new Vector3(0f, 0f, 0f); } } Options.Instance.init(); InputManager.Instance.init(); GameManager.Instance.init(); TaskManager.Instance.init(); MyCollider.createPool(); LockTarget.createPool(); Missile.createPool(); Bullet.createPool(); Enemy.createPool(); EnemyBullet.createPool(); Shutter.createPool(); Debris.Instance.init(debris_material_); Spark.Instance.init(spark_material_); Beam.Instance.init(beam_material_); Beam2.Instance.init(beam2_material_); Trail.Instance.init(trail_material_); Explosion.Instance.init(explosion_material_); Hahen.Instance.init(hahen_material_); Shockwave.Instance.init(shockwave_material_); // HUD.Instance.init(); LockonRange.Instance.init(lockon_range_material_); LockonRangeRenderer.Instance.init(camera_); Shield.Instance.init(shield_material_); Sight.Instance.init(sight_material_); if (SightRenderer.Instance) { SightRenderer.Instance.init(camera_); } VRSprite.Instance.init(sprites_, vrsprite_material_); if (VRSpriteRenderer.Instance) { VRSpriteRenderer.Instance.init(camera_); } Notice.createPool(); MySprite.Instance.init(sprites_, sprite_material_); MySpriteRenderer.Instance.init(camera_); MyFont.Instance.init(font_, font_material_); MyFontRenderer.Instance.init(camera_); draw_buffer_ = new DrawBuffer[2]; for (int i = 0; i < 2; ++i) { draw_buffer_[i].init(); } manual_reset_event_ = new System.Threading.ManualResetEvent(false); #if UNITY_PS4 setFPS(120); #else setFPS(90); #endif update_frame_ = 0; update_sync_frame_ = 0; update_time_ = 0f; render_frame_ = 0; render_sync_frame_ = 0; camera_holder_transform_ = camera_holder_.transform; ProjectionMatrix = camera_.projectionMatrix; if (zako_prefab_ != null) { zako_pool_ = new GameObject[ZAKO_MAX]; for (var i = 0; i < ZAKO_MAX; ++i) { zako_pool_[i] = Instantiate(zako_prefab_) as GameObject; zako_pool_[i].SetActive(false); } } if (dragon_head_prefab_ != null) { dragon_head_pool_ = new GameObject[DRAGON_HEAD_MAX]; for (var i = 0; i < DRAGON_HEAD_MAX; ++i) { dragon_head_pool_[i] = Instantiate(dragon_head_prefab_) as GameObject; dragon_head_pool_[i].SetActive(false); } } if (dragon_body_prefab_ != null) { dragon_body_pool_ = new GameObject[DRAGON_BODY_MAX]; for (var i = 0; i < DRAGON_BODY_MAX; ++i) { dragon_body_pool_[i] = Instantiate(dragon_body_prefab_) as GameObject; dragon_body_pool_[i].SetActive(false); } } if (dragon_tail_prefab_ != null) { dragon_tail_pool_ = new GameObject[DRAGON_TAIL_MAX]; for (var i = 0; i < DRAGON_TAIL_MAX; ++i) { dragon_tail_pool_[i] = Instantiate(dragon_tail_prefab_) as GameObject; dragon_tail_pool_[i].SetActive(false); } } if (shutter_prefab_ != null) { shutter_pool_ = new GameObject[SHUTTER_MAX]; for (var i = 0; i < SHUTTER_MAX; ++i) { shutter_pool_[i] = Instantiate(shutter_prefab_) as GameObject; shutter_pool_[i].SetActive(false); } } uv_scroller_list_ = new UVScroller[8]; // audio audio_sources_bullet_ = new AudioSource[AUDIOSOURCE_BULLET_MAX]; for (var i = 0; i < AUDIOSOURCE_BULLET_MAX; ++i) { audio_sources_bullet_[i] = gameObject.AddComponent <AudioSource>(); audio_sources_bullet_[i].clip = se_bullet_; audio_sources_bullet_[i].volume = 0.4f; } audio_source_bullet_index_ = 0; audio_sources_explosion_ = new AudioSource[AUDIOSOURCE_EXPLOSION_MAX]; for (var i = 0; i < AUDIOSOURCE_EXPLOSION_MAX; ++i) { audio_sources_explosion_[i] = gameObject.AddComponent <AudioSource>(); audio_sources_explosion_[i].clip = se_explosion_; audio_sources_explosion_[i].volume = 0.25f; } audio_source_explosion_index_ = 0; audio_sources_missile_ = new AudioSource[AUDIOSOURCE_MISSILE_MAX]; for (var i = 0; i < AUDIOSOURCE_MISSILE_MAX; ++i) { audio_sources_missile_[i] = gameObject.AddComponent <AudioSource>(); audio_sources_missile_[i].clip = se_missile_; audio_sources_missile_[i].volume = 0.25f; } audio_source_missile_index_ = 0; audio_sources_lockon_ = new AudioSource[AUDIOSOURCE_LOCKON_MAX]; for (var i = 0; i < AUDIOSOURCE_LOCKON_MAX; ++i) { audio_sources_lockon_[i] = gameObject.AddComponent <AudioSource>(); audio_sources_lockon_[i].clip = se_lockon_; audio_sources_lockon_[i].volume = 0.20f; } audio_source_lockon_index_ = 0; audio_sources_shield_ = new AudioSource[AUDIOSOURCE_SHIELD_MAX]; for (var i = 0; i < AUDIOSOURCE_SHIELD_MAX; ++i) { audio_sources_shield_[i] = gameObject.AddComponent <AudioSource>(); audio_sources_shield_[i].clip = se_shield_; audio_sources_shield_[i].volume = 0.25f; } audio_source_shield_index_ = 0; audio_sources_voice_ikuyo_ = gameObject.AddComponent <AudioSource>(); audio_sources_voice_ikuyo_.clip = se_voice_ikuyo_; audio_sources_voice_ikuyo_.volume = 0.75f; audio_sources_voice_uwaa_ = gameObject.AddComponent <AudioSource>(); audio_sources_voice_uwaa_.clip = se_voice_uwaa_; audio_sources_voice_uwaa_.volume = 0.75f; audio_sources_voice_sorosoro_ = gameObject.AddComponent <AudioSource>(); audio_sources_voice_sorosoro_.clip = se_voice_sorosoro_; audio_sources_voice_sorosoro_.volume = 0.75f; audio_sources_voice_ototo_ = gameObject.AddComponent <AudioSource>(); audio_sources_voice_ototo_.clip = se_voice_ototo_; audio_sources_voice_ototo_.volume = 0.75f; audio_sources_voice_yoshi_ = gameObject.AddComponent <AudioSource>(); audio_sources_voice_yoshi_.clip = se_voice_yoshi_; audio_sources_voice_yoshi_.volume = 0.75f; audio_sources_bgm_ = gameObject.AddComponent <AudioSource>(); audio_sources_bgm_.clip = bgm01_; audio_sources_bgm_.volume = 0.5f; audio_sources_bgm_.loop = true; is_bgm_playing_ = false; gc_start_count_ = System.GC.CollectionCount(0 /* generation */); my_camera_ = MyCamera.create(); player_ = Player.create(); flow_speed_target_ = 0f; flow_speed_ = 0f; }
private void main_loop() { long begin_time = stopwatch_.ElapsedTicks; // flip int updating_front = 1 - rendering_front_; // update if (!pause_) { // adaptive frame rate setFPS((int)(1f / elapsed_frame_time_)); // call here for stable DT during pause. if (Options.Instance.PerformanceMeter && InputManager.Instance.getButton(InputManager.Button.FFWPlus) > 0) { fast_forward_ratio_ += 9; } if (InputManager.Instance.getButton(InputManager.Button.FFWMinus) > 0) { fast_forward_ratio_ -= 9; } fast_forward_ratio_ = Mathf.Clamp(fast_forward_ratio_, 1, 10); for (var i = 0; i < fast_forward_ratio_; ++i) { update_flow_speed(dt_); TubeScroller.Instance.update(dt_, flow_speed_); GameManager.Instance.update(dt_, update_time_); Player.Instance.update(dt_, update_time_, flow_speed_); TaskManager.Instance.update(dt_, update_time_, flow_speed_); // lockon bool locked = false; if (player_.isNowLocking()) { locked = LockTarget.checkAll(player_, update_time_); } // collision MyCollider.calculate(); if (locked) { registSound(DrawBuffer.SE.Lockon); } if (InputManager.Instance.getButton(InputManager.Button.Pause) > 0) { pause_ = true; registBgm(DrawBuffer.BGM.Pause); registMotion(DrawBuffer.Motion.Pause); } ++update_frame_; update_time_ += dt_; } } else { if (InputManager.Instance.getButton(InputManager.Button.Pause) > 0) { pause_ = false; registBgm(DrawBuffer.BGM.Resume); registMotion(DrawBuffer.Motion.Resume); } else { if (InputManager.Instance.getButton(InputManager.Button.Back) > 0) { long elapsed_tick = stopwatch_.ElapsedTicks - pause_back_time_; float elapsed = (float)elapsed_tick / ((float)System.Diagnostics.Stopwatch.Frequency); if (elapsed > 1f) { GameManager.Instance.setReplayMode(false); restart(); pause_ = false; } } else { pause_back_time_ = stopwatch_.ElapsedTicks; } } } // profile update_tick_ = stopwatch_.ElapsedTicks - begin_time; begin_time = stopwatch_.ElapsedTicks; // begin MyFont.Instance.begin(); MySprite.Instance.begin(); VRSprite.Instance.begin(); Sight.Instance.begin(); Beam.Instance.begin(updating_front); Beam2.Instance.begin(updating_front); Trail.Instance.begin(updating_front); Spark.Instance.begin(); Explosion.Instance.begin(); Hahen.Instance.begin(); Shockwave.Instance.begin(); Shield.Instance.begin(); // renderUpdate draw_buffer_[updating_front].beginRender(); my_camera_.renderUpdate(updating_front, ref draw_buffer_[updating_front]); player_.renderUpdate(updating_front, ref draw_buffer_[updating_front]); TaskManager.Instance.renderUpdate(updating_front, my_camera_, ref draw_buffer_[updating_front]); // debug info renderUpdate_debug_info(updating_front); // end Shield.Instance.end(updating_front); Shockwave.Instance.end(updating_front); Hahen.Instance.end(updating_front); Explosion.Instance.end(updating_front); Spark.Instance.end(updating_front); Trail.Instance.end(); Beam2.Instance.end(); Beam.Instance.end(); Sight.Instance.end(updating_front); VRSprite.Instance.end(updating_front); MySprite.Instance.end(updating_front); MyFont.Instance.end(updating_front); render_update_tick_ = stopwatch_.ElapsedTicks - begin_time; }