public void HitImplement(float damage)
 {
     //如果不能收到伤害,不执行任何操作
     Debug.LogFormat("GameObject {0} get Damage {1}", this.gameObject.name, damage);
     if (!CanBeHurt)
     {
         return;
     }
     m_CurrentHealth -= damage;
     if (m_CurrentHealth <= 0f && m_Death == false)
     {
         m_Death = true;
         //调用死亡函数, 机器人不进行调用
         if (IsPlayer)
         {
             PlayerDie();
         }
         // 从controller List中移除现有AI
         else
         {
             AIController.instance.DestroyAI(this.gameObject.name);
             AIActionController controller = gameObject.GetComponent <AIActionController>();
             if (controller == null)
             {
                 Debug.LogError("Controller Not Found");
             }
             controller.Die();
         }
     }
 }
Exemplo n.º 2
0
    public void RecvAIRPC(ProtocolBase protoBase)
    {
        //Debug.Log("Reach RecvAIRPC");
        if (is_master_client)
        {
            return;
        }

        ProtocolBytes proto     = (ProtocolBytes)protoBase;
        int           start     = 0;
        string        protoName = proto.GetString(start, ref start);
        // master_client 直接忽略AI的RPC信息

        int rpcCnt = proto.GetInt(start, ref start);

        //Debug.Log("rpcCnt = " + rpcCnt);
        for (int i = 0; i < rpcCnt; i++)
        {
            string   aiName     = proto.GetString(start, ref start);
            string   methodName = proto.GetString(start, ref start);
            object[] parameters = proto.GetObjects(start, ref start);   // 应该为(start, ref start)
            //Debug.Log("aiName :" + aiName);
            //Debug.Log("methodName:" + methodName);
            if (AI_List.ContainsKey(aiName))
            {
                AIActionController actionController = AI_Action_List[aiName];
                Type t = actionController.GetType();
                //Debug.Log("Type t:" + t);
                MethodInfo method = t.GetMethod(methodName);
                if (method == null)
                {
                    Debug.LogError("No public method in class " + t);
                }
                method.Invoke(actionController, parameters);
            }
        }
    }