public override void Start(ActionUsingNode node) { base.Start(node); var model = ItemPool.Spawn(UnityDirs.Models, ModelData, Vector3.zero, Quaternion.identity); if (model != null) { node.ParentSpawn(model.Transform); node.ActionEvent.Action.Entity.Add(new RenderingComponent(model.GetComponent <IRenderingComponent>())); node.ActionEvent.Action.Entity.Add(new TransformComponent(model.transform)); } var dmgComponent = node.Entity.GetOrAdd <BlockDamage>(); if (!node.Entity.Tags.Contain(EntityTags.Player)) { dmgComponent.DamageBlockers.Add(BlockDamageFlat); _isWaiting = true; _vitalStat = null; return; } _vitalStat = node.Stats.GetVital(TargetVital); var skillMulti = 1f; if (!string.IsNullOrEmpty(_skill)) { var skillValue = node.Entity.FindStatValue(_skill); skillMulti = Mathf.Clamp(1 - (skillValue * CostVital.SkillPercent), CostVital.SkillMaxReduction, 1); } dmgComponent.CollisionHandlers.Add(EvadeDamageWithStats); _fxComponent = node.ActionEvent.Action.Fx; _finalCost = Cost * skillMulti; }
public void OnActionSpawn(ActionEvent state) { var focus = state.Target; if (focus == null) { return; } var rect = World.Get <CharacterRectSystem>().GetEntityRect(focus.Entity); //if (focus == null || !focus.HasComponent<PlayerComponent>()) { // return; //} if (rect == null) { return; } if (_matSource == null) { _matSource = GetComponent <Renderer>(); } var spawn = ItemPool.Spawn(StringConst.ParticleUI, false, false); var altParticle = spawn.GetComponent <UIAnimation>(); if (altParticle == null) { Debug.LogErrorFormat("{0} tried to convert to UI animation for {1} targeting {2} at state {3} spawn {4}", name, state.State, focus.Get <LabelComponent>(), state, spawn.name); ItemPool.Despawn(spawn); return; } altParticle.transform.SetParent(rect.RectTr); altParticle.Play(_animationUi, _matSource != null ? _matSource.sharedMaterial : null); ItemPool.Despawn(gameObject); }
private void SpawnModel(Transform parent) { var model = ItemPool.Spawn(_modelName); if (parent != null) { model.transform.SetParentResetPos(parent); } _loadedModel = model.GetComponent <IModelComponent>(); if (_loadedModel == null) { ItemPool.Despawn(model.gameObject); return; } var entity = this.GetEntity(); MonoBehaviourToEntity.RegisterToEntity(model.gameObject, entity); _loadedComponents.Add(entity.Add(new ModelComponent(_loadedModel))); entity.Tr = model.Transform; _loadedComponents.Add(entity.Add(new FloatingTextStatusComponent(model.Transform, new Vector3(0, 1.5f, 0)))); var animTr = model.GetComponent <IAnimTr>(); if (animTr != null) { _loadedComponents.Add(entity.Add(new AnimTr(animTr.AnimTr))); } var rb = model.GetComponent <Rigidbody>(); if (rb != null) { _loadedComponents.Add(entity.Add(new RigidbodyComponent(rb))); } }
public static void Log(string text, float length = 2f) { if (!Application.isPlaying) { Debug.Log(text); return; } if (main == null) { return; } if (_lastText == text) { return; } _lastText = text; var newText = main._textTimers.New(); ItemPool.Spawn(LazyDb.Main.DebugTextTemp, textObject => { textObject.Transform.parent = main.TempRoot; textObject.GetComponent <Text>().text = text; newText.Time.StartNewTime(length); newText.TextObject = textObject.gameObject; main._tempText.Add(newText); }); }
public void Handle(ActionStateEvent arg) { if (arg.State == EndEvent && _activeGameObject != null) { ItemPool.Despawn(_activeGameObject); } else if (arg.State == StartEvent && Prefab != null) { var animTr = this.Get <AnimTr>().Tr; if (Parent && animTr != null) { _activeGameObject = ItemPool.Spawn(Prefab); if (_activeGameObject != null) { _activeGameObject.transform.SetParentResetPos(animTr); } } else { this.GetEntity().FindSpawn(out var spawnPos, out var spawnRot); _activeGameObject = ItemPool.Spawn(Prefab, spawnPos, spawnRot); } if (EndEvent == ActionStateEvents.None) { _activeGameObject = null; } } }
public static void UpdatePermText(string label, string text) { if (!Application.isPlaying) { Debug.Log(text); return; } if (main == null) { return; } if (!main._permTextDict.TryGetValue(label, out var objText)) { ItemPool.Spawn(LazyDb.Main.DebugTextPerm, textObject => { textObject.Transform.parent = main.PermRoot; objText = textObject.GetComponent <Text>(); objText.text = string.Format("{0} - {1}", label, text); main._permTextDict.Add(label, objText); }); } else { objText.text = string.Format("{0} - {1}", label, text); } }
public void Trigger(ActionUsingNode node, string eventName) { var model = ItemPool.Spawn(UnityDirs.Models, Data, Vector3.zero, Quaternion.identity); if (model != null) { node.ParentSpawn(model.Transform); node.ActionEvent.Action.Entity.Add(new RenderingComponent(model.GetComponent <IRenderingComponent>())); } }
public void Handle(ReadyActionsChanged arg) { if (arg.Action == null) { return; } var weaponModelComponent = arg.Action.Weapon; if (weaponModelComponent == null) { if (arg.Container == null) { arg.Action.Entity.Remove <SpawnPivotComponent>(); } else { var actionPivots = arg.Container.GetEntity().Get <ActionPivotsComponent>(); if (actionPivots != null) { arg.Action.Entity.Add(new SpawnPivotComponent(arg.Action.Config.Primary ? actionPivots.PrimaryPivot : actionPivots .SecondaryPivot)); } } return; } if (arg.Container == null) { ItemPool.Despawn(weaponModelComponent.Loaded.Tr.gameObject); arg.Action.Entity.Remove <TransformComponent>(); arg.Action.Entity.Remove <SpawnPivotComponent>(); weaponModelComponent.Set(null); } else { if (weaponModelComponent.Loaded != null) { return; } var weaponModel = ItemPool.Spawn(UnityDirs.Weapons, weaponModelComponent.Prefab, Vector3.zero, Quaternion.identity, false, false); if (weaponModel == null) { return; } var projectileSpawn = arg.Container.GetEntity().Get <ActionPivotsComponent>(); if (projectileSpawn != null) { weaponModel.Transform.SetParentResetPos(arg.Action.Config.Primary? projectileSpawn.PrimaryPivot : projectileSpawn .SecondaryPivot); } weaponModelComponent.Set(weaponModel.GetComponent <IWeaponModel>()); arg.Action.Entity.Add(new TransformComponent(weaponModel.transform)); arg.Action.Entity.Add(new SpawnPivotComponent(weaponModel.Transform)); } }
protected PrefabEntity GetWorldEntity() { var db = ScriptableDatabases.GetDatabase(_db); var entity = db.GetObject <PrefabEntity>(_name); if (entity != null) { return(ItemPool.Spawn(entity)); } var go = db.GetObject <GameObject>(_name); return(go != null?ItemPool.Spawn(go) : null); }
public static void SpawnProjectile(Entity owner, ProjectileConfig config, Vector3 target, Vector3 spawnPos, Quaternion spawnRot, ActionFx actionFx = null) { var entity = Main.GetProjectile(config); entity.ParentId = owner.Id; var projectileEvent = _loadPool.New(); if (config.Type == ProjectileType.SpriteAnimation) { config.Animation.LoadAsset(); } projectileEvent.Set(config, entity, target, spawnPos, spawnRot, actionFx); ItemPool.Spawn(projectileEvent); }
public void TriggerSpawn(SpawnOnEvent spawnEvent, ActionEvent arg) { if (arg.State == spawnEvent.End && spawnEvent.ActiveGameObject != null) { ItemPool.Despawn(spawnEvent.ActiveGameObject); } else if (arg.State == spawnEvent.Start && spawnEvent.Prefab != null) { arg.GetSpawnPositionRotation(out var spawnPos, out var spawnRot); spawnEvent.ActiveGameObject = ItemPool.Spawn(spawnEvent.Prefab, spawnPos, spawnRot); if (spawnEvent.End == ActionState.None) { spawnEvent.ActiveGameObject = null; } } }
public SimplePathfindingAgent SetupPathfindEntity(Entity entity) { if (!entity.HasComponent <MoveSpeed>()) { entity.Add(new MoveSpeed(_pathfinderMoveSpeed)); } if (_debugAgents) { var spawned = ItemPool.Spawn(UnityDirs.System, "PathfindDebug", Vector3.zero, Quaternion.identity, false, false); spawned.transform.SetParent(entity.Tr); spawned.transform.localPosition = new Vector3(0, 2, 0); spawned.transform.localRotation = Quaternion.Euler(90, 0, 0); entity.Add(new PathfindingDebugging(spawned.GetComponentInChildren <LineRenderer>(), spawned.GetComponentInChildren <TextMesh>())); } return(entity.Add(new SimplePathfindingAgent(_grid, _pathfinderRepathTime))); }
private void HandleLoader(EquipmentChanged arg, ModelLoaderComponent loader) { if (!loader.OnlyActiveWhileEquipped) { return; } var entity = arg.Owner; if (arg.Owner == null && loader.LoadedComponents.Count > 0) { UnityToEntityBridge.Unregister(entity); for (int i = 0; i < loader.LoadedComponents.Count; i++) { entity.Remove(loader.LoadedComponents[i]); } loader.LoadedComponents.Clear(); loader.LoadedModel = null; } else if (arg.Owner != null && loader.LoadedModel == null) { var parent = arg.Slot.EquipTr; var model = ItemPool.Spawn(loader.ModelName); if (parent != null) { model.transform.SetParentResetPos(parent); } loader.LoadedModel = new CachedGenericComponent <IRenderingComponent>(model.GetComponent <IRenderingComponent>()); if (loader.LoadedModel == null) { ItemPool.Despawn(model.gameObject); return; } UnityToEntityBridge.RegisterToEntity(model.gameObject, entity); loader.LoadedComponents.Add(entity.Add(new RenderingComponent(loader.LoadedModel.Value)).GetType()); loader.LoadedComponents.Add(entity.Add(new TransformComponent(model.Transform)).GetType()); loader.LoadedComponents.Add( entity.Add(new FloatingTextStatusComponent(model.Transform, new Vector3(0, 1.5f, 0))).GetType()); var rb = model.GetComponent <Rigidbody>(); if (rb != null) { loader.LoadedComponents.Add(entity.Add(new RigidbodyComponent(rb)).GetType()); } } }
public void Trigger(ActionEvent ae, string eventName) { var model = ItemPool.Spawn(UnityDirs.Models, Data, Vector3.zero, Quaternion.identity); if (model != null) { var spawn = ae.Origin.Entity.Get <SpawnPivotComponent>(); if (spawn != null) { spawn.SetNewChild(model.Transform); } else { ae.Origin.Tr.SetParent(model.Transform); model.Transform.ResetPos(); } ae.Action.Entity.Add(new RenderingComponent(model.GetComponent <IRenderingComponent>())); } }
public void TriggerSpawn(SpawnOnEvent spawnEvent, ActionStateEvent arg) { if (arg.State == spawnEvent.EndEvent && spawnEvent.ActiveGameObject != null) { ItemPool.Despawn(spawnEvent.ActiveGameObject); } else if (arg.State == spawnEvent.StartEvent && spawnEvent.Prefab != null) { var animData = arg.Origin.Entity.Find <AnimatorComponent>(); var spawnPos = animData?.Value?.GetEventPosition ?? (arg.Origin.Tr != null ? arg.Origin.Tr.position : Vector3.zero); var spawnRot = animData?.Value?.GetEventRotation ?? (arg.Origin.Tr != null ? arg.Origin.Tr.rotation : Quaternion.identity); spawnEvent.ActiveGameObject = ItemPool.Spawn(spawnEvent.Prefab, spawnPos, spawnRot); if (spawnEvent.EndEvent == ActionStateEvents.None) { spawnEvent.ActiveGameObject = null; } } }
public void Trigger(ActionEvent ae, string eventName) { ItemPool.Spawn(Data, model => { if (model != null) { var spawn = ae.Origin.Entity.Get <SpawnPivotComponent>(); if (spawn != null) { spawn.SetNewChild(model.Transform); } else { ae.Origin.Tr.SetParent(model.Transform); model.Transform.ResetPos(); } ae.Action.Entity.Add(new RenderingComponent(model.GetComponent <IRenderingComponent>())); } }); }
private void SpawnPrefab(SpawnPrefabOnDeath spawnComponent, DeathEvent arg) { var position = arg.Target.Tr.position; var count = spawnComponent.CountRange.Get(); if (count <= 0) { return; } for (int i = 0; i < count; i++) { var spawnPos = position + Random.insideUnitSphere * (spawnComponent.Radius * 0.5f); spawnPos.y = position.y; var spawn = ItemPool.Spawn(UnityDirs.Items, spawnComponent.Prefab, Vector3.Lerp(spawnPos, spawnPos + Vector3.up, Random.value), Quaternion.identity, true); if (spawn == null) { continue; } var rb = spawn.GetComponent <FakePhysicsObject>(); if (rb == null) { continue; } WhileLoopLimiter.ResetInstance(); while (WhileLoopLimiter.InstanceAdvance()) { var throwPos = spawnPos + (Random.insideUnitSphere * spawnComponent.Radius); throwPos.y = position.y; if (!Physics.Linecast(spawn.transform.position, throwPos, LayerMasks.Environment)) { if (Physics.Raycast(throwPos, Vector3.down, out var hit, 5f, LayerMasks.Floor)) { throwPos = hit.point; } rb.Throw(throwPos); break; } } } }
public override void OnEnter(RuntimeStateNode lastNode) { base.OnEnter(lastNode); var action = Graph.Entity.Get <CurrentAction>()?.Value; if (action == null) { return; } _actionEntity = action.Entity; _owner = Graph.Entity.GetTemplate <ActionUsingTemplate>(); _config = _actionEntity.Get <BlockDamageAction>(); var model = ItemPool.Spawn(UnityDirs.Models, _config.ModelData, Vector3.zero, Quaternion.identity); if (model != null) { var spawnPivot = _actionEntity.Get <SpawnPivotComponent>(); spawnPivot.SetNewChild(model.Transform); _actionEntity.Add(new RenderingComponent(model.GetComponent <IRenderingComponent>())); _actionEntity.Add(new TransformComponent(model.transform)); } if (!Graph.Entity.Tags.Contain(EntityTags.Player)) { Graph.Entity.Add(new BlockDamageFlat()); _isWaiting = true; _vitalStat = null; return; } _vitalStat = _owner.Stats.GetVital(_config.TargetVital); var skillMulti = 1f; if (!string.IsNullOrEmpty(_config.Skill)) { var skillValue = _owner.Entity.FindStatValue(_config.Skill); skillMulti = Mathf.Clamp(1 - (skillValue * CostVital.SkillPercent), CostVital.SkillMaxReduction, 1); } Graph.Entity.GetOrAdd <RuleEventListenerComponent>().Handlers.Add(this); _fxComponent = action.Fx?.Value; _finalCost = _config.Cost * skillMulti; }
public Entity SpawnProjectile(Entity owner) { var spawnComponent = owner.Get <ActionSpawnComponent>(); var entity = GetProjectile(spawnComponent.Data); entity.Get <DespawnTimer>().StartTimer(); if (string.IsNullOrEmpty(spawnComponent.Prefab)) { return(entity); } owner.FindSpawn(out var spawnPos, out var spawnRot); var spawn = ItemPool.Spawn(UnityDirs.Projectiles, spawnComponent.Prefab, spawnPos, spawnRot); if (spawn == null) { return(entity); } entity.Tr = spawn.Transform; entity.Add(new RigidbodyComponent(spawn.GetComponent <Rigidbody>())); entity.Get <ModelComponent>().Model = spawn.GetComponent <IModelComponent>(); MonoBehaviourToEntity.RegisterToEntity(spawn.gameObject, entity); entity.ParentId = owner.Id; return(entity); }
public GameObject ToGameObject(Transform parent) { GameObject go = null; PrefabEntity mc = null; switch (_metadata.AssetType) { case AssetType.Prefab: mc = ItemPool.Spawn(_metadata.PrefabPath); if (mc != null) { go = mc.gameObject; //Metadata.ComponentDiff.ApplyPatch(go); } break; } if (go == null) { go = new GameObject(); mc = go.GetOrAddComponent <PrefabEntity>(); AddComponentsToNewGo(go); } mc.Metadata = _metadata; go.name = _name; if (parent != null) { go.transform.SetParent(parent); } _tr.Restore(go.transform); foreach (var childNode in _children) { var child = childNode.ToGameObject(go.transform); child.transform.SetParent(go.transform); } return(go); }
protected PrefabEntity GetWorldEntity() { return(ItemPool.Spawn(_path)); }
public Entity SpawnProjectile(Entity owner, string id, Vector3 target, Vector3 spawnPos, Quaternion spawnRot) { if (_templates.Count == 0) { Init(); } if (!_templates.TryGetValue(id, out var template)) { #if DEBUG DebugLog.Add("Couldn't find project template " + id, false); #endif return(null); } var entity = GetProjectile(template); var node = entity.GetNode <ProjectileNode>(); node.MoveTarget.SetMoveTarget(target); if (template.ActionFx != null) { node.ActionFx.ChangeFx(template.ActionFx); } var prefab = ItemPool.Spawn(UnityDirs.ActionSpawn, template.Type, spawnPos, spawnRot); if (prefab == null) { return(entity); } var spawn = prefab.GetComponent <IProjectile>(); entity.Add(new TransformComponent(prefab.Transform)); switch (template.Type) { default: case "Simple": break; case "SpriteAnimation": spawn.SetColor(template.MainColor, Color.white * template.GlowPower); if (template.Animation != null) { var spriteRenderer = prefab.Renderers[0] as SpriteRenderer; entity.Add(new SpriteAnimationComponent(spriteRenderer, template.Animation, false, template.Billboard)); } break; case "VolumeLaser": spawn.SetColor(template.MainColor, template.OffsetColor); break; } spawn.SetSize(template.Size, template.Length); switch (template.Movement) { case "Forward": case "Arc": prefab.Transform.LookAt(target, prefab.Transform.up); break; case "Force": //var force = transform.forward * ForceRange.Lerp(Mathf.Clamp01(charging.ElapsedTime / MaxChargeTime)); break; } if (spawn.Rigidbody != null) { node.Rb.SetRb(spawn.Rigidbody); } entity.Tags.Add(EntityTags.Moving); node.Rendering.Set(spawn); UnityToEntityBridge.RegisterToEntity(prefab.Transform.gameObject, entity); entity.ParentId = owner.Id; entity.Post(new ProjectileSpawned(template, entity)); return(entity); }
public static void Spawn(string text, float duration, Vector3 start, Vector3 end) { var spawn = ItemPool.Spawn <FloatingText>("UI/FloatingTextStandard", start, Quaternion.identity, true, false); spawn.StartText(text, duration, end); }
public static void Message(string message, Vector3 start) { var spawn = ItemPool.Spawn <FloatingText>("UI/FloatingTextStandard", start, Quaternion.identity, true, false); spawn.StartText(message, 1.5f, start + DefaultEnd); }
public static void Damage(float amount, Vector3 start) { var spawn = ItemPool.Spawn <FloatingText>("UI/FloatingTextDamage", start, Quaternion.identity, true, false); spawn.StartText(amount.ToString("F0"), 4f, start + DefaultEnd); }
public static void Message(string message, Vector3 start, Color color) { var spawn = ItemPool.Spawn <FloatingText>(UnityDirs.UI, "FloatingTextStandard", start, Quaternion.identity, true, false); spawn.StartText(message, 1.5f, start + DefaultEnd, color); }