override public void UpdateAmmoGraphics(bool redraw = false)
    {
        //		// commented Debug.Log("update:"+numberHeld);
        //		if (PlayerGadgetController.inst.currentWeapon != this) return; // don't mess with graphics if this weapon isn't selected.
        base.UpdateAmmoGraphics();
        if (ammoGraphics)
        {
            UnityEngine.Object.Destroy(ammoGraphics);
        }
        //		if (ammoGraphics) UnityEngine.Object.Destroy(ammoGraphics);
        //		// commented Debug.Log("modifying throw gfx");
        if (numberHeld)
        {
            //			// commented Debug.Log ("number held:"+numberHeld);
            //			// commented Debug.Log ("number held:"+numberHeld.GetComponent<NumberInfo>().fraction);

            //			// commented Debug.Log ("throw static");
            NumberInfo ni = numberHeld.GetComponent <NumberInfo>();
            if (ni)
            {
                // for numbers we do want to keep certain scripts on them as ammo, such as alwaysfaceplayer
                ammoGraphics = NumberManager.inst.CreateNumberAmmo(ni.fraction, ni.myShape);
            }
            else
            {
//				Debug.Log("no ni");
            }

//			Debug.Log("ammograph:"+ammoGraphics);
            CleanComponentsForAmmo(ammoGraphics);

            PickUppableObject pip = numberHeld.GetComponent <PickUppableObject>();
            ammoGraphics.transform.parent = gadgetGraphics.transform;

            ammoGraphics.transform.localScale *= 0.3f;

            Transform m1 = ammoGraphics.transform.Find("mesh");
            if (m1)
            {
                m1.localScale = Vector3.one * 0.5f;
                //				// commented Debug.Log ("set to 0.5");
            }
            Transform m2 = ammoGraphics.transform.Find("mesh2");
            if (m2)
            {
                m2.localScale = playerHoldingScale * Vector3.one;
            }

            ammoGraphics.transform.localPosition = new Vector3(0.173f, 0.348f, -0.506f);           // = gadgetGraphics.transform.position + Vector3.up * 5;// new Vector3(.3f,.078f,-.1f);

            ammoGraphics.SetActive(true);
            ni = ammoGraphics.GetComponent <NumberInfo>();
            if (ni)
            {
                ni.InitSinGrowAttributes(.100f);
                ni.SinGrowOnce();
            }
        }
        else
        {
//			Debug.Log("update ammo num null");
            numberHeld = null;
        }
    }
Exemple #2
0
    void AddNumberToBlob(NumberInfo ni)
    {
        ni.greaterThanCombine = 0;
        ni.lessThanCombine    = 1;      // re-allow combos
        Animal a = ni.GetComponent <Animal>();

        if (a)
        {
            a.animalDisabled = true;            // disable animal for consumption, but don't "destroy" or change it.
        }
        targetCheckTimer = Random.Range(2f, 4f);
        if (type == SnailType.Multiples)
        {
            bool proceed = false;             // only proceed if we matched a number. Other numbers will be deconstructed.
            foreach (NumberInfo n2 in blobNumbers)
            {
                if (Fraction.Equals(Fraction.GetAbsoluteValue(n2.fraction), Fraction.GetAbsoluteValue(ni.fraction)))
                {
                    proceed = true;
                    break;
                }
            }
            if (!proceed)              // This happens when a larger multiple was broken down into smaller ones. We stop the checking process, break it up, and eat each piece.
//				Debug.Log("donot");
            {
                List <NumberInfo> numsToAdd = new List <NumberInfo>();
                foreach (NumberInfo n2 in blobNumbers)
                {
                    if (ni.fraction.IsMultipleOf(n2.fraction))
                    {
                        int count = Mathf.Abs(Fraction.Divide(ni.fraction, n2.fraction).numerator);
                        ni.SetNumber(n2.fraction);                         // important to set the number before instantiation because cctext will lose mesh / mesh 0 vertices if you reverse this
//						Debug.Log("set");
                        for (int i = 0; i < count; i++)
                        {
                            // if an 8 is eaten by a Multiple Snal, it makes 4 2's in front of it and eats them one by one.
                            GameObject newNum = (GameObject)Instantiate(ni.gameObject, ni.transform.position + transform.forward * i * 3f, Quaternion.identity);
                            NumberInfo ni3    = newNum.GetComponent <NumberInfo>();
                            numsToAdd.Add(ni3);
                            newNum.GetComponent <Rigidbody>().useGravity = false;
                            ni3.greaterThanCombine = 1;                             // prevent combos.
                            ni3.lessThanCombine    = 0;
//							eatingNumbers.Add(ni);
//							ni.GetComponent<Collider>().enabled = false;
//							Debug.Log("add:"+newNum);
                        }
                        NumberManager.inst.DestroyOrPool(ni);
                        break;
                    }
                }
                foreach (NumberInfo n3 in numsToAdd)
                {
                    AddNumberToBlob(n3);
//					Debug.Log("adding;"+n3);
                }
                return;                 // after a dconstruction don't add anything to blob, add all the deconstructed pieces individualy in the for loop above.
            }
        }


        eatingNumbers.Add(ni);
        ni.GetComponent <Collider>().enabled = false;



        ni.transform.parent = transform;
        ni.InitSinGrowAttributes(0.5f, true);
        Rigidbody rb = ni.GetComponent <Rigidbody>();

        if (ni.GetComponent <PickUppableObject>())
        {
            Destroy(ni.gameObject.GetComponent <PickUppableObject>());
        }
        if (!rb)
        {
            rb = ni.gameObject.AddComponent <Rigidbody>();
        }
        rb.isKinematic = false;
        rb.drag        = 3f;
        ni.gameObject.AddComponent <BlobNumber>();
        rb.useGravity = false;



//		if ( blobNumbers.Add(ni);
    }
    override public void UpdateAmmoGraphics(bool redraw = false)
    {
//		// commented Debug.Log("update:"+numberHeld);
//		if (PlayerGadgetController.inst.currentWeapon != this) return; // don't mess with graphics if this weapon isn't selected.
        base.UpdateAmmoGraphics();
        if (ammoGraphics)
        {
            UnityEngine.Object.Destroy(ammoGraphics);
        }
//		if (ammoGraphics) UnityEngine.Object.Destroy(ammoGraphics);
        //		// commented Debug.Log("modifying throw gfx");
        if (numberHeld)
        {
//			// commented Debug.Log ("number held:"+numberHeld);
            //			// commented Debug.Log ("number held:"+numberHeld.GetComponent<NumberInfo>().fraction);

            //			// commented Debug.Log ("throw static");
            NumberInfo ni = numberHeld.GetComponent <NumberInfo>();
            if (ni)
            {
                // for numbers we do want to keep certain scripts on them as ammo, such as alwaysfaceplayer
                ammoGraphics = NumberManager.inst.CreateNumberAmmo(ni.fraction, ni.myShape);
                // Did the oriignal number info have soap bubbles? (bad place for this to be? lol)
                if (ni.IsSoapable() && ni.soapFx.activeSelf)
                {
                    GameObject soapCopy = (GameObject)GameObject.Instantiate(ni.soapFx, ammoGraphics.transform.position, ammoGraphics.transform.rotation);
                    soapCopy.transform.parent = ammoGraphics.transform;
                    ParticleSystem             ps  = soapCopy.GetComponentInChildren <ParticleSystem>();
                    ParticleSystem.ShapeModule pss = ps.shape;
                    pss.radius *= 0.5f;
//					ps.sh
                }
            }
            else
            {
                // otherwise, do not duplicate/strip the ammo, intead reconstruct it from scratch.
                ammoGraphics = Utils.ConstructFakeCopyOfAmmo(numberHeld);

                ammoGraphics.transform.rotation = Quaternion.identity;
            }
//			(GameObject)UnityEngine.Object.Instantiate(numberHeld);

//			if (ueo) ueo.isSerializeableForSceneInstance = false;

//			ammoGraphics.name = "ammo graphics";
            CleanComponentsForAmmo(ammoGraphics);

            PickUppableObject pip = numberHeld.GetComponent <PickUppableObject>();
            ammoGraphics.transform.parent = PlayerGadgetController.inst.GetPlayerLocationForGadget(gadgetLocationOnPlayer);
            if (pip)
            {
                ammoGraphics.transform.localScale *= pip.heldScale;
            }
            else
            {
                ammoGraphics.transform.localScale = Vector3.one * 0.5f;                // * 0.5f; // * Player.inst.transform.localScale.x
            }
            Transform m1 = ammoGraphics.transform.Find("mesh");
            if (m1)
            {
                m1.localScale = Vector3.one * 0.5f;
                //				// commented Debug.Log ("set to 0.5");
            }
            Transform m2 = ammoGraphics.transform.Find("mesh2");
            if (m2)
            {
                m2.localScale = playerHoldingScale * Vector3.one;
            }

            ammoGraphics.transform.localPosition = playerHoldingPos;            // Vector3.zero;// new Vector3(.3f,.078f,-.1f);
            if (pip.alwaysFacePlayerAsAmmo)
            {
                ammoGraphics.AddComponent <AlwaysFacePlayer>();
            }
//			ammoGraphics.transform.LookAt(Player.inst.transform);
//			ammoGraphics.transform.rotation = Utils.FlattenRotation(ammoGraphics.transform.rotation);
            ammoGraphics.SetActive(true);
            ni = ammoGraphics.GetComponent <NumberInfo>();
            if (ni)
            {
                ni.InitSinGrowAttributes(.100f);
                ni.SinGrowOnce();
            }
//			// commented Debug.Log("ammogrpahics:"+ammoGraphics.transform.localPosition+", playerhod:"+playerHoldingPos);
//			// commented Debug.Log ("setting ammograph localpos to:"+ammoGraphics.transform.localPosition+", but player hollding pos was;"+playerHoldingPos);
//			// commented Debug.Log ("moved to:"+ammoGraphics.transform.localPosition);
//			ammoGraphics.transform.localRotation = Quaternion.identity;
//			ammoGraphics.SendMessage("OnPlayerEquip",SendMessageOptions.DontRequireReceiver);
        }
        else
        {
            numberHeld = null;

            MascotAnimatorController.inst.HoldRightArm(false);
        }
    }