Esempio n. 1
0
        public static Creature LoadCreature(string resref, AuroraGIT.ACreature gitData)
        {
            AuroraUTC ac = data.Get <AuroraUTC>(resref, ResourceType.UTC);
            Creature  c  = Creature.Create(ac, gitData);

            return(c);
        }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (gitData == null)
        {
            return;
        }
        // Update the GIT with information on this
        switch (transform.parent.name)
        {
        case "Creatures":
            AuroraGIT.ACreature aCreature = (AuroraGIT.ACreature)gitData;
            aCreature.XPosition = transform.position.x;
            aCreature.YPosition = transform.position.z;
            aCreature.ZPosition = transform.position.y;

            // Calculate orientation from bearing
            // This is an "xy vector pointing in the direction of the creature's orientation"
            Vector2 cForward = new Vector2(transform.forward.x, transform.forward.z);
            cForward.Normalize();
            aCreature.XOrientation = cForward.x;
            aCreature.YOrientation = cForward.y;
            break;

        case "Placeables":
            // TODO: Calculate bearing
            AuroraGIT.APlaceable aPlaceable = (AuroraGIT.APlaceable)gitData;
            aPlaceable.X = transform.position.x;
            aPlaceable.Y = transform.position.z;
            aPlaceable.Z = transform.position.y;

            // Bearing is in radians, measured counterclockwise from North
            aPlaceable.Bearing = CalculateBearing(transform);
            break;

        case "Doors":
            // TODO: Door orientation and transform information (link, etc.)
            AuroraGIT.ADoor aDoor = (AuroraGIT.ADoor)gitData;
            aDoor.X = transform.position.x;
            aDoor.Y = transform.position.z;
            aDoor.Z = transform.position.y;

            aDoor.Bearing = CalculateBearing(transform);
            break;

        case "Triggers":
            AuroraGIT.ATrigger aTrigger = (AuroraGIT.ATrigger)gitData;

            aTrigger.XPosition = transform.position.x;
            aTrigger.YPosition = transform.position.z;
            aTrigger.ZPosition = transform.position.y;

            // This doesn't matter, and should be zero, according to BioWare documentation
            aTrigger.XOrientation = 0f;
            aTrigger.YOrientation = 0f;
            aTrigger.ZOrientation = 0f;
            break;

        case "Encounters":
            // TODO: Encounter geometry and spawn points
            AuroraGIT.AEncounter aEncounter = (AuroraGIT.AEncounter)gitData;
            aEncounter.XPosition = transform.position.x;
            aEncounter.YPosition = transform.position.z;
            aEncounter.ZPosition = transform.position.y;
            break;

        case "Sounds":
            // TODO: Sound orientation and data
            AuroraGIT.ASound aSound = (AuroraGIT.ASound)gitData;
            aSound.XPosition = transform.position.x;
            aSound.YPosition = transform.position.z;
            aSound.ZPosition = transform.position.y;
            break;

        case "Stores":
            // TODO: Orientation
            AuroraGIT.AStore aStore = (AuroraGIT.AStore)gitData;
            aStore.XPosition = transform.position.x;
            aStore.YPosition = transform.position.z;
            aStore.ZPosition = transform.position.y;

            // This is an "xy vector pointing in the direction of the creature's orientation"
            Vector2 sForward = new Vector2(transform.forward.x, transform.forward.z);
            sForward.Normalize();
            aStore.XOrientation = sForward.x;
            aStore.YOrientation = sForward.y;
            break;

        case "Waypoints":
            AuroraGIT.AWaypoint aWaypoint = (AuroraGIT.AWaypoint)gitData;
            aWaypoint.XPosition = transform.position.x;
            aWaypoint.YPosition = transform.position.z;
            aWaypoint.ZPosition = transform.position.y;

            // This is an "xy vector pointing in the direction of the creature's orientation"
            Vector2 wForward = new Vector2(transform.forward.x, transform.forward.z);
            wForward.Normalize();
            aWaypoint.XOrientation = wForward.x;
            aWaypoint.YOrientation = wForward.y;
            break;

        case "Cameras":
            AuroraGIT.ACamera aCamera = (AuroraGIT.ACamera)gitData;
            // Don't ask me why we don't flip y and z here, I don't know :P
            aCamera.Position = new Vector3(
                transform.position.x,
                transform.position.y,
                transform.position.z
                );

            // To reverse the quaternion map, we do the
            // exact same transformation as the original map!
            aCamera.Orientation = new Quaternion(
                -transform.rotation.x,
                -transform.rotation.z,
                -transform.rotation.y,
                transform.rotation.w
                );
            break;

        default:
            break;
        }
    }
Esempio n. 3
0
        public static Creature Create(AuroraUTC utc, AuroraGIT.ACreature gitData)
        {
            //GameObject gameObject;
            //get the resource reference for this object, which we'll use as it's in-engine name
            string name = utc.TemplateResRef;

            //get the appearance row number in appearance.2da
            int appearance = utc.Appearance_Type;

            string modelType = Resources.From2DA("appearance", appearance, "modeltype");

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

            if (modelRef == null)
            {
                // This should only happen if we didn't find the row in appearance
                modelRef = Resources.Load2DA("appearance")[appearance, "race"];
            }

            string texRef = Resources.Load2DA("appearance")[appearance, "texa"];

            string cubemapRef = Resources.From2DA("appearance", appearance, "envmap");

            if (Resources.data.GetStream(modelRef, ResourceType.MDL) == null)
            {
                modelRef = Resources.Load2DA("appearance")[appearance, "modelb"];
                texRef   = Resources.Load2DA("appearance")[appearance, "texb"];
            }

            if (cubemapRef == "" || cubemapRef == "DEFAULT")
            {
                cubemapRef = null;
            }

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

            gameObject.name = name;

            GameObject headObj = null;

            switch (modelType.ToLower())
            {
            case "b":
                // Model requires a head
                int    headID   = int.Parse(Resources.From2DA("appearance", appearance, "normalhead"));
                string headName = Resources.From2DA("heads", headID, "head");
                headObj = Resources.LoadModel(headName, null, gameObject, cubemapRef);
                break;

            case "f":
            default:
                // Model includes head
                break;
            }

            // Add a character controller for movement
            NavMeshAgent agent = gameObject.AddComponent <NavMeshAgent>();

            // Make the creature commandable by default
            utc.Commandable = 1;

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

            creature.template = utc;
            creature.gitData  = gitData;

            creature.head = headObj;

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

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

            //if (headObj != null)
            //{
            //    Transform headPosition = gameObject.transform.Find("cutscenedummy/rootdummy/torso_g/torsoupr_g/headhook");
            //    character.head.transform.localPosition = headPosition.position - character.head.transform.position;
            //    character.head.transform.localRotation = Quaternion.identity;
            //}

            return(creature);
        }
Esempio n. 4
0
    public void BuildGIT(AuroraGIT git)
    {
        // Update the GIT with information on this
        switch (transform.parent.name)
        {
        case "Creatures":
            AuroraGIT.ACreature creature = (AuroraGIT.ACreature)gitData;
            creature.structid = 4;
            git.CreatureList.Add(creature);
            break;

        case "Placeables":
            AuroraGIT.APlaceable placeable = (AuroraGIT.APlaceable)gitData;
            placeable.structid = 9;
            git.PlaceableList.Add(placeable);
            break;

        case "Doors":
            AuroraGIT.ADoor door = (AuroraGIT.ADoor)gitData;
            door.structid = 8;
            git.DoorList.Add(door);
            break;

        case "Triggers":
            AuroraGIT.ATrigger trigger = (AuroraGIT.ATrigger)gitData;
            trigger.structid = 1;
            git.TriggerList.Add(trigger);
            break;

        case "Encounters":
            AuroraGIT.AEncounter encounter = (AuroraGIT.AEncounter)gitData;
            encounter.structid = 7;
            git.EncounterList.Add(encounter);
            break;

        case "Sounds":
            AuroraGIT.ASound sound = (AuroraGIT.ASound)gitData;
            sound.structid = 6;
            git.SoundList.Add(sound);
            break;

        case "Stores":
            AuroraGIT.AStore store = (AuroraGIT.AStore)gitData;
            store.structid = 11;
            git.StoreList.Add(store);
            break;

        case "Waypoints":
            AuroraGIT.AWaypoint waypoint = (AuroraGIT.AWaypoint)gitData;
            waypoint.structid = 5;
            git.WaypointList.Add(waypoint);
            break;

        case "Cameras":
            AuroraGIT.ACamera cam = (AuroraGIT.ACamera)gitData;
            cam.structid = 14;
            git.CameraList.Add(cam);
            break;

        default:
            throw new System.Exception("Unknown parent " + transform.parent.name + " found.");
        }
    }