public virtual IList <AttachmentController> DiscoverNearbyAttachable() { List <AttachmentController> nearby = new List <AttachmentController>(); Collider[] hitColliders = Physics.OverlapSphere(transform.position, PullRadius); foreach (Collider collider in hitColliders) { PullableController pullable = collider.transform.GetComponent <PullableController>(); if (pullable == null || pullable.CapturedBy != null) { continue; } AttachmentController attachment = collider.transform.GetComponent <AttachmentController>(); if (attachment == null) { continue; } HardpointController mounting = attachment.FindMountingHardpoint(); if (mounting == null || mounting.Attached != null) { continue; } nearby.Add(attachment); } return(nearby); }
public PullTogether(HardpointController point, AttachmentController attachment, HardpointController attachmentPoint) { Point = point; Attachment = attachment; AttachmentPoint = attachmentPoint; AttachmentPullable = attachment.GetComponent <PullableController>(); }
public virtual bool Detach(HardpointController point) { AttachmentController attachment = point.Attached; if (attachment == null) { return(false); } if (!attachment.OnDetach()) { return(false); } FixedJoint[] joints = gameObject.GetComponents <FixedJoint>(); foreach (FixedJoint joint in joints) { if (joint.connectedBody == attachment.rigidbody) { joint.connectedBody = null; Destroy(joint); } } point.Detach(); attachment.rigidbody.AddForceAtPosition(point.transform.up * 10, point.transform.position); return(true); }
void Awake() { aiAir = GetComponent <AI_Aircraft>(); myFlow = GetComponent <CombatFlow>(); outgoingMissiles = new List <BasicMissile>(); hardpoints = GetComponent <PlayerInput_Aircraft>().hardpointController; myRadar = GetComponent <Radar>(); aiEvade = GetComponent <AI_MissileEvade>(); aiGrndAttack = GetComponent <AI_GroundAttack>(); }
// Start is called before the first frame update void Start() { myRadar = GetComponent <Radar>(); playerInput = GetComponent <PlayerInput_Aircraft>(); mainHud = hudControl.mainHud.GetComponent <hudControl>(); localPlayerFlow = GetComponent <CombatFlow>(); hardpointController = playerInput.hardpointController; if (localPlayerFlow.isLocalPlayer) { linkToRangeLadder(); } }
public void Detach() { if (Attached != null) { Attached.ParentAttachment = null; Attached = null; } if (AttachedPoint != null) { AttachedPoint.Attached = null; AttachedPoint.AttachedPoint = null; AttachedPoint = null; } }
public virtual bool Detach(HardpointController point, bool ignore) { AttachmentController attachment = point.Attached; if (Detach(point)) { if (ignore) { IgnoreAttachments[attachment.GetInstanceID()] = attachment; } return(true); } return(false); }
public override bool Attach(HardpointController point, AttachmentController attachment, HardpointController attachmentPoint) { bool result = base.Attach(point, attachment, attachmentPoint); if (result) { if (FlightComputer != null) { EngineController engine = attachment as EngineController; if (engine != null) { FlightComputer.AddEngine(engine); } } } return(result); }
protected void ShipUpdate() { if (Shields < MaxShields) { if (LastHitTime + ShieldWaitTime < Time.time) { Shields += ShieldRegen * Time.deltaTime; if (Shields > MaxShields) { Shields = MaxShields; } } } Counter++; if (Counter > 10) { IList <AttachmentController> nearby = DiscoverNearbyAttachable(); if (nearby.Count > 0) { foreach (AttachmentController attachment in nearby) { if (IgnoreAttachments.ContainsKey(attachment.GetInstanceID())) { continue; } HardpointController attachMounting = attachment.FindMountingHardpoint(); if (attachMounting == null) { continue; } HardpointController mounting = FindMountingHardpoint(attachMounting.HardpointType, true); if (mounting == null) { continue; } PullAndAttach(mounting, attachment, attachMounting); } } Counter = 0; } }
public virtual bool Attach(HardpointController point, AttachmentController attachment, HardpointController attachmentPoint) { if (attachment == null) { Debug.Log("Cannot attach null attachment"); return(false); } if (ConnectedAttachments.ContainsKey(attachment.GetInstanceID())) { return(false); } // Move into position then attach. if (attachment.rigidbody == null) { Debug.Log("Cannot attach if it does not have a rigidbody!"); return(false); } FixedJoint joint = gameObject.AddComponent("FixedJoint") as FixedJoint; RotateConnect(point.transform, attachment.transform, attachmentPoint.transform); //attachment.transform.parent = transform; Vector3 translate = point.transform.position - attachmentPoint.transform.position; attachment.transform.Translate(translate, Space.World); point.Attached = attachment; point.AttachedPoint = attachmentPoint; attachmentPoint.Attached = this; attachmentPoint.AttachedPoint = point; joint.connectedBody = attachment.rigidbody; attachment.ParentAttachment = this; return(true); }
public virtual void PullAndAttach(HardpointController point, AttachmentController attachment, HardpointController attachmentPoint) { PullableController pullable = attachment.GetComponent <PullableController>(); if (pullable == null) { Debug.Log("Cannot pull object that is not pullable."); return; } PullObjectsController puller = point.GetComponent <PullObjectsController>(); if (puller == null) { //Debug.Log("Cannot pull and attach as there is no puller on the point."); Attach(point, attachment, attachmentPoint); DiscoverConnected(); return; } puller.PullSpecific = pullable; PullingTogether.Add(new PullTogether(point, attachment, attachmentPoint)); }
protected void AttachmentStart() { Hardpoints = new HardpointController[0]; DiscoverHardpoints(); CalculateCenterOfMass(); }