Пример #1
0
        public static void Start(GUnit unit, int id, Vector3 param, bool sync = true)
        {
            var stateProcessData = unit.GetData <ObjectStateProcessData>();
            var stateData        = ObjectStateDataDict.Get(unit, id);

            if (!stateData.objectState.CanStart(unit, stateProcessData, stateData, param))
            {
                return;
            }

            if (sync && unit.GetData <ObjectSyncData>() == null)
            {
                sync = false;
            }

            if (sync)
            {
                ObjectSyncServer.AddState(unit, id, param, ObjectStateType.Start);
            }
            else
            {
                stateData.param = param;
                Start(stateProcessData, stateData);
            }
        }
Пример #2
0
        protected override void OnAdd(GUnit unit)
        {
            var unitData       = unit.GetData <UnitData>();
            var objectSyncData = unit.GetData <ObjectSyncData>();

            objectSyncData.stateSyncInfoList.ObserveAdd().Subscribe(_ =>
            {
                if (objectSyncData.checkSyncDispose != null)
                {
                    return;
                }

                objectSyncData.checkSyncDispose = ObjectSyncServer.EverySyncUpdate().Subscribe(frameInfo =>
                {
                    if (objectSyncData.stateSyncInfoList.Count == 0)
                    {
                        objectSyncData.checkSyncDispose.Dispose();
                        objectSyncData.checkSyncDispose = null;
                        return;
                    }

                    var stateSyncInfoList = objectSyncData.stateSyncInfoList;
                    for (var i = 0; i < stateSyncInfoList.Count;)
                    {
                        var syncInfo = objectSyncData.stateSyncInfoList[i];
#if DEBUG
                        if (syncInfo.serverKeyFrame < frameInfo.Item1 ||
                            (syncInfo.serverKeyFrame == frameInfo.Item1 && syncInfo.internalFrame < frameInfo.Item2))
                        {
                            Log.W("Sync {0} state {1} {2} failed!", syncInfo.stateType,
                                  syncInfo.stateId, syncInfo.stateParam);
                            objectSyncData.stateSyncInfoList.RemoveAt(i);
                            return;
                        }
#endif
                        if (syncInfo.serverKeyFrame == frameInfo.Item1 && syncInfo.internalFrame == frameInfo.Item2)
                        {
                            DoState(unit, syncInfo);
                            objectSyncData.stateSyncInfoList.RemoveAt(i);
                        }
                        else
                        {
                            i++;
                        }
                    }
                });
            }).AddTo(unitData.disposable);
        }
Пример #3
0
        public static void Finish(GUnit unit, int id, bool sync = true)
        {
            var stateProcessData = unit.GetData <ObjectStateProcessData>();
            var stateData        = ObjectStateDataDict.Get(unit, id);

            if (!stateData.objectState.CanFinish(unit, stateProcessData, stateData))
            {
                return;
            }

            if (sync && unit.GetData <ObjectSyncData>() == null)
            {
                sync = false;
            }

            if (sync)
            {
                ObjectSyncServer.AddState(unit, id, Vector3.zero, ObjectStateType.Finish);
            }
            else
            {
                Finish(unit, stateProcessData, stateData);
            }
        }