public Snake(Texture2D texture, Vector2 position, Vector2 screenSize, LevelManager levelManager, FruitManager fruitManager, Splash splash, Score score) : base(texture, position, screenSize) { sections.Add(this); speed = 1; state = new UpState(this); this.levelManager = levelManager; this.fruitManager = fruitManager; this.splash = splash; this.score = score; }
// 画像更新 // フレームバッファを転送用フォーマットに変換してバッファに保存 // OnPostRender()内で実行してください。 public void OnPostRender() { switch (_updateState) { case UpState.Non: // フレームバッファを取得 if (_srcTexture != null) { _updateState = UpState.ReadPixel; _readReqest = AsyncGPUReadback.Request(_srcTexture, 0, (AsyncGPUReadbackRequest readReq) => { if (!readReq.hasError) { Profiler.BeginSample("_srcTexture.GetPixels32"); int nextSize = readReq.GetData <Color32>().Length; if ((_pixBuffer?.Length ?? 0) < nextSize) { _pixBuffer = new Color32[nextSize]; } readReq.GetData <Color32>().CopyTo(_pixBuffer); _pixBufferSize = nextSize; Profiler.EndSample(); } _updateState = UpState.SendBuffer; }); } break; case UpState.ReadPixel: #if false // pixcelリード中なら終了まで待つ if (!_readReqest.done) { Profiler.BeginSample("_readReqest.WaitForCompletion"); _readReqest.WaitForCompletion(); Profiler.EndSample(); } #endif break; case UpState.SendBuffer: break; default: break; } }
void Start() { //ani = GetComponent<Animation>(); IdleState idle = new IdleState(1, this); LeftState left = new LeftState(2, this); RightState right = new RightState(3, this); UpState up = new UpState(4, this); DownState down = new DownState(5, this); AttackState attack = new AttackState(6, this); machine = new StateMachine(idle); machine.AddState(left); machine.AddState(right); machine.AddState(up); machine.AddState(down); machine.AddState(attack); }
// バックグラウンドでエンコード開始 private void BackGroundEncode() { while (_enableBackground) { // 更新がなければ無処理 while (_updateState != UpState.SendBuffer) { if (!_enableBackground) { return; } } this.Encode(); _updateState = UpState.Non; // 無処理状態に戻る } }
public void Setup(int width, int hight, int bitrate, int useCpu, Texture srcTexture) { this.Width = Mathf.Min(Screen.width, width); this.Hight = Mathf.Min(Screen.height, hight); VpxDllCall.EncodeSetup(this.Width, this.Hight, bitrate, useCpu); _srcTexture = null; // 出力 this.WriteBuffer(); _enableBackground = true; _updateState = UpState.Non; _srcTexture = srcTexture; _backgroundEncoder = Task.Run(BackGroundEncode); }
public UpTransition(Player _player) { player = _player; nextState = new UpState(_player); }