// Use this for initialization void Start() { data = (JsonObject)JsonValue.Parse (entityDef.ToString ()); // consider making these joints foreach(JsonObject node in data["nodes"]) { GameObject obj = (GameObject)Object.Instantiate(nodeType, new Vector3(node["pos"][0], node["pos"][1], node["pos"][2]), new Quaternion()); obj.transform.parent = transform; euids[node["euid"]] = new EntityComponent(node, obj); } // Yay add sprite data foreach (JsonObject bone in data["bones"]) { EntityComponent from = euids[bone["from"]]; EntityComponent to = euids[bone["to"]]; GameObject boneObject = GameObject.CreatePrimitive(PrimitiveType.Cylinder); boneObject.transform.position = from.gameObject.transform.position; boneObject.transform.LookAt(to.gameObject.transform.position); boneObject.transform.localScale.Set(1, 1, Vector3.Distance(from.gameObject.transform.position, to.gameObject.transform.position)); boneObject.transform.parent = transform; euids[bone["euid"]] = new EntityComponent(bone, boneObject); } }
public override void HandleOnTargetHit(ProjectileEntity source, EntityComponent target) { base.HandleOnTargetHit(source, target); target.Damage(Magnitude, MyEntityComponent); target.BroadcastMessage("BeingAttacked", this.MyEntityComponent); }
/// <summary> /// Initializes a new instance of the <see cref="EntityComponentEventArgs"/> struct. /// </summary> /// <param name="entity">The entity.</param> /// <param name="componentKey">The component key.</param> /// <param name="previousComponent">The previous component.</param> /// <param name="newComponent">The new component.</param> public EntityComponentEventArgs(Entity entity, PropertyKey componentKey, EntityComponent previousComponent, EntityComponent newComponent) { Entity = entity; ComponentKey = componentKey; PreviousComponent = previousComponent; NewComponent = newComponent; }
protected void HandleBossDied(EntityComponent boss, EntityComponent lastAttacker) { boss.onEntityDeath -= HandleBossDied; if (OnBossDeath != null) OnBossDeath(boss, lastAttacker); }
void HandleOnHeroDied(EntityComponent died, EntityComponent lastAttacker) { NumHeroesAlive--; if (onHeroDied != null) onHeroDied(died, lastAttacker); }
void HandleOnEntityDestroyed (EntityComponent entityComponent) { myEntity.onHealthChanged -= OnTargetHealthChanged; myEntity.onEntityDestroyed -= HandleOnEntityDestroyed; healthBarGUIManager.onToggleHealthBar -= HandleOnToggleHealthBar; }
/// <summary> /// Initializes a new instance of the <see cref="EntityComponentEventArgs"/> struct. /// </summary> /// <param name="entity">The entity.</param> /// <param name="componentKey">The component key.</param> /// <param name="previousComponent">The previous component.</param> /// <param name="newComponent">The new component.</param> public EntityComponentEventArgs(Entity entity, int index, EntityComponent previousComponent, EntityComponent newComponent) { Entity = entity; Index = index; PreviousComponent = previousComponent; NewComponent = newComponent; }
void HandleOnNoticedEntityEvent(EntityComponent noticed) { if (!unitsNoticed.Contains(noticed)) { noticed.onEntityDeath += HandleOnEntityDeath; unitsNoticed.Add(noticed); } }
protected override void OnStopTargeting (EntityComponent attacker, EntityComponent attackee) { //Let us start moving again normally. myEntityComponent.myMovement.ResumeMovement(); myEntityComponent.myMovement.CurrTarget = null; base.OnStopTargeting (attacker, attackee); }
void HandleOnChargingActionEvent(EntityComponent attacker, EntityComponent target, float chargeTime) { if (chargingActionEffectScript != null) { chargingActionEffectScript.Target = target.transform; chargingActionEffectScript.Visible = true; chargingActionEffectScript.Play(); } }
protected void HandleOnHeroDied(EntityComponent source, EntityComponent killer) { if (killer != null && killer is MonsterComponent) { int gold = EntityFactory.GetInstance().GetHeroInfo(source.DataName).gold; AddGold(gold); goldGUIManager.FireGoldParticle(gold, source.transform.position); } }
public override bool Attach(EntityComponent targetEntity) { bool attached = base.Attach(targetEntity); if (attached) timeRemaining = totalEffectTime; return attached; }
public virtual void Detach() { if (target != null) { target.DetachModifier(this); } ResetEntity(); target = null; }
protected void OnHeroDeath(EntityComponent dead, EntityComponent lastAttacker) { if (dead is HeroComponent) { RemovePartyMember(dead as HeroComponent); dead.onEntityDeath -= OnHeroDeath;; if (OnHeroDied != null) OnHeroDied(dead, lastAttacker); } }
protected void OnAttackStateTransition(EntityComponent source, AttackManagerState state) { //If we're transitioning to idle then set our current target to the current waypoint if (state == AttackManagerState.Idle && CurrWaypoint != null) { CurrTarget = CurrWaypoint.transform; ForceRepath(); performingActions = false; } else if (state == AttackManagerState.Attacking) { performingActions = true; } }
void HandleOnWatchedHeroDeath(EntityComponent source, EntityComponent killer) { HeroComponent heroComp = source as HeroComponent; if (heroComp != null) { heroComp.onEntityDeath -= HandleOnWatchedHeroDeath; enemiesInRange.Remove(heroComp); if (enemyTracking == heroComp) { SetEnemy(); } } }
public virtual void HandleOnTargetHit(ProjectileEntity source, EntityComponent target) { //Apply our attack effects. if (target != null && target.Alive) { foreach (EntityModifier modifier in actionModifiers.Values) { modifier.DeepClone().Attach(target); } } //Let any listeners know if (OnTargetHitEvent != null) OnTargetHitEvent(MyEntityComponent, MyActionManager.myBehaviorManager.CurrentTarget); }
public bool AddComponent(EntityComponent component) { if(!HasComponentOfType(component.GetType())) { if(component.AllDependenciesLinked()) { component.entity = this; component.OnLink(); components.Add(component); return true; } Console.WriteLine("Error! Not all dependencies were linked in type {0}", component.GetType()); return false; } Console.WriteLine("Error! Already had component of type {0}", component.GetType()); return false; }
public virtual bool Attach(EntityComponent targetEntity) { bool attached = false; if (targetEntity != null) { attached = targetEntity.AttachModifier(this); if (attached) { this.target = targetEntity; ModifyEntity(); } } return attached; }
public override void HandleOnTargetHit(ProjectileEntity source, EntityComponent target) { base.HandleOnTargetHit(source, target); Collider[] colliders = Physics.OverlapSphere(target.transform.position, Radius, layerMask); //Loop through all resulting colliders, seeing if we can snatch an EntityComponent from them that is of our target type //Then damage it if that is the case! foreach (Collider collider in colliders) { EntityComponent entity = collider.gameObject.GetComponent<EntityComponent>(); if (entity != null && entity.GetType() == myTargetType) { entity.Damage(Magnitude, MyEntityComponent); entity.BroadcastMessage("BeingAttacked", this.MyEntityComponent); } } }
public virtual void FireAction(EntityComponent target) { OnPerformingAction(target); if (Projectile != null) //We're firing a projectile, wait for it before we apply the results of our action! { Vector3 offset = MyEntityComponent.attackPoint.position; offset.x += Projectile.GetComponent<ProjectileEntity>().FiringOffset.x * (MyEntityComponent.Facing == Facing.Left ? -1 : 1); offset.z += Projectile.GetComponent<ProjectileEntity>().FiringOffset.y; GameObject newProj = (GameObject) GameObject.Instantiate(Projectile, offset, Quaternion.identity); AnimatedProjectile projectileEntityScript = newProj.GetComponent<AnimatedProjectile>(); projectileEntityScript.Target = target; projectileEntityScript.speed = Projectile.GetComponent<ProjectileEntity>().speed; //projectileEntityScript.animationName = Projectile.GetComponent<AnimatedProjectile>().animationName; projectileEntityScript.OnProjectileHitTargetEvent += HandleOnTargetHit; } else HandleOnTargetHit(null, target); }
protected override void HandleOnBehaviorStateChangedEvent(EntityComponent entity, BaseBehaviorStates newState) { //If we're performing actions at this point in time then mark that down so we don't change our Current Waypoint //And then let's stop moving! if (newState == BaseBehaviorStates.PerformingActions) { performingActions = true; StopMovement(); } else if (newState == BaseBehaviorStates.Moving) //If we're moving then we have to find out if we need to grab a new target or not... { if (CurrTarget == null && CurrWaypoint != null) //We have no target, set our waypoint to our target { CurrTarget = CurrWaypoint.transform; } ResumeMovement(); ForceRepath(); performingActions = false; } base.HandleOnBehaviorStateChangedEvent (entity, newState); }
void Start () { if (entityComponent == null) entityComponent = transform.parent.parent.GetComponent<EntityComponent>(); if (actionManager == null) actionManager = transform.parent.parent.FindChild("Attack").GetComponent<ActionManager>(); if (mySprite == null) mySprite = this.GetComponent<tk2dAnimatedSprite>(); //Attach ourselves to the relevant events entityComponent.onEntityDeath += HandleOnEntityDeath; entityComponent.onEntityDestroyed += HandleOnEntityDestroyed; if (actionManager != null) { actionManager.OnChargingActionEvent += HandleOnChargingActionEvent; actionManager.OnPerformingActionEvent += HandleOnActionEvent; actionManager.OnTargetHitEvent += HandleOnTargetHitEvent; } prevFacing = Facing.Right; playingIdleAnim = true; playingWalkAnim = false; playingEventAnim = false; mySprite.animationCompleteDelegate = OnAnimationComplete; mySprite.animationEventDelegate = OnAnimationEvent; //When the Entity moves we want to play the movement animation //When the Entity does a pre/during/post attack we want to play the pre/during/post attack animation //We'll have to check every once in a while to see if the entity is moving or not in Update and change the animation accordingly //while also keeping track of the fact that we don't want to co-opt other animations currently playing. }
public EntityComponentReference(EntityReference entity, PropertyKey component) { this.entity = entity; this.component = component; this.value = null; }
private static void GenerateSampleTemplate() { Assets.LoadAssets(); GameObject mockGo = new GameObject(); GameObject fxShrapnelPrefab = new GameObject("FX_Shrapnel"); TurnScheduler scheduler = mockGo.AddComponent <TurnScheduler>(); Locator.Scheduler = scheduler; EntityComponent[] components = new EntityComponent[] { new Actor() { Control = ActorControl.None }, new AI(new ApproachUtility(), new AttackUtility(), new FleeUtility()), new Ammo() { Type = AmmoType.Cartridges, Damages = new Damage[] { new Damage() { Type = DamageType.Piercing, Min = 3, Max = 7 } }, OnLandCommand = new ExplodeCommand(null) { Prefab = fxShrapnelPrefab, Pattern = ExplosionPattern.Square, Damages = new Damage[] { new Damage() { Type = DamageType.Searing, Min = 3, Max = 7 } } }, }, new Body(), new Corpse(), new Dialogue(), new Evocable(), new Health(), new Inventory(20), new Location(), new Melee( new MeleeAttack( new Damage[] { new Damage() { Type = DamageType.Slashing, Min = 2, Max = 5 } }, 80, 120)), new OnDamageTaken(), new OnUse(TurnScheduler.TurnTime), new Relic() { Name = "Orb of Zot" }, new Size(1), new Species(null), new Splat() { Sound = null }, new Status(), new Talented() { Talents = new Talent[] { new Talent() { ID = "Talent_Foobar" }, } }, new Weight(50), new Wield(2) }; EntityTemplate template = new EntityTemplate { ID = "SAMPLE_ID", EntityName = "SAMPLE_NAME", Flags = EntityFlag.Unique | EntityFlag.Blocking, Components = components, Inventory = new EntityTemplate[] { new EntityTemplate { ID = "Item_SampleItem" } }, Wielded = new EntityTemplate[] { new EntityTemplate { ID = "Item_SampleWeapon" } } }; string path = Application.dataPath + $"/Sample/sample_template.json"; if (File.Exists(path)) { File.Delete(path); } JsonSerializerSettings settings = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto, SerializationBinder = Binders._entity, Formatting = Formatting.Indented, Converters = new List <JsonConverter>() { new GameObjectConverter(), new SpriteConverter(), new TalentConverter(), new TileConverter(), new RuleTileConverter(), new SpeciesDefinitionConverter(), new BodyPartConverter(), new StatusConverter() } }; File.AppendAllText(path, JsonConvert.SerializeObject(template, settings)); AssetDatabase.Refresh(); Object.DestroyImmediate(mockGo as GameObject); Object.DestroyImmediate(fxShrapnelPrefab as GameObject); Debug.Log($"Wrote sample template with all components to {path}."); Assets.UnloadAssets(); }
protected void OnComponentRemovedEvent(Entity entity, EntityComponent component) { UnwatchComponent(component); FireRefreshRequest(entity); }
public static void ShowThruster(this EntityComponent entityComponent, ThrusterData data) { entityComponent.ShowEntity(typeof(Thruster), "Thruster", data); }
public static int GenerateSerialId(this EntityComponent entityComponent) { return(--s_SerialId); }
public BackgroundGizmo(EntityComponent component) : base(component, "Background", GizmoResources.BackgroundGizmo) { }
public void OnComponentChanged(Entity entity, int index, EntityComponent oldComponent, EntityComponent newComponent) { action(new EntityComponentEvent(entity, index, oldComponent, newComponent)); }
/// <summary> /// 自定义的实体显示方法 /// </summary> /// <param name="logicType">实体类型</param> /// <param name="entityGroup">实体组</param> /// <param name="path">实体路径</param> /// <param name="data">实体数据</param> public static void ShowCustomEntity(this EntityComponent entityComponent, Type logicType, string entityGroup, string seasonPath, string path, EntityData data) { entityComponent.ShowEntity(logicType, entityGroup, seasonPath, path, Constant.AssetPriority.GroundModelAsset, data); }
public static void ShowFruit(this EntityComponent entityCompoennt, FruitData data) { entityCompoennt.ShowEntity(typeof(Fruit), "Fruit", Constant.AssetPriority.FruitAsset, data); }
public static void AttachEntity(this EntityComponent entityComponent, Entity entity, int ownerId, string parentTransformPath = null, object userData = null) { entityComponent.AttachEntity(entity.Entity, ownerId, parentTransformPath, userData); }
public static void HideEntity(this EntityComponent entityComponent, Entity entity) { entityComponent.HideEntity(entity.Entity); }
public static EntityComponentReference New(EntityComponent entityComponent) { return new EntityComponentReference(entityComponent); }
public EntityLink(ComponentBase referencer, Script script, MemberPath path) { Referencer = referencer; Entity = null; EntityScript = script; EntityComponent = null; Path = path; }
public EntityComponentEvent(Entity entity, int index, EntityComponent oldComponent, EntityComponent newComponent) { Entity = entity; this.Index = index; OldComponent = oldComponent; NewComponent = newComponent; }
public PhysicsGizmo(EntityComponent component) : base(component) { }
private static IEnumerator WaitToHide(EntityComponent entityComponent, Entity entity, float fTime) { yield return(new WaitForSeconds(fTime)); HideEntity(entityComponent, entity); }
public static void ShowWeapon(this EntityComponent entityComponent, WeaponData data) { entityComponent.ShowEntity(typeof(Weapon), "Weapon", data); }
internal override void OnEntityComponentRemoved(EntityComponent component) { base.OnEntityComponentRemoved(component); }
public static void ShowAircraft(this EntityComponent entityComponent, AircraftData data) { entityComponent.ShowEntity(typeof(Aircraft), "Aircraft", data); }
public CustomEntityComponentEventArgs(CustomEntityComponentEventType type, Entity entity, EntityComponent component) { Type = type; Entity = entity; Component = component; }
protected void OnComponentAddedEvent(Entity entity, EntityComponent component) { WatchComponent(component); FireRefreshRequest(entity); }
public bool EntityContains <T>(EntityComponent entity) where T : IComponent { return(_allComponents[TypeRegistry <T> .typeID][(int)entity.id] != null); }
protected virtual void UnwatchComponent(EntityComponent component) { }
public T GetComponent <T>(EntityComponent entityID) where T : IComponent { return((T)_allComponents[TypeRegistry <T> .typeID][(int)entityID.id]); }
public BaseEditor(EntityComponent component, ComponentPropertyItem property) { Component = component; ComponentProperty = property; }
public static void HideEntity(this EntityComponent entityComponent, Entity entity, float fTime) { entityComponent.StartCoroutine(WaitToHide(entityComponent, entity, fTime)); }
public EntityComponentReference(EntityComponent entityComponent) { this.entity = new EntityReference { Id = entityComponent.Entity.Id }; this.component = entityComponent.GetDefaultKey(); this.value = entityComponent; }
public static void ShowEffect(this EntityComponent entityComponent, EffectData data) { entityComponent.ShowEntity(typeof(Effect), "Effect", data); }
public EntityLink(ComponentBase referencer, Entity entity, MemberPath path) { Referencer = referencer; Entity = entity; EntityScript = null; EntityComponent = null; Path = path; }
public static void ShowAsteroid(this EntityComponent entityCompoennt, AsteroidData data) { entityCompoennt.ShowEntity(typeof(Asteroid), "Asteroid", data); }
void HandleOnActionHitEvent(EntityComponent attacker, EntityComponent target) { if (hitActionEffectScript != null) { hitActionEffectScript.Target = target.transform; hitActionEffectScript.Visible = true; hitActionEffectScript.Play(); } }
public static void ShowBullet(this EntityComponent entityCompoennt, BulletData data) { entityCompoennt.ShowEntity(typeof(Bullet), "Bullet", data); }
void HandleOnActionStartedEvent(EntityComponent attacker, EntityComponent target) { if (startedActionEffectScript != null) { startedActionEffectScript.Target = target.transform; startedActionEffectScript.Visible = true; startedActionEffectScript.Play(); } }
public static void ShowArmor(this EntityComponent entityComponent, ArmorData data) { entityComponent.ShowEntity(typeof(Armor), "Armor", data); }
public LightSpotGizmo(EntityComponent component) : base(component, "Spot", GizmoResources.SpotLightGizmo) { }
public static T GetBaseEntity <T>(EntityComponent <T> entityComponent) where T : BaseEntity { var propertyInfo = entityComponent.GetType().GetProperty("baseEntity", BindingFlags.Instance | BindingFlags.NonPublic); return((T)propertyInfo.GetValue(entityComponent, null)); }