void Start() { config = MagicConfig.Get(MagicId); lifeTime = config.Duration / 1000f; delay = config.Delay / 1000f; period = config.Period / 1000f; }
new void Start() { base.Start(); var card = GetComponent <Property>().CardID; var _unitID = CardConfig.Get(card).Value; skillID = UnitConfig.Get(_unitID).Skill; skillCD = UnitConfig.Get(_unitID).SkillCD; magicC = MagicConfig.Get(skillID); }
void IDragHandler.OnDrag(PointerEventData eventData) { transform.position = Input.mousePosition; var image = gameObject.GetComponent <Image>(); var ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, int.MaxValue, 1 << LayerMask.NameToLayer(CONSTANT.CONST.LAYER_GROUND))) { image.enabled = false; if (prefab) { prefab.SetActive(true); prefab.transform.position = hit.point; } else { var config = CardConfig.Get(cardID); switch ((ENUM_TYPE)config.Type) { case ENUM_TYPE.UNIT: var path = UnitConfig.Get(config.Value).Resource; prefab = Instantiate(Resources.Load(path), GameObject.Find(CONSTANT.CONST.PATH_AREA_A).transform) as GameObject; foreach (var component in prefab.GetComponents <Component>()) { if (!(component is Transform)) { Destroy(component); } } prefab.transform.position = hit.point; prefab.transform.Rotate(new Vector3(0, 90, 0)); break; case ENUM_TYPE.MAGIC: var path2 = MagicConfig.Get(config.Value).Resource; prefab = Instantiate(Resources.Load(path2), GameObject.Find(CONSTANT.CONST.PATH_AREA_A).transform) as GameObject; prefab.transform.position = hit.point; break; default: Debug.LogError("ENUM_TYPE can not find"); break; } } } else { image.enabled = true; if (prefab) { prefab.SetActive(false); } } }
public void CreateMagic(int id, Vector3 position) { var path = MagicConfig.Get(id).Resource; var parent = GameObject.Find(CONSTANT.CONST.PATH_BORN_C).transform; var obj = Instantiate(Resources.Load(path), position, Quaternion.Euler(new Vector3(0, 90, 0)), parent) as GameObject; var ppt = obj.GetComponent <Property>(); ppt.CardID = id; ppt.Side = ENUM_SIDE.A; ppt.UnitType = ENUM_UNIT_TYPE.OTHER; }
static List <GameObject> SearchTarget(MagicConfig config, Transform parent, Property ppt) { List <GameObject> result = new List <GameObject>(); //遍历所有 List <GameObject> list = null; if (!FightSystem.Instance) { return(null); } switch ((ENUM_TARGET)config.SideType) { case ENUM_TARGET.ANY: break; case ENUM_TARGET.OTHER: if (ppt.Side == ENUM_SIDE.A) { list = FightSystem.Instance.SideB; } else if (ppt.Side == ENUM_SIDE.B) { list = FightSystem.Instance.SideA; } break; case ENUM_TARGET.SAME: if (ppt.Side == ENUM_SIDE.A) { list = FightSystem.Instance.SideA; } else if (ppt.Side == ENUM_SIDE.B) { list = FightSystem.Instance.SideB; } break; default: Debug.LogError("ENUM_TARGET can not find"); break; } //范围 switch ((ENUM_RANGE)config.RangeType) { case ENUM_RANGE.SINGLE: GameObject temp = null; var dis = Mathf.Infinity; if (list != null && list.Count > 0) { foreach (var obj in list) { if (obj) { if (obj != parent.gameObject) { var _temp = parent.position - obj.transform.position; var tempDis = _temp.sqrMagnitude; if (tempDis < dis) { dis = tempDis; temp = obj; } } } } } result.Add(temp); break; case ENUM_RANGE.COLLIDER: break; case ENUM_RANGE.ALL: result.AddRange(list); if (result.Contains(parent.gameObject)) { result.Remove(parent.gameObject); } break; default: Debug.LogError("ENUM_RANGE can not find"); break; } return(result); }
public static void Init(MagicConfig config, Transform parent, Property ppt) { //确定目标(可能多个) var targets = SearchTarget(config, parent, ppt); //连接方式(没有目标) if ((ENUM_RANGE)config.RangeType == ENUM_RANGE.COLLIDER) { var obj = Instantiate(Resources.Load(config.Resource), parent) as GameObject; var magic = obj.GetComponent <Magic>(); magic.MagicId = config.ID; magic.Parent = ppt; obj.transform.parent = GameObject.Find(CONSTANT.CONST.PATH_BORN_C).transform; } else { foreach (var target in targets) { //加载特效 var obj = Instantiate(Resources.Load(config.Resource)) as GameObject; var magic = obj.GetComponent <Magic>(); magic.MagicId = config.ID; magic.Parent = ppt; magic.Target = target; switch ((ENUM_CONNECT)config.Connect) { case ENUM_CONNECT.AIR: obj.transform.parent = target.transform; Util.ResetObj(obj); break; case ENUM_CONNECT.PROJECTILE: obj.transform.parent = parent.transform; Util.ResetObj(obj); break; case ENUM_CONNECT.LASER: obj.transform.parent = parent.transform; Util.ResetObj(obj); break; case ENUM_CONNECT.LINE: obj.transform.parent = GameObject.Find(CONSTANT.CONST.PATH_BORN_C).transform; Util.ResetObj(obj); var line = obj.GetComponent <UVChainLightning>(); line.start = parent; line.target = target.transform; break; case ENUM_CONNECT.CHAIN: obj.transform.parent = GameObject.Find(CONSTANT.CONST.PATH_BORN_C).transform; Util.ResetObj(obj); var chain = obj.GetComponent <UVChainLightning>(); chain.start = parent; chain.target = target.transform; break; case ENUM_CONNECT.PRISM: obj.transform.parent = GameObject.Find(CONSTANT.CONST.PATH_BORN_C).transform; Util.ResetObj(obj); var prism = obj.GetComponent <UVChainLightning>(); prism.start = parent; prism.target = target.transform; break; default: Debug.LogError("ENUM_CONNECT can not find"); break; } } } }