public void SaveRecord()
        {
            //TODO: Chamar metodo SaveRecord de todas as propriedades linkadas

            int idRecord = ReturnId();

            if (FindById(idRecord) == null)
            {
                string scriptInsert =
                    FactoryScript.Insert(this.GetType(), this._schemaName) + FactoryScript.ReturnId(this.GetType());

                idRecord = _connection.Query <int>(scriptInsert, this).FirstOrDefault <int>();

                PropertyInfo[] properties = this.GetType().GetProperties();

                foreach (PropertyInfo property in properties)
                {
                    if (FactoryScript.ContainAttribute(property, typeof(KeyAttribute)))
                    {
                        property.SetValue(this, idRecord);
                        break;
                    }
                }
            }
            else
            {
                string scriptUpdate = FactoryScript.Update(this.GetType(), this._schemaName);

                GetConnection().Execute(scriptUpdate, this);
            }

            SaveLinks(idRecord);
        }
        public static T FindById(int Id)
        {
            using (var connection = FactoryConnection.GetConnection())
            {
                string scriptSelect = FactoryScript.Select(typeof(T), Id, "public");

                var Result = connection.Query <T>(scriptSelect).FirstOrDefault <T>();

                return(Result);
            }
        }
        public static List <T> FindAll()
        {
            using (var connection = FactoryConnection.GetConnection())
            {
                string scriptSelect = FactoryScript.Select(typeof(T), "public");

                var Result = connection.Query <T>(scriptSelect).ToList <T>();

                return(Result);
            }
        }
        private int ReturnId()
        {
            PropertyInfo[] properties = this.GetType().GetProperties();

            foreach (PropertyInfo property in properties)
            {
                if (FactoryScript.ContainAttribute(property, typeof(KeyAttribute)))
                {
                    return((int)property.GetValue(this));
                }
            }

            return(0);
        }
        public bool Delete()
        {
            try
            {
                string scriptDelete = FactoryScript.Delete(typeof(T), "public");

                GetConnection().Execute(scriptDelete, this);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 6
0
    IEnumerator BuildRoutine()
    {
        UnitFuncScript.m_Instance.ClearFunc();
        m_IsBuild            = true;
        imgSelectbar.enabled = false;
        Building             = BuildScript.BuildingTemp;
        Building.GetComponentInChildren <Renderer>().material.color = Color.red;
        unitState = UnitState.walk;
        m_Animator.SetBool("IsPick", true);
        BuildScript.m_IsBuild = false;
        float dis = 0.0f;

        switch (Building.tag)
        {
        case "B_ToyFactory": dis = 6f; break;

        default: dis = 4f; break;
        }
        NavMesh.CalculatePath(transform.position, BuildScript.BuildPos, NavMesh.AllAreas, m_Path);
        Vector3[] Corners = m_Path.corners;
        int       Index   = 1;

        while (Index < Corners.Length)
        {
            Debug.DrawRay(Camera.main.transform.position, BuildScript.BuildPos - Camera.main.transform.position, Color.red);
            m_Dir = (Corners[Index] - transform.position).normalized;
            transform.position += m_Dir * m_MoveSpeed * Time.deltaTime;
            transform.rotation  = Quaternion.LookRotation(m_Dir);
            if (Vector3.Distance(transform.position, Corners[Index]) < dis)
            {
                Index++;
            }
            yield return(null);
        }

        //Building.GetComponent<NavMeshObstacle>().enabled = true;
        transform.rotation    = Quaternion.LookRotation(BuildScript.BuildPos - transform.position);
        BuildScript.m_IsBuild = false;
        unitState             = UnitState.build;
        m_Animator.SetBool("IsPick", false);
        m_Animator.SetBool("IsBuild", true);

        yield return(new WaitForSeconds(5.0f));

        Building.GetComponentInChildren <Renderer>().material.color = Color.white;
        unitState = UnitState.idle;
        m_Animator.SetBool("IsBuild", false);
        m_IsSelect = false;
        SelectUnitScript.m_Instance.SelectedUnit.Remove(transform.GetComponent <PlayerMove>());
        m_IsBuild = false;

        switch (Building.tag)
        {
        case "B_Zenga":
            BuildScript.AttackArea.gameObject.SetActive(true);
            break;

        case "B_ToyFactory":
            FactoryScript FactoryFunc = Building.GetComponent <FactoryScript>();
            FactoryFunc.enabled = true;
            break;

        default:
            break;
        }

        StopCoroutine("BuildRoutine");
    }