void CheckMerge(GameObject col) { //Check that Collision object is Valid if (col == null) { return; } if (col.transform.childCount <= 0 || !col.CompareTag(Props.Tags.Group)) { return; } //Check that Collision object is not this / avoid duplicate collisions if (gameObject == col || gameObject.GetInstanceID() < col.GetInstanceID()) { return; } //Get Collision object color CompoundMaterial colMaterial = FindMaterial(col); if (material == colMaterial) { //If either is frozen, then we will combine into the other automatically Rigidbody selfRb = gameObject.GetComponent <Rigidbody>(); Rigidbody colRb = col.GetComponent <Rigidbody>(); CompoundMaterialComponent selfComp = gameObject.GetComponent <CompoundMaterialComponent> (); CompoundMaterialComponent colComp = col.GetComponent <CompoundMaterialComponent> (); if (selfComp.isFrozen) { Merge(col, gameObject); } else if (colComp.isFrozen) { Merge(gameObject, col); } else if (selfRb.isKinematic || selfRb.constraints != RigidbodyConstraints.None) { //flip Merge(col, gameObject); } else if (colRb.isKinematic || colRb.constraints != RigidbodyConstraints.None) { Merge(gameObject, col); } else { MergeJoints(col); toMerge.Add(col); } toRemove.Add(col); } }
// Use this for initialization void Start() { //Set color material = FindMaterial(gameObject); //Check that this is a Group Object if (!gameObject.CompareTag(Props.Tags.Group)) { Debug.LogError(name + " does not have a 'Group' tag, and therefore cannot be treated as a Group object"); } }
void Start() { if (compoundMaterial != null) { originalMaterial = compoundMaterial; SetMaterial(compoundMaterial); } foreach (Transform child in gameObject.transform) { originalChildren.Add(child); } }
public void SecondaryFire() { GameObject objGroup = GetClicked(); if (objGroup != null) { SwitchToFull(); paintMaterial = FindMaterial(objGroup); paintRend.material = paintMaterial.material; } Animator canvasAnim = GameObject.FindWithTag(Props.Tags.ReticleCanvas).GetComponent <Animator> (); canvasAnim.SetTrigger(Props.CanvasTriggers.ExpandReticle); anim.SetTrigger(Props.PaintBucketTriggers.TiltUp); }
public void MainFire() { GameObject objGroup = GetClicked(); if (objGroup != null && paintMaterial != null) { SetMaterial(objGroup, paintMaterial); paintMaterial = null; SwitchToEmpty(); } Animator canvasAnim = GameObject.FindWithTag(Props.Tags.ReticleCanvas).GetComponent <Animator> (); canvasAnim.SetTrigger(Props.CanvasTriggers.ContractReticle); anim.SetTrigger(Props.PaintBucketTriggers.TiltDown); }
// Update is called once per frame void Update() { //reset color foreach (FixedJoint joint in jointsToDelete) { Destroy(joint); } jointsToDelete.Clear(); if (toMerge.Count > 0) { foreach (GameObject col in toMerge) { if (col != null) { MergeWithPhysics(col); } } toMerge.Clear(); } foreach (GameObject col in toRemove) { currentCollisions.RemoveAll(x => x == col); } toRemove.Clear(); material = FindMaterial(gameObject); //Delete empty groups if (gameObject.transform.childCount <= 0) { // Destroy (gameObject); gameObject.SetActive(false); } //Check all collisions for merge foreach (GameObject col in currentCollisions) { if (col.CompareTag(Props.Tags.Group)) { CheckMerge(col); } } }
private void ApplyMaterialProperties(CompoundMaterial mat) { if (!gameObject.CompareTag(Props.Tags.Group)) { Debug.LogError("Cannot set material for something that is not a \"Group\""); } Rigidbody rig = gameObject.GetComponent <Rigidbody> (); if (isFrozen) { rig.isKinematic = true; rig.constraints = RigidbodyConstraints.FreezeAll; } else { // rig.isKinematic = false; // rig.constraints = RigidbodyConstraints.None; rig.SetDensity(mat.density); if (rig.mass < 4.0f && rig.mass / mat.density < 1.0f) { rig.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; } } rig.drag = mat.drag; rig.angularDrag = mat.angularDrag; rig.useGravity = mat.useGravity; foreach (Transform child in gameObject.transform) { if (child.gameObject.CompareTag(Props.Tags.Object)) { Collider coll = child.gameObject.GetComponent <Collider> (); coll.material = mat.physicMaterial; Renderer rend = child.gameObject.GetComponent <Renderer> (); rend.material = mat.material; } } }
void SetMaterial(GameObject objGroup, CompoundMaterial c) { objGroup.GetComponent <CompoundMaterialComponent> ().SetMaterial(c); }
public void SetMaterial(CompoundMaterial newMaterial) { compoundMaterial = newMaterial; ApplyMaterialProperties(newMaterial); }