示例#1
0
    private void SetupTrack()
    {
        BehaviorUtils.MakeVisible(GameObject.Find(RaceTrackName), true);
        Debug.Log("About to get self");
        Participant self = GetSelf();

        Debug.Log("Self is " + self);
        Debug.Log("About to get a list of connected participants");
        List <Participant> racers = GetRacers();

        Debug.Log("Racers is  " + racers + " with count of " + racers.Count);
        int i;

        for (i = 0; i < CarNames.Length; i++)
        {
            Debug.Log("Looking at i value of " + i);
            GameObject car = GameObject.Find(CarNames[i]);
            Debug.Log("Looking for car name " + CarNames[i]);
            Participant racer = i < racers.Count ? racers[i] : null;
            Debug.Log("Racer is " + racer);

            bool isSelf = racer != null && racer.ParticipantId.Equals(self.ParticipantId);
            if (racer != null)
            {
                Debug.Log("Racer is not null!");
                BehaviorUtils.MakeVisible(car, true);
                CarController controller = car.GetComponent <CarController>();
                controller.SetParticipantId(racer.ParticipantId);
                controller.SetBlinking(isSelf);
            }
            else
            {
                Debug.Log("Hiding racer");
                BehaviorUtils.MakeVisible(car, false);
            }
        }
    }
示例#2
0
        /// <summary>
        /// load entity list from datatable
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dt"></param>
        /// <returns></returns>
        public List <T> LoadEntities <T>(DataTable dt)
        {
            if (dt == null)
            {
                return(null);
            }
            if (dt.Rows.Count == 0)
            {
                return(new List <T>());
            }
            Type type = typeof(T);
            List <PropertyInfo> properties = type.GetProperties().ToList();

            // remove property where it is not exist
            for (int i = 0; i < properties.Count; i++)
            {
                bool isExist = dt.Columns.IndexOf(properties[i].Name) != -1 ? true : false;
                if (!isExist)
                {
                    properties.RemoveAt(i);
                    i--;
                }
            }
            // freach properties
            List <T> objects = new List <T>();
            List <PropertyBehavior> behaviors = null;

            if (dt.Rows.Count > 0)
            {
                behaviors = BehaviorUtils.GetBehaviors(dt.Rows[0], properties);
            }
            foreach (DataRow dr in dt.Rows)
            {
                T o = System.Activator.CreateInstance <T>();
                foreach (PropertyBehavior behavior in behaviors)
                {
                    bool isNull = dr[behavior.Property.Name] is System.DBNull;
                    if (!isNull)
                    {
                        switch (behavior.Behavior)
                        {
                        case BehaviorType.IntToBoolean:
                            if ((int)dr[behavior.Property.Name] == 0)
                            {
                                behavior.Property.SetValue(o, false);
                            }
                            else
                            {
                                behavior.Property.SetValue(o, true);
                            }
                            break;

                        case BehaviorType.StringToDate:
                            DateTime dateTime = DateTime.Parse(dr[behavior.Property.Name].ToString());
                            behavior.Property.SetValue(o, dateTime);
                            break;

                        case BehaviorType.StringToDecimal:
                            behavior.Property.SetValue(o, decimal.Parse(dr[behavior.Property.Name].ToString()));
                            break;

                        default:
                            behavior.Property.SetValue(o, dr[behavior.Property.Name]);
                            break;
                        }
                    }
                }
                objects.Add(o);
            }
            return(objects);
        }
 private void MakeVisible(bool visible)
 {
     BehaviorUtils.MakeVisible(gameObject, visible);
 }
 void Start()
 {
     BehaviorUtils.MakeVisible(gameObject, false);
 }