public MapPointObj(MapObjConf conf, InGameBaseMapObj obj, Vector2 pos, Vector3 scale) { this.conf = conf; this.obj = obj; this.pos = pos; this.scale = scale; }
void Atk() { state = ActionState.atkend; parent.SetAnimatorState(InGameBaseCharacter.AnimatorState.Idle, 1); if (target != null) { if (GameConst.CAMP_ATK[(int)target.camp, (int)parent.camp] == 0) { if (target.GetObjType() == InGameBaseObj.enObjType.map) { InGameBaseMapObj mapobj = (InGameBaseMapObj)target; bool isdie = mapobj.Hurt(parent); if (isdie) { state = ActionState.non; return; } } } else { BaseSkill.CreateSkill(parent.GetBaseSkillID(), parent, (InGameBaseCharacter)target); } } //((InGameBaseCharacter)target).ChangeLife(-parent.GetAtkForce()); }
//从池里取出一个物体 protected InGameBaseMapObj GetPoolObj(MapObjConf conf) { InGameBaseMapObj obj = null; if (!objPool.ContainsKey(conf.id) || objPool[conf.id].Count <= 0) { } else { List <InGameBaseMapObj> objlise = objPool[conf.id]; for (int i = 0; i < objlise.Count; i++) { obj = objlise[i]; if (obj.isAction) { continue; } objlise.RemoveAt(i); mapObjActionList.Add(obj); return(obj); } } return(CreateNewObj(conf)); }
//把物体放到池里 protected void AddPoolObj(int id, InGameBaseMapObj obj) { //obj.transform.position = new Vector3(-10000, 0, 0); if (!objPool.ContainsKey(id)) { objPool.Add(id, new List <InGameBaseMapObj>()); } objPool[id].Add(obj); mapObjActionList.Add(obj); obj.Hide(); }
InGameBaseMapObj CreateNewObj(MapObjConf conf) { GameObject column = (GameObject)Resources.Load(conf.path); if (column == null) { Debug.LogError(conf.path + " is null!!!!"); return(null); } GameObject insobj = MonoBehaviour.Instantiate(column); insobj.transform.parent = mapObj.transform; InGameBaseMapObj obj = insobj.GetComponent <InGameBaseMapObj>(); return(obj); }
void StartAtk() { state = ActionState.atkbegin; if (target == null || target.IsDie()) { state = ActionState.non; return; } if (Vector2.Distance(parent.transform.position, target.transform.position) > parent.GetAtkDis(target)) { state = ActionState.move; return; } if (GameConst.CAMP_ATK[(int)target.camp, (int)parent.camp] == 0) { if (target.GetObjType() == InGameBaseObj.enObjType.equip) { InGameBaseEquip equip = (InGameBaseEquip)target; EquipData e = EquipSystem.GetInstance().RandEquipProperty(equip); InGameManager.GetInstance().inGamePlayerManager.AddEquip(e); MonoBehaviour.Destroy(equip.gameObject); parent.StopAction(); return; } else if (target.GetObjType() == InGameBaseObj.enObjType.map) { InGameBaseMapObj mapobj = (InGameBaseMapObj)target; bool isfin = mapobj.HandleFuntion(parent); if (!isfin) { Debug.Log("stop action"); parent.StopAction(); return; } Debug.Log("continue action"); } } parent.SetAnimatorState(parent.GetAtkAnimator(), parent.GetAtkSpeed()); atkTime = 0; parent.SetDir(target.transform.position.x - parent.transform.position.x); }
static void OnSceneGUI(SceneView sceneView) { if (Event.current.type == EventType.MouseDown) { mouseStartDownpos = Event.current.mousePosition; return; } if (Event.current.type == EventType.MouseUp) { if (Vector3.Distance(mouseStartDownpos, Event.current.mousePosition) > 0.3f) { return; } //Event.current.Use(); if (Selection.gameObjects.Length <= 0) { return; } GameObject obj = Selection.gameObjects[0]; //Debug.Log(obj.name); InGameBaseMapObj mapObj = obj.GetComponent <InGameBaseMapObj>(); if (mapObj == null) { return; } MapObjConf conf = ConfigManager.GetEditorMapObjConfManager().map[mapObj.confid]; GameObject tempObj = Resources.Load(conf.path) as GameObject; tempObj = (GameObject)Instantiate(tempObj); tempObj.transform.position = GetWorldPosition(sceneView); tempObj.transform.parent = obj.transform.parent; GameCommon.SetObjZIndex(tempObj, conf.depth); //聚焦到当前物体 Selection.activeGameObject = tempObj; copyObj = tempObj; //Event.current.Use(); } }
public static void CreatePrefabs() { //获取场景中全部道具 Object[] objects = Object.FindObjectsOfType(typeof(GameObject)); GameObject prefabListObj = null; foreach (GameObject sceneObject in objects) { if (sceneObject.name == "prefabs") { prefabListObj = sceneObject; break; } } if (prefabListObj != null) { DestroyImmediate(prefabListObj); } prefabListObj = new GameObject("prefabs"); //==========================生成预制体================================ List <MapObjConf> confs = ConfigManager.GetEditorMapObjConfManager().datas; MapObjConfManager confMgr = ConfigManager.GetEditorMapObjConfManager(); UnityEngine.Object[] arr = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.TopLevel); //for (int i = 0; i < arr.Length; i++) //{ // string path = AssetDatabase.GetAssetPath(arr[i]); // Debug.Log(path); //} //GameObject[] gos = Selection.gameObjects; Material mat = Resources.Load <Material>("Materials/item_obj"); for (int i = 0; i < arr.Length; i++) { string path = AssetDatabase.GetAssetPath(arr[i]); Debug.Log(path); int indexnum = path.LastIndexOf('/') + 1; string prefabFullName = path.Substring(indexnum, path.Length - indexnum); Debug.Log(prefabFullName); indexnum = prefabFullName.LastIndexOf('.') + 1; string prefabName = prefabFullName.Substring(0, indexnum - 1); Debug.Log(prefabName); MapObjConf conf = confMgr.GetConfByPrefabName(prefabName); if (conf == null) { Debug.LogError(prefabName + " config is null!!"); continue; } GameObject gameObj = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Resources/" + conf.path + ".prefab"); if (gameObj != null) { continue; } Debug.Log("create " + prefabName + " prefab !"); //创建gameobject GameObject prefabObj = new GameObject(prefabName); InGameBaseMapObj mapobj = prefabObj.AddComponent <InGameBaseMapObj>(); mapobj.confid = conf.id; //加载sprite Sprite sprite = AssetDatabase.LoadAssetAtPath <Sprite>(path); if (sprite == null) { Debug.LogError(prefabName + " sprite is null !!!!"); continue; } //创建spriterenderer GameObject spriteObj = new GameObject("sprite"); SpriteRenderer sr = spriteObj.AddComponent <SpriteRenderer>(); spriteObj.transform.parent = prefabObj.transform; sr.sprite = sprite; spriteObj.transform.localScale = new Vector3(2.2f, 2.2f, 1f); spriteObj.transform.localPosition = new Vector3(0f, 0f, 0f); spriteObj.GetComponent <Renderer>().material = mat; //创建预制体 PrefabUtility.CreatePrefab("Assets/Resources/" + conf.path + ".prefab", prefabObj); //生成预制体物体 //GameObject tempObj = Resources.Load(conf.path) as GameObject; GameObject pre = AssetDatabase.LoadAssetAtPath("Assets/Resources/" + conf.path + ".prefab", typeof(GameObject)) as GameObject; pre = PrefabUtility.InstantiatePrefab(pre) as GameObject; //Debug.Log("create : " + prefabName); pre.transform.parent = prefabListObj.transform; DestroyImmediate(prefabObj); } }
//动态生成地面 public override void Update() { smallMap.Update(); Vector2 startPos = InGameManager.GetInstance().inGameCameraManager.GetCameraPos(); Vector2 startMapPos = GameCommon.GetMapPos(startPos); int startX = (int)startMapPos.x - UPDATE_MAP_SIZE / 2; int startY = (int)startMapPos.y - UPDATE_MAP_SIZE / 2; for (int i = 0; i < lastScreenObj.Count; i++) { Vector2 pos = lastScreenObj[i].pos; if (pos.x >= startX && pos.x < startX + UPDATE_MAP_SIZE && pos.y >= startY && pos.y < startY + UPDATE_MAP_SIZE) { continue; } List <MapPointObj> _list = lastScreenObj[i].objList; for (int j = 0; j < _list.Count; j++) { if (_list[j].obj == null) { continue; } AddPoolObj(_list[j].conf.id, _list[j].obj); _list[j].obj = null; } } lastScreenObj.Clear(); for (int x = 0; x < UPDATE_MAP_SIZE; x++) { for (int y = 0; y < UPDATE_MAP_SIZE; y++) { int sx = startX + x; int sy = startY + y; int _x = UPDATE_MAP_SIZE / 2 - x; int _y = UPDATE_MAP_SIZE / 2 - y; if (sx < 0 || sx >= map.GetLength(0)) { break; } if (sy < 0 || sy >= map.GetLength(1)) { continue; } bool isopen = false; //小地图中的点是否打开,如果已经打开 则不用计算距离 if (!smallMap.IsOpenPoint(sx, sy)) { if (Mathf.Sqrt(_x * _x + _y * _y) <= UPDATE_MAP_SIZE / 2) { isopen = true; } } InGameMapPointData data = map[sx, sy]; if (data == null) { if (isopen) { smallMap.OpenUnit(sx, sy, MazeCreate.PointType.nullpoint); } continue; } if (isopen) { smallMap.OpenUnit(sx, sy, data.type); } for (int i = 0; i < data.objList.Count; i++) { if (data.objList[i].obj == null) { MapPointObj mapPointObj = data.objList[i]; InGameBaseMapObj obj = GetPoolObj(mapPointObj.conf); obj.transform.position = GameCommon.GetWorldPos(mapPointObj.pos) + new Vector2(0, Random.Range(0, 0.1f)); obj.transform.localScale = mapPointObj.scale; GameCommon.SetObjZIndex(obj.gameObject, mapPointObj.conf.depth); mapPointObj.obj = obj; obj.Show(); mapObjActionList.Add(obj); } } lastScreenObj.Add(data); } } //处理mapobj 动画 for (int i = mapObjActionList.Count - 1; i >= 0; i--) { InGameBaseMapObj obj = mapObjActionList[i]; obj.ActionUpdate(); if (!obj.isAction) { mapObjActionList.RemoveAt(i); } } }