示例#1
0
    public void DropWearing()
    {
        if (myWearing != null)
        {
            RemoveJoint(myWearingJoint);
            myWearingJoint = null;
            myWearing.Drop(this);

            myWearing = null;
        }
    }
示例#2
0
            public override bool Init(CS_RuleSet g_ruleSet)
            {
                if (!base.Init(g_ruleSet))
                {
                    return(false);
                }

                if (myRuleInfo.myScoreType != ScoreType.Duration)
                {
                    Debug.LogError(this.gameObject.name + " need to be Duration!");
                }


                //find goal
                myWearPrefab = CS_EverythingManager.Instance.GetRandomPrefab(Constants.NAME_PROP_WEARABLE);

                for (int i = 0; i < CS_PlayerManager.Instance.GetTeamCount(); i++)
                {
                    isPlayerWearing.Add(false);
                    myPlayerWearingTime.Add(0);
                }

                if (myRuleInfo.isTeamBased)
                {
                    //create goals accoring to team count
                    for (int i = 0; i < CS_PlayerManager.Instance.GetTeamCount(); i++)
                    {
                        GameObject f_goal = Instantiate(myWearPrefab, CS_EverythingManager.Instance.transform) as GameObject;

                        CS_Prop_Wearable t_wear = f_goal.GetComponent <CS_Prop_Wearable> ();
                        t_wear.AddRule(this);
                        t_wear.SetTeamNumber(i);
                        //add goal to the list
                        myWears.Add(f_goal);
                    }

                    //calculate the angle for each goal
                    float t_baseAngle  = Random.Range(0, 360f);
                    float t_deltaAngle = 360f / CS_PlayerManager.Instance.GetTeamCount();

                    //move the goal and look at center
                    for (int i = 0; i < myWears.Count; i++)
                    {
                        myWears [i].transform.position =
                            Quaternion.AngleAxis(t_baseAngle + t_deltaAngle * i, Vector3.up) * Vector3.forward * myWearDistance +
                            Vector3.up * Constants.DISTANCE_INIT_HEIGHT;
                    }
                }
                else
                {
                    GameObject f_goal     = Instantiate(myWearPrefab, CS_EverythingManager.Instance.transform) as GameObject;
                    Vector3    f_startPos = Random.insideUnitSphere * myWearDistance;
                    f_startPos.y = Constants.DISTANCE_INIT_HEIGHT;
                    f_goal.transform.position = f_startPos;

                    CS_Prop_Wearable t_wear = f_goal.GetComponent <CS_Prop_Wearable> ();
                    t_wear.AddRule(this);

                    myWears.Add(f_goal);
                }

                return(true);
            }
示例#3
0
    private void PickUp()
    {
        if (myPickup == null)
        {
            //pick up

            int        t_layerMask           = (int)Mathf.Pow(2, 8) + (int)Mathf.Pow(2, 10);
            Collider[] hitColliders          = Physics.OverlapSphere(this.transform.position, myPlayerSettings.myPickUpRadius, t_layerMask);
            float      t_minSqrDistance      = myPlayerSettings.myPickUpRadius;
            Collider   t_closestBallCollider = null;
            for (int i = 0; i < hitColliders.Length; i++)
            {
                if (hitColliders [i].gameObject == this.gameObject ||
                    (hitColliders [i].GetComponent <CS_Prop_Pickup> () == null &&
                     hitColliders [i].GetComponent <CS_Prop_Button> () == null &&
                     hitColliders [i].GetComponent <CS_Prop_Wearable> () == null))
                {
                    continue;
                }
                float t_sqrDistance = Vector3.SqrMagnitude(this.transform.position - hitColliders [i].ClosestPoint(this.transform.position));
                if (t_sqrDistance < t_minSqrDistance)
                {
                    t_minSqrDistance      = t_sqrDistance;
                    t_closestBallCollider = hitColliders [i];
                }
            }

            if (t_closestBallCollider != null)
            {
                Rigidbody t_closestBallRigidbody = t_closestBallCollider.GetComponent <Rigidbody> ();

//				if (!(t_closestBallCollider.GetComponent <CS_Prop_Heavy> ())) {
//					t_closestBallRigidbody.useGravity = false;
//				} else {
//					t_springjoin.spring = 100000;
//				}

//				t_closestBallRigidbody.drag = 2;
                GameObject t_object = t_closestBallCollider.gameObject;

                CS_Prop_Button t_button = t_object.GetComponent <CS_Prop_Button> ();
                if (t_button != null)
                {
                    Debug.Log("on button");
                    CS_GameManager.Instance.OnButton(t_button.MyButtonType);
                }

                CS_Prop_Pickup t_pickUp = t_object.GetComponent <CS_Prop_Pickup> ();
                if (t_pickUp != null)
                {
                    myPickup = t_pickUp;

                    Vector3 t_connectedAnchor = Vector3.zero;
                    if (t_pickUp.IsBig)
                    {
                        t_connectedAnchor = t_object.transform.InverseTransformPoint(
                            t_closestBallCollider.ClosestPointOnBounds(this.transform.position)
                            );
                    }

                    myPickupJoint = CreateJoint(
                        t_closestBallRigidbody,
                        Vector3.up,
                        t_connectedAnchor
                        );

                    myPickup.OnHold   = true;
                    myPickup.MyHolder = this.gameObject;

                    onPickup = true;

                    // play sound
                    AiryAudioManager.Instance.GetAudioData("GrabSounds").Play(this.transform.position);
                }

                CS_Prop_Wearable t_wear = t_object.GetComponent <CS_Prop_Wearable> ();
                if (t_wear != null)
                {
                    if (myWearing != null)
                    {
                        DropWearing();
                    }
                    myWearing      = t_wear;
                    myWearingJoint = CreateJoint(t_closestBallRigidbody, Vector3.up * 1.5f, Vector3.zero);
                    myWearing.SetMyHolder(this);

                    Debug.Log("Wear!");
                    // play sound
                    AiryAudioManager.Instance.GetAudioData("GrabSounds").Play(this.transform.position);
                }

//				mySpriteRenderer.sprite = myPlayerSettings.myPickUpSprite;
            }
        }
        else
        {
            //throw
            onThrowCharge      = true;
            myThrowChargeTimer = 0;
            //			mySpriteRenderer.sprite = myPlayerSettings.myNormalSprite;

            // play sound
            AiryAudioManager.Instance.GetAudioData("DropSounds").Play(this.transform.position);
        }
    }