// Update is called once per frame void Update() { if (m_bCanLoadMap == false) { return; } m_fCurTime = GlobalVarFun.GetTime(); m_fDeltaTime = GlobalVarFun.GetSmoothDeltaTime(); // 地图更新 (包括普通的Collider) if (MapManager.Instance != null) { MapManager.Instance.Update(m_fDeltaTime, m_fCurTime); } // Role更新 TODO if (RoleManager.Instance != null) { RoleManager.Instance.Update(m_fDeltaTime, m_fCurTime); } // 时间事件更新 TODO // 伤害体更新 TODO if (DamageBodyManager.Instance != null) { DamageBodyManager.Instance.Update(m_fDeltaTime, m_fCurTime); } }
/// <summary> /// 添加伤害体 TODO /// </summary> /// <param name="damageBodyObj"></param> /// <param name="skillId"></param> /// <param name="damageId"></param> /// <returns></returns> public DamageBody AddDamageBody(BaseRole host, int dirX, int dirY, int skillId, int damageId) { if (MapManager.Instance == null || MapManager.Instance.HasCurMap == false) { return(null); } DamageBodyInfo dbInfo = DamageDataManager.Instance.GetDamageBodyInfo(damageId); if (dbInfo == null) { return(null); } GameObject obj = new GameObject(); if (obj == null) { return(null); } string handleName = skillId + "_" + GetHandleIndex(); // 没想好 obj.name = handleName; GlobalVarFun.AttachChild(m_rootObj, obj); DamageBody db = obj.AddComponent <DamageBody>(); db.InitDamage(host, handleName, dirX, dirY, skillId, dbInfo); m_damageBodyDic.Add(handleName, db); return(db); }
/// <summary> /// 设置Role初始数据 创建gameObject /// </summary> /// <param name="baseInfo"></param> /// <param name="initInfo"></param> public bool InitBaseRole(string handleName, BaseRoleInfo baseInfo, MapRoleInfo initInfo) { if (baseInfo == null || initInfo == null) { m_bStarted = false; return(false); } // 初始化数据 m_sHandleName = handleName; m_eRoleType = (eRoleType)initInfo.RoleType; m_baseInfo = baseInfo; m_initInfo = initInfo; m_fWidth = baseInfo.Width; m_fHeight = baseInfo.Height; m_fPosX = initInfo.InitPosX; m_fPosY = initInfo.InitPosY; int curHp = initInfo.InitHP; if (curHp == -1) { m_iCurHp = m_baseInfo.MaxHp; } else { m_iCurHp = curHp; } m_ulAction = (ulong)initInfo.InitStatus; m_curStatus = (ePhtatus)m_ulAction; m_bIsStatic = initInfo.IsStatic; m_bCanMove = initInfo.CanMove; // 初始化ShowObject GameObject prefabObj = Resource.LoadObj(m_baseInfo.PrefabName) as GameObject; if (null == prefabObj) { m_bStarted = false; return(false); } GameObject showObj = GameObject.Instantiate(prefabObj); showObj.name = "actor"; GlobalVarFun.AttachChild(gameObject, showObj); m_showObj = showObj; // 初始化m_mapRole if (m_mapRole == null) { m_mapRole = new MapRole(this); } m_mapRole.OnChangeMap(MapManager.Instance.curMapWorld, m_fPosX, m_fPosY, m_fWidth, m_fHeight); m_mapRole.SetInitData(m_baseInfo, m_initInfo); Clear(); m_bStarted = true; return(true); }
public DamageBodyManager() { _instance = this; m_rootObj = GlobalVarFun.GetGlobalObj("DamageBodyRoot"); if (m_rootObj == null) { m_bLoaded = false; return; } m_bLoaded = true; }
/// <summary> /// 设置伤害体初始数据 /// </summary> /// <returns></returns> public bool InitDamage(BaseRole host, string handleName, int dirX, int dirY, int skillId, DamageBodyInfo node) { if (host == null || node == null) { m_bStarted = false; return(false); } m_host = host; m_sHandleName = handleName; m_iSkillID = skillId; m_eDamageType = (eDamageBodyType)node.DamageType; m_eMoveType = (eDamageMoveType)node.MoveType; m_damageBodyInfo = node; // TODO 可能有很多个? GameObject prefabObj = Resource.LoadObj(m_damageBodyInfo.PrefabName) as GameObject; if (null == prefabObj) { m_bStarted = false; return(false); } GameObject showObj = GameObject.Instantiate(prefabObj); showObj.name = "node"; GlobalVarFun.AttachChild(gameObject, showObj); m_fWidth = m_damageBodyInfo.Width; m_fHeight = m_damageBodyInfo.Height; m_fEsTime = m_damageBodyInfo.EsTime; m_iDamageCount = m_damageBodyInfo.DamageCount; m_iDamage = m_damageBodyInfo.DamageValue; m_fPosX = host.m_fPositionX + m_damageBodyInfo.OffsetX; m_fPosY = host.m_fPositionY + m_damageBodyInfo.OffsetY; m_iDirX = dirX; m_iDirY = dirY; m_fVelocityX = dirX * m_damageBodyInfo.MoveVelocity; m_fVelocityY = dirY * m_damageBodyInfo.MoveVelocity; m_velocity.x = m_fVelocityX; m_velocity.y = m_fVelocityY; if (m_mapDamage == null) { m_mapDamage = new MapDamage(this); } m_mapDamage.InitB2Body(MapManager.Instance.curMapWorld, m_fPosX, m_fPosY, m_fWidth, m_fHeight); m_mapDamage.SetCurVelocityX(m_fVelocityX); m_mapDamage.SetCurVelocityY(m_fVelocityY); Clear(); m_bStarted = true; m_fBeginTime = GlobalVarFun.GetTime(); return(true); }
public bool AddRoleObj(string handleName, GameObject roleObj, MapRoleInfo initInfo) { BaseRole baseRole = null; if (true == initInfo.CanControl) { baseRole = CreatePlayer(roleObj); } else { baseRole = CreateBaseRole(roleObj); } if (baseRole == null) { return(false); } BaseRoleInfo baseInfo = RoleDataManager.Instance.GetRoleBaseInfo(initInfo.RoleID); if (baseInfo == null) { GameObject.Destroy(roleObj); return(false); } bool setSuc = baseRole.InitBaseRole(handleName, baseInfo, initInfo); if (setSuc) { GameObject sideObj = GetSideObj(initInfo.RoleType); if (sideObj == null) { sideObj = m_rootObj; } GlobalVarFun.AttachChild(sideObj, roleObj); m_roleDic.Add(handleName, baseRole); } else { GameObject.Destroy(roleObj); return(false); } return(true); }
public RoleManager() { _instance = this; m_rootObj = GlobalVarFun.GetGlobalObj("RoleRoot"); if (m_rootObj == null) { m_bLoaded = false; return; } for (int i = 0; i < 4; i++) { GameObject side = new GameObject(); // GlobalVarFun.GetChild(m_rootObj, "side_" + i); if (side == null) { break; } side.name = "side_" + i; GlobalVarFun.AttachChild(m_rootObj, side); m_sideList.Add(side); } m_bLoaded = true; }
// Update is called once per frame void Update() { if (m_bStarted == false) { return; } if (m_fEsTime != -1) { m_fEsTimer = m_fEsTimer + GlobalVarFun.GetSmoothDeltaTime(); if ((m_fEsTimer - m_fEsTime) < GlobalVarFun.FloatCompareRatio) { Destroy(); } } m_fSingleDamageTimer = m_fSingleDamageTimer + GlobalVarFun.GetSmoothDeltaTime(); if ((m_fSingleDamageTimer - m_fSingleDamageTime) < GlobalVarFun.FloatCompareRatio) { m_fSingleDamageTimer = 0; // 造成Damage OnDamage(); } UpdateMove(); }
protected void DrawBox2DBodyGizmos(VelcroPhysics.Dynamics.World b2World) { for (int ib = 0, count = b2World.BodyList.Count; ib < count; ++ib) { VelcroPhysics.Dynamics.Body body = b2World.BodyList[ib]; if (null == body) { continue; } Color fixtureColor; if (body.IsStatic) { fixtureColor = new Color(1, 0, 1); } else { if (body.BodyType == VelcroPhysics.Dynamics.BodyType.Kinematic) { fixtureColor = Color.yellow; } else { fixtureColor = Color.green; } if ((body._flags & VelcroPhysics.Dynamics.BodyFlags.AwakeFlag) == 0) { fixtureColor = Color.gray * 0.5f + fixtureColor * 0.5f; } } Microsoft.Xna.Framework.Vector2 center = body.WorldCenter; for (int ifix = 0, countFix = body.FixtureList.Count; ifix < countFix; ++ifix) { VelcroPhysics.Dynamics.Fixture fixture = body.FixtureList[ifix]; if (fixture.Friction > 5f) { fixtureColor.b = 1.0f; } if (fixture.Shape.ShapeType == VelcroPhysics.Collision.Shapes.ShapeType.Circle) { float radius = fixture.Shape.Radius * GlobalVarFun.DisplayToPhysicUnitRatio; Vector3 v3Center = GlobalVarFun.GetDisplayPosition(center.X, center.Y); Gizmos.color = fixtureColor; Gizmos.DrawWireSphere(v3Center, radius); } else if (fixture.Shape.ShapeType == VelcroPhysics.Collision.Shapes.ShapeType.Polygon) { var shape = fixture.Shape as VelcroPhysics.Collision.Shapes.PolygonShape; int vertexCount = shape.Vertices.Count; for (int iv = 0; iv < vertexCount; ++iv) { Microsoft.Xna.Framework.Vector2 src = (shape.Vertices[(iv) % vertexCount]); Microsoft.Xna.Framework.Vector2 des = (shape.Vertices[(iv + 1) % vertexCount]); src = ChangeRotation(body, src); des = ChangeRotation(body, des); Vector3 v3Src = GlobalVarFun.GetDisplayPosition(src.X, src.Y); Vector3 v3Des = GlobalVarFun.GetDisplayPosition(des.X, des.Y); v3Src.z = 0; v3Des.z = 0; Gizmos.color = fixtureColor; Gizmos.DrawLine(v3Src, v3Des); } } else if (fixture.Shape.ShapeType == VelcroPhysics.Collision.Shapes.ShapeType.Edge) { var shape = fixture.Shape as VelcroPhysics.Collision.Shapes.EdgeShape; Microsoft.Xna.Framework.Vector2 startPos = shape._vertex1; Microsoft.Xna.Framework.Vector2 endPos = shape._vertex2; Microsoft.Xna.Framework.Vector2 src = startPos; Microsoft.Xna.Framework.Vector2 des = endPos; src = ChangeRotation(body, src); des = ChangeRotation(body, des); Vector3 v3Src = GlobalVarFun.GetDisplayPosition(src.X, src.Y); Vector3 v3Des = GlobalVarFun.GetDisplayPosition(des.X, des.Y); v3Src.z = 0; v3Des.z = 0; Gizmos.color = fixtureColor; Gizmos.DrawLine(v3Src, v3Des); } } } }
public bool SaveData(string fileName) { if (m_nodes == null || m_nodes.Count <= 0) { return(false); } string reta = "ID,名字,Body类型,创建类型,位置,X大小(BOX),Y大小(BOX),半径,vertices点,Edge起点,Edge终点,IsBreakable,Break物体主物体名,过滤类型,默认是否激活,是否传感器,Senesor速度参数,是否单向通行,单项通行方向,Sensor是否固定,Sensor外加力方向"; reta += "\r\n"; reta += "ID,NAME,BODYTYPE,CREATETYPE,COLLISIONID,POSITION,SIZEX,SIZEY,RADIUS,VERTICES,STARTPOS,ENDPOS,ISBREAKABLE,BREAKMAINNAME,FILTERTYPE,ISACTIVE,ISSENSOR,SPEEDRATIO,ISONEWAY,ONEWAYDIR,ISSTUCKDIR,FORCEDOR"; reta += "\r\n"; for (int i = 0; i < m_nodes.Count; i++) { SingleNode nd = m_nodes[i]; if (nd != null) { reta += i.ToString(); reta += ","; reta += "Collider_" + i.ToString(); reta += ","; reta += "0"; reta += ","; reta += ((int)nd.type).ToString(); reta += ","; reta += "0"; reta += ","; reta += nd.position.x + ";" + nd.position.y; reta += ","; reta += nd.sizeX.ToString(); reta += ","; reta += nd.sizeY.ToString(); reta += ","; reta += nd.radius.ToString(); reta += ","; if (nd.vertices != null) { for (int j = 0; j < nd.vertices.Count; j++) { Vector2 vertice = nd.vertices[j]; reta += vertice.x + ";" + vertice.y; if (j != nd.vertices.Count - 1) { reta += "="; } } } reta += ","; reta += nd.startPos.x + ";" + nd.startPos.y; reta += ","; reta += nd.endPos.x + ";" + nd.endPos.y; reta += ","; reta += "FALSE"; reta += ","; reta += "0"; reta += ","; reta += "0"; reta += ","; reta += "TRUE"; reta += ","; reta += nd.isSensor; reta += ","; if (nd.sensorNode != null) { reta += nd.sensorNode.SpeedRatio; reta += ","; reta += nd.sensorNode.IsOneWay; reta += ","; reta += nd.sensorNode.OneWayDir.x + ";" + nd.sensorNode.OneWayDir.y; reta += ","; reta += nd.sensorNode.IsStuckDir; reta += ","; reta += nd.sensorNode.ForceDir.x + ";" + nd.sensorNode.ForceDir.y; } else { reta += ","; reta += ","; reta += ","; reta += ","; } reta += "\r\n"; } } string filePath = GlobalVarFun.m_streamAssets + "Map/" + fileName + ".csv"; GlobalVarFun.SaveStringToFile(reta, filePath); return(true); }