public static void AddComponent(this IContainerManager containerManager, Type service, IEnumerable<Type> implementations) { foreach (var item in implementations) { containerManager.AddComponent(service, item, item.FullName); } }
public static IEntity CreateLabelAspect(this IEntity entity, string label, int x, int y) { var stringComponent = new StringComponent {Value = label}; var xyComponent = new XYComponent {X = x, Y = y}; entity.AddComponent(stringComponent).AddComponent(xyComponent); return entity; }
public static MainRootRTSComponent GetMainRootRTSComponent(this GameObject gameObject) { MainRootRTSComponent ret_comp = gameObject.GetComponent<MainRootRTSComponent>(); if(ret_comp == null){ ret_comp = gameObject.AddComponent<MainRootRTSComponent>(); } return ret_comp; }
public static void AddComponents(this Entity entity, IComponent[] components) { foreach (var component in components) { entity.AddComponent(component); } entity.Refresh(); }
public static void Play(this GameObject go, BaseAction action, Action callback = null, bool isSelfDestroy = true) { // Add action script ActionScript actionScript = go.AddComponent<ActionScript>(); // Play action actionScript.Play(action, callback, isSelfDestroy); }
public static ButtonEventHelper GetClickedEventHelper(this GameObject obj) { if (obj == null) return null; var buttonEventHelper = obj.GetComponent<ButtonEventHelper>(); if (buttonEventHelper == null) buttonEventHelper = obj.AddComponent<ButtonEventHelper>(); return buttonEventHelper; }
public static object GetComponentOrAdd(this GameObject o, Type type) { if (type != typeof(GameObject)) { var c = o.GetComponent(type); if (c == null) c = o.AddComponent(type); return c; } else return o; }
public static void RegisterEvent(this Entity entity, int eventId, EventHandler handler) { var component = entity.GetComponent<EventHandlerComponent>(); if (component == null) { component = new EventHandlerComponent(); entity.AddComponent(component); } if (!component.EventHandlers.ContainsKey(eventId)) component.EventHandlers[eventId] = null; component.EventHandlers[eventId] += handler; }
public static void AddTag(this GameObject go, Tag tag) { TagIt tagIt = go.GetComponent<TagIt>(); if (tagIt == null) { tagIt = go.AddComponent<TagIt>(); tagIt.tags = new List<Tag>(); } else if (tagIt.tags.Contains(tag)) return; tagIt.tags.Add(tag); }
public static List<GraphicComponentMock> SetupContainer(this Container container, int number, float initialSize = 30.0f) { var ret = new List<GraphicComponentMock>(); for(int i = 0; i < number; i++) { var comp = new GraphicComponentMock(); comp.Width = initialSize; comp.Height = initialSize; ret.Add(comp); container.AddComponent(comp); } return ret; }
/// <summary> /// Add a tag to this gameobject if it does not already exist. Also add the tagger component to the gameobject if it doesn't exist /// </summary> /// <param name="go">The game object</param> /// <returns>A list of tags</returns> public static void AddTag(this GameObject go, Tags tag) { var tagger = go.GetComponent<TagFrenzyList>(); if (tagger == null) { tagger = go.AddComponent<TagFrenzyList>(); } //Make sure no deleted tags are hanging around before we add new ones tagger.CleanupDeletedTags(); if (!tagger.SelectedEditorTags.Where(t => t.Tag == tag.ToString()).Any()) { EditorTag et = MultiTagManager.EditorTags.Where(t => t.Tag == tag.ToString()).FirstOrDefault(); tagger.SelectedEditorTags.Add(et); } }
/// <summary> /// Adds the copy of a Component to a GameObject. /// </summary> /// <param name="go">The GameObject that will get the new Component</param> /// <param name="original">The original component to copy</param> /// <returns>The reference to the newly added Component copy</returns> public static Component AddComponent(this GameObject go, Component original) { var c = go.AddComponent(original.GetType()); var originalSerialized = new SerializedObject(original).GetIterator(); var nso = new SerializedObject(c); var newSerialized = nso.GetIterator(); if(originalSerialized.Next(true)) { newSerialized.Next(true); while(originalSerialized.NextVisible(true)) { newSerialized.NextVisible(true); newSerialized.SetValue(originalSerialized.GetValue()); } } nso.ApplyModifiedProperties(); return c; }
public static void AddComponentA(this Entity e) { e.AddComponent(CID.ComponentA, Component.A); }
/** * AddTag */ public static void AddTag(this GameObject go, string stag) { if (go == null) throw new System.ArgumentNullException("go"); var multitag = go.GetComponent<MultiTag>(); if (multitag != null) { multitag.AddTag(stag); } else { if (MultiTag.IsEmptyTag(go.tag)) { go.tag = stag; } else { multitag = go.AddComponent<MultiTag>(); multitag.AddTag(stag); } } }
//ADD TAG GameObject Extention public static void AddTag (this GameObject go, string newTag) { MultiTags CurrentGameComponent = go.GetComponent<MultiTags> (); if (CurrentGameComponent == null) { go.AddComponent<MultiTags>(); CurrentGameComponent = go.GetComponent<MultiTags> (); } if (!HasTagPrivate (CurrentGameComponent,newTag)) { MT newItem = new MT(); newItem.Name = newTag; CurrentGameComponent.localTagList.Add(newItem); } }
public static void RegisterConfig(this IContainerManager containerManager, XElement root) { var compEles = root.Element("components").Elements("component"); foreach (var ele in compEles) { var serviceType = GetTypeByFullName(ele.Attribute("type").Value); var interfaceType = GetTypeByFullName(ele.Attribute("service").Value); ComponentLifeStyle scope = ComponentLifeStyle.Transient; if (ele.Attribute("scope") != null) { switch (ele.Attribute("scope").Value.ToLower()) { case "singleton": scope = ComponentLifeStyle.Singleton; break; case "request": scope = ComponentLifeStyle.InRequestScope; break; case "thread": scope = ComponentLifeStyle.InThreadScope; break; case "transiant": default: scope = ComponentLifeStyle.Transient; break; } } string name = ele.Attribute("name") == null ? null : ele.Attribute("name").Value; if (ele.HasElements) { var paraEles = ele.Element("parameters").Elements("parameter"); var constructors = serviceType.GetConstructors(); foreach (var constructor in constructors) { var parameters = constructor.GetParameters(); List<object> pvals = new List<object>(); try { foreach (var para in parameters) { var pele = paraEles.FirstOrDefault(e => e.Attribute("name").Value.ToLower() == para.Name.ToLower()); object val = null; if (pele != null) { val = ConvertTo(para.ParameterType, pele.Attribute("value").Value); } else { val = containerManager.TryResolve(para.ParameterType); } pvals.Add(val); } object instance = constructor.Invoke(pvals.ToArray()); containerManager.AddComponentInstance(interfaceType, instance, name); } catch { continue; } } } else { containerManager.AddComponent(interfaceType, serviceType, name, scope); } } var moduleEles = root.Element("modules").Elements("module"); foreach (var ele in moduleEles) { var moduleType = Type.GetType(ele.Attribute("type").Value); IIocModule module = Activator.CreateInstance(moduleType) as IIocModule; containerManager.RegisterModule(module); } }
public static void AddComponentF(this Entity e) { e.AddComponent(CID.ComponentF, Component.F); }
public static void AddComponentD(this Entity e) { e.AddComponent(CID.ComponentD, Component.D); }
public static iTweener MoveTo(this GameObject go, Vector3[] path) { iTweener output = go.AddComponent<iTweener>(); output.Subject(go); output.type = iTweener.TweenType.MoveTo; output.TargetPositions(path); return output; }
public static Mesh CombineMeshes(this GameObject aGo) { MeshRenderer[] meshRenderers = aGo.GetComponentsInChildren<MeshRenderer>(false); int totalVertexCount = 0; int totalMeshCount = 0; if (meshRenderers != null && meshRenderers.Length > 0) { foreach (MeshRenderer meshRenderer in meshRenderers) { MeshFilter filter = meshRenderer.gameObject.GetComponent<MeshFilter>(); if (filter != null && filter.sharedMesh != null) { totalVertexCount += filter.sharedMesh.vertexCount; totalMeshCount++; } } } if (totalMeshCount == 0) { Debug.Log("No meshes found in children. There's nothing to combine."); return null; } if (totalMeshCount == 1) { Debug.Log("Only 1 mesh found in children. There's nothing to combine."); return null; } if (totalVertexCount > 65535) { Debug.Log("There are too many vertices to combine into 1 mesh (" + totalVertexCount + "). The max. limit is 65535"); return null; } Mesh mesh = new Mesh(); Matrix4x4 myTransform = aGo.transform.worldToLocalMatrix; List<Vector3> vertices = new List<Vector3>(); List<Vector3> normals = new List<Vector3>(); List<Vector2> uv1s = new List<Vector2>(); List<Vector2> uv2s = new List<Vector2>(); Dictionary<Material, List<int>> subMeshes = new Dictionary<Material, List<int>>(); if (meshRenderers != null && meshRenderers.Length > 0) { foreach (MeshRenderer meshRenderer in meshRenderers) { MeshFilter filter = meshRenderer.gameObject.GetComponent<MeshFilter>(); if (filter != null && filter.sharedMesh != null) { MergeMeshInto(filter.sharedMesh, meshRenderer.sharedMaterials, myTransform*filter.transform.localToWorldMatrix, vertices, normals, uv1s, uv2s, subMeshes); if (filter.gameObject != aGo) { filter.gameObject.SetActive(false); } } } } mesh.vertices = vertices.ToArray(); if (normals.Count > 0) mesh.normals = normals.ToArray(); if (uv1s.Count > 0) mesh.uv = uv1s.ToArray(); if (uv2s.Count > 0) mesh.uv2 = uv2s.ToArray(); mesh.subMeshCount = subMeshes.Keys.Count; Material[] materials = new Material[subMeshes.Keys.Count]; int mIdx = 0; foreach (Material m in subMeshes.Keys) { materials[mIdx] = m; mesh.SetTriangles(subMeshes[m].ToArray(), mIdx++); } if (meshRenderers != null && meshRenderers.Length > 0) { MeshRenderer meshRend = aGo.GetComponent<MeshRenderer>(); if (meshRend == null) meshRend = aGo.AddComponent<MeshRenderer>(); meshRend.sharedMaterials = materials; MeshFilter meshFilter = aGo.GetComponent<MeshFilter>(); if (meshFilter == null) meshFilter = aGo.AddComponent<MeshFilter>(); meshFilter.sharedMesh = mesh; } return mesh; }
public static Collider AddPrimitiveCollider(this GameObject go, PrimitiveType type, bool bTrigger) { switch (type) { case PrimitiveType.Cube: return go.AddComponent<BoxCollider>(); case PrimitiveType.Capsule: case PrimitiveType.Cylinder: var cap = go.AddComponent<CapsuleCollider>(); cap.radius = 0.5f; cap.height = 2.0f; return cap; case PrimitiveType.Sphere: return go.AddComponent<SphereCollider>(); case PrimitiveType.Plane: case PrimitiveType.Quad: var box = go.AddComponent<BoxCollider>(); box.size = new Vector3(1f, 0.01f, 1f); return box; } return null; }
public static void AddComponentB(this Entity e) { e.AddComponent(CID.ComponentB, Component.B); }
public static void AddComponentC(this Entity e) { e.AddComponent(CID.ComponentC, Component.C); }
public static void AddDebugLayer(this GameState state, float defaultLineWidth, Renderer.ViewportPolicy viewportPolicy, SpriteFont font) { state.AddComponent(new DebugLayer(defaultLineWidth, viewportPolicy, font)); }
public static void AddComponentE(this Entity e) { e.AddComponent(CID.ComponentE, Component.E); }
public static Entity AddComponentC(this Entity e) { return e.AddComponent(CID.ComponentC, Component.C); }
public static Entity AddComponentA(this Entity e) { return e.AddComponent(CID.ComponentA, Component.A); }
/// <summary> /// Starts a coroutine that can be serialized and deserialized /// </summary> /// <returns> /// The running coroutine /// </returns> /// <param name='GameObject'> /// The Game Object to start the routine on /// </param> /// <param name='coRoutine'> /// The function to use as a coroutine /// </param> public static RadicalRoutine StartExtendedCoroutine(this GameObject go, IEnumerator coRoutine) { var behaviour = go.GetComponent<MonoBehaviour>() ?? go.AddComponent<RadicalRoutineBehaviour>(); return behaviour.StartExtendedCoroutine(coRoutine); }
public static iTweener ScaleTo(this GameObject go, Vector3 targetScale) { iTweener output = go.AddComponent<iTweener>(); output.Subject(go); output.type = iTweener.TweenType.ScaleTo; output.TargetScale(targetScale); return output; }
public static Entity AddComponentB(this Entity e) { return e.AddComponent(CID.ComponentB, Component.B); }