public void CreateData(DaggerfallConnect.DFBlock.RmbBlock3dObjectRecord data, bool isExterior)
 {
     HideComponents();
     type = 0;
     this.isExterior = isExterior;
     id = data.ModelId;
     objectType = data.ObjectType;
 }
Exemple #2
0
        private GameObject Create3DObject(DaggerfallConnect.DFBlock.RmbBlock3dObjectRecord blockRecord)
        {
            GameObject go = LocationEditorHelper.Add3dObject(blockRecord);

            go.transform.parent = parent.transform;
            go.AddComponent <LocationEditorObject>().CreateData(blockRecord, false);
            return(go);
        }
Exemple #3
0
        private void GUIElement3DSwitchType(ref LocationEditorObject data, ref int elementIndex, string[] tempArray)
        {
            int pos = ArrayUtility.IndexOf(tempArray, data.id.ToString());

            GUI.BeginGroup(new Rect(8, 120 + (56 * elementIndex), Screen.width - 16, 48), lightGrayBG);
            {
                if (GUI.Button(new Rect(16, 12, 32, 24), "<"))
                {
                    pos--;

                    if (pos < 0)
                    {
                        pos = tempArray.Length - 1;
                    }
                }

                GUI.Label(new Rect(50, 16, 48, 28), tempArray[pos]);

                if (GUI.Button(new Rect(96, 12, 32, 24), ">"))
                {
                    pos++;

                    if (pos >= tempArray.Length)
                    {
                        pos = 0;
                    }
                }

                if (pos != ArrayUtility.IndexOf(tempArray, data.id.ToString()))
                {
                    data.id = tempArray[pos];
                    DaggerfallConnect.DFBlock.RmbBlock3dObjectRecord newBlockRecord = new DaggerfallConnect.DFBlock.RmbBlock3dObjectRecord();
                    newBlockRecord.ModelId    = data.id;
                    newBlockRecord.ModelIdNum = uint.Parse(data.id);
                    GameObject tempGo = Create3DObject(newBlockRecord);
                    data.gameObject.GetComponent <MeshRenderer>().sharedMaterials = tempGo.GetComponent <MeshRenderer>().sharedMaterials;
                    data.gameObject.GetComponent <MeshFilter>().sharedMesh        = tempGo.GetComponent <MeshFilter>().sharedMesh;
                    data.gameObject.GetComponent <MeshCollider>().sharedMesh      = tempGo.GetComponent <MeshFilter>().sharedMesh;
                    data.gameObject.name = tempGo.gameObject.name;
                    DestroyImmediate(tempGo);
                }
            }
            elementIndex++;
            GUI.EndGroup();
        }
Exemple #4
0
        private void GUIElementSwitchSet(ref LocationEditorObject data, ref int elementIndex)
        {
            GUI.BeginGroup(new Rect(8, 120 + (56 * elementIndex), Screen.width - 16, 48), lightGrayBG);
            {
                if (GUI.Button(new Rect(8, 8, 96, 32), "Switch set"))
                {
                    foreach (GameObject obj in Selection.objects)
                    {
                        if (obj.GetComponent <LocationEditorObject>() && obj.GetComponent <LocationEditorObject>().objectType == LocationEditorHelper.InteriorHousePart)
                        {
                            DaggerfallConnect.DFBlock.RmbBlock3dObjectRecord blockRecord = new DaggerfallConnect.DFBlock.RmbBlock3dObjectRecord();
                            LocationEditorObject interiorPiece = obj.GetComponent <LocationEditorObject>();
                            int currentSet = int.Parse(interiorPiece.id[interiorPiece.id.Length - 3].ToString());
                            currentSet++;

                            if (currentSet > 8)
                            {
                                currentSet = 0;
                            }

                            interiorPiece.id       = interiorPiece.id.Remove(interiorPiece.id.Length - 3, 1);
                            interiorPiece.id       = interiorPiece.id.Insert(interiorPiece.id.Length - 2, currentSet.ToString());
                            blockRecord.ModelIdNum = uint.Parse(interiorPiece.id);
                            blockRecord.ModelId    = interiorPiece.id;
                            blockRecord.ObjectType = interiorPiece.objectType;
                            GameObject tempGo = LocationEditorHelper.Add3dObject(blockRecord);

                            interiorPiece.gameObject.GetComponent <MeshRenderer>().sharedMaterials = tempGo.GetComponent <MeshRenderer>().sharedMaterials;
                            DestroyImmediate(tempGo);
                        }
                    }
                }
            }
            elementIndex++;
            GUI.EndGroup();
        }
Exemple #5
0
        private void UpdateLevelData()
        {
            ArrayUtility.Clear(ref levelData.RmbSubRecord.Exterior.Block3dObjectRecords);
            ArrayUtility.Clear(ref levelData.RmbSubRecord.Interior.Block3dObjectRecords);
            ArrayUtility.Clear(ref levelData.RmbSubRecord.Exterior.BlockFlatObjectRecords);
            ArrayUtility.Clear(ref levelData.RmbSubRecord.Interior.BlockFlatObjectRecords);
            ArrayUtility.Clear(ref levelData.RmbSubRecord.Exterior.BlockPeopleRecords);
            ArrayUtility.Clear(ref levelData.RmbSubRecord.Interior.BlockPeopleRecords);
            ArrayUtility.Clear(ref levelData.RmbSubRecord.Exterior.BlockDoorRecords);
            ArrayUtility.Clear(ref levelData.RmbSubRecord.Interior.BlockDoorRecords);

            Vector3 modelPosition;
            LocationEditorObject data;

            foreach (Transform child in parent.GetComponentInChildren <Transform>())
            {
                if (child.GetComponent <LocationEditorObject>() == null)
                {
                    return;
                }

                data = child.GetComponent <LocationEditorObject>();

                //3D models
                if (data.type == (int)LocationEditorHelper.DataType.Object3D)
                {
                    DaggerfallConnect.DFBlock.RmbBlock3dObjectRecord record = new DaggerfallConnect.DFBlock.RmbBlock3dObjectRecord();
                    record.ModelId    = data.id;
                    record.ModelIdNum = uint.Parse(data.id);
                    record.ObjectType = data.objectType;

                    if (data.objectType == 3)
                    {
                        Vector3[] vertices = child.GetComponent <MeshFilter>().sharedMesh.vertices;

                        // Props axis needs to be transformed to lowest Y point
                        Vector3 bottom = vertices[0];
                        for (int j = 0; j < vertices.Length; j++)
                        {
                            if (vertices[j].y < bottom.y)
                            {
                                bottom = vertices[j];
                            }
                        }
                        modelPosition = new Vector3(child.localPosition.x, (child.localPosition.y + (bottom.y)), child.localPosition.z) / MeshReader.GlobalScale;
                    }
                    else
                    {
                        modelPosition = new Vector3(child.localPosition.x, -child.localPosition.y, child.localPosition.z) / MeshReader.GlobalScale;
                    }

                    record.XPos      = Mathf.RoundToInt(modelPosition.x);
                    record.YPos      = Mathf.RoundToInt(modelPosition.y);
                    record.ZPos      = Mathf.RoundToInt(modelPosition.z);
                    record.XRotation = (short)(-child.eulerAngles.x * DaggerfallConnect.Arena2.BlocksFile.RotationDivisor);
                    record.YRotation = (short)(-child.eulerAngles.y * DaggerfallConnect.Arena2.BlocksFile.RotationDivisor);
                    record.ZRotation = (short)(-child.eulerAngles.z * DaggerfallConnect.Arena2.BlocksFile.RotationDivisor);
                    record.XScale    = child.localScale.x;
                    record.YScale    = child.localScale.y;
                    record.ZScale    = child.localScale.z;


                    if (data.isExterior)
                    {
                        ArrayUtility.Add(ref levelData.RmbSubRecord.Exterior.Block3dObjectRecords, record);
                    }
                    else
                    {
                        ArrayUtility.Add(ref levelData.RmbSubRecord.Interior.Block3dObjectRecords, record);
                    }
                }

                else if (data.type == (int)LocationEditorHelper.DataType.Flat)
                {
                    DaggerfallConnect.DFBlock.RmbBlockFlatObjectRecord record = new DaggerfallConnect.DFBlock.RmbBlockFlatObjectRecord();
                    record.TextureArchive = int.Parse(data.id.Split('.')[0]);
                    record.TextureRecord  = int.Parse(data.id.Split('.')[1]);
                    record.FactionID      = data.factionID;
                    record.Flags          = data.flags;

                    modelPosition = child.transform.localPosition / MeshReader.GlobalScale;
                    record.XPos   = Mathf.RoundToInt(modelPosition.x);
                    record.YPos   = Mathf.RoundToInt(-((child.localPosition.y - (child.GetComponent <DaggerfallBillboard>().Summary.Size.y / 2)) / MeshReader.GlobalScale));
                    record.ZPos   = Mathf.RoundToInt(modelPosition.z);

                    if (data.isExterior)
                    {
                        ArrayUtility.Add(ref levelData.RmbSubRecord.Exterior.BlockFlatObjectRecords, record);
                    }
                    else
                    {
                        ArrayUtility.Add(ref levelData.RmbSubRecord.Interior.BlockFlatObjectRecords, record);
                    }
                }

                else if (data.type == (int)LocationEditorHelper.DataType.Person)
                {
                    DaggerfallConnect.DFBlock.RmbBlockPeopleRecord record = new DaggerfallConnect.DFBlock.RmbBlockPeopleRecord();
                    record.TextureArchive = int.Parse(data.id.Split('.')[0]);
                    record.TextureRecord  = int.Parse(data.id.Split('.')[1]);
                    record.FactionID      = data.factionID;
                    record.Flags          = data.flags;

                    modelPosition = child.transform.localPosition / MeshReader.GlobalScale;
                    record.XPos   = Mathf.RoundToInt(modelPosition.x);
                    record.YPos   = Mathf.RoundToInt(-((child.localPosition.y - (child.GetComponent <DaggerfallBillboard>().Summary.Size.y / 2)) / MeshReader.GlobalScale));
                    record.ZPos   = Mathf.RoundToInt(modelPosition.z);

                    if (data.isExterior)
                    {
                        ArrayUtility.Add(ref levelData.RmbSubRecord.Exterior.BlockPeopleRecords, record);
                    }
                    else
                    {
                        ArrayUtility.Add(ref levelData.RmbSubRecord.Interior.BlockPeopleRecords, record);
                    }
                }

                else if (data.type == (int)LocationEditorHelper.DataType.Door)
                {
                    DaggerfallConnect.DFBlock.RmbBlockDoorRecord record = new DaggerfallConnect.DFBlock.RmbBlockDoorRecord();
                    record.OpenRotation = data.openRotation;
                    modelPosition       = child.transform.localPosition / MeshReader.GlobalScale;
                    record.XPos         = Mathf.RoundToInt(modelPosition.x);
                    record.YPos         = -Mathf.RoundToInt(modelPosition.y);
                    record.ZPos         = Mathf.RoundToInt(modelPosition.z);
                    record.YRotation    = (short)(-child.eulerAngles.y * DaggerfallConnect.Arena2.BlocksFile.RotationDivisor);

                    if (data.isExterior)
                    {
                        ArrayUtility.Add(ref levelData.RmbSubRecord.Exterior.BlockDoorRecords, record);
                    }
                    else
                    {
                        ArrayUtility.Add(ref levelData.RmbSubRecord.Interior.BlockDoorRecords, record);
                    }
                }
            }
        }
Exemple #6
0
        private void AddItemWindow()
        {
            GUI.BeginGroup(new Rect(8, 64, Screen.width - 16, 32), lightGrayBG);
            chooseFileMode = GUI.SelectionGrid(new Rect(8, 4, 312, 24), chooseFileMode, chooseFileModeString, 2);
            GUI.EndGroup();

            GUI.BeginGroup(new Rect(8, 104, Screen.width - 16, 32), lightGrayBG);
            listMode = GUI.SelectionGrid(new Rect(8, 4, (listModeString.Length * 80) + 8, 24), listMode, listModeString, listModeString.Length);
            GUI.EndGroup();

            if (chooseFileMode == 0)
            {
                if (listMode == 0)
                {
                    GUI.BeginGroup(new Rect(8, 144, Screen.width - 16, 32), lightGrayBG);
                    modelSubList = GUI.SelectionGrid(new Rect(8, 4, (modelSubListString.Length * 80) + 8, 24), modelSubList, modelSubListString, modelSubListString.Length);
                    GUI.EndGroup();
                }


                else if (listMode == 1)
                {
                    GUI.BeginGroup(new Rect(8, 144, Screen.width - 16, 32), lightGrayBG);
                    billboardSubList = GUI.SelectionGrid(new Rect(8, 4, (billboardSubListString.Length * 80) + 8, 24), billboardSubList, billboardSubListString, billboardSubListString.Length);
                    GUI.EndGroup();
                }

                if (listMode != 3)
                {
                    GUI.Label(new Rect(new Rect(16, 190, 64, 16)), "Search: ");
                    searchField = EditorGUI.TextField(new Rect(70, 190, 156, 16), searchField);

                    if (GUI.changed)
                    {
                        UpdateSearchList();
                    }

                    scrollPosition2 = GUI.BeginScrollView(new Rect(4, 210, 312, 418), scrollPosition2, new Rect(0, 0, 256, 20 + (searchListNames.Count * 24)));
                    objectPicker    = GUI.SelectionGrid(new Rect(10, 10, 256, searchListNames.Count * 24), objectPicker, searchListNames.ToArray(), 1);
                    GUI.EndScrollView();
                }
            }

            else if (chooseFileMode == 1)
            {
                GUI.Label(new Rect(new Rect(16, 160, 96, 16)), "Object ID : ");
                selectedObjectID = EditorGUI.TextField(new Rect(128, 160, 156, 16), selectedObjectID);
            }

            if (GUI.Button(new Rect(16, 642, 96, 20), "OK"))
            {
                if (chooseFileMode == 0)
                {
                    selectedObjectID = searchListID[objectPicker];
                }

                GameObject go = null;

                if (listMode == 0 || listMode == 4)
                {
                    DaggerfallConnect.DFBlock.RmbBlock3dObjectRecord blockRecord = new DaggerfallConnect.DFBlock.RmbBlock3dObjectRecord();

                    blockRecord.XScale = 1;
                    blockRecord.YScale = 1;
                    blockRecord.ZScale = 1;

                    blockRecord.ModelIdNum = uint.Parse(selectedObjectID);

                    if (isExteriorMode)
                    {
                        blockRecord.ObjectType = LocationEditorHelper.ExteriorBuilding;
                    }

                    else if (listMode == 4)
                    {
                        blockRecord.ObjectType = LocationEditorHelper.InteriorHousePart;
                    }

                    blockRecord.ModelId = blockRecord.ModelIdNum.ToString();
                    go = LocationEditorHelper.Add3dObject(blockRecord);

                    //Rotate Carpets
                    if (blockRecord.ModelId == "74800")
                    {
                        go.transform.rotation = Quaternion.Euler(270, 0, 0);
                    }

                    go.AddComponent <LocationEditorObject>().CreateData(blockRecord, isExteriorMode);
                }

                else if (listMode == 1)
                {
                    DaggerfallConnect.DFBlock.RmbBlockFlatObjectRecord blockRecord = new DaggerfallConnect.DFBlock.RmbBlockFlatObjectRecord();
                    blockRecord.TextureArchive = int.Parse(selectedObjectID.Split('.')[0]);
                    blockRecord.TextureRecord  = int.Parse(selectedObjectID.Split('.')[1]);
                    go = LocationEditorHelper.AddFlatObject(blockRecord);
                    go.AddComponent <LocationEditorObject>().CreateData(blockRecord, isExteriorMode);

                    // Add point lights
                    if (blockRecord.TextureArchive == DaggerfallWorkshop.Utility.TextureReader.LightsTextureArchive)
                    {
                        LocationEditorHelper.AddLight(go.transform, blockRecord);
                    }
                }

                else if (listMode == 2)
                {
                    DaggerfallConnect.DFBlock.RmbBlockPeopleRecord blockRecord = new DaggerfallConnect.DFBlock.RmbBlockPeopleRecord();
                    blockRecord.TextureArchive = int.Parse(selectedObjectID.Split('.')[0]);
                    blockRecord.TextureRecord  = int.Parse(selectedObjectID.Split('.')[1]);
                    go = LocationEditorHelper.AddPersonObject(blockRecord);
                    go.AddComponent <LocationEditorObject>().CreateData(blockRecord, isExteriorMode);
                }

                else if (listMode == 3)
                {
                    DaggerfallConnect.DFBlock.RmbBlockDoorRecord blockRecord = new DaggerfallConnect.DFBlock.RmbBlockDoorRecord();
                    blockRecord.OpenRotation = 95; //Seems to be the default rotation used in the game
                    go = LocationEditorHelper.AddDoorObject(blockRecord);
                    go.AddComponent <LocationEditorObject>().CreateData(blockRecord, isExteriorMode);
                }

                if (go != null)
                {
                    go.transform.parent = parent.transform;

                    Ray        newRay = new Ray(SceneView.lastActiveSceneView.camera.transform.position, SceneView.lastActiveSceneView.camera.transform.forward);
                    RaycastHit hit    = new RaycastHit();
                    if (Physics.Raycast(newRay, out hit, 200))
                    {
                        go.transform.position = hit.point;
                    }
                }

                editMode = EditMode.EditMode;
            }

            if (GUI.Button(new Rect(128, 642, 96, 20), "Cancel"))
            {
                editMode = EditMode.EditMode;
            }
        }