Esempio n. 1
0
        public void EditUser(SocialGroup socGroup)
        {
            using (var context = new JoinINN.Infrastructure.GroupsDb())
            {
                try
                {
                    var existingSocGroup = context.SocialGroups.FirstOrDefault(x => x.Id == socGroup.Id);

                    existingSocGroup.AffinityType    = context.AffinityTypes.FirstOrDefault(x => x.Id == socGroup.AffinityType_Id);
                    existingSocGroup.Password        = socGroup.Password;
                    existingSocGroup.Name            = socGroup.Name;
                    existingSocGroup.OfficialWebUrl  = socGroup.OfficialWebUrl;
                    existingSocGroup.FacebookPageUrl = socGroup.FacebookPageUrl;
                    existingSocGroup.photoUrl        = socGroup.photoUrl;
                    existingSocGroup.ContactNumber   = socGroup.ContactNumber;
                    existingSocGroup.Description     = socGroup.Description;

                    context.SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {
                }
            }
        }
Esempio n. 2
0
    void FixedUpdate()
    {
        Debug.Log(state);
        //If wandering, update its state
        if (state == 0)
        {
            if (decide_next_target < 0)
            {
                NextTarget();
                decide_next_target = 2f;
            }
            decide_next_target -= Time.deltaTime;

            Seek();

            int index = NearSocialAgent();
            if (index >= 0)
            {
                //Other social agents around
                if (new System.Random(System.Guid.NewGuid().GetHashCode()).Next(0, 100) < 5)
                {
                    nearest_social_agent = social_agent_list[index];
                    state = 1;
                }
            }
        }
        else if (state == 1)
        {
            //Self is ready to form a group
            SocialAgent other = nearest_social_agent.GetComponent <SocialAgent>();
            //If far away from the other agent, then back to wandering
            if (Vector3.Distance(transform.position, other.transform.position) > 2f)
            {
                state = 0;
            }
            else
            {
                if (other.state == 1)
                {
                    //Other is ready to form a group, then create group
                    socialGroup.SetCenter(transform.position, other.transform.position);
                    target = (socialGroup.center + transform.position) / 2;
                    socialGroup.agent_number++;
                    state = 2;
                }
                else if (other.state == 2 || other.state == 3)
                {
                    //Other is forming or already in group, then join
                    other.socialGroup.agent_number++;
                    socialGroup = other.socialGroup;
                    target      = (socialGroup.center + transform.position) / 2;
                    state       = 2;
                }
                this.other = other;
            }
        }
        else if (state == 2)
        {
            velocity = new Vector3(0, 0, 0);
            Seek();
            transform.rotation = Quaternion.LookRotation(other.transform.position - transform.position);
            //Apply steer force to from a group
            if (Vector3.Distance(transform.position, target) < 1.2f)
            {
                //Complete forming process, transfer to state 3
                state = 3;
                conversation_timer = new System.Random(System.Guid.NewGuid().GetHashCode()).Next(50, 200) / 100f;
            }
        }
        else if (state == 3)
        {
            //In conversation, stay still
            //Do nothing
            transform.rotation = Quaternion.LookRotation(other.transform.position - transform.position);
            velocity           = new Vector3(0, 0, 0);
            //In a random period of time, leave group
            if (conversation_timer < 0)
            {
                state             = 4;
                renderer.material = wander_material;
                head.ChangeToWanderMaterial();
                cool_down_timer = 2f;
                socialGroup.agent_number--;
            }
            if (socialGroup.agent_number <= 1)
            {
                state             = 4;
                renderer.material = wander_material;
                head.ChangeToWanderMaterial();
                cool_down_timer          = 2f;
                socialGroup.agent_number = 0;
                socialGroup.SetCenter(0, 0, 0);
            }
            conversation_timer -= Time.deltaTime;
        }
        else
        {
            //Wandering
            if (decide_next_target < 0)
            {
                NextTarget();
                decide_next_target = 2f;
            }
            decide_next_target -= Time.deltaTime;
            Seek();

            //In cooldown
            if (cool_down_timer < 0)
            {
                state             = 0;
                renderer.material = social_material;
                head.ChangeToSocialMaterial();
            }
            cool_down_timer -= Time.deltaTime;
        }
    }