示例#1
0
文件: 2568.cs 项目: kubiix/StyleCop
        /// <summary>
        /// Instantiate a NsDataAccess object from a record ID.
        /// </summary>
        /// <param name="state">dataset state object</param>
        /// <param name="instantiateNewForm">Indicates whether to create a new form object if it doesn't exist.</param>
        /// <param name="parentFormHandle">Form handle of the parent form. Applicable only to subforms.</param>
        /// <param name="parentControlName">controlName of the control in the parent form representing the subform. Applicable only to subforms.</param>
        /// <param name="instantiatedForm"> True if and only if a new form was instantiated.</param>
        /// <returns>A new NsDataObject.</returns>
        public static NsDataAccess Create(
            NavRecordState state, Boolean instantiateNewForm, Guid parentFormHandle, String parentControlName, out Boolean instantiatedForm)
        {
            instantiatedForm = false;
            if (state.IsResourceDefinedForm)
            {
                return(new NsTableDataAccess(ApplicationFactory.GetResourceDefinedFormTable(state.FormId)));
            }
            else if (state.FormId != 0 || state.ServerFormHandle != Guid.Empty)
            {
                NavConnection connection = NavConnection.Current;

                // Try to retrieve an existing instance of the form.
                NavForm form = connection.GetForm(state.ServerFormHandle);

                if (form == null)
                {
                    if (instantiateNewForm)
                    {
                        // Not found - create new instance.
                        if ((parentFormHandle != Guid.Empty) && (!String.IsNullOrEmpty(parentControlName)))
                        {
                            // Subform information provided - try to instantiate through the parent form
                            NavForm parentForm = connection.GetForm(parentFormHandle);
                            using (parentForm)
                            {
                                if (parentForm.TryGetUIPart(parentControlName, out form))
                                {
                                    form.AddReference();
                                }
                            }
                        }

                        if (form == null)
                        {
                            // Form not instantiated as subform, try to instantiate as independent form
                            form = NavEnvironment.Instance.ApplicationFactory.GetForm(state.FormId);
                        }

                        if (form != null)
                        {
                            instantiatedForm       = true;
                            state.ServerFormHandle = form.Handle;
                            Debug.Assert(state.FormId == form.FormId);
                        }
                    }
                    else
                    {
                        throw new NavException(NavException.NCL.ErrFormNotOpen);
                    }
                }

                return(new NsFormDataAccess(form));
            }
            else
            {
                Debug.Assert(state.TableId != 0);
                return(new NsTableDataAccess(state.TableId));
            }
        }
        // -------------------------------------------------------------------
        // Initialization

        public virtual void Initialize(NavSection navSection, NavConnection destination)
        {
            m_CurrentNavSection = navSection;
            RegisterVehicle(m_CurrentNavSection, true);
            m_CurrentOutConnection = destination;
            agent.enabled          = true;
            speed             = TrafficSystem.Instance.GetAgentSpeedFromKPH(Mathf.Min(navSection.speedLimit, maxSpeed));
            agent.speed       = speed;
            agent.destination = destination.transform.position;
        }
示例#3
0
        // -------------------------------------------------------------------
        // Collisions

        public override void OnTriggerEnter(Collider col)
        {
            if (col.tag == "RoadConnection")
            {
                NavConnection connection = col.GetComponent <NavConnection>();
                if (connection.navSection != m_CurrentNavSection)
                {
                    SwitchRoad(connection);
                }
            }
            base.OnTriggerEnter(col);
        }
示例#4
0
        // -------------------------------------------------------------------
        // Switch Road

        private void SwitchRoad(NavConnection newConnection)
        {
            RegisterVehicle(m_CurrentNavSection, false);
            speed               = TrafficSystem.Instance.GetAgentSpeedFromKPH(Mathf.Min(newConnection.navSection.speedLimit, maxSpeed));
            agent.speed         = speed;
            m_CurrentNavSection = newConnection.navSection;
            RegisterVehicle(m_CurrentNavSection, true);
            m_CurrentOutConnection = newConnection.GetOutConnection();
            if (m_CurrentOutConnection != null)
            {
                agent.destination = m_CurrentOutConnection.transform.position;
            }
        }
示例#5
0
        public virtual void Initialize(NavSection navSection, NavConnection destination)
        {
            m_CurrentNavSection = navSection;
            RegisterVehicle(m_CurrentNavSection, true);
            m_CurrentOutConnection = destination;
            agent.enabled          = true;
            speed             = TrafficSystem.Instance.GetAgentSpeedFromKPH(Mathf.Min(navSection.speedLimit, maxSpeed));
            agent.speed       = speed;
            agent.destination = destination.transform.position;

            mqttClient = new MqttClient("35.193.52.170");
            mqttClient.Connect(System.Guid.NewGuid().ToString());
            agentMessage       = gameObject.AddComponent <AgentMessage>();
            time               = 0.0f;
            publishesPerSecond = 1.0f;
        }
示例#6
0
    static void goToNode(NavNode from, NavConnection con, List <NavNode> openList)
    {
        Profiler.BeginSample("checkIfThere");

        if (con.other.pInfo.phase != 0)
        {
            if (con.other.pInfo.moveCost > from.pInfo.moveCost + con.weight)
            {
                con.other.pInfo.parent   = from.pInfo;
                con.other.pInfo.moveCost = from.pInfo.moveCost + con.weight;
            }
            Profiler.EndSample();

            return;
        }
        Profiler.EndSample();
        openList.Add(con.other);
        con.other.pInfo.phase    = 1;
        con.other.pInfo.parent   = from.pInfo;
        con.other.pInfo.moveCost = from.pInfo.moveCost + con.weight;
    }