Пример #1
0
        public static Door LoadDoor(string resref, AuroraGIT.ADoor gitData)
        {
            AuroraUTD ad = data.Get <AuroraUTD>(resref, ResourceType.UTD);
            Door      d  = Door.Create(ad, gitData);

            return(d);
        }
Пример #2
0
        public static Door Create(AuroraUTD utd, AuroraGIT.ADoor gitData)
        {
            GameObject gameObject;

            //get the resource reference for this object, which we'll use as it's in-engine name
            string name = utd.TemplateResRef;

            //get the appearance row number in genericdoors.2da
            int appearance = utd.GenericType;

            //get the model name for this door id
            string modelRef = Resources.Load2DA("genericdoors")[appearance, "modelname"];

            //create a new game object and load the model into the scene
            gameObject      = Resources.LoadModel(modelRef);
            gameObject.name = name;

            //add the template component to the new object
            Door door = gameObject.AddComponent <Door>();

            door.template = utd;
            door.gitData  = gitData;

            LookAtHook hook = gameObject.GetComponentInChildren <LookAtHook>();

            if (hook != null)
            {
                hook.obj = door;
            }

            return(door);
        }
Пример #3
0
    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
                );;
        }
    }