本文整理汇总了C#中UnityEngine.Component类的典型用法代码示例。如果您正苦于以下问题:C# Component类的具体用法?C# Component怎么用?C# Component使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Component类属于UnityEngine命名空间,在下文中一共展示了Component类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractRigInfo
//Should only be created as part of our base framework
public static AiRig ExtractRigInfo(Component c)
{
var rig = c.GetComponent<AiRig>();
if (rig == null)
c.GetComponentInParent<AiRig>();
return rig;
}
示例2: getAttributesFrom
public override Dictionary<string, object> getAttributesFrom(Component component)
{
Dictionary<string, object> scriptAttributes = new Dictionary<string, object>();
addScriptFieldsToDictionary (scriptAttributes, component);
addScriptPropertiesToDictionary (scriptAttributes, component);
return scriptAttributes;
}
示例3: CreateChild
public static Component CreateChild(this Transform parent, Component child)
{
Component go = GameObject.Instantiate(child);
go.transform.SetParent(parent);
go.transform.Reset();
return go;
}
示例4: Process
public void Process(Component @object)
{
var label = (UILabel)@object;
// 图片字体! 打包字
if (label.bitmapFont != null)
{
string uiFontPath = KDepBuild_NGUI.BuildUIFont(label.bitmapFont);
//CResourceDependencies.Create(label, CResourceDependencyType.BITMAP_FONT, uiFontPath);
KAssetDep.Create<KBitmapFontDep>(label, uiFontPath);
label.bitmapFont = null;
}
else if (label.trueTypeFont != null)
{
string fontPath = KDependencyBuild.BuildFont(label.trueTypeFont);
//CResourceDependencies.Create(label, CResourceDependencyType.FONT, fontPath);
KAssetDep.Create<KUILabelDep>(label, fontPath);
label.trueTypeFont = null; // 挖空依赖的数据
}
else
{
Logger.LogWarning("找不到Label的字体: {0}, 场景: {1}", label.name, EditorApplication.currentScene);
}
}
示例5: ComponentField
public static Component ComponentField(Rect position, GUIContent label, Component value, System.Type inheritsFromType, bool allowSceneObjects, System.Type targetComponentType)
{
if (inheritsFromType == null) inheritsFromType = typeof(Component);
else if (!typeof(Component).IsAssignableFrom(inheritsFromType) && !typeof(IComponent).IsAssignableFrom(inheritsFromType)) throw new TypeArgumentMismatchException(inheritsFromType, typeof(IComponent), "Type must inherit from IComponent or Component.", "inheritsFromType");
if (targetComponentType == null) throw new System.ArgumentNullException("targetComponentType");
if (!typeof(Component).IsAssignableFrom(targetComponentType)) throw new TypeArgumentMismatchException(targetComponentType, typeof(Component), "targetComponentType");
if (value != null && !targetComponentType.IsAssignableFrom(value.GetType())) throw new TypeArgumentMismatchException(value.GetType(), inheritsFromType, "value must inherit from " + inheritsFromType.Name, "value");
if (TypeUtil.IsType(inheritsFromType, typeof(Component)))
{
return EditorGUI.ObjectField(position, label, value, inheritsFromType, true) as Component;
}
else
{
value = EditorGUI.ObjectField(position, label, value, typeof(Component), true) as Component;
var go = GameObjectUtil.GetGameObjectFromSource(value);
if (go != null)
{
foreach (var c in go.GetComponents(inheritsFromType))
{
if (TypeUtil.IsType(c.GetType(), targetComponentType))
{
return c as Component;
}
}
}
}
return null;
}
示例6: Start
new void Start()
{
base.Start ();
if (entity == null) {
Debug.LogError("Serenity Method Trigger miss a gameObject");
return;
}
if (method == null) {
MethodInfo mi = entity.GetType().GetMethod(methodName);
foreach(Component comp in entity.GetComponents<Component>()) {
mi = comp.GetType().GetMethod(methodName);
if(mi!=null)
{
component = comp;
break;
}
}
if(mi==null)
{
Debug.LogError ("Serenity Method Trigger miss a boolean-returned method with name "+methodName);
}
else {
method = mi;
}
} else {
methodName = method.Name;
}
}
示例7: Init
public override void Init(Reactor reactor)
{
base.Init(reactor);
ComponentMethod cm = null;
try {
cm = reactor.FindMethod(actionMethod);
} catch (ArgumentNullException e) {
Debug.LogError("[Action Node] Could not find method :" + actionMethod + "\n" + NodeNamesInStack());
throw e;
}
if(cm == null) {
Debug.LogError("Could not load action method: " + actionMethod);
} else {
if(cm.methodInfo.ReturnType == typeof(IEnumerator<NodeResult>)) {
component = cm.component;
methodInfo = cm.methodInfo;
if( methodParams != null )
{
methodParams.ConvertParams(methodInfo);
}
} else {
Debug.LogError("Action method has invalid signature: " + actionMethod);
}
}
}
示例8: Reset
public override void Reset()
{
GameObject = null;
Component = null;
ScreenPosition = null;
SendEvent = null;
}
示例9: FromComponent
public static KISItemModuleWrapper FromComponent(Component component)
{
if (component != null)
return new KISItemModuleWrapper(component);
return null;
}
示例10: WriteToJson
public void WriteToJson(IResMgr resmgr, GameObject node, Component component, MyJson.JsonNode_Object json)
{
SkinnedMeshRenderer ic = component as SkinnedMeshRenderer;
//json["type"] = new MyJson.JsonNode_ValueString(this.comptype.Name.ToLower());//必须的一行
//放到外面去了
//材质
MyJson.JsonNode_Array mats = new MyJson.JsonNode_Array();
json["mats"] = mats;
foreach (var m in ic.sharedMaterials)
{
string hash = resmgr.SaveMat(m);
mats.Add(new MyJson.JsonNode_ValueString(hash));
}
//bounds
json["center"] = new MyJson.JsonNode_ValueString(StringHelper.ToString(ic.localBounds.center));
json["size"] = new MyJson.JsonNode_ValueString(StringHelper.ToString(ic.localBounds.size));
//mesh
json["mesh"] = new MyJson.JsonNode_ValueString(resmgr.SaveMesh(ic.sharedMesh));
json["rootboneobj"] = new MyJson.JsonNode_ValueNumber(ic.rootBone.gameObject.GetInstanceID());
MyJson.JsonNode_Array bones = new MyJson.JsonNode_Array();
foreach (var b in ic.bones)
{
bones.Add(new MyJson.JsonNode_ValueNumber(b.gameObject.GetInstanceID()));
}
json["boneobjs"] = bones;
ic.rootBone.GetInstanceID();
}
示例11: Reset
public override void Reset()
{
GameObject = null;
Component = null;
ScreenFlickVector = null;
SendEvent = null;
}
示例12: Apply
public object Apply(Type targetType, Injector activeInjector, Dictionary<string, object> injectParameters)
{
if (parentObject == null)
{
object contextViewObj = (IContextView) activeInjector.GetInstance(typeof(IContextView));
if(contextViewObj != null)
{
object contextView = ((IContextView) contextViewObj).view;
if(contextView != null)
{
if (contextView is Transform) parentObject = (Transform) contextView;
else if (contextView is GameObject) parentObject = ((GameObject) contextView).transform;
}
}
}
if (parentObject == null)
{
destroyGameObjectWhenComplete = true;
parentObject = new GameObject("Unity Component Provider").transform;
}
component = parentObject.gameObject.AddComponent(componentType);
//TODO: Make auto InjectInto configurable
activeInjector.InjectInto(component);
if (_postApply != null)
{
_postApply(this, component);
}
return component;
}
示例13: OnExecute
/////////
protected override Status OnExecute(Component agent, IBlackboard blackboard)
{
if (nestedFSM == null || nestedFSM.primeNode == null){
return Status.Failure;
}
if (status == Status.Resting){
CheckInstance();
}
if (status == Status.Resting || nestedFSM.isPaused){
status = Status.Running;
nestedFSM.StartGraph(agent, blackboard, OnFSMFinish);
}
if (!string.IsNullOrEmpty(successState) && nestedFSM.currentStateName == successState){
nestedFSM.Stop();
return Status.Success;
}
if (!string.IsNullOrEmpty(failureState) && nestedFSM.currentStateName == failureState){
nestedFSM.Stop();
return Status.Failure;
}
return status;
}
示例14: OnExecute
protected override Status OnExecute(Component agent, IBlackboard blackboard)
{
currentProbability = probability;
for (var i = 0; i < outConnections.Count; i++){
if (failedIndeces.Contains(i))
continue;
if (currentProbability > childWeights[i].value){
currentProbability -= childWeights[i].value;
continue;
}
status = outConnections[i].Execute(agent, blackboard);
if (status == Status.Success || status == Status.Running)
return status;
if (status == Status.Failure){
failedIndeces.Add(i);
var newTotal = GetTotal();
for (var j = 0; j < failedIndeces.Count; j++){
newTotal -= childWeights[j].value;
}
probability = Random.Range(0, newTotal);
return Status.Running;
}
}
return Status.Failure;
}
示例15: Serialize
public ComponentData Serialize(Component component) {
var placedItem = (PlacedItem) component;
return new PlacedItemData {
Id = placedItem.CatalogEntry.Id,
Unique = placedItem.UniqueInSlot
};
}