private static void SetupSceneGrid(GameObject gridGameObject) { if (!gridGameObject.HasComponent <ConvertToSimEntity>()) { gridGameObject.AddComponent <ConvertToSimEntity>(); } Grid gridComponent = gridGameObject.HasComponent <Grid>() ? gridGameObject.GetComponent <Grid>() : gridGameObject.AddComponent <Grid>(); gridComponent.cellSize = new Vector3(1, 1, 0); gridComponent.cellGap = new Vector3(0, 0, 0); gridComponent.cellLayout = GridLayout.CellLayout.Rectangle; gridComponent.cellSwizzle = GridLayout.CellSwizzle.XYZ; LevelGridAuth levelGridAuth = gridGameObject.HasComponent <LevelGridAuth>() ? gridGameObject.GetComponent <LevelGridAuth>() : gridGameObject.AddComponent <LevelGridAuth>(); levelGridAuth.Grid = gridComponent; LevelGridSettings globalGridSettings = AssetDatabase.LoadAssetAtPath <LevelGridSettings>(SETTINGS_ASSET_PATH); if (globalGridSettings == null) { Debug.LogError($"Global Grid Settings missing (GridSettings.asset), please create the file in {SETTINGS_ASSET_PATH}"); return; } levelGridAuth.GlobalGridSettings = globalGridSettings; }
void DropOnSlot(GameObject draggedObject) { if (transform.childCount > 0) { return; } if (type == SlotType.UI) { if (draggedObject.HasComponent <RectTransform> ()) { DropUIToUI(draggedObject); } else { DropWorldToUI(draggedObject); } } else { if (draggedObject.HasComponent <RectTransform> ()) { DropUIToWorld(draggedObject); } else { DropWorldToWorld(draggedObject); } } }
public void HasComponentTest() { GameObject go = new GameObject(); Assert.IsFalse(go.HasComponent <FixtureComponent>(), "FixtureComponent がない"); go.AddComponent <FixtureComponent>(); Assert.IsTrue(go.HasComponent <FixtureComponent>(), "FixtureComponent がある"); }
public bool Contains <TSub>() where TSub : class, T { if (_container == null) { return(false); } return(_container.HasComponent <TSub>()); }
public static Type GrabType(this GameObject gameObject) { if (gameObject.HasComponent(typeof(ToggleDual))) { return(typeof(ToggleDual)); } if (gameObject.HasComponent(typeof(ToggleNormal))) { return(typeof(ToggleNormal)); } return(null); }
/// <summary> /// Determines if the gameObject is within the player's render distance. /// Players, and any object in the <see cref="BypassFilter"/> list, will /// always pass this check, regardless of distance. /// </summary> /// <param name="gameObject">Object to check the distance for.</param> /// <returns>Whether the object passes the render distance check.</returns> public bool View(GameObject gameObject) { if (gameObject == default) { return(false); } if (gameObject.TotalReplicaComponents == 3 && gameObject.HasComponent <SimplePhysicsComponent>() && gameObject.HasComponent <RendererComponent>() && gameObject.HasComponent <TriggerComponent>()) { return(true); } if (gameObject.Transform == default) { return(false); } if (gameObject is Player) { return(true); } if (this.BypassFilter.Contains(gameObject)) { return(true); } if (Override && Vector3.Distance(gameObject.Transform.Position, OverrideReferencePosition) <= Distance) { return(true); } return(Vector3.Distance(gameObject.Transform.Position, Player.Transform.Position) <= Distance); }
//+ INITIALIZATION internal static void InitInternalServices() { // Prevents the services from being initialized again if (internalServicesInit) { return; } //& Registering all services foreach (Type type in TypeUtils.GetChildsOf <IService>(GuuCore.MAIN_ASSEMBLIES.ToArray())) { if (!type.IsSubclassOf(typeof(Component)) || servicesObj.HasComponent(type)) { continue; } if (typeof(IServiceInternal).IsAssignableFrom(type)) { servicesObj.AddComponent(type); GuuCore.LOGGER?.Log($"- Registered internal service '{type.Name}'"); continue; } Component comp = servicesObj.AddComponent(type); if (comp is Behaviour behaviour) { behaviour.enabled = false; } GuuCore.LOGGER?.Log($"- Registered service '{type.Name}'"); } // Marks the services as initialized internalServicesInit = true; }
private ITriggerableMechanism[] GetCache(GameObject go) { //we don't trigger inactive GameObjects unless they are prefabs EventTriggerCache cache; if (go.activeInHierarchy) { cache = go.AddOrGetComponent <EventTriggerCache>(); return(cache.Targets ?? cache.RefreshCache()); } else if (go.HasComponent <PrefabToken>()) { cache = go.GetComponent <EventTriggerCache>(); if (cache != null) { return(cache.Targets ?? cache.RefreshCache()); } return(go.GetComponents <ITriggerableMechanism>()); } else { return(ArrayUtil.Empty <ITriggerableMechanism>()); } }
public static void Postfix(GameObject __instance) { if (__instance.HasComponent <Renderer>()) { Photon.SetRendererTexture(__instance.GetComponent <Renderer>()); } }
void ObjectComponent_OnCreatableDestroyed(object sender, NetCreatableInfo creatable) { ClientPlayer player = creatable.Creatable as ClientPlayer; if (player != null) { // If a player was destroyed we need to remove // anything associated with them. players.Remove(creatable.Id); player.Dispose(); if (player == OurPlayer) { // Notify the player OurPlayer.OnKilled(); // Remove the player OurPlayer = null; } } else { GameObject gameObject = creatable.Creatable as GameObject; if (gameObject.HasComponent <PhysicsBodyComponent>()) { physEntities.Remove(creatable.Id); } gameObject.Dispose(); } }
/// <summary> /// コンポーネントが入ってなかったら入れる。 /// 入っていたら何もしない /// </summary> /// <typeparam name="T"></typeparam> /// <param name="self"></param> /// <returns></returns> public static GameObject AddComponentGIfNotHave <T>(this GameObject self) where T : Component { if (!self.HasComponent <T>()) { self.AddComponent <T>(); } return(self); }
/// <summary> /// コンポーネントの有効化 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="self"></param> /// <returns></returns> public static GameObject EnableComponent <T>(this GameObject self) where T : Behaviour { if (self.HasComponent <T>()) { self.GetComponent <T>().enabled = true; } return(self); }
AudioSource GetCollisionSound(GameObject gobj) { if (gobj.HasComponent <AudioSource>()) { return(gobj.GetComponent <AudioSource>()); } return(null); }
/// <summary> /// Add/remove component to/from gameobject. /// This functionality is used for editor. /// </summary> public static void EnableComponent <T>(this GameObject gameObject, bool isEnable, bool hideInInspector = false) where T : MonoBehaviour { if (isEnable) { if (!gameObject.HasComponent <T>()) { var comp = gameObject.AddComponent <T>(); if (hideInInspector) { comp.hideFlags = HideFlags.HideInInspector; } } } else if (gameObject.HasComponent <T>()) { Object.DestroyImmediate(gameObject.GetComponent <T>()); } }
static User GetOwner(GameObject game_object) { if (!game_object.HasComponent <Owned>()) { return(null); } return(game_object.GetComponent <Owned>().Owner); }
/// <summary> /// 指定されたコンポーネントを取得 /// アタッチされていない場合は追加する /// </summary> public static T ForceGetComponent <T>(this GameObject self) where T : Component { if (!self.HasComponent <T>()) { return(self.AddComponent <T>()); } return(self.GetComponent <T>()); }
public virtual void Awake() { if (target != null) { rb = target.HasComponent <Rigidbody>() ? target.GetComponent <Rigidbody>() : null; } agent = GetComponent <Agent>(); }
public static bool AssertHasLikeComponent(GameObject go, System.Type tp) { if (!go.HasComponent(tp)) { Assert(System.String.Format("(GameObject:{1}) GameObject requires a component of type {0}.", tp.Name, go.name), go); return(true); } return(false); }
public static void Toggle(GameObject gameObject) { if (gameObject.HasComponent <StratusGameObjectBookmark>()) { gameObject.RemoveComponent <StratusGameObjectBookmark>(); } else { gameObject.AddComponent <StratusGameObjectBookmark>(); } }
private static void FixGrandParentSwipeEffect() { if (!swipeEffect.HasComponent <EffectComponent>()) { EffectComponent effectComponent = swipeEffect.AddComponent <EffectComponent>(); effectComponent.positionAtReferencedTransform = true; effectComponent.parentToReferencedTransform = false; effectComponent.applyScale = false; effectComponent.disregardZScale = false; } }
/// <summary> /// Adds a GameObject to the master catalog and returns true /// GameObject must be non-null and have a CharacterMaster component /// returns false if GameObject is null or is missing the component /// </summary> /// <param name="master">The master to register to the master catalog.</param> /// <returns></returns> public static bool RegisterNewMaster(GameObject master) { if (master && master.HasComponent <CharacterMaster>()) { EnigmaticThunder.Modules.Masters.RegisterMaster(master); LogCore.LogD("Registered master " + master.name + " to the master catalog!"); return(true); } LogCore.LogF("FATAL ERROR: " + master.name + " failed to register to the master catalog!"); return(false); }
/// <summary> /// Adds a GameObject to the projectile catalog and returns true /// GameObject must be non-null and have a ProjectileController component /// returns false if GameObject is null or is missing the component /// </summary> /// <param name="projectileObject">The projectile to register to the projectile catalog.</param> /// <returns></returns> public static bool RegisterNewProjectile(GameObject projectileObject) { if (projectileObject.HasComponent <ProjectileController>()) { EnigmaticThunder.Modules.Projectiles.RegisterProjectile(projectileObject); LogCore.LogD("Registered projectile " + projectileObject.name + " to the projectile catalog!"); return(true); } LogCore.LogF("FATAL ERROR:" + projectileObject.name + " failed to register to the projectile catalog!"); return(false); }
public static bool HasComponent <T>(this GameObject gameObject) where T : Component { T component; if (!gameObject) { return(false); } return(gameObject.HasComponent <T>(out component)); }
public override void Awake() { base.Awake(); targetAux = target.gameObject; target = new GameObject(); if (targetAux != null) { agentTarget = targetAux.HasComponent <SteeringBehaviours.Agent>()? targetAux.GetComponent <SteeringBehaviours.Agent>() : null; } }
/// <summary> /// 指定したコンポーネントが入ってなかったら追加して返す /// 既に入っていたら入っている物を取得して返す /// </summary> /// <returns></returns> public static T GetorAddComponent <T>(this GameObject self) where T : Component { if (self.HasComponent <T>()) { return(self.GetComponent <T>()); } else { return(self.AddComponent <T>()); } }
/// <summary> /// オブジェクト名をSerializeField付きの変数名にする /// </summary> /// <param name="currentObject">アタッチしているオブジェクト</param> /// <returns>変換後のテキストを挿入済みの画面に表示するテキスト</returns> private string ConvertSerializeFieldText(GameObject currentObject) { string outputText = "[SerializeField] private GameObject " + this.ConvertFirstTextLowerCase(currentObject.name) + "Object;\r\n\r\n"; if (currentObject.HasComponent <Text>()) { outputText += "[SerializeField] private Text " + this.ConvertFirstTextLowerCase(currentObject.name) + ";\r\n\r\n"; } if (currentObject.HasComponent <Button>()) { outputText += "[SerializeField] private Button " + this.ConvertFirstTextLowerCase(currentObject.name) + ";\r\n\r\n"; } if (currentObject.HasComponent <Image>()) { outputText += "[SerializeField] private Image " + this.ConvertFirstTextLowerCase(currentObject.name) + ";\r\n\r\n"; } return(outputText); }
/// <summary> /// リセットメソッドを作成する /// </summary> /// <param name="currentObject">アタッチしているオブジェクト</param> /// <returns>変換後のテキストを挿入済みの画面に表示するテキスト</returns> private string ConvertResetText(GameObject currentObject) { string outputText = " this." + this.ConvertFirstTextLowerCase(currentObject.name) + "Object = GameObject.Find(\"" + currentObject.name + "\").gameObject;\r\n\r\n"; if (currentObject.HasComponent <Text>()) { outputText += " this." + this.ConvertFirstTextLowerCase(currentObject.name) + " = GameObject.Find(\"" + currentObject.name + "\").GetComponent<Text>();\r\n\r\n"; } if (currentObject.HasComponent <Button>()) { outputText += " this." + this.ConvertFirstTextLowerCase(currentObject.name) + " = GameObject.Find(\"" + currentObject.name + "\").GetComponent<Button>();\r\n\r\n"; } if (currentObject.HasComponent <Image>()) { outputText += " this." + this.ConvertFirstTextLowerCase(currentObject.name) + " = GameObject.Find(\"" + currentObject.name + "\").GetComponent<Image>();\r\n\r\n"; } return(outputText); }
public static void Destroy(GameObject obj) { if (ObjectPool.Contains(obj)) ObjectPool.Add(obj); else { if (obj.HasComponent<NetworkIdentity>()) NetworkServer.Destroy(obj); else Object.Destroy(obj); } }
public IEnumerator has_component_test() { //Arrange GameObject A = new GameObject(); A.AddComponent <BoxCollider>(); //Act & Assert Assert.IsTrue(A.HasComponent <BoxCollider>()); yield return(null); }
private static void DrawRectIcon <T>(Rect selectionRect, GameObject go, Color textColor, ref int order, ref GUIStyle style) where T : Component { //Color oldColor = style.normal.textColor; //style.normal.textColor = textColor; if (go.HasComponent <T>()) { order += 1; var rect = GetRect(selectionRect, order); DrawIcon <T>(rect); } // style.normal.textColor = oldColor; }
private void collisionSystem_Collision(object sender, CollisionEventArgs e) { if (GameObject.HasComponent <ExplodableComponent>(e.Object1) && ExplodesWith(e.Object1, e.Object2)) { CreateParticles(e.Object1); } if (GameObject.HasComponent <ExplodableComponent>(e.Object2) && ExplodesWith(e.Object2, e.Object1)) { CreateParticles(e.Object2); } }
protected bool MustCheckCollision(GameObject obj1, GameObject obj2) { if (this._collisionTypeToCheck == CollisionType.All) { return true; } else if (this._collisionTypeToCheck == CollisionType.Action) { if (obj1.HasComponent(ComponentType.IsAction) && obj2.HasComponent(ComponentType.IsCharacter)) { return true; } } else if (this._collisionTypeToCheck == CollisionType.Physical) { if (obj1.HasComponent(ComponentType.IsPhysical) && obj2.HasComponent(ComponentType.IsPhysical)) { return true; } } return false; }
public void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID) { if (CommandMap[up].Evaluate()) { Owner.QueryComponent<Identity2D>().Transform.Position += new Vector2(0, -Speed); if (Owner.HasComponent<SpriteAnimator>() && Animate && UpAnimation != null) Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = UpAnimation; } if (CommandMap[down].Evaluate()) { Owner.QueryComponent<Identity2D>().Transform.Position += new Vector2(0, Speed); if (Owner.HasComponent<SpriteAnimator>() && Animate && DownAnimation != null) Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = DownAnimation; } if (CommandMap[left].Evaluate()) { Owner.QueryComponent<Identity2D>().Transform.Position += new Vector2(-Speed, 0); if (Owner.HasComponent<SpriteAnimator>() && Animate && LeftAnimation != null) Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = LeftAnimation; } if (CommandMap[right].Evaluate()) { Owner.QueryComponent<Identity2D>().Transform.Position += new Vector2(Speed, 0); if (Owner.HasComponent<SpriteAnimator>() && Animate && RightAnimation != null) Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = RightAnimation; } var pos = Owner.QueryComponent<Identity2D>().Transform.Position; if(oldPosition == pos) if (Owner.HasComponent<SpriteAnimator>() && Animate) Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = null; if (Owner.HasComponent<SpriteOscillator>() && Bobbing) Owner.QueryComponent<SpriteOscillator>().Oscillate = oldPosition != pos; oldPosition = pos; }