public void removeComponent(CComponent component, int layer) { _layers[layer].removeComponent(component); _componentRegistry.Remove(component); CMasterControl.commNet.Remove(component.address); _hasMapStateChanged = true; }
public void AddCom(CComponent com) { if (cobj != null) { cobj.AddCom(com); } }
public CComponent AddCComponent(Type type) { Type baseType = GetBaseType(type); CComponent oldComponent = null; if (m_ComponentMap.TryGetValue(baseType, out oldComponent)) { //判断新的组件是否由旧的组件派生 Type newType = type; if (oldComponent.GetType().IsAssignableFrom(newType) && oldComponent.GetType() != type) { //删除旧的组件并添加新的组件 RemoveCComponent(oldComponent); } else { //不用添加新的组件,因为新的组件的派生组件已在添加到实体里 return(GetCComponent(type)); } } CComponent component = CComponent.CreateComponent(type, this); m_ComponentMap.Add(baseType, component); if (entityState == EntityState.Alive) { component.InitializeComplete(); } return(component); }
private bool getComponentParameter(GameObject controller, CComponent comp) { bool ret = false; var ch = controller.transform.childCount; for (int i = 0; i < ch; i++) { GameObject child = controller.transform.GetChild(i).gameObject; if (comp == CComponent.Beam) { WaveVR_Beam wb = child.GetComponentInChildren <WaveVR_Beam>(); if (wb != null) { ret = wb.ShowBeam; PrintDebugLog("getComponentParameter() wb.ShowBeam is " + ret); break; } } else if (comp == CComponent.ControllerPointer) { WaveVR_ControllerPointer wcp = child.GetComponentInChildren <WaveVR_ControllerPointer>(); if (wcp != null) { ret = wcp.ShowPointer; PrintDebugLog("getComponentParameter() wcp.ShowPointer is " + ret); break; } } } return(ret); }
public void AddCom(CComponent com) { if (com == null) { Debug.LogError("CObject AddComponent error! com == null"); return; } if (mGameObj == null) { mGameObj = com.gameObject.transform.parent.gameObject; } else { if (mGameObj != com.gameObject.transform.parent.gameObject) { Debug.LogError("CObject AddComponent error! com.gameObject name:" + com.gameObject.transform.parent.gameObject.name); return; } } com.cobj = this; mComList.Add(com); // really add to game object // mGameObj.AddComponent(com.GetType()); mComDict[com.GetType().Name] = com; com.OnAttach(); }
public override void OnAttach() { CComponent acom = cobj.GetCom("AttrCom"); attrCom = acom as AttrCom; RegBroadcastEvent((int)Const_Util.BATTLE_EVENT.USE_GAS); }
//private CComponent compTest; //private CComponent menuComo; //Actors.Player.CPlayer[] perfTest; //CComponent perfComp = new CComponent(); //CComponent npcTester = new CComponent(); //Actors.NPC.Enemies.Chuchus.CGreenChuChu green = new Actors.NPC.Enemies.Chuchus.CGreenChuChu(10, 45.0f, 120); //Actors.NPC.Enemies.Chuchus.CGreenChuChu[] greenAr = new Actors.NPC.Enemies.Chuchus.CGreenChuChu[2000]; //Actors.NPC.Enemies.Keese.CKeese[] keeseAr = new Actors.NPC.Enemies.Keese.CKeese[2000]; //private Zone testingzone; public Testbed(ref CComponent comp, ref CComponent menu) { MenuText = "KoT Testbed"; //compTest = comp; //menuComo = menu; Initialize(); }
/// <summary> /// 获取组件 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public T GetCComponent <T>() where T : CComponent { Type baseType = GetBaseType(typeof(T)); CComponent c = null; if (m_ComponentMap.TryGetValue(baseType, out c)) { return(c as T); } return(null); }
public CComponent GetCComponent(Type type) { Type baseType = GetBaseType(type); CComponent c = null; if (m_ComponentMap.TryGetValue(baseType, out c)) { return(c); } return(null); }
public void addActorToComponent(CActor actor, int componentId) { CComponent component = queryComponentRegistry(componentId); if (component != null && component.actors != null && !component.actors.ContainsKey(actor.name)) { component.addActor(actor, actor.name); addToActorRegistry(actor); _layers[actor.layer].addToDrawList(actor); } }
public void RemoveCComponent(CComponent component) { if (component != null) { Type baseType = GetBaseType(component.GetType()); CComponent c = null; if (m_ComponentMap.TryGetValue(baseType, out c)) { c.BeginDestroy(); m_ComponentMap.Remove(baseType); } } }
public void UnRegEventID(int id, CComponent com) { List <CComponent> comList = null; if (mBroadcastEvent.TryGetValue(id, out comList)) { comList.Remove(com); if (comList.Count == 0) { mBroadcastEvent.Remove(id); } } }
static public CComponent CreateComponent(Type type, Entity entity) { CComponent component = Activator.CreateInstance(type) as CComponent; if (component.Initialize(entity)) { return(component); } else { return(null); } }
/// <summary> /// 删除组件 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public bool RemoveCComponent <T>() where T : CComponent { CComponent component = GetComponent <T>(); if (component != null) { RemoveCComponent(component); return(true); } else { return(false); } }
public void RegEventID(int id, CComponent com) { List <CComponent> comList = null; if (mBroadcastEvent.TryGetValue(id, out comList)) { comList.Add(com); } else { comList = new List <CComponent>(); comList.Add(com); mBroadcastEvent[id] = comList; } }
public void RegMsg(int msgID, CComponent com) { List <CComponent> coms = null; if (mMsgComsDict.TryGetValue(msgID, out coms)) { coms.Add(com); } else { coms = new List <CComponent>(); coms.Add(com); mMsgComsDict[msgID] = coms; } }
public void Init(Vector2 speedRef) { baseMoveSpeed = new Vector3(speedRef.x, speedRef.y, 0); CComponent acom = cobj.GetCom("AttrCom"); attrCom = acom as AttrCom; attrCom.SetAttr((int)Const_Util.UNIT_ATTR.MOVE_BASE_SPEED, 0, baseMoveSpeed); attrCom.SetAttr((int)Const_Util.UNIT_ATTR.MOVE_CUR_SPEED, 0, speed); unitHangNode = cobj.mGameObj.transform;//.parent; float unitTypeTemp = 0; Vector3 unitTypeUnUse = Vector3.zero; attrCom.GetAttr((int)Const_Util.UNIT_ATTR.UNIT_TYPE, out unitTypeTemp, out unitTypeUnUse); unitType = Mathf.RoundToInt(unitTypeTemp); moveRenderTr = cobj.GetRenderObjTr(); if (unitType != (int)Const_Util.UNIT_TYPE.AI) { if (unitType == (int)Const_Util.UNIT_TYPE.ROLE_HERO) { moveTr = Camera.main.transform; } else { moveTr = cobj.GetRenderObjTr(); } SetMoveSpeed(Vector3.zero); TriggerMoveChg(MoveType.ACC, baseMoveSpeed, TestConfig.HeroMoveAccTime); RegBroadcastEvent((int)Const_Util.BATTLE_EVENT.CHG_DIR); RegBroadcastEvent((int)Const_Util.BATTLE_EVENT.JUMP); RegMsg((int)Const_Util.UNIT_MSG.GAS_ACC); RegMsg((int)Const_Util.UNIT_MSG.SKILL_DESC); } else { moveTr = cobj.GetRenderObjTr(); SetMoveSpeed(baseMoveSpeed); moveType = MoveType.AVG; } hangNodeOriginPos = unitHangNode.localPosition; RegMsg((int)Const_Util.UNIT_MSG.COLLIDER_OCCUR); RegBroadcastEvent((int)Const_Util.BATTLE_EVENT.MOVE_SPEED_RATE); }
public void dropActor(string actor, string name, Vector2 position, int layer, string[] parameters) { Type actorType = Type.GetType(actor); CActor tempActor = (CActor)Activator.CreateInstance(actorType); CComponent tempComponent = null; bool dontAddComp = false; if (actorType == typeof(King_of_Thieves.Actors.Collision.CSolidTile)) { if (_currentMap._layers[layer].hitboxAddress == CReservedAddresses.HITBOX_NOT_PRESENT) { tempComponent = new CComponent(_currentMap.largestAddress + 1); _currentMap._layers[layer].hitboxAddress = tempComponent.address; } else { tempComponent = _currentMap.queryComponentRegistry(_currentMap._layers[layer].hitboxAddress); dontAddComp = true; } } else { tempComponent = new CComponent(_currentMap.largestAddress + 1); } tempActor.init(name, position, actorType.ToString(), 0, parameters); tempActor.layer = layer; tempActor.swapImage(CActor._MAP_ICON); tempActor.mapParams = new System.Collections.Generic.List <string>(parameters); tempComponent.addActor(tempActor, name); _currentMap.addToActorRegistry(tempActor); if (!dontAddComp) { _currentMap.addComponent(tempComponent, layer); } else { _currentMap._layers[layer].addToDrawList(tempActor); } }
public void switchComponentToLayer(CComponent component, int toLayer) { //draw list swap _layers[component.layer].removeFromDrawList(component.root); _layers[toLayer].addToDrawList(component.root); component.root.layer = toLayer; foreach (CActor actor in component.actors.Values) { _layers[component.layer].removeFromDrawList(actor); _layers[toLayer].addToDrawList(actor); actor.layer = toLayer; } int fromLayer = component.layer; _layers[fromLayer].removeComponent(component); component.layer = toLayer; _layers[toLayer].addComponent(component); _hasMapStateChanged = true; }
public void addComponent(CComponent component, int layer) { _layers[layer].addComponent(component); _componentRegistry.Add(component); _largestAddress = component.address; CMasterControl.commNet.Add(component.address, new List <CActorPacket>()); if (component.root != null) { _layers[layer].addToDrawList(component.root); } foreach (KeyValuePair <string, CActor> kvp in component.actors) { _layers[layer].addToDrawList(kvp.Value); } if (component.address > _largestAddress) { _largestAddress = component.address; } _hasMapStateChanged = true; }
public override void add(CComponent component) { }
public override void remove(CComponent component) { }
public override void Add(CComponent c) { Console.WriteLine("cannot add to a leaf"); }
public override void Remove(CComponent c) { Console.WriteLine("cannot remove a leaf"); ; }
public CMap(string fileName) { //_internalMap = Gears.Cartography.Map. _internalMap = Gears.Cartography.Map.deserialize(fileName); _layers = new CLayer[_internalMap.NUM_LAYERS]; int layerCount = 0; _tileIndex = new Graphics.CSprite(_internalMap.TILESET, Graphics.CTextures.textures[_internalMap.TILESET]); foreach (Gears.Cartography.layer layer in _internalMap.LAYERS) { uint componentAddresses = 0; int componentCount = 0; Actors.CComponent[] compList = new CComponent[layer.COMPONENTS == null ? 0 : layer.COMPONENTS.Count()]; //======================================================================= //Tiles //======================================================================= CTile[] tiles = new CTile[layer.TILES.Count()]; int tileCounter = 0; foreach (Gears.Cartography.tile tile in layer.TILES) { if (!_coordFormat.IsMatch(tile.COORDS)) { throw new FormatException("The coordinate format provided was not valid.\n" + "Tile: " + tile.COORDS); } if (!_coordFormat.IsMatch(tile.TILESELECTION)) { throw new FormatException("The coordinate format provided was not valid.\n" + "Tile: " + tile.TILESELECTION); } Vector2 atlasCoords = new Vector2((float)Convert.ToDouble(_valSplitter.Split(tile.TILESELECTION)[0]), (float)Convert.ToDouble(_valSplitter.Split(tile.TILESELECTION)[1])); Vector2 mapCoords = new Vector2((float)Convert.ToDouble(_valSplitter.Split(tile.COORDS)[0]), (float)Convert.ToDouble(_valSplitter.Split(tile.COORDS)[1])); tiles[tileCounter++] = new CTile(atlasCoords, mapCoords, tile.TILESET); } if (layer.COMPONENTS != null) { //======================================================================= //Components //======================================================================= foreach (Gears.Cartography.component component in layer.COMPONENTS) { CComponent tempComp = new CComponent(componentAddresses); bool root = true; foreach (Gears.Cartography.actors actor in component.ACTORS) { Type actorType = Type.GetType(actor.TYPE); CActor tempActor = (CActor)Activator.CreateInstance(actorType); Vector2 coordinates = Vector2.Zero; if (!_coordFormat.IsMatch(actor.COORDS)) { throw new FormatException("The coordinate format provided was not valid.\n" + "Actor: " + actor.TYPE.ToString() + " " + actor.NAME); } coordinates.X = (float)Convert.ToDouble(_valSplitter.Split(actor.COORDS)[0]); coordinates.Y = (float)Convert.ToDouble(_valSplitter.Split(actor.COORDS)[1]); tempActor.init(actor.NAME, coordinates, componentAddresses, actor.param == null ? null : actor.param.Split(',')); tempActor.layer = layerCount; if (root) { tempComp.root = tempActor; } else { tempComp.actors.Add(actor.NAME, tempActor); } root = false; _actorRegistry.Add(tempActor); } //register component CMasterControl.commNet.Add((int)componentAddresses++, new List <CActorPacket>()); compList[componentCount++] = tempComp; } } _layers[layerCount++] = new CLayer(layer.NAME, compList, tiles, ref _tileIndex); } }
public CMap(string fileName, Dictionary <string, Graphics.CSprite> atlasCache = null) { _hasMapStateChanged = true; _internalMap = Gears.Cartography.Map.deserialize(fileName); _layers = new List <CLayer>(_internalMap.NUM_LAYERS); int layerCount = 0; //cache bgm if (_internalMap.BGM_FILE != null) { if (!CMasterControl.audioPlayer.soundBank.ContainsKey(_internalMap.BGM_FILE.BGM_REF_NAME)) { CMasterControl.audioPlayer.soundBank.Add(_internalMap.BGM_FILE.BGM_REF_NAME, new Sound.CSound(CMasterControl.glblContent.Load <Song>(_internalMap.BGM_FILE.BGM_FILE_LOC), true, -1)); } _bgmRef = _internalMap.BGM_FILE.BGM_REF_NAME; _bgmLoc = _internalMap.BGM_FILE.BGM_FILE_LOC; } /*if (_internalMap.TILESET != null) * _tileIndex = new Graphics.CSprite(_internalMap.TILESET, Graphics.CTextures.textures[_internalMap.TILESET]);*/ _width = _internalMap.WIDTH; _height = _internalMap.HEIGHT; _largestAddress = 0; foreach (Gears.Cartography.layer layer in _internalMap.LAYERS) { int componentAddresses = 2; int componentCount = 0; int hitboxAddress = CReservedAddresses.HITBOX_NOT_PRESENT; Actors.CComponent[] compList = new CComponent[layer.COMPONENTS == null ? 0 : layer.COMPONENTS.Count()]; Dictionary <string, Graphics.CSprite> tileSets = new Dictionary <string, Graphics.CSprite>(); //======================================================================= //Tiles //======================================================================= CTile[] tiles = new CTile[layer.TILES.Count()]; int tileCounter = 0; foreach (Gears.Cartography.tile tile in layer.TILES) { if (!_coordFormat.IsMatch(tile.COORDS)) { throw new FormatException("The coordinate format provided was not valid.\n" + "Tile: " + tile.COORDS); } if (!_coordFormat.IsMatch(tile.TILESELECTION)) { throw new FormatException("The coordinate format provided was not valid.\n" + "Tile: " + tile.TILESELECTION); } Vector2 atlasCoords = new Vector2((float)Convert.ToDouble(_valSplitter.Split(tile.TILESELECTION)[0]), (float)Convert.ToDouble(_valSplitter.Split(tile.TILESELECTION)[1])); Vector2 mapCoords = new Vector2((float)Convert.ToDouble(_valSplitter.Split(tile.COORDS)[0]), (float)Convert.ToDouble(_valSplitter.Split(tile.COORDS)[1])); Vector2 atlasCoordsEnd = Vector2.Zero; if (tile.TILESELECTIONEND != null) { atlasCoordsEnd = new Vector2((float)Convert.ToDouble(_valSplitter.Split(tile.TILESELECTIONEND)[0]), (float)Convert.ToDouble(_valSplitter.Split(tile.TILESELECTIONEND)[1])); } if (!tileSets.ContainsKey(tile.TILESET)) { tileSets.Add(tile.TILESET, new Graphics.CSprite(tile.TILESET)); } if (tile.TILESELECTIONEND == null) { tiles[tileCounter++] = new CTile(atlasCoords, mapCoords, tile.TILESET); } else { tiles[tileCounter++] = new CAnimatedTile(atlasCoords, atlasCoordsEnd, mapCoords, tile.TILESET, tile.SPEED); } } List <CActor> actorsForDrawList = new List <CActor>(); if (layer.COMPONENTS != null) { //======================================================================= //Components //======================================================================= foreach (Gears.Cartography.component component in layer.COMPONENTS) { CComponent tempComp = new CComponent(component.ADDRESS); foreach (Gears.Cartography.actors actor in component.ACTORS) { Type actorType = Type.GetType(actor.TYPE); if (actorType == typeof(King_of_Thieves.Actors.Collision.CSolidTile)) { hitboxAddress = component.ADDRESS; hitBoxCounter += 1; } CActor tempActor = (CActor)Activator.CreateInstance(actorType); Vector2 coordinates = Vector2.Zero; if (!_coordFormat.IsMatch(actor.COORDS)) { throw new FormatException("The coordinate format provided was not valid.\n" + "Actor: " + actor.TYPE.ToString() + " " + actor.NAME); } coordinates.X = (float)Convert.ToDouble(_valSplitter.Split(actor.COORDS)[0]); coordinates.Y = (float)Convert.ToDouble(_valSplitter.Split(actor.COORDS)[1]); tempComp.addActor(tempActor, actor.NAME); tempActor.init(actor.NAME, coordinates, actorType.ToString(), componentAddresses, actor.param == null ? null : actor.param.Split(',')); tempActor.layer = layerCount; tempActor.swapImage(CActor._MAP_ICON); _actorRegistry.Add(tempActor); actorsForDrawList.Add(tempActor); //add queued actors while (tempActor.registrationsQueued) { CActor registration = tempActor.popActorForRegistration(); tempComp.addActor(registration, registration.name); registration.layer = layerCount; _actorRegistry.Add(registration); actorsForDrawList.Add(registration); } } //register component _componentRegistry.Add(tempComp); tempComp.layer = layerCount; if (tempComp.address > _largestAddress) { _largestAddress = tempComp.address; } compList[componentCount++] = tempComp; componentAddresses++; } } CLayer tempLayer = new CLayer(layer.NAME, compList, tiles, ref _tileIndex, layerCount, Convert.ToDouble(_internalMap.VERSION), hitboxAddress); tempLayer.addToDrawList(actorsForDrawList); actorsForDrawList.Clear(); _layers.Add(tempLayer); layerCount++; //_layers[layerCount] = new CLayer(layer.NAME, compList, tiles, ref _tileIndex, Convert.ToDouble(_internalMap.VERSION)); if (atlasCache == null) { tempLayer.otherImages = tileSets; } else { tempLayer.otherImages = atlasCache; } } /*Actors.CComponent[] managers = _createManagers(); * //add controllers * foreach (Actors.CComponent component in managers) * { * _layers[0].addComponent(component); * _componentRegistry.Add(component); * }*/ }