コード例 #1
0
            /// <inheritdoc />
            public void Initialize(IStateComponent state)
            {
                Assert.IsNull(m_State, "Missing Dispose call.");

                m_State = state as TStateComponent;
                BeginStateChange();
            }
コード例 #2
0
 /// <summary>
 /// Gets the current version of the state component.
 /// </summary>
 /// <param name="component">The state component.</param>
 /// <returns>The current version of the state component.</returns>
 internal static StateComponentVersion GetStateComponentVersion(this IStateComponent component)
 {
     return(new StateComponentVersion
     {
         HashCode = component.GetHashCode(),
         Version = component.CurrentVersion
     });
 }
コード例 #3
0
        public Character(string name) : base(name)
        {
            _physicsComponent = new PhysicsComponent(this);
            _damageComponent  = new DamageableComponent(this);
            _stateComponent   = new StateComponent <ChararacterState>(ChararacterState.Idle);

            DrawableComponent = new DrawableComponent(this);
        }
コード例 #4
0
        /// <summary>
        /// Serializes a <see cref="IStateComponent"/> to JSON.
        /// </summary>
        /// <param name="obj">The state component to serialize.</param>
        /// <returns>A JSON string containing the serialized state component.</returns>
        public static string Serialize(IStateComponent obj)
        {
            if (obj == null)
            {
                return("");
            }

            obj.BeforeSerialize();
            return(JsonUtility.ToJson(obj));
        }
コード例 #5
0
        public void SetState(Hash128 key, IStateComponent state)
        {
            ThrowIfInvalid(key);
            if (state == null)
            {
                throw new ArgumentNullException(nameof(state));
            }

            m_Cache[key] = state;
        }
コード例 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Observation" /> class.
        /// </summary>
        /// <param name="observer">The observer.</param>
        /// <param name="observedComponent">The observed state</param>
        /// <param name="updateObserverVersion">True if we should update the observer's observed version
        /// at the end of the observation (default). False otherwise.</param>
        internal Observation(IStateObserver observer, IStateComponent observedComponent, bool updateObserverVersion = true)
        {
            Assert.IsTrue(observer.ObservedStateComponents.Contains(observedComponent.StateSlotName),
                          $"Observer {observer.GetType().FullName} does not specify that it observes {observedComponent.StateSlotName}. Please add the state component to its {nameof(IStateObserver.ObservedStateComponents)}.");

            m_ObservedComponent     = observedComponent;
            m_Observer              = observer;
            m_UpdateObserverVersion = updateObserverVersion;

            var internalObserver    = m_Observer as IInternalStateObserver;
            var lastObservedVersion = internalObserver?.GetLastObservedComponentVersion(observedComponent.StateSlotName) ?? default;

            UpdateType          = m_ObservedComponent.GetUpdateType(lastObservedVersion);
            LastObservedVersion = lastObservedVersion.Version;
        }
コード例 #7
0
 public StateMachineTests()
 {
     this.core      = Mock.Of <IStateMachineCore>(MockBehavior.Strict);
     this.component = Mock.Of <IStateComponent>(MockBehavior.Strict);
 }
コード例 #8
0
 /// <summary>
 /// Creates a new <see cref="Observation"/> instance that will not update the observer's last observed version.
 /// </summary>
 /// <param name="observer">The observer.</param>
 /// <param name="stateComponent">The observed state component.</param>
 /// <returns>An <see cref="Observation"/> object.</returns>
 public static Observation PeekAtState(this IStateObserver observer, IStateComponent stateComponent)
 {
     return(new Observation(observer, stateComponent, false));
 }
コード例 #9
0
 /// <summary>
 /// Creates a new <see cref="Observation"/> instance that will update the observer's last observed version.
 /// </summary>
 /// <param name="observer">The observer.</param>
 /// <param name="stateComponent">The observed state component.</param>
 /// <returns>An <see cref="Observation"/> object.</returns>
 public static Observation ObserveState(this IStateObserver observer, IStateComponent stateComponent)
 {
     return(new Observation(observer, stateComponent));
 }
コード例 #10
0
ファイル: StateMachine.cs プロジェクト: emprax/St8-ment
 public StateMachine(IStateMachineCore core)
 {
     this.component = core.Component;
     this.Current   = core.InitialStateId;
 }
コード例 #11
0
 public ResultComponentTests()
 {
     this.next      = Mock.Of <IStateComponent>(MockBehavior.Strict);
     this.state     = TestStateId.Complete;
     this.component = new ResultComponent(this.state);
 }
コード例 #12
0
 public StateComponentCollectionTests()
 {
     this.next      = Mock.Of <IStateComponent>(MockBehavior.Strict);
     this.component = new StateComponentCollection();
 }
コード例 #13
0
 public void AddComponentState(SimpleComponent component, IStateComponent stateComponent)
 {
     States.Add(component, stateComponent);
 }
コード例 #14
0
 public SpecComponentTests()
 {
     this.next = Mock.Of <IStateComponent>(MockBehavior.Strict);
     this.spec = Mock.Of <ISpec <TestAction> >(MockBehavior.Strict);
 }
コード例 #15
0
 public ActionsComponentTests()
 {
     this.next      = Mock.Of <IStateComponent>(MockBehavior.Strict);
     this.component = new ActionsComponent();
 }
コード例 #16
0
 public StateComponentTests()
 {
     this.next             = Mock.Of <IStateComponent>(MockBehavior.Strict);
     this.defaultComponent = Mock.Of <IStateComponent>(MockBehavior.Strict);
     this.component        = new StateComponent();
 }
コード例 #17
0
 public CallbackComponentTests()
 {
     this.next     = Mock.Of <IStateComponent>(MockBehavior.Strict);
     this.callback = Mock.Of <ITransitionCallback <TestAction> >(MockBehavior.Strict);
 }
コード例 #18
0
ファイル: StateMachineCore.cs プロジェクト: emprax/St8-ment
 public StateMachineCore(StateId initialStateId, IStateComponent component)
 {
     this.InitialStateId = initialStateId;
     this.Component      = component;
 }