本文整理汇总了C#中Part.AddResource方法的典型用法代码示例。如果您正苦于以下问题:C# Part.AddResource方法的具体用法?C# Part.AddResource怎么用?C# Part.AddResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Part
的用法示例。
在下文中一共展示了Part.AddResource方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: setResourcesInPart
public void setResourcesInPart(Part part, float volume, bool fill)
{
part.Resources.list.Clear ();
PartResource[] resources = part.GetComponents<PartResource> ();
int len = resources.Length;
for (int i = 0; i < len; i++)
{
GameObject.Destroy(resources[i]);
}
int rawFuelUnits = (int)(volume * unitsPerCubicMeter);
int units;
ConfigNode resourceNode;
foreach (SSTUFuelEntry entry in fuelEntries)
{
units = entry.ratio * rawFuelUnits;
resourceNode = new ConfigNode("RESOURCE");
resourceNode.AddValue("name", entry.resourceName);
resourceNode.AddValue("maxAmount", units);
resourceNode.AddValue("amount", fill? units : 0);
part.AddResource(resourceNode);
}
}
示例2: setupTankInPart
private void setupTankInPart(Part currentPart, bool calledByPlayer)
{
currentPart.Resources.list.Clear();
PartResource[] partResources = currentPart.GetComponents<PartResource>();
for (int i = 0; i < partResources.Length; i++)
{
DestroyImmediate(partResources[i]);
}
for (int tankCount = 0; tankCount < tankList.Count; tankCount++)
{
if (selectedTankSetup == tankCount)
{
for (int resourceCount = 0; resourceCount < tankList[tankCount].resources.Count; resourceCount++)
{
if (tankList[tankCount].resources[resourceCount].name != "Structural")
{
//Debug.Log("new node: " + tankList[i].resources[j].name);
ConfigNode newResourceNode = new ConfigNode("RESOURCE");
newResourceNode.AddValue("name", tankList[tankCount].resources[resourceCount].name);
newResourceNode.AddValue("maxAmount", tankList[tankCount].resources[resourceCount].maxAmount);
if (calledByPlayer && !HighLogic.LoadedSceneIsEditor)
{
newResourceNode.AddValue("amount", 0.0f);
}
else
{
newResourceNode.AddValue("amount", tankList[tankCount].resources[resourceCount].amount);
}
//Debug.Log("add node to part");
currentPart.AddResource(newResourceNode);
}
else
{
//Debug.Log("Skipping structural fuel type");
}
}
}
}
currentPart.Resources.UpdateList();
updateWeight(currentPart, selectedTankSetup);
updateCost();
}
示例3: setResourcesToPart
public void setResourcesToPart(Part part, bool fill)
{
part.Resources.list.Clear();
PartResource[] resources = part.GetComponents<PartResource>();
int len = resources.Length;
for (int i = 0; i < len; i++)
{
GameObject.Destroy(resources[i]);
}
ConfigNode resourceNode;
float amt = 0;
foreach (String name in resourceMap.Keys)
{
amt = resourceMap[name];
resourceNode = new ConfigNode("RESOURCE");
resourceNode.AddValue("name", name);
resourceNode.AddValue("maxAmount", amt);
resourceNode.AddValue("amount", fill ? amt : 0);
part.AddResource(resourceNode);
}
}
示例4: AddResource
private void AddResource(Part part, int id, string name, double rate, bool full)
{
try
{
if (!part.Resources.Contains(id))
{
double max = part.CrewCapacity * rate * globalSettings.DefaultResourceAmount;
ConfigNode node = new ConfigNode("RESOURCE");
node.AddValue("name", name);
node.AddValue("maxAmount", max);
if (full)
{
node.AddValue("amount", max);
}
else
{
node.AddValue("amount", 0);
}
part.AddResource(node);
}
}
catch (Exception ex)
{
this.LogError("Failed to add resource " + name + " to " + part.name + ": " + ex.Message + "\n" + ex.StackTrace);
}
}
示例5: EvaAddResource
private void EvaAddResource(Part part, double rate, string name, bool full)
{
try
{
double max = rate * TacStartOnce.Instance.globalSettings.EvaDefaultResourceAmount;
ConfigNode resourceNode = new ConfigNode("RESOURCE");
resourceNode.AddValue("name", name);
resourceNode.AddValue("maxAmount", max);
if (full)
{
resourceNode.AddValue("amount", max);
}
else
{
resourceNode.AddValue("amount", 0);
}
resourceNode.AddValue("isTweakable", false);
PartResource resource = part.AddResource(resourceNode);
resource.flowState = true;
resource.flowMode = PartResource.FlowMode.Both;
}
catch (Exception ex)
{
if (!ex.Message.Contains("Object reference not set"))
{
this.LogError("Unexpected error while adding resource " + name + " to the EVA: " + ex.Message + "\n" + ex.StackTrace);
}
}
}
示例6: setResourcesToPart
/// <summary>
/// Actually set the resources from this list to the input part; if the current part resources match this list exactly they will be updated in-place,
/// else all resources from the part will be cleared and the new list of resources added.
/// </summary>
/// <param name="part"></param>
/// <param name="fill"></param>
public void setResourcesToPart(Part part)
{
int len = part.Resources.Count;
if (len == resourceList.Count)//potentially the same resources exist as we are trying to setup
{
bool foundAll = true;
foreach (String name in resourceList.Keys)
{
ResourceListEntry entry = resourceList[name];
if (part.Resources.Contains(name))//go ahead and set them as found; if not all are found we'll delete them anyway...
{
PartResource pr = part.Resources[name];
pr.maxAmount = entry.max;
pr.amount = entry.fill;
}
else
{
foundAll = false;
break;
}
}
if (foundAll)
{
SSTUModInterop.updatePartResourceDisplay(part);
return;
}
}
part.Resources.dict.Clear();
ConfigNode resourceNode;
foreach (String name in resourceList.Keys)
{
ResourceListEntry entry = resourceList[name];
resourceNode = new ConfigNode("RESOURCE");
resourceNode.AddValue("name", name);
resourceNode.AddValue("maxAmount", entry.max);
resourceNode.AddValue("amount", entry.fill);
part.AddResource(resourceNode);
}
SSTUModInterop.updatePartResourceDisplay(part);
}
示例7: setResourceMaxAmount
public static PartResource setResourceMaxAmount(Part part, string name, double max)
{
PartResource res = getResource(part, name);
if (res == null && max > 0)
{
ConfigNode node = new ConfigNode("RESOURCE");
node.AddValue("name", name);
node.AddValue("amount", 0);
node.AddValue("maxAmount", max);
res = part.AddResource(node);
}
else if (res != null && max > 0)
{
res.maxAmount = max;
}
else if (res != null && max <= 0)
{
part.Resources.list.Remove(res);
}
return res;
}
示例8: SetState
public void SetState(Part thatPart, bool newstate, GameObject objectLocal)
{
if (inverted)
newstate = !newstate;
switch (type) {
case ActuatorType.PartComponent:
// Note to other people who want to use this:
// If you want to control a JSIPartComponentToggle, this is how you do it!
var eventData = new BaseEventData (BaseEventData.Sender.USER);
eventData.Set ("moduleID", moduleID);
eventData.Set ("state", newstate);
eventData.Set ("objectLocal", objectLocal);
thatPart.SendEvent ("JSIComponentToggle", eventData);
break;
case ActuatorType.PartComponentGroup:
// Note to other people who want to use this:
// If you want to control a JSIPartComponentToggle, this is how you do it!
var eventgroupData = new BaseEventData (BaseEventData.Sender.USER);
eventgroupData.Set ("groupID", moduleID);
eventgroupData.Set ("state", newstate);
eventgroupData.Set ("objectLocal", objectLocal);
thatPart.SendEvent ("JSIGroupToggle", eventgroupData);
break;
case ActuatorType.PartModule:
controlledModule.enabled = newstate;
controlledModule.isEnabled = newstate;
break;
case ActuatorType.TransformTexture:
Renderer mat = targetTransform.GetComponent<Renderer> ();
mat.material.SetTexture (textureLayer, newstate ? GameDatabase.Instance.GetTexture (trueString, false) : GameDatabase.Instance.GetTexture (falseString, false));
break;
case ActuatorType.TransformShader:
Renderer shm = targetTransform.GetComponent<Renderer> ();
shm.material.shader = Shader.Find (newstate ? trueString : falseString);
break;
case ActuatorType.StraightParameter:
if (newstate) {
SetParameter (nameOfParameter, thatPart, originalParameterValue + addToParameterWhenEnabled);
} else {
SetParameter (nameOfParameter, thatPart, originalParameterValue);
}
break;
case ActuatorType.CrewCapacity:
var eventccData = new BaseEventData (BaseEventData.Sender.USER);
eventccData.Set ("state", newstate);
eventccData.Set ("objectLocal", objectLocal);
thatPart.SendEvent ("JSISetCrewCapacity", eventccData);
break;
case ActuatorType.Resource:
// We do not manipulate resource records out of the editor because fsckit.
if (HighLogic.LoadedSceneIsEditor) {
if (!newstate) {
if (resourcePointer == null) {
resourcePointer = thatPart.Resources [resourceName];
}
// We can, hopefully, avoid deleting the tank that this particular actuator did not create.
if (resourcePointer != null && resourcePointer.maxAmount == maxAmount) {
thatPart.Resources.Remove (resourcePointer);
//UnityEngine.Object.Destroy (resourcePointer);
resourcePointer = null;
}
}
if (newstate && resourcePointer == null && thatPart.Resources [resourceName] == null) {
var node = new ConfigNode ("RESOURCE");
node.AddValue ("name", resourceName);
node.AddValue ("amount", maxAmount);
node.AddValue ("maxAmount", maxAmount);
resourcePointer = thatPart.AddResource (node);
resourcePointer.flowState = true;
}
}
break;
case ActuatorType.AttachmentNode:
if (HighLogic.LoadedSceneIsEditor && savedNodePosition != faraway) {
var foundNode = thatPart.FindAttachNode (nodeName);
if (foundNode.attachedPart == null) {
foundNode.position = newstate ? faraway : savedNodePosition;
}
}
break;
}
if (HighLogic.LoadedSceneIsEditor) {
// We need to also notify the editor that we changed the part so that Engineers' Toolbox works.
GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
}
}
示例9: AddResource
private void AddResource(Part part, int id, string name, double rate, bool full)
{
try
{
if (!part.Resources.Contains(id))
{
double max = part.CrewCapacity * rate * settings.DefaultResourceAmount;
ConfigNode node = new ConfigNode("RESOURCE");
node.AddValue("name", name);
node.AddValue("maxAmount", max);
if (full)
{
node.AddValue("amount", max);
}
else
{
node.AddValue("amount", 0);
}
part.AddResource(node);
}
}
catch (Exception ex)
{
Debug.LogError("TAC Life Support (AddLifeSupport) [" + this.GetInstanceID().ToString("X") + "][" + Time.time
+ "]: Failed to add resource " + name + " to " + part.name + ": " + ex.Message + "\n" + ex.StackTrace);
}
}