示例#1
0
        void CreateModel()
        {
            m_unity_go = UnityResourceManager.Instance.CreateGameObject(m_asset_name);
            if (m_unity_go == null)
            {
                return;
            }

            if (m_bodyctrl_path != null)
            {
                m_bodyctrl_tr = m_unity_go.transform.FindChild(m_bodyctrl_path);
            }
            else
            {
                m_bodyctrl_tr = m_unity_go.transform;
            }
            m_bodyctrl_obj = m_bodyctrl_tr.gameObject;

            if (m_headctrl_path != null)
            {
                m_headctrl_tr = m_unity_go.transform.FindChild(m_headctrl_path);
            }
            if (m_headctrl_tr != null)
            {
                m_headctrl_obj = m_headctrl_tr.gameObject;
            }

            Entity logic_entity = GetLogicEntity();

            m_position_component = logic_entity.GetComponent(PositionComponent.ID) as PositionComponent;
            if (m_position_component != null)
            {
                m_last_position                = RenderWorld.Vector3FP_To_Vector3(m_position_component.CurrentPosition);
                m_bodyctrl_tr.localPosition    = m_last_position;
                m_bodyctrl_tr.localEulerAngles = new Vector3(0, (float)m_position_component.BaseAngle, 0);
                if (m_headctrl_tr != null)
                {
                    m_bodyctrl_tr.localEulerAngles = new Vector3(0, (float)m_position_component.HeadAngle, 0);
                }
            }

            UnityObjectBinding binding = m_bodyctrl_tr.gameObject.GetComponent <UnityObjectBinding>();

            if (binding == null)
            {
                binding = m_bodyctrl_tr.gameObject.AddComponent <UnityObjectBinding>();
            }
            binding.EntityID = logic_entity.ID;
        }
示例#2
0
        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
                }
            }
        }