Ejemplo n.º 1
0
    void OnEnable()
    {
        FloatParameter fparam = ParameterPool.GetParameter <FloatParameter>();

        fparam.value = gunAccuracy;
        GlobalEventQueue.EnQueueEvent(E_Event.GunChange, fparam);
    }
Ejemplo n.º 2
0
        /// <summary>
        /// Set up the simulation.
        /// </summary>
        /// <param name="entities">Entities that are included in the simulation.</param>
        /// <exception cref="ArgumentNullException">circuit</exception>
        /// <exception cref="CircuitException">{0}: No circuit objects for simulation".FormatString(Name)</exception>
        protected virtual void Setup(EntityCollection entities)
        {
            if (entities == null)
            {
                throw new ArgumentNullException(nameof(entities));
            }
            if (entities.Count == 0)
            {
                throw new CircuitException("{0}: No circuit objects for simulation".FormatString(Name));
            }

            // Use the same comparers as the circuit. This is crucial because they use the same identifiers!
            EntityParameters = new ParameterPool(entities.Comparer);
            EntityBehaviors  = new BehaviorPool(entities.Comparer, BehaviorTypes.ToArray());

            // Create the variables that will need solving
            if (Configurations.TryGet(out CollectionConfiguration cconfig))
            {
                Variables        = new VariableSet(cconfig.VariableComparer ?? EqualityComparer <string> .Default);
                _cloneParameters = cconfig.CloneParameters;
            }
            else
            {
                Variables        = new VariableSet();
                _cloneParameters = false;
            }

            // Setup all entity parameters and behaviors
            SetupParameters(entities);
            SetupBehaviors(entities);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Set up the simulation.
        /// </summary>
        /// <param name="circuit">The circuit that will be used.</param>
        /// <exception cref="ArgumentNullException">circuit</exception>
        /// <exception cref="CircuitException">{0}: No circuit objects for simulation".FormatString(Name)</exception>
        protected virtual void Setup(Circuit circuit)
        {
            if (circuit == null)
            {
                throw new ArgumentNullException(nameof(circuit));
            }

            // No use simulating an empty circuit
            if (circuit.Entities.Count == 0)
            {
                throw new CircuitException("{0}: No circuit objects for simulation".FormatString(Name));
            }

            // Use the same comparer as the circuit. This is crucial because they use the same identifiers!
            EntityParameters = new ParameterPool(circuit.Entities.Comparer);
            EntityBehaviors  = new BehaviorPool(circuit.Entities.Comparer);

            // Create the variables that will need solving
            Variables = Configurations.TryGet(out CollectionConfiguration cconfig)
                ? new VariableSet(cconfig.VariableComparer ?? EqualityComparer <string> .Default)
                : new VariableSet();

            // Setup all objects
            circuit.Entities.BuildOrderedComponentList();

            // Get all parameters
            SetupParameters(circuit.Entities);
        }
        /// <summary>
        /// Build the data provider
        /// </summary>
        /// <returns></returns>
        protected override SetupDataProvider BuildSetupDataProvider(ParameterPool parameters, BehaviorPool behaviors)
        {
            parameters.ThrowIfNull(nameof(parameters));
            behaviors.ThrowIfNull(nameof(behaviors));
            var provider = base.BuildSetupDataProvider(parameters, behaviors);

            // Add behaviors and parameters of the controlling voltage source
            provider.Add("control", behaviors[ControllingName]);
            provider.Add("control", parameters[ControllingName]);
            return(provider);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Build the data provider for setting up a behavior for the entity. The entity can control which parameters
        /// and behaviors are visible to behaviors using this method.
        /// </summary>
        /// <param name="parameters">The parameters in the simulation.</param>
        /// <param name="behaviors">The behaviors in the simulation.</param>
        /// <returns>A data provider for the behaviors.</returns>
        /// <exception cref="ArgumentNullException">
        /// parameters
        /// or
        /// behaviors
        /// </exception>
        protected virtual SetupDataProvider BuildSetupDataProvider(ParameterPool parameters, BehaviorPool behaviors)
        {
            parameters.ThrowIfNull(nameof(parameters));
            behaviors.ThrowIfNull(nameof(behaviors));

            // By default, we include the parameters of this entity
            var result = new SetupDataProvider();

            result.Add("entity", parameters[Name]);
            result.Add("entity", behaviors[Name]);
            return(result);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Destroys the simulation.
        /// </summary>
        protected virtual void Unsetup()
        {
            // Clear all parameters
            EntityBehaviors.Clear();
            EntityBehaviors = null;
            EntityParameters.Clear();
            EntityParameters = null;

            // Clear all nodes
            Variables.Clear();
            Variables = null;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Build the data provider for setting up a behavior for the entity. The entity can control which parameters
        /// and behaviors are visible to behaviors using this method.
        /// </summary>
        /// <param name="parameters">The parameters in the simulation.</param>
        /// <param name="behaviors">The behaviors in the simulation.</param>
        /// <returns>
        /// A data provider for the behaviors.
        /// </returns>
        protected override SetupDataProvider BuildSetupDataProvider(ParameterPool parameters, BehaviorPool behaviors)
        {
            var provider = base.BuildSetupDataProvider(parameters, behaviors);

            // Add our model parameters and behaviors
            if (!string.IsNullOrEmpty(Model))
            {
                provider.Add("model", parameters[Model]);
                provider.Add("model", behaviors[Model]);
            }

            return(provider);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Build the data provider for setting up behaviors
        /// </summary>
        /// <returns></returns>
        protected override SetupDataProvider BuildSetupDataProvider(ParameterPool parameters, BehaviorPool behaviors)
        {
            var provider = base.BuildSetupDataProvider(parameters, behaviors);

            // Add our model parameters and behaviors
            if (Model != null)
            {
                provider.Add("model", parameters.GetEntityParameters(Model.Name));
                provider.Add("model", behaviors.GetEntityBehaviors(Model.Name));
            }

            return(provider);
        }
Ejemplo n.º 9
0
    IEnumerator RoutineTooltip(Vector2 position)
    {
        yield return(new WaitForSecondsRealtime(tooltipTime));

        if (isDownStarted)
        {
            Debug.LogFormat("Tooltip : {0}", localKey);
            TooltipParameter p = ParameterPool.GetParameter <TooltipParameter>();
            p.localKey = localKey;
            p.position = position + Vector2.up * 20;
            GlobalEventQueue.EnQueueEvent(DefaultEvent.ShowTooltip, p);
        }
    }
Ejemplo n.º 10
0
        public void ListenPathfindEvent(object param)
        {
            PeekPointParameter p = param as PeekPointParameter;

            if (p.instanceID == instanceID ||
                p.instanceID == GlobalEventQueue.GlobalID)
            {
                ReqPathfind req = ParameterPool.GetParameter <ReqPathfind>();
                req.instanceID    = this.GetInstanceID();
                req.startPosition = this.transform.position;
                req.endPosition   = p.peekPoint;
                req.callback      = PathfindCompleteCallback;
                GlobalEventQueue.EnQueueEvent(DefaultEvent.ReqPathfind, req);
            }
        }
        /// <summary>
        /// Build the data provider
        /// </summary>
        /// <returns></returns>
        protected override SetupDataProvider BuildSetupDataProvider(ParameterPool parameters, BehaviorPool behaviors)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            if (behaviors == null)
            {
                throw new ArgumentNullException(nameof(behaviors));
            }
            var provider = base.BuildSetupDataProvider(parameters, behaviors);

            // Add behaviors and parameters of the controlling voltage source
            provider.Add("control", behaviors[ControllingName]);
            provider.Add("control", parameters[ControllingName]);
            return(provider);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Add inductances to the data provider for setting up behaviors
        /// </summary>
        /// <returns></returns>
        protected override SetupDataProvider BuildSetupDataProvider(ParameterPool parameters, BehaviorPool behaviors)
        {
            parameters.ThrowIfNull(nameof(parameters));
            behaviors.ThrowIfNull(nameof(behaviors));

            // Base execution (will add entity behaviors and parameters for this mutual inductance)
            var data = base.BuildSetupDataProvider(parameters, behaviors);

            // Register inductor 1
            data.Add("inductor1", parameters[InductorName1]);
            data.Add("inductor1", behaviors[InductorName1]);

            // Register inductor 2
            data.Add("inductor2", parameters[InductorName2]);
            data.Add("inductor2", behaviors[InductorName2]);

            return(data);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Build the data provider for setting up a behavior for the entity. The entity can control which parameters
        /// and behaviors are visible to behaviors using this method.
        /// </summary>
        /// <param name="parameters">The parameters in the simulation.</param>
        /// <param name="behaviors">The behaviors in the simulation.</param>
        /// <returns>A data provider for the behaviors.</returns>
        /// <exception cref="ArgumentNullException">
        /// parameters
        /// or
        /// behaviors
        /// </exception>
        protected virtual SetupDataProvider BuildSetupDataProvider(ParameterPool parameters, BehaviorPool behaviors)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            if (behaviors == null)
            {
                throw new ArgumentNullException(nameof(behaviors));
            }

            // By default, we include the parameters of this entity
            var result = new SetupDataProvider();

            result.Add("entity", parameters[Name]);
            result.Add("entity", behaviors[Name]);
            return(result);
        }
        /// <summary>
        /// Setup data provider
        /// </summary>
        /// <returns></returns>
        protected override SetupDataProvider BuildSetupDataProvider(ParameterPool parameters, BehaviorPool behaviors)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            if (behaviors == null)
            {
                throw new ArgumentNullException(nameof(behaviors));
            }
            var provider = base.BuildSetupDataProvider(parameters, behaviors);

            // Add the controlling source
            provider.Add("control", behaviors.GetEntityBehaviors(ControllingName));
            provider.Add("control", parameters.GetEntityParameters(ControllingName));

            return(provider);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Add inductances to the data provider for setting up behaviors
        /// </summary>
        /// <returns></returns>
        protected override SetupDataProvider BuildSetupDataProvider(ParameterPool parameters, BehaviorPool behaviors)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            if (behaviors == null)
            {
                throw new ArgumentNullException(nameof(behaviors));
            }

            // Base execution (will add entity behaviors and parameters for this mutual inductance)
            var data = base.BuildSetupDataProvider(parameters, behaviors);

            // Register inductor 1
            data.Add("inductor1", parameters.GetEntityParameters(InductorName1));
            data.Add("inductor1", behaviors.GetEntityBehaviors(InductorName1));

            // Register inductor 2
            data.Add("inductor2", parameters.GetEntityParameters(InductorName2));
            data.Add("inductor2", behaviors.GetEntityBehaviors(InductorName2));

            return(data);
        }
Ejemplo n.º 16
0
    void ShootRaycast()
    {
        ray.origin    = camTrans.position;
        ray.direction = camTrans.forward;

        if (Physics.Raycast(ray, out hit, enemyLayer.value))
        {
            ShotParameter sp = ParameterPool.GetParameter <ShotParameter>();
            sp.gunDmg     = gunDamage;
            sp.shotObject = hit.transform.gameObject;
            sp.shotPoint  = hit.point;
            GlobalEventQueue.EnQueueEvent(E_Event.Shot, sp);

            EffectParameter ep = ParameterPool.GetParameter <EffectParameter>();
            ep.effectName = "Prefabs/Decals/Bullet Hole";
            ep.parent     = hit.transform;
            ep.position   = hit.point + hit.normal * 0.005f;
            ep.rotation   = Quaternion.LookRotation(-hit.normal);
            ep.scale      = Vector3.one * 0.1f;
            GlobalEventQueue.EnQueueEvent(DefaultEvent.ShowEffect, ep);

            //Debug.LogFormat( "SHOT {0}" , hit.transform.name );
        }
    }