private Counterparts GetMenInTheMiddle(Counterparts list) { Counterparts c = new Counterparts(); if (!part) { return(c); } foreach (Tosh_AutoStrut m in list) { foreach (Strut s2 in m.mStruts) { foreach (Strut s1 in mStruts) { Vector3 v = s2.position - s1.position; foreach (RaycastHit r in Physics.RaycastAll(s1.position, v.normalized, v.magnitude)) { Part p = FromCollider(r.collider); if (p && p != part && p.vessel == part.vessel) { Tosh_AutoStrut a = GetMe(p); if (a && !list.Contains(a) && !c.Contains(a)) { c.Add(a); } } } } } } return(c); }
public Strut(Tosh_AutoStrut AOwner, Transform strut, Transform anchor) { mOwner = AOwner; mTransform = owner.part.transform; mAnchor = anchor; mStrut = strut; if (AOwner != null) { ownerRigidbody = AOwner.GetComponent <Rigidbody>(); } //if (mAnchor && anchorRenderer) // anchorRenderer.enabled = false; if (mAnchor) { anchorRenderer = mAnchor.GetComponent <Renderer>(); if (anchorRenderer) { anchorRenderer.enabled = false; } } if (mStrut) { strutRenderer = mStrut.GetComponent <Renderer>(); if (strutRenderer) { strutRenderer.enabled = false; if (owner.replacementStrutShader != "") { Shader s = Shader.Find(owner.replacementStrutShader); if (s) { strutRenderer.material.shader = s; } } mStrutMaterial = strutRenderer.material; mMainTexScale = mStrutMaterial.GetTextureScale("_MainTex"); mBumpTexScale = mStrutMaterial.GetTextureScale("_BumpMap"); } MeshFilter f = mStrut.GetComponent <MeshFilter>(); if (f) { mStrutMesh = f.mesh; } // FIXME. "mUp" may point just anywhere While assembling a craft // in the VAB (though everything's generally fine during the // flight). I need some other way to determine "initial up" // direction :( mUp = mTransform.InverseTransformDirection(mStrut.up); mOriginalScale = mStrut.localScale.z; } Debug.Log("Tosh_AutoStrut found " + this); }
public StrutConnection Find(Tosh_AutoStrut us, Tosh_AutoStrut them) { int i = IndexOf(us, them); if (i < 0) { return(null); } else { return(this[i]); } }
public int IndexOf(Tosh_AutoStrut us, Tosh_AutoStrut them) { for (int i = 0; i < Count; i++) { StrutConnection c = this[i]; if (c && c.from && c.to && (((c.from.owner == us) && (c.to.owner == them)) || ((c.from.owner == them) && (c.to.owner == us)))) { return(i); } } return(-1); }
// And here's where we get ALL the parts we can connect to. private Counterparts GetCounterparts() { Counterparts s = new Counterparts(); if (!part) { return(s); } if (connectToCounterparts) { foreach (Part p in part.symmetryCounterparts) { Tosh_AutoStrut m = GetMe(p); if (m && !s.Contains(m)) { s.Add(m); } } } if (connectToParent && GetMe(part.parent)) { s.Add(GetMe(part.parent)); } Tosh_AutoStrut a; foreach (Part p in part.children) { a = GetMe(p); if (a && a.connectToParent) { s.Add(a); } } if (detectManInTheMiddle) { Counterparts middle = GetMenInTheMiddle(s); ReviveMen(middle); s.AddRange(middle); RemoveDeadMen(); s.AddRange(mMenInMiddle); } return(s); }