Exemplo n.º 1
0
            /// <summary>
            /// Apply the transition to given state in order to calculate the next state.
            /// </summary>
            /// <param name="state">The state to transition from.</param>
            /// <param name="inPlace">Set to true if it's ok to modify the given state.</param>
            public IState ApplyToState(IState state, bool inPlace = false)
            {
                // Copy state.
                var worldState = state as WorldState;

                if (worldState == null)
                {
                    return(ApplyInReverse(state as RegressiveSearchWorldGoal, inPlace));
                }
                if (!inPlace)
                {
                    var prevWorldState = worldState;
                    worldState = WorldState.Borrow();
                    foreach (var kvp in prevWorldState)
                    {
                        worldState[kvp.Key] = kvp.Value;
                    }
                }
                // Apply change.
                var effects = actionData.GetDependentEffects(agent, target);

                foreach (var change in effects)
                {
                    // Add any new stateful objects that are affected by this transition
                    // to the new state.
                    if (!worldState.ContainsKey(change.Key))
                    {
                        worldState[change.Key] = change.Key.GetState();
                    }
                    worldState[change.Key] = worldState[change.Key].ApplyEffects(change.Value);
                }
                effects.ReturnSelf();
                // Apply movement.
                if (actionData.RequiresInRange())
                {
                    var agentState = worldState[agent];
                    var obj        = target as Component;
                    var x          = StateValue.NormalizeValue(obj.transform.position.x);
                    var y          = StateValue.NormalizeValue(obj.transform.position.y);
                    var z          = StateValue.NormalizeValue(obj.transform.position.z);
                    agentState["x"] = new StateValue(x);
                    agentState["y"] = new StateValue(y);
                    agentState["z"] = new StateValue(z);
                }
                return(worldState);
            }
Exemplo n.º 2
0
 public Effect(ModificationType modifier, object value)
 {
     this.modifier = modifier;
     this.value    = StateValue.NormalizeValue(value);
 }
 public Condition(CompareType comparison, object value)
 {
     this.comparison = comparison;
     this.value      = StateValue.NormalizeValue(value);
 }