public void OnClicked() { GameObject objUpload = transform.parent.parent.parent.FindChild("Upload").gameObject; GameObject objSelection = transform.parent.parent.parent.FindChild("Selection").gameObject; ScriptSelection ss = objSelection.GetComponent <ScriptSelection> (); ScriptUpload su = objUpload.GetComponent <ScriptUpload> (); objSelection.SetActive(true); objUpload.SetActive(false); int lastIdx = GetKey().LastIndexOf("/"); // su.StopThread (); su.transform.gameObject.SetActive(false); ss.SetTitle(GetKey().Substring(lastIdx + 1)); ss.SetImgList(su.GetList(GetKey())); ss.InitListUI(); }
public void DropItemAtValue(int number) { if (canUseInventory) { string item = playerInventory [number - 1]; lastDroppedItem = item; ScriptSelection script = null; if (itemScriptDictionary.TryGetValue(item, out script)) { if (script.executeFunctionOnDrop == true) { UseItemAtValue(number); } if (script.allowDropping == true) { playerInventory.RemoveAt(number - 1); GameObject icon = icons.transform.Find("icon" + number).gameObject; //hide icon image Color imageColor = icon.GetComponent <Image> ().color; imageColor.a = 0; icon.GetComponent <Image> ().color = imageColor; //hide icon text GameObject textChild = text.transform.Find("text" + number).gameObject; Color textColor = textChild.gameObject.GetComponent <Text> ().color; textColor.a = 0; textChild.GetComponent <Text> ().color = textColor; GameObject foundItem = null; if (dropItemDictionary.TryGetValue(item, out foundItem)) { //Drop item listed GameObject playerCam = GameObject.FindGameObjectWithTag("PlayerCamera"); Quaternion rotation = GameObject.FindGameObjectWithTag("PlayerCamera").transform.rotation; Vector3 position = playerCam.transform.position + playerCam.GetComponent <Camera>().transform.forward *0.5f; Instantiate(foundItem, position, rotation); } } } ReassignUIImages(); } }
public void UseItemAtValue(int number) { if (canUseInventory) { string item = playerInventory [number - 1]; GameObject icon = GameObject.FindGameObjectWithTag("UIIcons").transform.Find("icon" + number).gameObject; //hide icon image Color imageColor = icon.GetComponent <Image> ().color; imageColor.a = 0; icon.GetComponent <Image> ().color = imageColor; //hide icon text GameObject textChild = GameObject.FindGameObjectWithTag("UIText").transform.Find("text" + number).gameObject; Color textColor = textChild.gameObject.GetComponent <Text> ().color; textColor.a = 0; textChild.GetComponent <Text> ().color = textColor; ScriptSelection script = null; if (itemScriptDictionary.TryGetValue(item, out script)) { if (script.targetTag != "") //execute script according to tag { switch (script.argumentType) { case ArgType.Float: GameObject.FindGameObjectWithTag(script.targetTag).SendMessage(script.functionName, float.Parse(script.functionArgument)); break; case ArgType.Int: GameObject.FindGameObjectWithTag(script.targetTag).SendMessage(script.functionName, int.Parse(script.functionArgument)); break; case ArgType.String: GameObject.FindGameObjectWithTag(script.targetTag).SendMessage(script.functionName, script.functionArgument); break; case ArgType.Double: GameObject.FindGameObjectWithTag(script.targetTag).SendMessage(script.functionName, double.Parse(script.functionArgument)); break; case ArgType.Bool: bool inputArg = script.functionArgument == "true"; GameObject.FindGameObjectWithTag(script.targetTag).SendMessage(script.functionName, inputArg); break; } } else if (script.targetName != "") //execute script according to object name { if (GameObject.Find(script.targetName)) { switch (script.argumentType) { case ArgType.Float: GameObject.Find(script.targetName).SendMessage(script.functionName, float.Parse(script.functionArgument)); break; case ArgType.Int: GameObject.Find(script.targetName).SendMessage(script.functionName, int.Parse(script.functionArgument)); break; case ArgType.String: GameObject.Find(script.targetName).SendMessage(script.functionName, script.functionArgument); break; case ArgType.Double: GameObject.Find(script.targetName).SendMessage(script.functionName, double.Parse(script.functionArgument)); break; case ArgType.Bool: bool inputArg = script.functionArgument == "true"; GameObject.Find(script.targetName).SendMessage(script.functionName, inputArg); break; } } } else { //try to drop the item GameObject foundItem = null; if (dropItemDictionary.TryGetValue(item, out foundItem)) { //Drop item listed Vector3 position = GameObject.FindGameObjectWithTag("PlayerCamera").transform.position; Quaternion rotation = GameObject.FindGameObjectWithTag("PlayerCamera").transform.rotation; position = new Vector3(position.x, position.y, position.z + 1); Instantiate(foundItem, position, rotation); } } if (script.dontDestroyOnUse == false) { playerInventory.RemoveAt(number - 1); } } ReassignUIImages(); } }