コード例 #1
0
    public override void MouseUp(Vector3 mousePos, TileTypes tileType, floorplan script, Material mat)
    {
        Vector3[] points = new Vector3[]
        {
            mouseStart,
            mouseEnd,
            mouseStart - (new Vector3(width, 0, 0)),
            mouseEnd + (new Vector3(width, 0, 0))
        };

        switch (tileType)
        {
        case TileTypes.Wall:
            break;

        case TileTypes.Floor:
            Render(script.tileset.floorTiles[0], script, mat);
            break;

        case TileTypes.Pillar:
            break;
        }

        mouseStart = Vector3.zero;
        mouseEnd   = Vector3.zero;
    }
コード例 #2
0
    void Render(floorplan script, GameObject tile, Material mat)
    {
        GameObject gO = new GameObject("Walls");

        gO.transform.parent = GameObject.Find("New Floorplan Geometry").transform;
        Vector3 topLeft    = new Vector3(Mathf.Max(mouseStart.x, mouseEnd.x), mouseStart.y, Mathf.Max(mouseStart.z, mouseEnd.z));
        Vector3 bottomLeft = new Vector3(Mathf.Min(mouseStart.x, mouseEnd.x), mouseStart.y, Mathf.Min(mouseStart.z, mouseEnd.z));

        for (int x = 0; x < Mathf.Abs(width); x += (int)script.tileSize)
        {
            GameObject wall = script.createInstance(tile, (topLeft - new Vector3(x + script.tileSize, 0, 0)), Quaternion.LookRotation(Vector3.right, Vector3.up));
            wall.GetComponent <Renderer>().material = mat;
            wall.transform.parent.parent            = gO.transform;

            wall = script.createInstance(tile, (bottomLeft - new Vector3(-x, 0, 0)), Quaternion.LookRotation(Vector3.right, Vector3.up));
            wall.GetComponent <Renderer>().material = mat;
            wall.transform.parent.parent            = gO.transform;
        }
        for (int z = 0; z < Mathf.Abs(height); z += (int)script.tileSize)
        {
            GameObject wall = script.createInstance(tile, (topLeft - new Vector3(0, 0, z + script.tileSize)), Quaternion.identity);
            wall.GetComponent <Renderer>().material = mat;
            wall.transform.parent.parent            = gO.transform;

            wall = script.createInstance(tile, (bottomLeft - new Vector3(0, 0, -z)), Quaternion.identity);
            wall.GetComponent <Renderer>().material = mat;
            wall.transform.parent.parent            = gO.transform;
        }
        Undo.RegisterCreatedObjectUndo(gO, "Undo wall creation");
    }
コード例 #3
0
        void OnSceneGUI()
        {
            floorplan script = (floorplan)target;

            if (mouseEnd != Vector3.zero && mouseStart != Vector3.zero)
            {
                currentTool.RenderPreview();
            }
            HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Keyboard));
            Event e = Event.current;

            switch (e.type)
            {
            case EventType.KeyDown:
            {
                break;
            }

            case EventType.MouseDown:
            {
                if (Event.current.button == 1)
                {
                    return;
                }
                GetMousePosition(Event.current.mousePosition, out mouseStart);
                currentTool.MouseDown(mouseStart);
                break;
            }

            case EventType.MouseDrag:
            {
                if (Event.current.button == 1 || mouseStart == Vector3.zero)
                {
                    return;
                }
                GetMousePosition(Event.current.mousePosition, out mouseEnd);
                currentTool.MouseDrag(mouseEnd);
                break;
            }

            case EventType.MouseUp:
            {
                if (mouseEnd == Vector3.zero || mouseStart == Vector3.zero)
                {
                    return;
                }
                GetMousePosition(Event.current.mousePosition, out mouseEnd);
                currentTool.MouseUp(mouseEnd, (TileTypes)drawObjetInt, script, materials[selectedMaterial]);
                mouseEnd = Vector3.zero;
                break;
            }

            case EventType.ExecuteCommand:
            {
                Debug.Log(Event.current.commandName);
                break;
            }
            }
        }
コード例 #4
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();
            //Display drawing tools

            TitleLabels = new GUIStyle()
            {
                fontStyle = FontStyle.Normal
            };
            TitleLabels.normal.textColor = Color.white;
            script = (floorplan)target;

            //Saving certain variables (selected draw tool, selected object, selected material)
            EditorPrefs.SetInt("DrawTool", drawToolInt);
            EditorPrefs.SetInt("DrawObjet", drawObjetInt);
            EditorPrefs.SetInt("SelectedMaterial", selectedMaterial);

            //Generate toolbars for the drawing tools and objects.
            EditorGUILayout.BeginVertical("Box");
            {
                EditorGUILayout.BeginHorizontal("Box");
                {
                    GUILayout.Label("Drawing tools", TitleLabels, GUILayout.Height(16), GUILayout.Width(96));
                    drawToolInt = GUILayout.Toolbar(drawToolInt, drawToolStrings, GUILayout.Width(48 * drawToolStrings.Length), GUILayout.Height(48));

                    GUILayout.Label("Objects", TitleLabels, GUILayout.Height(16), GUILayout.Width(64));
                    drawObjetInt = GUILayout.Toolbar(drawObjetInt, drawItemTextures, GUILayout.Width(48 * drawItemTextures.Length), GUILayout.Height(48));
                    currentTool  = tools[drawToolInt];
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical("Box");
            {
                EditorGUILayout.LabelField("Materials", TitleLabels);
                scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(250), GUILayout.Height(64));
                {
                    //Generate material selection
                    materials = script.wallMaterials;
                    GUIContent[] materialPreviews = new GUIContent[materials.Length];
                    for (int m = 0; m < materials.Length; m++)
                    {
                        if (materials[m] != null)
                        {
                            materialPreviews[m] = new GUIContent(m.ToString(), materials[m].mainTexture, materials[m].name);
                        }
                    }
                    selectedMaterial = GUILayout.Toolbar(selectedMaterial, materialPreviews, GUILayout.Width(50 * materials.Length), GUILayout.Height(50));
                }
                EditorGUILayout.EndScrollView();
            }
            EditorGUILayout.EndVertical();
        }
コード例 #5
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        floorplan script = (floorplan)target;

        if (GUILayout.Button("Spawn Pillar"))
        {
            script.createInstance(script.tileset.pillarTile, script.gameObject.transform.position, Quaternion.identity);
        }
        if (GUILayout.Button("Spawn Floor Tile"))
        {
            script.createInstance(script.tileset.floorTile, script.gameObject.transform.position, Quaternion.LookRotation(Vector3.right, Vector3.up));
        }
    }
コード例 #6
0
    void OnSceneGUI()
    {
        floorplan script = (floorplan)target;
        Event     e      = Event.current;

        switch (e.type)
        {
        case EventType.KeyDown:
        {
            if (Event.current.keyCode == (KeyCode.Space))
            {
                script.ToggleTool();
            }
            break;
        }
        }
    }
コード例 #7
0
    public void Render(GameObject tile, floorplan script, Material[] mats)
    {
        GameObject gO = new GameObject("Floor");

        gO.transform.parent = script.geometry.transform;
        Vector3 topLeft = new Vector3(Mathf.Max(mouseStart.x, mouseEnd.x), mouseStart.y, Mathf.Max(mouseStart.z, mouseEnd.z));

        for (int y = 0; y < Mathf.Abs(height); y += (int)script.tileSize)
        {
            for (int x = 0; x < Mathf.Abs(width); x += (int)script.tileSize)
            {
                GameObject floor = script.createInstance(tile, (topLeft - new Vector3(x, 0, y + script.tileSize)), Quaternion.identity);
                floor.GetComponent <Renderer>().materials = mats;
                floor.transform.parent.parent             = gO.transform;
            }
        }
        Undo.RegisterCreatedObjectUndo(gO, "Undo floor creation");
    }
コード例 #8
0
 public void OnEnable()
 {
     script = (floorplan)target;
     if (SceneView.lastActiveSceneView)
     {
         SceneView.lastActiveSceneView.isRotationLocked = false;
         SceneView.lastActiveSceneView.rotation         = Quaternion.LookRotation(-Vector3.up, Vector3.up);
         SceneView.lastActiveSceneView.isRotationLocked = true;
         SceneView.lastActiveSceneView.orthographic     = true;
     }
     drawToolStrings = new GUIContent[] {
         new GUIContent("0", Resources.Load <Texture>("icons/RectTool"), "Rectangle"),
         new GUIContent("1", Resources.Load <Texture>("icons/FilledRectTool"), "Filled rectangle")
     };
     drawItemTextures = new GUIContent[] {
         new GUIContent("0", Resources.Load <Texture>("icons/BrickIcon"), "Wall"),
         new GUIContent("1", Resources.Load <Texture>("icons/PillarIcon"), "Pillar"),
         new GUIContent("2", Resources.Load <Texture>("icons/FloorIcon"), "Floor")
     };
     drawToolInt  = EditorPrefs.GetInt("DrawTool", 0);
     drawObjetInt = EditorPrefs.GetInt("DrawObjet", 0);
     materials    = new Material[0];
     if (script.selected.Count < 4 || selectedMaterials.Count < 4)
     {
         selectedMaterials = new List <int>(4)
         {
             -1, -1, -1, -1
         };
         script.selected = selectedMaterials;
     }
     else if (script.selected.Count > 4 || selectedMaterials.Count > 4)
     {
         selectedMaterials = new List <int>(4)
         {
             -1, -1, -1, -1
         };
         script.selected = selectedMaterials;
     }
 }
コード例 #9
0
 private void Awake()
 {
     script    = (floorplan)target;
     materials = new Material[0];
 }
コード例 #10
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();
            //Display drawing tools

            TitleLabels = new GUIStyle()
            {
                fontStyle = FontStyle.Normal
            };
            TitleLabels.normal.textColor = Color.white;
            script = (floorplan)target;

            //Saving certain variables (selected draw tool, selected object, selected material)
            EditorPrefs.SetInt("DrawTool", drawToolInt);
            EditorPrefs.SetInt("DrawObjet", drawObjetInt);

            //Generate toolbars for the drawing tools and objects.
            EditorGUILayout.BeginVertical("Box");
            {
                EditorGUILayout.BeginHorizontal("Box");
                {
                    GUILayout.Label("Drawing tools", TitleLabels, GUILayout.Height(16), GUILayout.Width(96));
                    drawToolInt = GUILayout.Toolbar(drawToolInt, drawToolStrings, GUILayout.Width(48 * drawToolStrings.Length), GUILayout.Height(48));

                    GUILayout.Label("Objects", TitleLabels, GUILayout.Height(16), GUILayout.Width(64));
                    drawObjetInt = GUILayout.Toolbar(drawObjetInt, drawItemTextures, GUILayout.Width(48 * drawItemTextures.Length), GUILayout.Height(48));
                    currentTool  = tools[drawToolInt];
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical("Box");
            {
                EditorGUILayout.LabelField("Tile", TitleLabels);
                scrollPos2 = EditorGUILayout.BeginScrollView(scrollPos2, GUILayout.Width(450), GUILayout.Height(64));
                {
                    selecting = IndexToTileArray(drawObjetInt);
                    GUIContent[] thumbnails = new GUIContent[selecting.Length];

                    for (int t = 0; t < selecting.Length; t++)
                    {
                        if (selecting[t] != null)
                        {
                            thumbnails[t] = new GUIContent(t.ToString(), AssetPreview.GetAssetPreview(selecting[t]), selecting[t].name);
                        }
                    }
                    selectedObject = GUILayout.Toolbar(selectedObject, thumbnails, GUILayout.Width(75 * selecting.Length), GUILayout.Height(50));
                }
                EditorGUILayout.EndScrollView();
            }
            EditorGUILayout.EndVertical();

            currentObjectRenderer = selecting[selectedObject].GetComponentInChildren <Renderer>();

            for (int i = 0; i < currentObjectRenderer.sharedMaterials.Length; i++)
            {
                if (!materials.Any(x => (x == null)))
                {
                    EditorGUILayout.BeginVertical("Box");
                    {
                        EditorGUILayout.LabelField("Material " + (i + 1).ToString(), TitleLabels);
                        scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(250), GUILayout.Height(64));
                        {
                            //Generate material selection
                            materials = script.wallMaterials;
                            GUIContent[] materialPreviews = new GUIContent[materials.Length];

                            for (int m = 0; m < materials.Length; m++)
                            {
                                if (materials[m] != null)
                                {
                                    materialPreviews[m] = new GUIContent(m.ToString(), materials[m].mainTexture, materials[m].name);
                                }
                            }
                            selectedMaterials[i] = GUILayout.Toolbar(selectedMaterials[i], materialPreviews, GUILayout.Width(50 * materials.Length), GUILayout.Height(50));
                        }
                        EditorGUILayout.EndScrollView();
                    }
                    EditorGUILayout.EndVertical();
                }
            }
        }
コード例 #11
0
    public override void MouseUp(Vector3 mousePos, TileTypes tileType, GameObject tile, floorplan script, Material[] mat, List <int> selected)
    {
        Vector3[] points = new Vector3[]
        {
            mouseStart,
            mouseEnd,
            mouseStart - (new Vector3(width, 0, 0)),
            mouseEnd + (new Vector3(width, 0, 0))
        };
        List <Material> mats = new List <Material>();

        selected.RemoveAll(o => o == -1);
        for (int i = 0; i < selected.Count; i++)
        {
            mats.Add(mat[selected[i]]);
        }
        //Should we even do this (manage which tiletypes a tool can create) inside tools? Should this be handled by something else?
        switch (tileType)
        {
        case TileTypes.Wall:
            Debug.LogWarning("Trying to draw type Wall with incorrect tool");
            break;

        case TileTypes.Floor:
            Render(tile, script, mats.ToArray());
            break;

        case TileTypes.Pillar:
            Debug.LogWarning("Trying to draw type Pillar with incorrect tool");
            break;
        }

        mouseStart = Vector3.zero;
        mouseEnd   = Vector3.zero;
    }
コード例 #12
0
    public override void MouseUp(Vector3 mousePos, TileTypes tileType, GameObject tile, floorplan script, Material[] mat, List <int> selected)
    {
        //Get the 4 corners of the rectangle
        Vector3[] points = new Vector3[]
        {
            mouseStart,
            mouseEnd,
            mouseStart - (new Vector3(width, 0, 0)),
            mouseEnd + (new Vector3(width, 0, 0))
        };
        List <Material> mats = new List <Material>();

        selected.RemoveAll(o => o == -1);
        Debug.Log(selected.Count);
        for (int i = 0; i < selected.Count; i++)
        {
            mats.Add(mat[selected[i]]);
        }
        switch (tileType)
        {
        case TileTypes.Wall:
            Render(script, tile, mats.ToArray());
            break;

        case TileTypes.Floor:
            Debug.LogWarning("Trying to draw type Floor with incorrect tool");
            break;
        }
        Editor.DestroyImmediate(depthText);
        Editor.DestroyImmediate(widthText);
        mouseStart = Vector3.zero;
        mouseEnd   = Vector3.zero;
    }
コード例 #13
0
 public abstract void MouseUp(Vector3 mousePos, TileTypes tileType, GameObject tile, floorplan script, Material[] mat, List <int> selected);
コード例 #14
0
    void Render(floorplan script, GameObject tile, Material[] mats)
    {
        GameObject pillar = script.getTilesFromType(TileTypes.Pillar)[0];
        GameObject gO     = new GameObject("Walls");

        gO.transform.parent = script.geometry.transform;
        Vector3 topLeft    = new Vector3(Mathf.Max(mouseStart.x, mouseEnd.x), mouseStart.y, Mathf.Max(mouseStart.z, mouseEnd.z));
        Vector3 bottomLeft = new Vector3(Mathf.Min(mouseStart.x, mouseEnd.x), mouseStart.y, Mathf.Min(mouseStart.z, mouseEnd.z));

        for (int x = 0; x < Mathf.Abs(width); x += (int)script.tileSize)
        {
            Vector3 offset  = topLeft - new Vector3(x + script.tileSize / 2, -.5f, 0);
            Vector3 offset2 = bottomLeft - new Vector3(-x - script.tileSize / 2, -.5f, 0);

            GameObject wall = null;
            if (!Physics.CheckSphere(offset, .1f))
            {
                wall = script.createInstance(tile, (topLeft - new Vector3(x + script.tileSize, 0, 0)), Quaternion.LookRotation(Vector3.right, Vector3.up));
                wall.GetComponent <Renderer>().materials = mats;
                wall.transform.parent.parent             = gO.transform;
            }
            if (!Physics.CheckSphere(offset2, .1f))
            {
                wall = script.createInstance(tile, (bottomLeft - new Vector3(-x - script.tileSize, 0, 0)), Quaternion.LookRotation(-Vector3.right, Vector3.up));
                wall.GetComponent <Renderer>().materials = mats;
                wall.transform.parent.parent             = gO.transform;
            }
        }
        for (int z = 0; z < Mathf.Abs(height); z += (int)script.tileSize)
        {
            Vector3    offset  = topLeft - new Vector3(0, -.5f, z + script.tileSize / 2);
            Vector3    offset2 = bottomLeft - new Vector3(0, -.5f, -z - script.tileSize / 2);
            GameObject wall    = null;
            if (!Physics.CheckSphere(offset, .1f))
            {
                wall = script.createInstance(tile, (topLeft - new Vector3(0, 0, z)), Quaternion.LookRotation(-Vector3.forward, Vector3.up));
                wall.GetComponent <Renderer>().materials = mats;
                wall.transform.parent.parent             = gO.transform;
            }

            if (!Physics.CheckSphere(offset2, .1f))
            {
                wall = script.createInstance(tile, (bottomLeft - new Vector3(0, 0, -z)), Quaternion.identity);
                wall.GetComponent <Renderer>().materials = mats;
                wall.transform.parent.parent             = gO.transform;
            }
        }
        //Create pillars. God all of the code in this place is awful. I'm sorry.
        GameObject pillarTopLeft     = script.createInstance(pillar, bottomLeft, Quaternion.identity);
        GameObject pillarBottomLeft  = script.createInstance(pillar, topLeft, Quaternion.identity);
        GameObject pillarTopRight    = script.createInstance(pillar, topLeft + new Vector3(width, 0, 0), Quaternion.identity);
        GameObject pillarBottomRight = script.createInstance(pillar, bottomLeft + new Vector3(-width, 0, 0), Quaternion.identity);

        pillarTopLeft.GetComponent <Renderer>().materials     = mats;
        pillarBottomLeft.GetComponent <Renderer>().materials  = mats;
        pillarTopRight.GetComponent <Renderer>().materials    = mats;
        pillarBottomRight.GetComponent <Renderer>().materials = mats;


        pillarTopLeft.transform.parent.parent     = gO.transform;
        pillarBottomLeft.transform.parent.parent  = gO.transform;
        pillarTopRight.transform.parent.parent    = gO.transform;
        pillarBottomRight.transform.parent.parent = gO.transform;

        Undo.RegisterCreatedObjectUndo(gO, "Undo wall creation");
    }
コード例 #15
0
 public abstract void MouseUp(Vector3 mousePos, TileTypes tileType, floorplan script, Material mat);