示例#1
0
		public static HEU_ShelfToolData LoadToolFromJsonString(string json, string jsonFilePath)
		{
			//Debug.Log("Loading json: " + jsonFilePath);

			// Get environment variable for tool path
			string envValue = HEU_Platform.GetEnvironmentValue(HEU_Defines.HEU_PATH_KEY_TOOL);
			string envKey = string.Format("<{0}>", HEU_Defines.HEU_PATH_KEY_TOOL);

			HEU_ShelfToolData toolData = null;

			if (!string.IsNullOrEmpty(json))
			{
				try
				{
					JSONNode jsonShelfNode = JSON.Parse(json);
					if (jsonShelfNode != null)
					{
						bool isObject = jsonShelfNode.IsObject;
						bool isArray = jsonShelfNode.IsArray;

						toolData = new HEU_ShelfToolData();

						toolData._name = jsonShelfNode["name"];

						toolData._toolType = (HEU_ShelfToolData.ToolType)System.Enum.Parse(typeof(HEU_ShelfToolData.ToolType), jsonShelfNode["toolType"]);

						toolData._toolTip = jsonShelfNode["toolTip"];

						toolData._iconPath = jsonShelfNode["iconPath"];

						toolData._assetPath = jsonShelfNode["assetPath"];

						toolData._helpURL = jsonShelfNode["helpURL"];

						JSONArray targetArray = jsonShelfNode["target"].AsArray;
						if(targetArray != null)
						{
							int targetCount = targetArray.Count;
							toolData._targets = new string[targetCount];
							for(int j = 0; j < targetCount; ++j)
							{
								toolData._targets[j] = targetArray[j];
							}
						}
	}
				}
				catch (System.Exception ex)
				{
					Debug.LogErrorFormat("Exception when trying to parse shelf json file at path: {0}. Exception: {1}", jsonFilePath, ex.ToString());
					return null;
				}

				toolData._jsonPath = jsonFilePath;

				if (toolData != null && !string.IsNullOrEmpty(toolData._name))
				{
					// Make sure this tool targets Unity (must have "all" or "unity" set in target field)
					bool bCompatiple = false;
					if(toolData._targets != null)
					{
						int numTargets = toolData._targets.Length;
						for(int i = 0; i < numTargets; ++i)
						{
							if (toolData._targets[i].Equals(TARGET_ALL) || toolData._targets[i].Equals(TARGET_UNITY))
							{
								bCompatiple = true;
								break;
							}
						}
					}

					if (bCompatiple)
					{
						if (!string.IsNullOrEmpty(toolData._assetPath))
						{
							toolData._assetPath = toolData._assetPath.Replace(HEU_Defines.HEU_PATH_KEY_PROJECT + "/", "");
							if (toolData._assetPath.Contains(envKey))
							{
								if (string.IsNullOrEmpty(envValue))
								{
									Debug.LogErrorFormat("Environment value {0} used but not set in environment.", HEU_Defines.HEU_PATH_KEY_TOOL);
								}
								else
								{
									toolData._assetPath = toolData._assetPath.Replace(envKey, envValue);
								}
							}
						}
						else
						{
							toolData._assetPath = GetToolAssetPath(toolData, toolData._assetPath);
						}

						string realPath = HEU_PluginStorage.Instance.ConvertEnvKeyedPathToReal(toolData._assetPath);
						if (!HEU_Platform.DoesFileExist(realPath))
						{
							Debug.LogErrorFormat("Houdini Engine shelf tool at {0} does not exist!", realPath);
							return null;
						}

						if (!string.IsNullOrEmpty(toolData._iconPath))
						{
							toolData._iconPath = toolData._iconPath.Replace(HEU_Defines.HEU_PATH_KEY_PROJECT + "/", "");
							if (toolData._iconPath.Contains(envKey))
							{
								if (string.IsNullOrEmpty(envValue))
								{
									Debug.LogErrorFormat("Environment value {0} used but not set in environment.", HEU_Defines.HEU_PATH_KEY_TOOL);
								}
								else
								{
									toolData._iconPath = toolData._iconPath.Replace(envKey, envValue);
								}
							}
						}
						else
						{
							toolData._iconPath = GetToolIconPath(toolData, toolData._iconPath);
						}

						return toolData;
					}
				}
			}

			return null;
		}
示例#2
0
		public static bool LoadToolFromJsonString(string json)
		{
			// Get environment variable for tool path
			string envValue = HEU_Platform.GetEnvironmentValue(HEU_Defines.HEU_PATH_KEY_TOOL);
			string envKey = string.Format("<{0}>", HEU_Defines.HEU_PATH_KEY_TOOL);

			if (!string.IsNullOrEmpty(json))
			{
				HEU_ShelfToolData toolData = JsonUtility.FromJson<HEU_ShelfToolData>(json);

				if(toolData != null 
					&& !string.IsNullOrEmpty(toolData.name) 
					&& !string.IsNullOrEmpty(toolData.assetPath)
					&& !string.IsNullOrEmpty(toolData.iconPath))
				{
					// Make sure this tool targets Unity (must have "all" or "unity" set in target field)
					bool bCompatiple = false;
					if(toolData.target != null)
					{
						int numTargets = toolData.target.Length;
						for(int i = 0; i < numTargets; ++i)
						{
							if (toolData.target[i].Equals(TARGET_ALL))
							{
								bCompatiple = true;
								break;
							}
							else if(toolData.target[i].Equals(TARGET_UNITY))
							{
								bCompatiple = true;
								break;
							}
						}
					}

					if (bCompatiple)
					{
						toolData.assetPath = toolData.assetPath.Replace(HEU_Defines.HEU_PATH_KEY_PROJECT + "/", "");
						toolData.iconPath = toolData.iconPath.Replace(HEU_Defines.HEU_PATH_KEY_PROJECT + "/", "");

						if(toolData.assetPath.Contains(envKey))
						{
							if(string.IsNullOrEmpty(envValue))
							{
								Debug.LogErrorFormat("Environment value {0} used but not set in environment.", HEU_Defines.HEU_PATH_KEY_TOOL);
							}
							else
							{
								toolData.assetPath = toolData.assetPath.Replace(envKey, envValue);
							}
						}

						if (toolData.iconPath.Contains(envKey))
						{
							if (string.IsNullOrEmpty(envValue))
							{
								Debug.LogErrorFormat("Environment value {0} used but not set in environment.", HEU_Defines.HEU_PATH_KEY_TOOL);
							}
							else
							{
								toolData.iconPath = toolData.iconPath.Replace(envKey, envValue);
							}
						}

						_tools.Add(toolData);
						Debug.LogFormat("Added tool: {0}", toolData.name);
					}
				}

				return true;
			}

			return false;
		}