Reputation: 1
I'm trying to automatise some Unity3D process to can call this from a PHP script.
I've already create an shell script that call some UNITY command line to create a project and for execute methods and if I use it in the terminal, works fine.
The problem is when I use it into a PHP script:
- I'm using shell_exec
command to execute my script and all shell methods works (ls, mkdir, echo) but when I call to application nothing happend.
I was reading that is a permission problem into apache but after some hours I still without find a solution so.
I've mounted a server in my mac (Sierra) enabling apache and PHP 5 to test.
Regards, Gabriel
EDIT 1
I add here my code
This is my shell_script
that works fine if i execute it in a terminal.
#!/bin/bash
UNITY_EXEC=/Applications/Unity_5.6.1f1/Unity.app/Contents/MacOS/Unity
if [ -z "$2" ]; then echo "You must provide a path to the bundle assets and a path to the resulting bundle."; exit 1; fi
export UNITY_ASSET_BUNDLE_PATH=${2}
CREATION_TIME=`date +%s`
ASSET_BUNDLE_PROJECT_DIR=/tmp/AssetBundle-${CREATION_TIME}
echo "Creating temporary project.";
${UNITY_EXEC} -batchmode -quit -createProject ${ASSET_BUNDLE_PROJECT_DIR};
echo "Copying resources from source folder to assets folder.";
cd $1; cp -r . ${ASSET_BUNDLE_PROJECT_DIR}/Assets;
echo "Finding assets.";
cd ${ASSET_BUNDLE_PROJECT_DIR};
ASSETS_TO_BUNDLE=`find Assets -type f -not -name *.meta -not -name .DS_Store -not -name AssetsBundler.cs | sed 's/^.\///g' | sed 's/^/assetPathsList.Add("/g' | sed 's/$/");/g'`
mkdir ${ASSET_BUNDLE_PROJECT_DIR}/Assets/Editor/;
cat << EOT >> ${ASSET_BUNDLE_PROJECT_DIR}/Assets/Editor/AssetsBundler.cs
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
public class AssetsBundler{
public static void Bundle(){
List<string> assetPathsList = new List<string>();
${ASSETS_TO_BUNDLE}
ArrayList assetList = new ArrayList();
foreach(string assetPath in assetPathsList)
{
UnityEngine.Object[] assets = AssetDatabase.LoadAllAssetsAtPath(assetPath);
foreach(UnityEngine.Object asset in assets)
{
assetList.Add(asset);
}
}
UnityEngine.Object[] allAssets = (UnityEngine.Object[]) assetList.ToArray(typeof(UnityEngine.Object));
BuildPipeline.BuildAssetBundle(allAssets[0], allAssets, "${UNITY_ASSET_BUNDLE_PATH}", BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, BuildTarget.Android);
}
}
EOT
echo "Building the bundle.";
${UNITY_EXEC} -batchmode -quit -projectProject ${ASSET_BUNDLE_PROJECT_DIR} -executeMethod AssetsBundler.Bundle;
And this is my PHP_script
<?php
$old_path = getcwd();
chdir('./AssetBundleBuilder/');
$output = shell_exec('./AssetBundleBuilder ./Bundlify ./result.unity3d');
chdir($old_path);
echo $output;
?>
If i execute my PHP script from firefox, i receive as output all echo
messages so thats tell me that the script is working. The thing is that the UNITY calls doesn't works.
Upvotes: 0
Views: 165
Reputation: 1
I'll response my self.
Finally i got a solution using sockets. I've created a server socket in python to call the bash script in every connection and my client socket is in php that is the file that i call from a browser.
Thanks! Gabriel
Upvotes: 0