public override JSONNode Remove(JSONNode aNode)
 {
     m_List.Remove(aNode);
     return(aNode);
 }
Exemple #2
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;
	}
 public virtual JSONNode Remove(JSONNode aNode)
 {
     return(aNode);
 }
        public static JSONNode Parse(string aJSON)
        {
            Stack <JSONNode> stack      = new Stack <JSONNode>();
            JSONNode         ctx        = null;
            int           i             = 0;
            StringBuilder Token         = new StringBuilder();
            string        TokenName     = "";
            bool          QuoteMode     = false;
            bool          TokenIsQuoted = false;

            while (i < aJSON.Length)
            {
                switch (aJSON[i])
                {
                case '{':
                    if (QuoteMode)
                    {
                        Token.Append(aJSON[i]);
                        break;
                    }
                    stack.Push(new JSONObject());
                    if (ctx != null)
                    {
                        ctx.Add(TokenName, stack.Peek());
                    }
                    TokenName    = "";
                    Token.Length = 0;
                    ctx          = stack.Peek();
                    break;

                case '[':
                    if (QuoteMode)
                    {
                        Token.Append(aJSON[i]);
                        break;
                    }

                    stack.Push(new JSONArray());
                    if (ctx != null)
                    {
                        ctx.Add(TokenName, stack.Peek());
                    }
                    TokenName    = "";
                    Token.Length = 0;
                    ctx          = stack.Peek();
                    break;

                case '}':
                case ']':
                    if (QuoteMode)
                    {
                        Token.Append(aJSON[i]);
                        break;
                    }
                    if (stack.Count == 0)
                    {
                        throw new Exception("JSON Parse: Too many closing brackets");
                    }

                    stack.Pop();
                    if (Token.Length > 0 || TokenIsQuoted)
                    {
                        ctx.Add(TokenName, ParseElement(Token.ToString(), TokenIsQuoted));
                    }
                    TokenIsQuoted = false;
                    TokenName     = "";
                    Token.Length  = 0;
                    if (stack.Count > 0)
                    {
                        ctx = stack.Peek();
                    }
                    break;

                case ':':
                    if (QuoteMode)
                    {
                        Token.Append(aJSON[i]);
                        break;
                    }
                    TokenName     = Token.ToString();
                    Token.Length  = 0;
                    TokenIsQuoted = false;
                    break;

                case '"':
                    QuoteMode     ^= true;
                    TokenIsQuoted |= QuoteMode;
                    break;

                case ',':
                    if (QuoteMode)
                    {
                        Token.Append(aJSON[i]);
                        break;
                    }
                    if (Token.Length > 0 || TokenIsQuoted)
                    {
                        ctx.Add(TokenName, ParseElement(Token.ToString(), TokenIsQuoted));
                    }
                    TokenIsQuoted = false;
                    TokenName     = "";
                    Token.Length  = 0;
                    TokenIsQuoted = false;
                    break;

                case '\r':
                case '\n':
                    break;

                case ' ':
                case '\t':
                    if (QuoteMode)
                    {
                        Token.Append(aJSON[i]);
                    }
                    break;

                case '\\':
                    ++i;
                    if (QuoteMode)
                    {
                        char C = aJSON[i];
                        switch (C)
                        {
                        case 't':
                            Token.Append('\t');
                            break;

                        case 'r':
                            Token.Append('\r');
                            break;

                        case 'n':
                            Token.Append('\n');
                            break;

                        case 'b':
                            Token.Append('\b');
                            break;

                        case 'f':
                            Token.Append('\f');
                            break;

                        case 'u':
                        {
                            string s = aJSON.Substring(i + 1, 4);
                            Token.Append((char)int.Parse(
                                             s,
                                             System.Globalization.NumberStyles.AllowHexSpecifier));
                            i += 4;
                            break;
                        }

                        default:
                            Token.Append(C);
                            break;
                        }
                    }
                    break;

                default:
                    Token.Append(aJSON[i]);
                    break;
                }
                ++i;
            }
            if (QuoteMode)
            {
                throw new Exception("JSON Parse: Quotation marks seems to be messed up.");
            }
            if (ctx == null)
            {
                return(ParseElement(Token.ToString(), TokenIsQuoted));
            }
            return(ctx);
        }
 public virtual void Add(string aKey, JSONNode aItem)
 {
 }
 public virtual void Add(JSONNode aItem)
 {
     Add("", aItem);
 }
 public static JSONNode Parse(string aJSON)
 {
     return(JSONNode.Parse(aJSON));
 }
 public override void Add(string aKey, JSONNode aItem)
 {
     Set(new JSONObject()).Add(aKey, aItem);
 }
 public override void Add(JSONNode aItem)
 {
     Set(new JSONArray()).Add(aItem);
 }
 public JSONLazyCreator(JSONNode aNode, string aKey)
 {
     m_Node = aNode;
     m_Key  = aKey;
 }
 public JSONLazyCreator(JSONNode aNode)
 {
     m_Node = aNode;
     m_Key  = null;
 }