Пример #1
0
        /// <summary>
        /// 周囲の道路状況から自分自身の道路モデルを設定する
        /// </summary>
        /// <param name="cellEvent"></param>
        private void UpdateModel(CellEvent cellEvent)
        {
            var cellMapper = GameSystem.Instance.CellManager.Mapper;
            var bit        = 0;

            bit |= this.ExistsRoad(cellMapper, cellEvent, Vector2Int.up) ? Direction.Up : 0;
            bit |= this.ExistsRoad(cellMapper, cellEvent, Vector2Int.down) ? Direction.Down : 0;
            bit |= this.ExistsRoad(cellMapper, cellEvent, Vector2Int.left) ? Direction.Left : 0;
            bit |= this.ExistsRoad(cellMapper, cellEvent, Vector2Int.right) ? Direction.Right : 0;
            Assert.IsTrue(this.modelMapper.Map.ContainsKey(bit), $"Origin = {cellEvent.Origin}, bit = {bit}の道路マップがありませんでした");
            var modelParameter = this.modelMapper.Map[bit];

            // モデルが違った場合のみ切り替える
            if (modelParameter.ModelPrefab != this.currentPrefab)
            {
                this.ReturnToPoolModel();
                this.currentPool  = pools.Get(modelParameter.ModelPrefab);
                this.currentModel = this.currentPool.Rent();
                this.currentModel.transform.SetParent(this.transform);
                this.currentModel.transform.localPosition = Vector3.zero;
                this.currentPrefab = modelParameter.ModelPrefab;
            }

            this.currentModel.transform.localEulerAngles = Vector3.up * modelParameter.Rotation;
        }
Пример #2
0
        public void OnChange(CellEvent eventType, ICellEvent sender, DateTime epoch, ISession session)
        {
            switch (eventType)
            {
            case CellEvent.Invalidate:
            case CellEvent.Delete:
            case CellEvent.JoinSession:
            case CellEvent.Link:
            case CellEvent.Calculate:
                _target.OnNext(new Tuple <ISession, Generic.ICell <T>, CellEvent, ICell, DateTime>(session, _source, eventType, ((ICell)sender), epoch));
                break;

            case CellEvent.Error:
                try
                {
                    _target.OnNext(new Tuple <ISession, Generic.ICell <T>, CellEvent, ICell, DateTime>(session, _source, eventType, (ICell)sender, epoch));
                }
                catch (Exception e)
                {
                    _target.OnError(e);
                }
                break;

            default:
                break;
            }
        }
Пример #3
0
        private void OnChange(CellEvent eventType, ICellEvent root, ICellEvent sender, DateTime epoch, ISession session)
        {
            var c = root as Generic.ICell <T>;

            if (c != null)
            {
                switch (eventType)
                {
                case CellEvent.Calculate:
                    _target.OnNext(new KeyValuePair <string, T>(c.Mnemonic, c.Value));
                    break;

                case CellEvent.Delete:
                    _target.OnCompleted();
                    break;

                case CellEvent.Error:
                    try
                    {
                        _target.OnNext(new KeyValuePair <string, T>(c.Mnemonic, c.Value));
                    }
                    catch (Exception e)
                    {
                        _target.OnError(e);
                    }
                    break;

                default:
                    break;
                }
            }
        }
Пример #4
0
 /// <summary>
 /// 上下左右にある道路のモデル設定をリクエストする
 /// </summary>
 private void PublishRequestUpdateRoadModelCross(CellEvent cellEvent)
 {
     this.PublishRequestUpdateRoadModel(cellEvent, Vector2Int.up);
     this.PublishRequestUpdateRoadModel(cellEvent, Vector2Int.down);
     this.PublishRequestUpdateRoadModel(cellEvent, Vector2Int.left);
     this.PublishRequestUpdateRoadModel(cellEvent, Vector2Int.right);
 }
Пример #5
0
        public void OnChange(CellEvent eventType, ICellEvent sender, DateTime epoch, ISession session)
        {
            switch (eventType)
            {
            case CellEvent.Calculate:
                var lastsession = Session.Current;
                Session.Current = session;
                _target.OnNext(new KeyValuePair <ISession, KeyValuePair <string, T> >(session, new KeyValuePair <string, T>(_source.Mnemonic, _source.Value)));
                Session.Current = lastsession;
                break;

            case CellEvent.Delete:
                _target.OnCompleted();
                break;

            case CellEvent.Error:
                try
                {
                    _target.OnNext(new KeyValuePair <ISession, KeyValuePair <string, T> >(session, new KeyValuePair <string, T>(_source.Mnemonic, _source.Value)));
                }
                catch (Exception e)
                {
                    _target.OnError(e);
                }
                break;

            default:
                break;
            }
        }
Пример #6
0
        public void GenerateOnDeserialize(CellEvent instance)
        {
            this.cellMapper.Add(instance, instance.Origin);
            instance.Initialize(instance.Origin, true);

            Broker.Global.Publish(AddedCellEvent.Get(instance));
        }
Пример #7
0
 public virtual void OnChange(CellEvent eventType, ICellEvent root, DateTime epoch, ISession session)
 {
     if (Change != null)
     {
         Change(eventType, root, epoch, session);
     }
 }
 public CellEventInstance(int cell, int data, int data2, CellEvent ev)
     : base(ev)
 {
     this.cell  = cell;
     this.data  = data;
     this.data2 = data2;
 }
Пример #9
0
        public void Attach(CellEvent cellEvent)
        {
            Assert.IsNotNull(cellEvent);

            var productHolder = cellEvent as IProductHolder;

            Assert.IsNotNull(productHolder);

            // 既に何か生産している場合は吹き出しを即座に表示する
            if (productHolder.Products.Count > 0)
            {
                var productId = productHolder.Products[productHolder.Products.Count - 1];
                var record    = GameSystem.Instance.MasterData.Item.Records.Get(productId);
                this.Apply(record);
            }
            else
            {
                this.Hidden();
            }

            cellEvent.Broker.Receive <AddedFacilityProduct>()
            .SubscribeWithState(this, (x, _this) =>
            {
                _this.Apply(x.Product);
            })
            .AddTo(this);

            cellEvent.Broker.Receive <AcquiredFacilityProduct>()
            .SubscribeWithState(this, (_, _this) =>
            {
                GameSystem.Instance.SEController.Play(collectSE);
                _this.Hidden();
            })
            .AddTo(this);
        }
Пример #10
0
 /// <summary>
 /// при наведении мышкой
 /// </summary>
 private void OnMouseEnter()
 {
     if (Input.GetMouseButton(0))
     {
         CellEvent.Enter(this);
     }
 }
Пример #11
0
        public void OnChange(CellEvent eventType, ICellEvent root, ICellEvent sender, DateTime epoch, ISession session)
        {
            switch (eventType)
            {
            case CellEvent.Calculate:
                _target.OnNext((ICell)root);
                break;

            case CellEvent.Delete:
                _target.OnCompleted();
                break;

            case CellEvent.Error:
                try
                {
                    _target.OnNext((ICell)root);
                }
                catch (Exception e)
                {
                    _target.OnError(e);
                }
                break;

            default:
                break;
            }
        }
Пример #12
0
        public void OnChange(CellEvent eventType, ICellEvent root, ICellEvent sender, DateTime epoch, ISession session)
        {
            switch (eventType)
            {
            case CellEvent.Invalidate:
            case CellEvent.Delete:
            case CellEvent.JoinSession:
            case CellEvent.Link:
            case CellEvent.Calculate:
                _target.OnNext(new Tuple <ISession, Generic.ICell <T>, CellEvent, ICell, DateTime>(session, _source, eventType, ((ICell)sender), epoch));
                _retry = 0;
                break;

            case CellEvent.Error:
                try
                {
                    _target.OnNext(new Tuple <ISession, Generic.ICell <T>, CellEvent, ICell, DateTime>(session, _source, eventType, (ICell)sender, epoch));
                }
                catch (Exception e)
                {
                    _target.OnError(e);
                    if (root is ICell c && _retry++ < Cell.ErrorRetry)
                    {
                        Thread.Sleep(_retry * Cell.ErrorRetry * 100);
                        c.OnChange(CellEvent.Calculate, this, this, DateTime.Now, session);
                    }
                }
                break;

            default:
                break;
            }
        }
Пример #13
0
        public virtual void OnChange(CellEvent eventType, ICellEvent root, DateTime epoch, ISession session)
        {
            switch (eventType)
            {
            case CellEvent.Calculate:
                if (session != null && session.State == SessionState.Open)
                {
                    _pending++;
                }
                else
                {
                    RaiseChange(CellEvent.Invalidate, root, epoch, session);
                    if (Cell.Parellel)
                    {
                        Task.Run(() => PoolCalculate(DateTime.Now, session));
                    }
                    else
                    {
                        PoolCalculate(epoch, session);
                    }
                }
                break;

            case CellEvent.Invalidate:
                var lastState = (CellState)Interlocked.Exchange(ref _state, (int)CellState.Dirty);
                if (lastState == CellState.Calculating || lastState == CellState.Blocking)
                {
                    lastState = (CellState)Interlocked.Exchange(ref _state, (int)lastState);
                }
                else
                {
                    RaiseChange(eventType, root, epoch, session);
                }
                break;

            case CellEvent.JoinSession:
                session.Join(this);
                RaiseChange(eventType, root, epoch, session);
                break;

            case CellEvent.Error:
                bool taken = false;
                _spinLock.Enter(ref taken);
                if (taken)
                {
                    SetState(CellState.Error);
                    _spinLock.Exit();
                }
                else
                {
                    Thread.Sleep(100);
                    OnChange(eventType, root, epoch, session);
                }
                break;

            default:
                break;
            }
        }
Пример #14
0
 public virtual void OnChange(CellEvent eventType, ICellEvent root, ICellEvent sender, DateTime epoch, ISession session)
 {
     if (sender == Parent)
     {
         return;
     }
     RaiseChange(eventType, root, this, epoch, session);
 }
Пример #15
0
    ////////////////////
    /// CONSTRUCTORS ///
    ////////////////////

    public Cell(Topography topography, Vector2Int position, CellEvent cellChanged, Cell[,] cellMap, bool borderTile = false)
    {
        this.topography            = GameObject.Instantiate(topography) as Topography;
        this.topography.parentCell = this;
        this.position    = position;
        this.borderTile  = borderTile;
        this.cellChanged = cellChanged;
        this.cellMap     = cellMap;
    }
Пример #16
0
        /// <summary>
        /// <paramref name="direction"/>方向に道路があるか返す
        /// </summary>
        private bool ExistsRoad(CellMapper mapper, CellEvent owner, Vector2Int direction)
        {
            var position = owner.Origin + direction;

            if (!mapper.CellEvent.Map.ContainsKey(position))
            {
                return(false);
            }

            return(mapper.CellEvent.Map[position] is IRoad);
        }
Пример #17
0
 private void RaiseChange(CellEvent eventType, ICellEvent root, ICellEvent sender, DateTime epoch, ISession session)
 {
     if (Change != null)
     {
         Change(eventType, root, this, epoch, session);
     }
     if (Parent != null)
     {
         Parent.OnChange(eventType, root, this, epoch, session);
     }
 }
Пример #18
0
        /// <summary>
        /// <paramref name="direction"/>方向にある道路のモデル設定をリクエストする
        /// </summary>
        private void PublishRequestUpdateRoadModel(CellEvent owner, Vector2Int direction)
        {
            var cellEventMap = GameSystem.Instance.CellManager.Mapper.CellEvent.Map;
            var position     = owner.Origin + direction;

            if (!cellEventMap.ContainsKey(position))
            {
                return;
            }

            cellEventMap[position].Broker.Publish(RequestUpdateRoadModel.Get());
        }
Пример #19
0
        public void OnChange(CellEvent eventType, ICellEvent root, ICellEvent sender, DateTime epoch, ISession session)
        {
            switch (eventType)
            {
            case CellEvent.Calculate:
                _target.OnNext(_source.Value);
                _retry = 0;
                break;

            case CellEvent.Delete:
                _target.OnCompleted();
                break;

            case CellEvent.Error:
                try
                {
                    _target.OnNext(_source.Value);
                }
                catch (Exception e)
                {
                    _target.OnError(e);
                    if (root is ICell c && _retry++ < Cell.ErrorRetry)
                    {
                        Thread.Sleep(_retry * Cell.ErrorRetry * 100);
                        c.OnChange(CellEvent.Calculate, this, this, DateTime.Now, session);
                    }
                }
                break;

            case CellEvent.Link:
                if (_source.Parent != null && _source.Parent is Model)
                {
                    var source = ((Model)_source.Parent)[_source.Mnemonic] as Generic.ICell <T>;
                    if (source != null)
                    {
                        _source = source;
                        OnChange(CellEvent.Calculate, sender, sender, epoch, session);
                    }
                }
                break;

            default:
                break;
            }
        }
Пример #20
0
        public void Initialize(CellEvent cellEvent)
        {
            var color = GameSystem.Instance.Constants.Color.CellEvent.Get(cellEvent.Category);

            this.message.text = this.format.Format(ColorUtility.ToHtmlStringRGBA(color), ">", cellEvent.EventName);
            var gimmick = Instantiate(cellEvent.GimmickPrefab, this.gimmickViewParent, false).transform;

            gimmick.localPosition = Vector3.zero;
            gimmick.localRotation = Quaternion.identity;
            gimmick.gameObject.SetLayerRecursive(Layers.Id.UI);

            this.decideButton.OnClickAsObservable()
            .SubscribeWithState(this, (_, _this) =>
            {
                _this.Close();
            })
            .AddTo(this);
        }
Пример #21
0
        private void OnChange(CellEvent eventType, ICellEvent root, ICellEvent sender, DateTime epoch, ISession session)
        {
            switch (eventType)
            {
            case CellEvent.Calculate:
                var lastsession = Session.Current;
                Session.Current = session;
                ICell  c = ((ICell)root).Parent;
                string n = ((ICell)root).Mnemonic;
                while (c != null)
                {
                    n = c.Mnemonic + "|" + n;
                    c = c.Parent;
                }
                _target.OnNext(new KeyValuePair <ISession, KeyValuePair <string, ICell> >(session, new KeyValuePair <string, ICell>(n, (ICell)sender)));
                Session.Current = lastsession;
                break;

            case CellEvent.Delete:
                _target.OnCompleted();
                break;

            case CellEvent.Error:
                try
                {
                    c = ((ICell)sender).Parent;
                    n = ((ICell)sender).Mnemonic;
                    while (c != null)
                    {
                        n = c.Mnemonic + "|" + n;
                        c = c.Parent;
                    }
                    _target.OnNext(new KeyValuePair <ISession, KeyValuePair <string, ICell> >(session, new KeyValuePair <string, ICell>(n, (ICell)sender)));
                }
                catch (Exception e)
                {
                    _target.OnError(e);
                }
                break;

            default:
                break;
            }
        }
Пример #22
0
        public void OnChange(CellEvent eventType, ICellEvent sender, DateTime epoch, ISession session)
        {
            switch (eventType)
            {
            case CellEvent.Calculate:
                _target.OnNext(_source.Value);
                break;

            case CellEvent.Delete:
                _target.OnCompleted();
                break;

            case CellEvent.Error:
                try
                {
                    _target.OnNext(_source.Value);
                }
                catch (Exception e)
                {
                    _target.OnError(e);
                }
                break;

            case CellEvent.Link:
                if (_source.Parent != null && _source.Parent is Model)
                {
                    var source = ((Model)_source.Parent)[_source.Mnemonic] as Generic.ICell <T>;
                    if (source != null)
                    {
                        _source = source;
                        OnChange(CellEvent.Calculate, sender, epoch, session);
                    }
                }
                break;

            default:
                break;
            }
        }
Пример #23
0
        public void Attach(CellEvent cellEvent)
        {
            Assert.IsNotNull(cellEvent);

            this.modelMapper = new ModelMapper(
                this.straight,
                this.turn,
                this.junctionT,
                this.crossroads
                );

            this.UpdateModel(cellEvent);

            cellEvent.Broker.Receive <RequestUpdateRoadModel>()
            .SubscribeWithState2(this, cellEvent, (_, _this, _cellEvent) =>
            {
                _this.UpdateModel(_cellEvent);
            })
            .AddTo(this);

            this.PublishRequestUpdateRoadModelCross(cellEvent);
        }
Пример #24
0
        public void OnChange(CellEvent eventType, ICellEvent root, ICellEvent sender, DateTime epoch, ISession session)
        {
            switch (eventType)
            {
            case CellEvent.Calculate:
                var lastsession = Session.Current;
                Session.Current = session;
                _target.OnNext(new KeyValuePair <ISession, KeyValuePair <string, T> >(session, new KeyValuePair <string, T>(_source.Mnemonic, _source.Value)));
                Session.Current = lastsession;
                _retry          = 0;
                break;

            case CellEvent.Delete:
                _target.OnCompleted();
                break;

            case CellEvent.Error:
                try
                {
                    _target.OnNext(new KeyValuePair <ISession, KeyValuePair <string, T> >(session, new KeyValuePair <string, T>(_source.Mnemonic, _source.Value)));
                }
                catch (Exception e)
                {
                    _target.OnError(e);
                    if (root is ICell c && _retry++ < Cell.ErrorRetry)
                    {
                        Thread.Sleep(_retry * Cell.ErrorRetry * 100);
                        c.OnChange(CellEvent.Calculate, this, this, DateTime.Now, session);
                    }
                }
                break;

            default:
                break;
            }
        }
Пример #25
0
 public Record(SpreadSheetData.CellEventData data)
 {
     this.cachedId  = 0;
     this.eventData = CellEvent.GetOrCreateAsset(data);
 }
Пример #26
0
 public void Detach(CellEvent cellEvent)
 {
 }
Пример #27
0
 public void Detach(CellEvent cellEvent)
 {
     this.PublishRequestUpdateRoadModelCross(cellEvent);
     this.ReturnToPoolModel();
 }
Пример #28
0
        public virtual void OnChange(CellEvent eventType, ICellEvent root, ICellEvent sender, DateTime epoch, ISession session)
        {
            if (_disposd && root != this && eventType != CellEvent.Delete)
            {
                sender.OnChange(CellEvent.Delete, this, this, epoch, session);
            }
            if (sender == Parent || root == this)
            {
                return;
            }
            switch (eventType)
            {
            case CellEvent.Calculate:
                if (session != null && session.State == SessionState.Open)
                {
                    _pending++;
                }
                else if (epoch > _epoch)
                {
                    _epoch = epoch;
                    OnChange(CellEvent.Invalidate, root, this, epoch, session);
                    if (Cell.Parellel)
                    {
                        Task.Run(() => PoolCalculate(epoch, session));
                    }
                    else
                    {
                        PoolCalculate(epoch, session);
                    }
                }
                break;

            case CellEvent.Delete:
                _link   = true;
                Change -= root.OnChange;
                break;

            case CellEvent.Invalidate:
                var lastState = (CellState)Interlocked.Exchange(ref _state, (int)CellState.Dirty);
                if (lastState == CellState.Calculating || lastState == CellState.Blocking)
                {
                    lastState = (CellState)Interlocked.Exchange(ref _state, (int)lastState);
                }
                else
                {
                    RaiseChange(eventType, root, this, epoch, session);
                }
                break;

            case CellEvent.Link:
                if (root == this)
                {
                    throw new CyclicDependencyException();
                }
                _link = true;
                _flip = true;
                if (_func != null)
                {
                    SetState(CellState.Dirty);
                }
                OnChange(CellEvent.Calculate, root, this, epoch, session);
                break;

            case CellEvent.JoinSession:
                session.Join(this);
                RaiseChange(eventType, root, this, epoch, session);
                break;

            case CellEvent.Error:
                bool taken = false;
                _spinLock.Enter(ref taken);
                while (!taken)
                {
                    Thread.Yield();
                    _spinLock.Enter(ref taken);
                }
                SetState(CellState.Error);
                _spinLock.Exit();
                break;
            }
        }
Пример #29
0
 public static void RegisterEvent(CellEvent cellEvent)
 {
     eventList.Add(cellEvent);
 }
 void Awake()
 {
     SelectedCellEvent = new CellEvent();
 }