예제 #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
파일: ObjectSync.cs 프로젝트: nottvlike/EGP
        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);
            }
        }