public static Placeable LoadPlaceable(string resref, AuroraGIT.APlaceable gitData) { AuroraUTP ap = data.Get <AuroraUTP>(resref, ResourceType.UTP); Placeable p = Placeable.Create(ap, gitData); return(p); }
public override void Update() { AuroraUTP template = (AuroraUTP)placeable.template; // Load the items List <AuroraUIElement> items = new List <AuroraUIElement>(); foreach (AuroraUTP.AItem item in template.ItemList) { // Create an item instance for each item in the inventory // (this will be transferred into the player's inventory when they pick the item up) UnityEngine.Debug.Log("Loading item " + item.InventoryRes); Item uiItem = new Item(this.width, this.height * 2 / 9, AuroraEngine.Resources.LoadItem(item.InventoryRes)); uiItem.button.Clicked += (_, __) => PlayerTakeItem(item); uiItem.button.Clicked += (_, __) => placeable.OnInvDisturbed(); items.Add(uiItem); } // Create the scrollable list scroll = new ScrollableList(width, height * 2 / 3, items); // Create the buttons getItems = new Button(width, height / 12, "Get Items"); getItems.Clicked += GetAllItems; switchToGiveItems = new Button(width, height / 12, "Switch to Give Items"); switchToGiveItems.Clicked += SwitchToGiveItems; close = new Button(width, height / 12, "Close"); close.Clicked += Close; }
void PlayerTakeItem(AuroraUTP.AItem item) { // Give a copy of the item to the player ((AuroraUTC)gui.stateSystem.PC.template).ItemList.Add(new AuroraUTC.AItem() { InventoryRes = item.InventoryRes }); // Remove the item from the placeable AuroraUTP utp = (AuroraUTP)placeable.template; utp.ItemList.Remove(item); // Update Update(); }
public static Placeable Create(AuroraUTP utp, AuroraGIT.APlaceable gitData) { if (guiSystem == null) { guiSystem = GameObject.Find("GUI System").GetComponent <GUISystem>(); } GameObject gameObject; //get the resource reference for this object, which we'll use as it's in-engine name string name = utp.TemplateResRef; //get the appearance row number in placeables.2da int appearance = (int)utp.Appearance; //get the model name for this appearance id string modelRef = Resources.Load2DA("placeables")[appearance, "modelname"]; if (modelRef == "PLC_Invis") { gameObject = new GameObject(name); } else { gameObject = Resources.LoadModel(modelRef); gameObject.name = name; } //add the template component to the new object Placeable placeable = gameObject.AddComponent <Placeable>(); placeable.template = utp; placeable.gitData = gitData; LookAtHook hook = gameObject.GetComponentInChildren <LookAtHook>(); if (hook != null) { hook.obj = placeable; } return(placeable); }
void DrawHooks() { selectedHook = null; GUIStyle style = new GUIStyle(); style.fontSize = 16; style.normal.textColor = Color.red; style.alignment = TextAnchor.MiddleCenter; List <GameObject> allHooks = new List <GameObject>(); foreach (GameObject obj in GameObject.FindGameObjectsWithTag("LookAtHook")) { //Debug.Log("Considering object " + obj.name); AuroraObject auroraObject = obj.GetComponent <LookAtHook>().obj; if (auroraObject == null) { continue; } if (auroraObject.GetType() == typeof(Door)) { Door door = (Door)auroraObject; AuroraUTD utd = (AuroraUTD)door.template; // TODO: Support closing doors? Don't think this is a thing in KotOR/TSL if (door.open) { //Debug.Log("Door is open, so not drawing hook"); continue; } //Debug.Log("Drawing hook for door"); allHooks.Add(obj); } else if (auroraObject.GetType() == typeof(Creature)) { // Check if the creature has a default conversation Creature creature = (Creature)auroraObject; AuroraUTC utc = (AuroraUTC)creature.template; bool selectable = false; if (utc.Conversation == null || utc.Conversation == "") { //Debug.Log("Creature has no conversation, so not drawing hook"); selectable = true; } else if (NWScript.GetIsEnemy(creature, stateSystem.PC) > 0) { selectable = true; } if (selectable) { allHooks.Add(obj); } } else if (auroraObject.GetType() == typeof(Placeable)) { // Check if the placeable can be interacted with Placeable placeable = (Placeable)auroraObject; AuroraUTP utp = (AuroraUTP)placeable.template; if (utp.Useable == 0) { //Debug.Log("Placeable is not useable, so not drawing hook"); continue; } //Debug.Log("Drawing hook for placeable"); allHooks.Add(obj); } } //Debug.Log("Considering " + allHooks.Count + " hooks"); List <GameObject> hooks = new List <GameObject>(); foreach (GameObject g in allHooks) { //Debug.Log("Checking if hook " + g.name + " is visible"); // Determine whether the object is blocked by another collider Vector2 point = Camera.main.WorldToScreenPoint(g.transform.position); Ray r = Camera.main.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(r, out hit, float.MaxValue, hookMask)) { // We might hit the boundary of the object represented by the hook? if (hit.transform.gameObject == g || Vector3.Distance(hit.point, g.transform.position) < 1f) { hooks.Add(g); } } } //Debug.Log("Showing " + hooks.Count + " hooks"); float dist = float.PositiveInfinity; selectedHook = null; foreach (GameObject h in hooks) { Vector2 hPos = Camera.main.WorldToScreenPoint(h.transform.position); float d = Vector2.Distance( new Vector2(hPos.x, Screen.height - hPos.y), new Vector2( Screen.width / 2, Screen.height / 2 ) ); if (d < dist) { dist = d; selectedHook = h; } } foreach (GameObject g in hooks) { Vector2 point = Camera.main.WorldToScreenPoint(g.transform.position); if (g == selectedHook) { if (Vector3.Distance(pc.transform.position, selectedHook.transform.position) < interactionRange) { style.normal.textColor = Color.green; style.fontSize = 28; } else { style.normal.textColor = Color.blue; style.fontSize = 28; } } else { style.normal.textColor = Color.red; style.fontSize = 16; } Rect labelRect = new Rect(point.x - 90, Screen.height - point.y - 240, 180, 240); AuroraObject obj = g.GetComponent <LookAtHook>().obj; if (obj.GetType() == typeof(Door)) { TooltipWindow doorTooltip = ((Door)obj).GetTooltip(); using (new GUILayout.AreaScope(labelRect)) { doorTooltip.Draw(); } } GUI.Label( new Rect(point.x - 25, Screen.height - point.y - 25, 50, 50), "O", style );; } }