bool HandleEntityTarget(EntityTargetCommand cmd) { Entity entity = m_logic_world.GetEntityManager().GetObject(cmd.m_entity_id); if (entity == null) { return(false); } Entity target = m_logic_world.GetEntityManager().GetObject(cmd.m_target_entity_id); if (target == null) { return(false); } TargetingComponent targeting_component = entity.GetComponent(TargetingComponent.ID) as TargetingComponent; if (targeting_component == null) { return(false); } targeting_component.StartTargeting(target); return(true); }
void OnPick(RaycastHit hit) { GameObject go = hit.transform.gameObject; UnityObjectBinding binding = go.GetComponent <UnityObjectBinding>(); if (binding == null) { Debug.Log("RenderWorld.OnPick(), YOU CHOOSE A POINT" + hit.point.ToString()); if (m_current_operate_entityi_id < 0) { return; } RenderEntity render_entity = m_render_entity_manager.GetObject(m_current_operate_entityi_id); if (render_entity == null) { return; } LocomotorComponent locomotor_component = render_entity.GetLogicEntity().GetComponent(LocomotorComponent.ID) as LocomotorComponent; if (locomotor_component == null || !locomotor_component.IsEnable()) { return; } EntityMoveCommand cmd = Command.Create <EntityMoveCommand>(); cmd.ConstructAsDestination(m_current_operate_entityi_id, Vector3_To_Vector3FP(hit.point)); PushLocalCommand(cmd); #if UNITY_EDITOR if (m_draw_grid && m_grid_graph != null) { PositionComponent position_component = render_entity.GetLogicEntity().GetComponent(PositionComponent.ID) as PositionComponent; if (!m_grid_graph.FindPath(position_component.CurrentPosition, Vector3_To_Vector3FP(hit.point))) { Debug.LogError("FindPath Failed!"); } else { List <Vector3FP> path = m_grid_graph.GetPath(); m_current_path.Clear(); for (int i = 0; i < path.Count; ++i) { m_current_path.Add(Vector3FP_To_Vector3(path[i])); } } } #endif } else { RenderEntity render_entity = m_render_entity_manager.GetObject(binding.EntityID); if (render_entity == null) { return; } if (m_combat_client.LocalPlayerPstid == m_logic_world.GetPlayerManager().Objectid2Pstid(render_entity.GetOwnerPlayerID())) { m_current_operate_entityi_id = binding.EntityID; Debug.Log("RenderWorld.OnPick(), YOU CHOOSE YOUR ENTITY " + hit.transform.parent.name); } else { Debug.Log("RenderWorld.OnPick(), YOU CHOOSE AN ENEMY " + hit.transform.parent.name); if (m_current_operate_entityi_id < 0) { return; } EntityTargetCommand cmd = Command.Create <EntityTargetCommand>(); cmd.Construct(m_current_operate_entityi_id, render_entity.ID); PushLocalCommand(cmd); #if UNITY_EDITOR if (m_draw_grid && m_grid_graph != null) { RenderEntity self_entity = m_render_entity_manager.GetObject(m_current_operate_entityi_id); PositionComponent self_position_component = self_entity.GetLogicEntity().GetComponent(PositionComponent.ID) as PositionComponent; PositionComponent target_position_component = render_entity.GetLogicEntity().GetComponent(PositionComponent.ID) as PositionComponent; if (!m_grid_graph.FindPath(self_position_component.CurrentPosition, target_position_component.CurrentPosition)) { Debug.LogError("FindPath Failed!"); } else { List <Vector3FP> path = m_grid_graph.GetPath(); m_current_path.Clear(); for (int i = 0; i < path.Count; ++i) { m_current_path.Add(Vector3FP_To_Vector3(path[i])); } } } #endif } } }