// 0 default // of the hardpoints readyToFire, select one with most roundsRemaining short selectGroupStartIndex() { short mostRoundsRemainIndex = 0; short mostRoundsRemain = 0; for (short i = 0; i < weaponTypeHardpointLists[activeTypeIndex].Count; i++) { Hardpoint currentHardpoint = weaponTypeHardpointLists[activeTypeIndex][i]; if (currentHardpoint.readyToFire) { Weapon loadedWeap = currentHardpoint.loadedWeaponObj.GetComponent <Weapon>(); if (loadedWeap != null) { if (loadedWeap.roundsRemain > mostRoundsRemain) { mostRoundsRemain = loadedWeap.roundsRemain; mostRoundsRemainIndex = i; } } } } return(mostRoundsRemainIndex); }
/// <summary> /// Do some checks before installing a module in a hardpoint to make sure /// that we can actually install it. /// </summary> public ModuleResult CanInstallModuleInto(Hardpoint hardpoint, GameObject prefab) { if (hardpoint == null) { return(ModuleResult.InvalidHardpoint); } if (!hardpoint.IsEmpty) { return(ModuleResult.HardpointNotEmpty); } if (prefab == null) { return(ModuleResult.NoModule); } ActorModule module = prefab.GetComponent <ActorModule>(); if (module == null) { return(ModuleResult.NoModule); } if (!hardpoint.IsCompatible(module.socket)) { return(ModuleResult.IncompatibleSocket); } return(ModuleResult.Success); }
/// <summary> /// Handles the drawing of a socket into the scene view. /// </summary> /// <param name="socket">The socket to draw into the scene view.</param> private void SceneGUIHandleSocket(ref Hardpoint socket) { Vector3 point = shipTx.TransformPoint(socket.position); Quaternion rot = shipRot * socket.rotation; if (Tools.current == Tool.Move || Tools.current == Tool.Rotate) { // Draw the transform gizmo for the socket if we are rotating or moving. EditorGUI.BeginChangeCheck(); if (Tools.current == Tool.Move) // Draw the move gizmo { point = Handles.DoPositionHandle(point, shipRot); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(ship, "Move Socket"); EditorUtility.SetDirty(ship); socket.position = shipTx.InverseTransformPoint(point); } } else if (Tools.current == Tool.Rotate) // Draw the rotation gizmo { rot = Handles.DoRotationHandle(rot, point); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(ship, "Rotate Socket"); EditorUtility.SetDirty(ship); socket.rotation = Quaternion.Inverse(shipRot) * rot; } } } // Draw the socket itself. SceneGUIDrawSocket(ref socket, point, rot); }
/// <summary> /// Draw the representation of the socket into the scene view. Will draw the /// arc limits. /// </summary> /// <param name="socket">The socket to draw.</param> /// <param name="position">The position of the socket in world space.</param> /// <param name="rotation">The rotation of the socket in world space.</param> private void SceneGUIDrawSocket(ref Hardpoint socket, Vector3 position, Quaternion rotation) { Matrix4x4 mat4 = Handles.matrix; Color color = Handles.color; // Set the matrix to make it local to the socket. Handles.matrix = Matrix4x4.TRS(position, rotation, Vector3.one); // Draw the horizontal arc limits. Handles.color = new Color(1, 0, 0, 0.3f); Handles.DrawSolidArc( Vector3.zero, Vector3.up, AHMath.HeadingAngleToVectorXZ(socket.arcLimits.left), socket.arcLimits.left + socket.arcLimits.right, 0.05f ); // Draw the vertical arg limits. Handles.color = new Color(0, 1, 0, 0.3f); Handles.DrawSolidArc( Vector3.zero, Vector3.left, AHMath.HeadingAngleToVectorYZ(-socket.arcLimits.down), socket.arcLimits.down + socket.arcLimits.up, 0.05f ); // Restore the Handles stuff. Handles.matrix = mat4; Handles.color = color; }
/// <summary> /// Try and disable the module in the specified hardpoint. /// </summary> public ModuleResult DisableModuleIn(Hardpoint hardpoint, ActorModule.DisabledReason reason = ActorModule.DisabledReason.User) { if (hardpoint == null) { return(ModuleResult.InvalidHardpoint); } if (hardpoint.IsEmpty) { return(ModuleResult.NoModule); } else if (!hardpoint.Module.IsEnabled) { return(ModuleResult.AlreadyDisabled); } else { ModuleResult result = hardpoint.Module.DisableModule(reason); if (result == ModuleResult.Success) { --_totalActive; if (reason == ActorModule.DisabledReason.ResourceLoss) { ++_autoDisabled; } if (onChange != null) { onChange(ActorModule.Change.Disabled, hardpoint.Module); } } return(result); } }
/// <summary> /// Try and enable the module installed in the provided Hardpoint. /// Can return a Partial result if the module exists, but there is not /// enough energy or computer resources to enable the module. /// </summary> public OperationResult EnableModule(Hardpoint hardpoint) { ModuleResult res = hardpoints.EnableModuleIn(hardpoint); switch (res) { case ModuleResult.Success: return(OperationResult.OK()); case ModuleResult.NoModule: return(OperationResult.Fail("No Module to disable")); case ModuleResult.AlreadyEnabled: return(OperationResult.OK("Module already enabled")); case ModuleResult.InsufficientPower: return(OperationResult.Partial("Not enough energy to activate Module")); case ModuleResult.InsufficientCpu: return(OperationResult.Partial("Not enough CPU")); default: return(OperationResult.Fail("Failed because: " + res.ToString())); } }
public override Hardpoint AddHardpoint() { ComboBox groupComboBox = (ComboBox)mainWindow.GetElement("groupComboBox"); ComboBox weaponComboBox = (ComboBox)mainWindow.GetElement("weaponComboBox"); CheckBox omniCheckBox = (CheckBox)mainWindow.GetElement("omniCheckBox"); Log.updateLog(Log.LogType.HARDPOINT, "User clicked the AddHardpoint button"); string weaponType = ""; string locationName = ""; try { Log.updateLog(Log.LogType.HARDPOINT, "Attempting to store location from groupComboBox"); locationName = groupComboBox.SelectedItem.ToString(); Log.updateLog(Log.LogType.HARDPOINT, "location: " + locationName); Log.updateLog(Log.LogType.HARDPOINT, "Attempting to store weaponType from weaponComboBox"); weaponType = weaponComboBox.SelectedItem.ToString(); Log.updateLog(Log.LogType.HARDPOINT, "weaponType: " + weaponType); } catch (Exception ex) { string exception = "Encountered exception while attempting to add a hardpoint: " + ex.Message; Log.updateLog(Log.LogType.EXCEPTION, exception); MessageBox.Show(exception, "Add Hardpoint Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } Hardpoint h = new Hardpoint(); h.WeaponMount = weaponType; h.Omni = omniCheckBox.Checked; model.AddHardpoint(locationName, h, MainWindow.ProcessMode.SINGLE); return(h); }
/// <summary> /// Try and enable the module in the specified hardpoint. /// </summary> public ModuleResult EnableModuleIn(Hardpoint hardpoint) { if (hardpoint.IsEmpty) { return(ModuleResult.NoModule); } else { ActorModule.DisabledReason disabledReason = hardpoint.Module.DisabledBy; ModuleResult res = hardpoint.Module.EnableModule(); if (res == ModuleResult.Success) { ++_totalActive; if (disabledReason != ActorModule.DisabledReason.User) { --_autoDisabled; } if (onChange != null) { onChange(ActorModule.Change.Enabled, hardpoint.Module); } } return(res); } }
public Hardpoint GetHardpointNear(Vector3 worldPos, float maxRange, Hardpoint.hardpoint_type type) { Hardpoint hardpoint; List <Hardpoint> .Enumerator enumerator = this._points.GetEnumerator(); try { while (enumerator.MoveNext()) { Hardpoint current = enumerator.Current; if (current.type == type) { if (current.IsFree()) { if (Vector3.Distance(current.transform.position, worldPos) > maxRange) { continue; } hardpoint = current; return(hardpoint); } } } return(null); } finally { ((IDisposable)(object)enumerator).Dispose(); } return(hardpoint); }
public void DisplayHardpoint(Hardpoint h) { Clear(); hardpoint = h; if (hardpoint.part == null || displayPart == false) { allowableTypesText.gameObject.SetActive(true); allowableSizeText.gameObject.SetActive(true); partImage.gameObject.SetActive(false); partNameBackground.SetActive(false); partNameText.gameObject.SetActive(false); allowableTypesText.text = Constants.ColoredPartTypeString[hardpoint.allowableType]; allowableSizeText.text = hardpoint.allowableSize.ToString(); } else { allowableTypesText.gameObject.SetActive(false); allowableSizeText.gameObject.SetActive(false); partNameBackground.SetActive(true); partNameText.gameObject.SetActive(true); partImage.gameObject.SetActive(true); partNameText.text = hardpoint.part.ModelName; partImage.sprite = hardpoint.part.sprite; partImage.color = Constants.PartColor[hardpoint.part.partType]; } }
/// <summary> /// Determines whether this group can add the specified hardpoint. /// </summary> /// <param name="hardpoint">The hardpoint to try and add to the group.</param> /// <returns><c>true</c> if this group can add the specified hardpoint; otherwise, <c>false</c>.</returns> public bool CanAddHardPoint(Hardpoint hardpoint) { if (hardpoint.Module == null) { return(false); // Cannot add an empty socket. } // See if the socket group can take the module. ActorModule module = hardpoint.Module; HPSocket typeFlags = module.socket; if ((typeFlags & HPSocket.Passive) == HPSocket.Passive) { return((flags & Flags.Passive) == Flags.Passive); } if ((typeFlags & HPSocket.Utility) == HPSocket.Utility) { return((flags & Flags.Utility) == Flags.Utility); } if ((typeFlags & HPSocket.Targeted) == HPSocket.Targeted) { return((flags & Flags.Targeted) == Flags.Targeted); } // Dunno what happened, so no. return(false); }
public Hardpoint GetHardpointNear(Vector3 worldPos, float maxRange, Hardpoint.hardpoint_type type) { Hardpoint hardpoint; List<Hardpoint>.Enumerator enumerator = this._points.GetEnumerator(); try { while (enumerator.MoveNext()) { Hardpoint current = enumerator.Current; if (current.type == type) { if (current.IsFree()) { if (Vector3.Distance(current.transform.position, worldPos) > maxRange) { continue; } hardpoint = current; return hardpoint; } } } return null; } finally { ((IDisposable)(object)enumerator).Dispose(); } return hardpoint; }
/// <summary> /// Called when adding or inserting a socket into the sockets array from the Inspector GUI. /// The added socket is initialized to the default values. /// </summary> /// <param name="sockets">The Serialized sockets array to add a socket into.</param> /// <param name="index">The index to insert the socket, if we are inserting.</param> private void InspectorAddSocket(SerializedProperty sockets, int index) { if (index == -1) { index = sockets.arraySize; sockets.arraySize += 1; } else { sockets.InsertArrayElementAtIndex(index); } Hardpoint def = new Hardpoint(); SerializedProperty socket = sockets.GetArrayElementAtIndex(index); socket.FindPropertyRelative("socketName").stringValue = def.name; SerializedProperty arc = socket.FindPropertyRelative("arcLimits"); arc.FindPropertyRelative("up").floatValue = def.arcLimits.up; arc.FindPropertyRelative("down").floatValue = def.arcLimits.down; arc.FindPropertyRelative("left").floatValue = def.arcLimits.left; arc.FindPropertyRelative("right").floatValue = def.arcLimits.right; socket.FindPropertyRelative("position").vector3Value = def.position; socket.FindPropertyRelative("rotation").quaternionValue = def.rotation; }
public void setPosition(Hardpoint hp) { originalOpacity = opacity; HP = hp; HP.hpb = this; if (HP.hasWeapon) { opacity = wopacity; rm.Close(); rm.enabled = false; } myControl.Opacity = opacity; offsetPoint = HP.transform.position + offset; var screenPoint = manager.ScreenToGui(mainCamera.WorldToScreenPoint(offsetPoint)); transform.localScale = Vector3.one; screenPoint.x -= (myControl.Width / 2) * HP.transform.localScale.x; screenPoint.y -= myControl.Height * HP.transform.localScale.y; var direction = (HP.transform.position - mainCamera.transform.position).normalized; var inFrontOfCamera = Vector3.Dot(mainCamera.transform.forward, direction) > float.Epsilon; if (!inFrontOfCamera) { myControl.IsVisible = false; return; } else { myControl.IsVisible = true; } myControl.RelativePosition = (Vector3)screenPoint; }
short nextAvailableHardpointIndex(short typeIndex) { float smallestReloadTime = 0; //Debug.Log("NextavailableHardpointIndex called"); // check if current is null -- no need to search if this index is already good if (!weaponTypeHardpointLists[typeIndex][activeHardpointIndexes[typeIndex]].readyToFire) { activeHardpointIndexes[typeIndex]++; // increment index for this type // if we need to search for a different hardpoint if (activeHardpointIndexes[typeIndex] > weaponTypeHardpointLists[typeIndex].Count - 1 || // check if index is past range for this type !weaponTypeHardpointLists[typeIndex][activeHardpointIndexes[typeIndex]].readyToFire) // check if this next index is good as well { // loop through all in weaponTypeList, select first available // if that fails, select the one with least reload time remaining bool availableFound = false; float smallestTimeRemainVal = -1f; // -1 to signify first value hasn't been selected short smallestTimeRemainIndex = 0; // default to first index // loop through all the hardpoints for this type for (short i = 0; i < weaponTypeHardpointLists[typeIndex].Count && !availableFound; i++) { Hardpoint currentHardpoint = weaponTypeHardpointLists[typeIndex][i]; //Debug.Log("Reloadtime at " + i + ": " + currentHardpoint.currentTimer); // check if current hardpoint is ready to fire -- (controller depends on hardpoints to accurately report this) if (currentHardpoint.readyToFire) { availableFound = true; activeHardpointIndexes[typeIndex] = i; Debug.Log("Available found at index: " + activeHardpointIndexes[typeIndex]); } // save smallest timer value and index if (currentHardpoint.currentReloadTimer < smallestTimeRemainVal || smallestTimeRemainVal < 0) { Debug.Log("New small time found: " + currentHardpoint.currentReloadTimer); smallestTimeRemainVal = currentHardpoint.currentReloadTimer; smallestReloadTime = smallestTimeRemainVal; smallestTimeRemainIndex = i; } } // looped through all, couldn't find available. Select least reload time remaining if (!availableFound) { activeHardpointIndexes[typeIndex] = smallestTimeRemainIndex; Debug.Log("None available found. Defaulting to least time remaining at: " + smallestTimeRemainIndex); } } } //Debug.Log("============== RESULT: hardpoint " + activeHardpointIndexes[typeIndex] + " selected, with reload time remaining: "); return(activeHardpointIndexes[typeIndex]); }
private void Start() { _core = GetComponentInParent <MechaCoreComponent>(); if (_core) { Hardpoint hp = _core.hardpoints.Get(this); _core.EnableModule(hp); } }
public void Initialize(Hardpoint hp) { HP = hp; HP.hpm = this; WeaponInfoPanel.wip.SetInfo(hp); updateReadouts(); initialized = true; hpb.resetValue(); }
/// <summary> /// Internal method that is called from Hardpoint.UninstallEquipment. Do not call from anywhere else! /// </summary> internal void HandleUninstallation() { var hardpoint = Hardpoint; Disengage(); Hardpoint = null; Uninstalled?.Invoke(this, hardpoint); }
public void ClickOnHardpointDisplay(Hardpoint h) { if (holdingAttachment) { //if you've got an attachment PlaceAttachment (heldAttachment, h); } else if (h.isOccupied) { heldAttachment = h.RemoveAttachment (false); holdingAttachment = true; } }
public void SetInfo(Hardpoint hp) { HP = hp; HP.hpb.indicateActive(); BehaviorManager.bm.allowed = false; BehaviorManager.bm.Initialize(); refreshText(); infoPanel.ip.setTab(0); }
private void OnHardpointMounted(Hardpoints sender, Hardpoint hardpoint) { if (hardpoint.IsEquipmentInstalled) { OnSomeEquipmentInstalled(hardpoint.InstalledEquipment); } hardpoint.EquipmentInstalled += OnSomeEquipmentInstalled; hardpoint.EquipmentUninstalled += OnSomeEquipmentUninstalled; }
/// <summary> /// Instantiates an instance of a module prefab and installs it into a specified hardpoint on a /// specified parent GameObject. The instance of the module component is returned. /// </summary> public static ActorModule Instantiate(GameObject prefab, Hardpoint hardpoint, GameObject parent) { GameObject go = GameObject.Instantiate(prefab, parent.transform); ActorModule mod = go.GetComponent <ActorModule>(); mod._prefab = prefab; mod.InstantiateModule(hardpoint.position, hardpoint.rotation); hardpoint.SetModule(mod); return(mod); }
public void Clear() { hardpoint = null; partImage.sprite = null; partImage.gameObject.SetActive(false); partNameBackground.SetActive(false); partNameText.gameObject.SetActive(false); allowableTypesText.gameObject.SetActive(false); allowableSizeText.gameObject.SetActive(false); }
/// <summary> /// Add a HardPoint into the group, if it doesn't already exist. /// </summary> /// <param name="hardpoint">The HardPoint to add to the group.</param> /// <returns>True if the hardpoint was added, false if it already is in the group.</returns> public bool Add(Hardpoint hardpoint) { if (Contains(hardpoint.name)) { return(false); } hardpoints = AHArray.Added(hardpoints, hardpoint); return(true); }
public void AddNewHardpoint() { Hardpoint h = new Hardpoint((PartSize)sizeDropdown.value, newHardpointType, newHardpointOrientation); GameObject g = hardpointListPool.GetGameObject(); var passHardpoint = h; var passListElement = g.GetComponent <HardpointListElement>(); passListElement.DisplayHardpoint(h); passListElement.deleteButton.onClick.AddListener(delegate { DeleteHardpoint(passListElement, passHardpoint); }); }
private static IFortressComponent MakeTestComponentAt(int x, int y, int z) { var testHardpoint = new Hardpoint(x, y, z); var testComponent = new MockFortressComponent() { Position = Position.OneByOneAt(testHardpoint), ComponentType = FoundationComponentType.Else }; return(testComponent); }
internal GameObject MakeHardpoint(GameObject parent, Hardpoint <Vector3> hardpointNode, PartDescriptor <Vector3> partDescriptor) { var hardpointObj = Object.Instantiate(Craft.HardpointBase) as GameObject; hardpointObj.name = hardpointNode.WeaponType.ToString(); Helpers.AttachTransform(parent, hardpointObj, hardpointNode.Location); Craft.ProcessHardpoint?.Invoke(hardpointObj, partDescriptor, hardpointNode); return(hardpointObj); }
public void createControls(Hardpoint HP) { if (HP.hasPowerToggle) return; GameObject o = TrashMan.spawn("hpPowerManager",transform.position,transform.rotation); HPPowerManager hpm = o.GetComponent<HPPowerManager>(); hpm.Initialize(HP); hpmList.Add(hpm); HP.hasPowerToggle = true; o.transform.parent = weaponsPanel.gameObject.transform; }
/// <summary> /// Remove any installed module from the provided Hardpoint, with the provided /// removal reason (Uninstalled or Destroyed). /// /// If there was a module installed, /// we try to return the prefab that the module was instantiated from. /// </summary> public GameObject RemoveModuleFrom(Hardpoint hardpoint, ActorModule.Change reason = ActorModule.Change.Uninstalled) { GameObject prefab; ModuleResult result = hardpoints.RemoveModuleFrom(hardpoint, reason, out prefab); if (result == ModuleResult.InvalidHardpoint) { Debug.LogError("Trying to remove module from invalid hardpoint!"); } return(prefab); }
private Element CreateHardpointElement(Hardpoint hp) { var elem = new Element("li"); elem.SetClass("hardpoint", true); var name = new Element("div"); name.InnerRml = $"{hp.GameObj.Name}"; elem.AppendChild(name); elem.Click += (o, e) => OnHardpointClick(elem, hp); return(elem); }
/// <summary> /// Register that a module was installed into a hardpoint after the fact. /// </summary> public void RegisterInstalledModuleIn(Hardpoint hardpoint, ActorModule module) { // TODO: Do something here. if (onChange != null) { onChange(ActorModule.Change.Installed, module); } if (module.DisabledBy == ActorModule.DisabledReason.ResourceLoss) { _autoDisabled += 1; } }
/// <summary> /// Remove the specified socket from the socket group. /// </summary> /// <param name="socketName">The name of the socket to remove.</param> /// <returns>The ShipSocket that was removed, or null if the socket wasn't found.</returns> public Hardpoint Remove(string socketName) { for (int i = 0; i < hardpoints.Length; ++i) { if (hardpoints[i].name == socketName) { Hardpoint hardpoint = hardpoints[i]; hardpoints = AHArray.Removed(hardpoints, i); return(hardpoint); } } return(null); }
/// <summary> /// Internal method that is called from Hardpoint.InstallEquipment. Do not call from anywhere else! /// </summary> internal void HandleInstallation(Hardpoint hardpoint) { Assert.IsFalse(IsInstalled, "Tried to install equipment that is already installed somewhere."); Assert.IsFalse(Enabled, "Tried to install enabled equipment."); Hardpoint = hardpoint; Installed?.Invoke(this, hardpoint); if (TargetEnabled) { TryToEngage(); } }
private void OnHardpointClick(Element elem, Hardpoint hp) { _selectedHardpoint = hp; _installListElem = _installListElem ?? Document.GetElementById("installList"); _installListElem.InnerRml = ""; // clear var inventory = _playerShip.GameObj.GetComponent <Inventory>(); if (inventory != null) { foreach (var items in inventory.Items) { } } _installListElem.SetProperty("display", "block"); }
// Get an array of all the hardpoints. // TODO Remove this. public Hardpoint[] GetAll() { int count = ((targeted != null) ? targeted.Length : 0) + ((utility != null) ? utility.Length : 0) + ((passive != null) ? passive.Length : 0) + ((structures != null) ? structures.Length : 0); Hardpoint[] all = new Hardpoint[count]; int offset = 0; if (targeted != null) { for (int i = 0; i < targeted.Length; ++i) { all[i] = targeted[i]; } offset += targeted.Length; } if (utility != null) { for (int i = 0; i < utility.Length; ++i) { all[i + offset] = utility[i]; } offset += utility.Length; } if (passive != null) { for (int i = 0; i < passive.Length; ++i) { all[i + offset] = passive[i]; } offset += passive.Length; } if (structures != null) { for (int i = 0; i < structures.Length; ++i) { all[i + offset] = structures[i]; } } return(all); }
public void DisplayHardpoint(Hardpoint h) { Clear(); hardpoint = h; string hardpointString = "Size " + hardpoint.allowableSize.ToString() + " "; if (h.orientation == Orientation.Internal) { hardpointString += "Internal " + Constants.ColoredPartTypeString[hardpoint.allowableType] + " Mount"; } else { hardpointString += hardpoint.orientation.ToString() + " " + Constants.ColoredPartTypeString[hardpoint.allowableType] + " Hardpoint"; } hardpointText.text = hardpointString; }
public static Hardpoint GetHardpointFromRay(Ray ray, Hardpoint.hardpoint_type type) { RaycastHit raycastHit; bool flag; MeshBatchInstance meshBatchInstance; if (Facepunch.MeshBatch.MeshBatchPhysics.Raycast(ray, out raycastHit, 10f, out flag, out meshBatchInstance)) { IDMain dMain = (!flag ? IDBase.GetMain(raycastHit.collider) : meshBatchInstance.idMain); if (dMain) { HardpointMaster component = dMain.GetComponent<HardpointMaster>(); if (component) { return component.GetHardpointNear(raycastHit.point, type); } } } return null; }
public void DisplayHardpoint(Hardpoint hardpoint) { if (hardpoint.isOccupied) { Attachment a = hardpoint.GetAttachment (); if (a != null) { this.DisplayAttachment (a); } } else { switch (hardpoint.attachmentRestriction) { case BlueprintType.CAB: nameText.text = "Crew Cabin Slot"; break; default: nameText.text = "Hardpoint"; break; } if (hardpoint.isInternal) { midText.text = "Internal Hardpoint"; } else { midText.text = "External Hardpoint"; } } }
internal void AssignHardpoint(Hardpoint hardpoint) { print("assigning hardpoint"); hardpoint.Occupied = true; this.AssignedHardpoint = hardpoint; this.AssignedHardpointObj = hardpoint.gameObject; }
public Hardpoint GetHardpointNear(Vector3 worldPos, Hardpoint.hardpoint_type type) { return this.GetHardpointNear(worldPos, 3f, type); }
public void AddHardpoint(Hardpoint point) { this._points.Add(point); }
private void PlaceAttachment(GameObject attachment, Hardpoint hardpoint) { Dictionary<ResourceType, int> price; Attachment a = attachment.GetComponent<Attachment> (); if (a.GetAttachmentType () != hardpoint.attachmentRestriction && hardpoint.attachmentRestriction != BlueprintType.None) { //if they don't match types and it has a restriction other than none Debug.LogWarning("Mismatched attachment type"); } else if (hardpoint.isOccupied) {//remove the cost of the old attachment GameObject oldattachment = hardpoint.GetAttachment().gameObject; price = oldattachment.GetComponent<Attachment>().GetCost(); foreach (ResourceType r in price.Keys) { //readd the cost of the now removed attachment costDisplay.UpdateResource(r, price[r]); } Destroy(oldattachment); //now that we've removed the cost, delete it } hardpoint.AddAttachment (attachment); holdingAttachment = false; Attachment na = attachment.GetComponent<Attachment> (); price = na.GetCost (); foreach (ResourceType r in price.Keys) { //subtract the cost of the new attachment costDisplay.UpdateResource(r, -price[r]); //notice how it's negative! } }
public void Parse(GameBitBuffer buffer) { Field0 = buffer.ReadFloat32(); Field1 = buffer.ReadFloat32(); Field2 = new Hardpoint(); Field2.Parse(buffer); }