using System; using System.Collections.Generic; using UnityEngine; using Entitas; using Game; using Articy.Touhou; using CleverCrow.Fluid.BTs.Trees; using FluidDynamics; namespace Game { public abstract partial class Util { public static Dictionary CompKeymap; public static int GetCompnentIndex() { if (CompKeymap == null) { CompKeymap = new Dictionary(); var compTypes = GameComponentsLookup.componentTypes; for (int i = 0; i < compTypes.Length; i++) { CompKeymap[compTypes[i]] = i; } } return CompKeymap[typeof(T)]; } } } public partial class GameEntity { static GameEntity() { } public void AddComponent() where T : IComponent { var index = Util.GetCompnentIndex(); var component = (T)CreateComponent(index, typeof(T)); AddComponent(index, component); } public void AddID(string cfgId, EntityCreateHandler callback) { var newId = UtilID.GetID(EIdType.Entity); AddID(newId, new CommonData()); iD.Data.IsCreate = true; iD.Data.IsDestroy = false; iD.Data.CfgId = cfgId; iD.Data.CreateCallback = callback; } public void AddMonsterView(string[] prefabNames) { var cfg = Util.GetMonsterConfigData(CfgId()); var monsterCfg = cfg.GetFeatureEntityParamMonster(); AddView(prefabNames[(int)monsterCfg.MonsterSize]); } public void AddView(string prefabPath) { AddComponent(); var entityPoolItem = EntityPoolManager.Instance.CreateEntity(prefabPath); var go = entityPoolItem.GameObject; view.EntityPoolItem = entityPoolItem; view.GameObject = go; view.GameObjectLogic = go.transform.Find("logic").gameObject; view.TransformLogic = view.GameObjectLogic.transform; view.TransformView = go.transform.Find("view"); view.TransformViewRot = go.transform.Find("view/viewRot"); view.TransformViewOffset = go.transform.Find("view/viewRot/viewOffset"); view.TransformViewMain = go.transform.Find("view/viewRot/viewOffset/animator"); view.TransformViewOther = go.transform.Find("view/other"); view.SpriteRenderer = view.TransformViewMain.GetComponent(); view.SpriteRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On; view.SpriteRenderer.receiveShadows = true; view.Material = view.SpriteRenderer.material; view.Collider = go.GetComponent(); view.LocalPositionOrder = Vector3.forward * GameRandom.Random(0, 0.01f); view.TransformViewRot.localRotation = GameConst.CommonRot; } public void AddMove() { AddComponent(); var go = view.GameObject; move.Transform = go.transform; move.TransformViewMain = view.TransformViewMain; move.Rigidbody = go.GetComponent(); move.MoveParam = new MoveParam(); } public void AddAnimation() { AddComponent(); var go = view.GameObject; animation.Animator = go.GetComponentInChildren(); animation.AnimatorOverrideController = new AnimatorOverrideController(animation.Animator.runtimeAnimatorController); animation.Animator.runtimeAnimatorController = animation.AnimatorOverrideController; animation.ResetMsg = true; } public void AddTimeline() { AddComponent(); timeline.Timeline = new TimelineObject(); } public void AddSkill() { AddComponent(); } public void AddCombo() { AddComponent(); //test 必须先加武器再加技能 Util.SetWeaponListAll(this); Util.AddSkillAll(this); } public void AddHp() { AddComponent(); hp.IsDamaged.Value = false; } public void AddPause() { AddComponent(); } public void AddInteract(EInteractType interactType) { AddComponent(); interact.InteractType = interactType; } public void AddBullet() { AddComponent(); } public void AddAI() { AddComponent(); aI.ThinkCdMax = 1; //保底思考频率1秒 aI.HungryMax.Value = 1; //保底最大饥饿值1 } public void AddBuff() { AddComponent(); } public void AddMasterSoul() { AddComponent(); masterSoul.Emitter = view.TransformViewMain.GetComponentInChildren(); } public void AddPoint() { AddComponent(); } public void AddBag() { AddComponent(); } public void AddProperty() { AddComponent(); Util.ClearProperty(this); } }