本文整理汇总了C#中Component类的典型用法代码示例。如果您正苦于以下问题:C# Component类的具体用法?C# Component怎么用?C# Component使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Component类属于命名空间,在下文中一共展示了Component类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddHealth
public static void AddHealth(Component entity, int health)
{
HealthHandler handler = entity.GetComponent<HealthHandler>();
if (handler) {
handler.AddHealth(health);
}
}
示例2: Main
static void Main(string[] args)
{
Component motherBoard1 = new Component("AsusP8H67/H67/1155", "Game Station", (decimal)155.00);
Component graphicCard1 = new Component("ATI Radeon HD7850", (decimal)229.00);
Component ram1 = new Component("2x4GB DDR3 1600Mhz", (decimal)129.00);
Computer pc1 = new Computer("Asus Game Machine", new List<Component> { motherBoard1, graphicCard1, ram1 });
Console.WriteLine(pc1);
Console.WriteLine();
Console.WriteLine("----------------------------------------------------------------");
Component motherBoard2 = new Component("ASUS P8H61-M LX2/SI/LGA1155", "Home Station", (decimal)98.00);
Component graphicCard2 = new Component("ATI Radeon HD 7750", (decimal)138.00);
Component ram2 = new Component("4 GB DDR3 1333 MHz", (decimal)65.00);
Computer pc2 = new Computer("Home Machine", new List<Component> { motherBoard2, graphicCard2, ram2 });
Console.WriteLine(pc2);
Console.WriteLine();
Console.WriteLine("----------------------------------------------------------------");
Component motherBoard3 = new Component("ASROCK Z87 PRO4 BULK", "Game Station", (decimal)217.00);
Component graphicCard3 = new Component("SAPPHIRE R9 270 2G GDDR5 OC", (decimal)358.00);
Component ram3 = new Component("2x4GB DDR3 1600 MHz", (decimal)148.00);
Computer pc3 = new Computer("Game Machine New", new List<Component> { motherBoard3, graphicCard3, ram3 });
Console.WriteLine(pc3);
Console.WriteLine();
Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine("----------------------------------------------------------------");
List<Computer> computers = new List<Computer>() { pc1, pc2, pc3 };
computers.OrderByDescending(computer => computer.Price).ToList().ForEach(computer => Console.WriteLine(computer.ToString()));
}
示例3:
void ICmpInitializable.OnShutdown(Component.ShutdownContext context)
{
if(context == ShutdownContext.Deactivate)
{
DualityApp.Sound.StopAll();
}
}
示例4: Deserialize
public void Deserialize(byte[] data, Component instance)
{
UnitySerializer.AddFinalAction(delegate
{
Animation animation = (Animation)instance;
animation.Stop();
Dictionary<string, AnimationState> dictionary = animation.Cast<AnimationState>().ToDictionary((AnimationState a) => a.name);
List<SerializeAnimations.StoredState> list = UnitySerializer.Deserialize<List<SerializeAnimations.StoredState>>(data);
foreach (SerializeAnimations.StoredState current in list)
{
if (current.asset != null && !dictionary.ContainsKey(current.name))
{
animation.AddClip(SaveGameManager.Instance.GetAsset(current.asset) as AnimationClip, current.name);
}
if (current.name.Contains(" - Queued Clone"))
{
AnimationState instance2 = animation.PlayQueued(current.name.Replace(" - Queued Clone", string.Empty));
UnitySerializer.DeserializeInto(current.data, instance2);
}
else
{
UnitySerializer.DeserializeInto(current.data, animation[current.name]);
}
}
});
}
示例5: SaveComponent
public int SaveComponent(IComponentDb componentDb, int? transactionNumber = null)
{
Component record;
var recordOld = new Component();
if (componentDb.ComponentId == 0)
{
record = new Component();
Context.AddToComponents(record);
}
else
{
record = Context.Components.Where(r => r.ComponentId == componentDb.ComponentId).First();
ReflectionHelper.CopyAllProperties(record, recordOld);
}
record.Name = componentDb.Name;
record.IsReadOnlyAccess = componentDb.IsReadOnlyAccess;
Context.SaveChanges();
if (componentDb.ComponentId == 0)
{
componentDb.ComponentId = record.ComponentId;
LogUnlinkedToDb(UserId, "Components", record.ComponentId, "I", XmlHelper.GetObjectXml(record), transactionNumber);
}
else
{
LogUnlinkedToDb(UserId, "Components", record.ComponentId, "U", XmlHelper.GetDifferenceXml(recordOld, record), transactionNumber);
}
return componentDb.ComponentId;
}
示例6: AddListener
public void AddListener(Component game_object, string notification_name)
{
if (listeners_dictionary.ContainsKey(notification_name))
listeners_dictionary.Add(notification_name, new List<Component>());
listeners_dictionary [notification_name].Add (game_object);
}
示例7: OnManaChange
void OnManaChange(Component Health, object newMana)
{
//If health has changed of this object
if (this.GetInstanceID() != Health.GetInstanceID()) return;
Debug.Log("Object: " + gameObject.name + "'s Mana is: " + newMana.ToString());
}
示例8: GetComponents
private static List<ComponentListFactor> GetComponents(Component component, bool isMultiply = true)
{
if (component is DualFactorComponent)
{
var dfc = (DualFactorComponent)component;
var leftComponent = Componentizer.ToComponent(dfc.LeftFactor);
var rightComponent = Componentizer.ToComponent(dfc.RightFactor);
var leftList = GetComponents(leftComponent, isMultiply);
var rightList = GetComponents(rightComponent, isMultiply == dfc.IsMultiply);
return leftList.Union(rightList).ToList();
}
if (component is IntegerFraction)
{
var frac = (IntegerFraction)component;
return new List<ComponentListFactor>
{
new ComponentListFactor(new NumericFactor(new Integer(frac.Numerator))),
new ComponentListFactor(new NumericFactor(new Integer(frac.Denominator)), false)
};
}
return new List<ComponentListFactor> { new ComponentListFactor(Factorizer.ToFactor(component), isMultiply) };
}
示例9: Main
public static void Main()
{
Console.Title = "Problem 3. PC Catalog";
Component monitor = new Component("monitor", 200);
Component keyboard = new Component("keyboard", 43);
Component mouse = new Component("mouse", 15);
Component motherboard = new Component("motherboard", "G560 Intel Motherboard LA-5752P", 540);
Component HDD = new Component("HDD", "256GB SSD", 188);
Component proccesor = new Component("processor", " Intel Pentium G6950 (2.80 GHz, 3 MB)", 433);
Computer firstPC = new Computer("Lenovo", motherboard, proccesor, HDD, monitor, mouse, keyboard);
Computer secondPC = new Computer("HP", motherboard, proccesor, HDD, monitor);
Computer thirdPC = new Computer("Acer", motherboard, proccesor, HDD);
Computer[] pcArr = { firstPC, secondPC, thirdPC };
pcArr = pcArr.OrderBy(pc => pc.Price()).ToArray();
foreach (Computer pc in pcArr)
{
Console.WriteLine(pc.ToString());
}
Console.WriteLine("{0}\nMake your best choice!", new string('.', 25));
}
示例10: Main
static void Main()
{
var HDD = new Component("SSD Intel 530 Ser.", 149.04, "120GB SATA");
var graphicsCard = new Component("Palit GTX750Ti KalmX", 321.00, "2GB");
var motherboard = new Component("ASROCK 970 PERFORMANCE", 201.59);
var processor = new Component("Intel i5-4460", 386.21, "3.2GHz 6MBs.1150");
var myComponents = new List<Component>();
myComponents.Add(processor);
myComponents.Add(HDD);
myComponents.Add(motherboard);
myComponents.Add(graphicsCard);
var hardDiscDrive = new Component("SSD KINGSTON", 190.51, "240GB V300 SATA3");
var videoCard = new Component("Palit Nvidia", 197.10, " GT740 2GB DDR5");
var CPU = new Component("AMD A8", 205.44, "X4 7650K BOX s.FM2+");
var monitor = new Component("23\'\' Samsung", 321.00, " C23A750X Wireles");
var yourComponents = new List<Component>() { hardDiscDrive, videoCard, CPU, monitor};
var computer = new Computer("MyComputer", myComponents);
var secondComputer = new Computer("YourComputer",yourComponents);
var computers = new List<Computer>() { computer, secondComputer };
computers.OrderBy(c => c.Price).ToList().ForEach(c => Console.WriteLine(c.ToString()));
}
示例11: GetContentByUrl
/// <summary>
/// Gets the raw string (xml) from the broker db by URL
/// </summary>
/// <param name="Url">URL of the page</param>
/// <returns>String with page xml or empty string if no page was found</returns>
public string GetContentByUrl(string Url)
{
Page page = new Page();
page.Title = Randomizer.AnyString(15);
page.Id = Randomizer.AnyUri(64);
page.Filename = Randomizer.AnySafeString(8) + ".html";
PageTemplate pt = new PageTemplate();
pt.Title = Randomizer.AnyString(20);
Field ptfieldView = new Field();
ptfieldView.Name = "view";
ptfieldView.Values.Add("Standard");
pt.MetadataFields = new FieldSet();
pt.MetadataFields.Add(ptfieldView.Name, ptfieldView);
page.PageTemplate = pt;
Schema schema = new Schema();
schema.Title = Randomizer.AnyString(10);
Component component = new Component();
component.Title = Randomizer.AnyString(30);
component.Id = Randomizer.AnyUri(16);
component.Schema = schema;
Field field1 = Randomizer.AnyTextField(6, 120, true);
Field field2 = Randomizer.AnyTextField(8, 40, false);
FieldSet fieldSet = new FieldSet();
fieldSet.Add(field1.Name, field1);
fieldSet.Add(field2.Name, field2);
component.Fields = fieldSet;
ComponentTemplate ct = new ComponentTemplate();
ct.Title = Randomizer.AnyString(20);
Field fieldView = new Field();
fieldView.Name = "view";
fieldView.Values.Add("DefaultComponentView");
ct.MetadataFields = new FieldSet();
ct.MetadataFields.Add(fieldView.Name, fieldView);
ComponentPresentation cp = new ComponentPresentation();
cp.Component = component;
cp.ComponentTemplate = ct;
page.ComponentPresentations = new List<ComponentPresentation>();
page.ComponentPresentations.Add(cp);
FieldSet metadataFields = new FieldSet();
page.MetadataFields = metadataFields;
var serializer = new XmlSerializer(typeof(Page));
StringBuilder builder = new StringBuilder();
StringWriter writer = new StringWriter(builder);
//XmlTextWriter writer = new XmlTextWriter(page.Filename, Encoding.UTF8);
//serializer.Serialize(writer, page);
serializer.Serialize(writer, page);
string pageAsString = builder.ToString();
return pageAsString;
}
示例12: Parser
public MyJson.IJsonNode Parser(Component com, NeedList needlist)
{
UISlider t = com as UISlider;
var json = new MyJson.JsonNode_Object();
json["value"] = new MyJson.JsonNode_ValueNumber(t.value);
json["alpha"] = new MyJson.JsonNode_ValueNumber(t.alpha);
json["numberOfSteps"] = new MyJson.JsonNode_ValueNumber(t.numberOfSteps);
if (t.foregroundWidget != null)
{
json["foregroundWidget"] = new MyJson.JsonNode_ValueNumber(GameObjParser.ObjToID(t.foregroundWidget.gameObject));
}
if (t.backgroundWidget != null)
{
json["backgroundWidget"] = new MyJson.JsonNode_ValueNumber(GameObjParser.ObjToID(t.backgroundWidget.gameObject));
}
if (t.thumb != null)
{
json["thumb"] = new MyJson.JsonNode_ValueNumber(GameObjParser.ObjToID(t.thumb.gameObject));
}
json["fillDirection"] = new MyJson.JsonNode_ValueString(t.fillDirection.ToString());
return json;
}
示例13: FadeOutAnimation
public FadeOutAnimation(Component i_BoundSprite)
: base(i_BoundSprite)
{
m_TimeLeft = r_FadeEffectTimeSpan;
m_AnimationTime = r_FadeEffectTimeSpan;
m_BoundSprite.Opacity = 100;
}
示例14: Format
public string Format(Component component)
{
Regex variable = new Regex("\\$[a-zA-z]+ ");
string plainVars = variable.Replace(Value, new MatchEvaluator(delegate(Match match)
{
string propertyName = match.Value.Replace("$", "").Trim().ToLowerInvariant();
ComponentProperty propertyInfo = component.FindProperty(propertyName);
if (propertyInfo != null)
return component.GetProperty(propertyInfo).ToString();
return "";
}));
variable = new Regex("\\$[a-zA-Z]+[\\(\\)a-z_0-9]+ ");
string formattedVars = variable.Replace(plainVars, new MatchEvaluator(delegate(Match match)
{
Regex propertyNameRegex = new Regex("\\$[a-zA-z]+");
string propertyName = propertyNameRegex.Match(match.Value).Value.Replace("$", "").Trim().ToLowerInvariant();
ComponentProperty propertyInfo = component.FindProperty(propertyName);
if (propertyInfo != null)
{
return ApplySpecialFormatting(component.GetProperty(propertyInfo), match.Value.Replace(propertyNameRegex.Match(match.Value).Value, "").Trim());
}
return "";
}));
Regex regex = new Regex(@"\\[uU]([0-9A-F]{4})");
return regex.Replace(formattedVars, match => ((char)Int32.Parse(match.Value.Substring(2), NumberStyles.HexNumber)).ToString());
}
示例15: switch
void ICmpInitializable.OnInit(Component.InitContext context)
{
if (context == InitContext.Activate && DualityApp.ExecContext != DualityApp.ExecutionContext.Editor)
{
AnimSpriteRenderer r = this.GameObj.Renderer as AnimSpriteRenderer;
SoundEmitter s = this.GameObj.GetComponent<SoundEmitter>();
Transform t = this.GameObj.Transform;
r.AnimDuration = MathF.RoundToInt(0.4f * r.AnimDuration * MathF.Rnd.NextFloat(0.8f, 1.25f) * MathF.Sqrt(intensity));
t.RelativeScale *= MathF.Sqrt(intensity);
t.RelativeAngle = MathF.Rnd.NextFloat(MathF.RadAngle360);
t.RelativeVel = new Vector3(MathF.Rnd.NextVector2(1.0f));
ContentRef<Sound> soundRes = ContentRef<Sound>.Null;
switch (MathF.Rnd.Next(5))
{
case 0: soundRes = GameRes.Data.Sound.Explo1_Sound; break;
case 1: soundRes = GameRes.Data.Sound.Explo2_Sound; break;
case 2: soundRes = GameRes.Data.Sound.Explo3_Sound; break;
case 3: soundRes = GameRes.Data.Sound.Explo4_Sound; break;
case 4: soundRes = GameRes.Data.Sound.Explo5_Sound; break;
}
SoundEmitter.Source source = new SoundEmitter.Source(soundRes, false);
source.Volume = MathF.Rnd.NextFloat(0.9f, 1.15f) * MathF.Sqrt(intensity);
source.Pitch = MathF.Rnd.NextFloat(0.8f, 1.25f) / MathF.Sqrt(intensity);
source.Paused = false;
s.Sources.Add(source);
}
}