PHP 一个文件的类实例调用另一个文件的类实例函数

示例:

<?php
require_once("phpServerWithUnityClient.php");

$wo = new ni();
$wo->say();

class ni 
{
	public function say(){
		$unity = new  phpServerWithUnityClient();
		$unity->SendToUnity();
	}
}
?>


<?PHP
class phpServerWithUnityClient{

// 这个函数可以接收Unity 发送过来的消息
	function  ReceiveFromUnity(){
		if (isset($_POST['Parameter1'])) {
			$Parameter1 = $_POST['Parameter1'];
		} else {
			$Parameter1 = null;
		}

		if (isset($_POST['Parameter2'])) {
			$Parameter2 = $_POST['Parameter2'];
		} else {
			$Parameter2 = null;
		}
		echo "Your pass values 1 : " . $Parameter1 . ", pass value 2 " . $Parameter2;
	}

	 function SendToUnity(){
		//有订阅事件告知unity		
		$result="Hello,会思考的猴子";
 		echo $result;
		return $result;
	}
}
?>

猜你喜欢

转载自blog.csdn.net/qq_39097425/article/details/112965326
今日推荐