Пример #1
0
    public static void LoadData()
    {
        var    jsonAsset = Resources.Load <TextAsset>("ModelShapes");
        string jsonText  = jsonAsset.text;

        var jsonDict = MiniJSON.Json.Deserialize(jsonText) as Dictionary <string, object>;
        var data     = jsonDict["data"] as List <object>;

        palette = new ModelShape[data.Count];
        table   = new Dictionary <string, ModelShape>();

        for (int i = 0; i < data.Count; i++)
        {
            var shape = data[i] as Dictionary <string, object>;

            string name        = (string)shape["name"];
            int    id          = (int)(long)shape["id"];
            string displayName = (string)shape["displayName"];
            float  scale       = (float)(double)shape["scale"];

            var prefab = Resources.Load <GameObject>("Models/" + name);
            if (prefab == null)
            {
                Debug.LogError("Models/" + name + " is not found.");
            }
            bool enterable = (bool)shape["enterable"];

            palette[i] = new ModelShape(name, id, displayName, prefab, scale, enterable);
            table.Add(name, palette[i]);
        }
    }
Пример #2
0
    public static void LoadData()
    {
        string jsonText = File.ReadAllText(Application.streamingAssetsPath + "/ModelShapes.json");

        var jsonDict = MiniJSON.Json.Deserialize(jsonText) as Dictionary <string, object>;
        var data     = jsonDict["data"] as List <object>;

        palette = new ModelShape[data.Count];
        table   = new Dictionary <string, ModelShape>();

        for (int i = 0; i < data.Count; i++)
        {
            var shape = data[i] as Dictionary <string, object>;

            string name        = (string)shape["name"];
            string path        = (string)shape["path"];
            string displayName = shape.ContainsKey("displayName") ? (string)shape["displayName"] : name;
            float  scale       = shape.ContainsKey("scale") ? (float)(double)shape["scale"] : 1.0f;
            float  offsetY     = shape.ContainsKey("offsetY") ? (float)(double)shape["offsetY"] : 0.0f;
            bool   enterable   = shape.ContainsKey("enterable") ? (bool)shape["enterable"] : false;

            var model = OBJLoader.LoadModel(Application.streamingAssetsPath + "/ObjectModels/" + path);
            if (model != null)
            {
                palette[i] = new ModelShape(name, displayName, model, new Vector3(0.0f, offsetY, 0.0f), scale, enterable);
                table.Add(name, palette[i]);
                ModelPalette.Instance.AddModel(name, displayName);
            }
        }
    }
Пример #3
0
 public Model(ModelShape shape, Vector3 position, int rotation = 0, float scale = 1.0f)
 {
     this.shape = shape;
     this.SetPosition(position);
     this.SetRotation(rotation);
     this.SetScale(scale);
     this.Show();
 }
Пример #4
0
    public void SetModel(ModelShape shape)
    {
        this.Reset();
        GameObject go = this.modelObject = shape.Build(surfaceRenderer.sharedMaterial);

        go.transform.parent        = this.gameObject.transform;
        go.transform.localPosition = Vector3.zero;
        go.transform.localScale    = Vector3.one;
    }
Пример #5
0
        public void addModelShape()
        {
            Random rnd = new Random();
            int    x   = rnd.Next(100, 1000);
            int    y   = rnd.Next(100, 600);

            ModelShape shape = new ModelShape(new RectangleF(x, y, 100, 100));

            ShapeList.Add(shape);
        }
Пример #6
0
    public void AddModel(Vector3 position, int rotation)
    {
        EditLayer layer      = this.CurrentLayer;
        var       modelShape = ModelShape.Find(this.toolModel);
        var       model      = new Model(modelShape, position, rotation);

        this.AddCommand(new Command(
                            () => {
            layer.AddModel(model);
        }, () => {
            layer.RemoveModel(model, true);
        }));
    }
Пример #7
0
    public void SetModel(string typeName)
    {
        ModelShape shape = ModelShape.Find(typeName);

        if (shape == null)
        {
            return;
        }

        this.transform.rotation = Quaternion.identity;
        var meshFilter = shape.prefab.GetComponent <MeshFilter>();

        this.guide.SetMesh(meshFilter.sharedMesh, null);
        this.guide.transform.localPosition = Vector3.zero;
        this.guide.transform.localScale    = Vector3.one * shape.scale;
    }
Пример #8
0
    public void SetModel(string typeName)
    {
        ModelShape shape = ModelShape.Find(typeName);

        if (shape == null)
        {
            return;
        }

        this.transform.rotation = Quaternion.identity;
        //this.guide.SetMesh(shape.model.GetMesh(0), null, false);
        this.guide.SetModel(shape);
        this.guide.transform.localPosition = shape.offset;
        this.guide.transform.localScale    = Vector3.one * shape.scale;
        this.guide.transform.localRotation = Quaternion.identity;
    }
Пример #9
0
    void Awake()
    {
        if (EditManager.Instance)
        {
            throw new Exception("EditManager is found.");
        }
        EditManager.Instance     = this;
        Application.wantsToQuit += WantToQuit;
        this.Layers              = new List <EditLayer>();

        var gridObj = new GameObject("Grid");

        gridObj.transform.parent = this.transform;
        this.Grid = gridObj.AddComponent <Grid>();

        var cursorObj = new GameObject("EditCursor");

        cursorObj.transform.parent = EditManager.Instance.transform;
        this.Cursor = cursorObj.AddComponent <EditCursor>();

        var selectionObj = new GameObject("Selector");

        selectionObj.transform.parent = this.transform;
        this.Selector = selectionObj.AddComponent <Selector>();

        var routePathObj = new GameObject("RoutePath");

        selectionObj.transform.parent = this.transform;
        this.RoutePath = routePathObj.AddComponent <RoutePath>();
        routePathObj.SetActive(false);

        this.ToolMenu        = GameObject.FindObjectOfType <ToolMenu>();
        this.ModelProperties = GameObject.FindObjectOfType <ModelProperties>();
        this.MetaInfo        = GameObject.FindObjectOfType <MetaInfo>();

        this.QuitDialog = GameObject.FindObjectOfType <QuitDialog>();
        this.QuitDialog.Close();

        this.LayerListView = GameObject.FindObjectOfType <LayerListView>();

        this.BlockMaterial = Resources.Load <Material>("Materials/BlockMaterial");
        this.WaterMaterial = Resources.Load <Material>("Materials/WaterMaterial");
        this.ModelMaterial = Resources.Load <Material>("Materials/ModelMaterial");

        BlockShape.LoadData();
        ModelShape.LoadData();
    }
Пример #10
0
        public void OnLoad(object sender, EventArgs e)
        {
            var groundModel   = GltfImporter.Load("./Resources/Models/test_1.gltf");
            var playerModel   = GltfImporter.Load("./Resources/Models/postpose.gltf");
            var pineTreeModel = GltfImporter.Load("./Resources/Models/pine_tree_1.gltf");

            foreach (var mesh in playerModel.Meshes)
            {
                mesh.Material = new BasicShadedColoredMaterial();
            }

            foreach (var mesh in pineTreeModel.Meshes)
            {
                mesh.Material = new BasicShadedColoredMaterial();
            }

            var groundMaterial = new BasicShadedMaterial()
            {
                Color = new Vector3(1, 1, 1)
            };

            foreach (var mesh in groundModel.Meshes)
            {
                mesh.Material = groundMaterial;
            }

            var ground = new GameObject();

            ground.AddComponent(new ModelComponent()
            {
                Model = groundModel
            });

            var groundShape = new ModelShape(groundModel);

            ground.AddComponent(new PhysicsComponent()
            {
                RigidBody = new RigidBody(groundShape.Shape)
                {
                    IsStatic          = true,
                    AllowDeactivation = false
                }
            });

            var player      = new GameObject();
            var playerShape = new ModelShape(playerModel);

            var pineTree = new GameObject();

            pineTree.AddComponent(new ModelComponent()
            {
                Model = pineTreeModel
            });
            pineTree.Transform.Position = new Vector3(80, 73, 100);
            pineTree.Transform.Scale    = new Vector3(4, 4, 4);

            player.AddComponent(new ModelComponent
            {
                Model = playerModel
            });
            player.AddComponent(new PhysicsComponent
            {
                RigidBody = new RigidBody(new BoxShape(1f, 0.5f, 1))
                {
                    AffectedByGravity = true,
                    AllowDeactivation = false
                }
            });
            player.AddComponent(new MonkeyComponent());

            player.Transform.Position = new Vector3(145.0654f, 100.74099f, 173.0334f);
            player.Transform.Rotation = new Vector3(215.9143f, 0f, 0f);

            var camera = WindowManager.Scene.ActiveCamera;

            camera.AddComponent(new FollowCameraComponent()
            {
                FollowGameObject = player
            });

            /*
             * camera.AddComponent(new FreelookCameraComponent()
             * {
             *  FollowGameObject = player
             * });
             *
             * camera.Transform.Position = new Vector3(154.0654f, 80.74099f, 185.0334f);
             * camera.Transform.Rotation = new Vector3(224.9143f, -2.557277f, 0f);
             */
        }
Пример #11
0
    public static void Import(string path)
    {
        {
            //try {
            string       allText = File.ReadAllText(path);
            StringReader stm     = new StringReader(allText);

            // フォーマットバージョンを取得
            int version = int.Parse(stm.ReadLine());

            List <string> modelList = new List <string>();

            // オブジェクトのリストを取得
            for (int i = 0; i < MaxObjects; i++)
            {
                string line = stm.ReadLine();
                if (!String.IsNullOrEmpty(line))
                {
                    modelList.Add(line);
                }
            }

            // マップサイズを取得
            int cx, cz;
            {
                string   line  = stm.ReadLine();
                string[] items = line.Split(',');
                cx = int.Parse(items[0]);
                cz = int.Parse(items[1]);
            }

            // ヘッダ行を読み飛ばす
            stm.ReadLine();

            var          layer  = EditManager.Instance.CurrentLayer;
            BlockShape[] shapes = new BlockShape[256];
            shapes[0]  = BlockShape.Find("cube");
            shapes[1]  = BlockShape.Find("slope");
            shapes[2]  = BlockShape.Find("slope");
            shapes[3]  = BlockShape.Find("slope");
            shapes[4]  = BlockShape.Find("slope");
            shapes[5]  = BlockShape.Find("diag-slope-large");
            shapes[6]  = BlockShape.Find("diag-slope-large");
            shapes[7]  = BlockShape.Find("diag-slope-large");
            shapes[8]  = BlockShape.Find("diag-slope-large");
            shapes[9]  = BlockShape.Find("diag-slope-small");
            shapes[10] = BlockShape.Find("diag-slope-small");
            shapes[11] = BlockShape.Find("diag-slope-small");
            shapes[12] = BlockShape.Find("diag-slope-small");
            shapes[21] = BlockShape.Find("steep-slope");
            shapes[22] = BlockShape.Find("steep-slope");
            shapes[23] = BlockShape.Find("steep-slope");
            shapes[24] = BlockShape.Find("steep-slope");
            shapes[25] = BlockShape.Find("steep-diag-slope-large");
            shapes[26] = BlockShape.Find("steep-diag-slope-large");
            shapes[27] = BlockShape.Find("steep-diag-slope-large");
            shapes[28] = BlockShape.Find("steep-diag-slope-large");
            shapes[29] = BlockShape.Find("steep-diag-slope-small");
            shapes[30] = BlockShape.Find("steep-diag-slope-small");
            shapes[31] = BlockShape.Find("steep-diag-slope-small");
            shapes[32] = BlockShape.Find("steep-diag-slope-small");

            BlockDirection[] directions = new BlockDirection[256];
            directions[0]  = BlockDirection.Zplus;
            directions[1]  = BlockDirection.Xminus;
            directions[2]  = BlockDirection.Zminus;
            directions[3]  = BlockDirection.Xplus;
            directions[4]  = BlockDirection.Zplus;
            directions[5]  = BlockDirection.Zplus;
            directions[6]  = BlockDirection.Xminus;
            directions[7]  = BlockDirection.Zminus;
            directions[8]  = BlockDirection.Xplus;
            directions[9]  = BlockDirection.Xminus;
            directions[10] = BlockDirection.Zminus;
            directions[11] = BlockDirection.Xplus;
            directions[12] = BlockDirection.Zplus;

            for (int z = 0; z < cz; z++)
            {
                int x;
                for (x = 0; x < cx; x++)
                {
                    string   line  = stm.ReadLine();
                    string[] items = line.Split(',');

                    int  blockHeight  = int.Parse(items[0]);
                    int  blockShapeId = int.Parse(items[1]);
                    bool canEntry     = int.Parse(items[2]) == 0;
                    int  objId        = int.Parse(items[3]);
                    int  objAngle     = int.Parse(items[4]);
                    int  objScale     = int.Parse(items[5]);
                    int  objY         = int.Parse(items[6]);
                    int  texId        = int.Parse(items[7]);

                    BlockShape blockShape = null;
                    while ((blockShape = shapes[blockShapeId]) == null)
                    {
                        blockShapeId -= 20;
                    }

                    for (int y = 0; y < blockHeight; y++)
                    {
                        bool isTop = (y == blockHeight - 1);
                        var  shape = isTop ? blockShape : shapes[0];
                        if (shape != null)
                        {
                            var direction = isTop ? directions[blockShapeId % 20] : directions[0];
                            var block     = new Block(
                                new Vector3((float)x, (float)y / 2, (float)-z),
                                direction, shape);
                            block.enterable = canEntry;
                            layer.AddBlock(block);

                            if (isTop)
                            {
                                block.SetTextureChip(BlockDirection.Yplus, false,
                                                     (texId % 20) + (texId / 20) * 100);
                                block.SetTextureChip(BlockDirection.Zplus, false, 7);
                                block.SetTextureChip(BlockDirection.Zminus, false, 7);
                                block.SetTextureChip(BlockDirection.Xplus, false, 7);
                                block.SetTextureChip(BlockDirection.Xminus, false, 7);
                            }
                            else
                            {
                                block.SetTextureChip(BlockDirection.Zplus, false, 6);
                                block.SetTextureChip(BlockDirection.Zminus, false, 6);
                                block.SetTextureChip(BlockDirection.Xplus, false, 6);
                                block.SetTextureChip(BlockDirection.Xminus, false, 6);
                            }
                        }
                        else
                        {
                            Debug.LogWarning("Unknown block shape: " + blockShape);
                        }
                    }
                    if (objId > 0)
                    {
                        string fileName   = modelList[objId - 1];
                        string modelName  = Path.GetFileNameWithoutExtension(fileName);
                        var    modelShape = ModelShape.Find(modelName);
                        if (modelShape != null)
                        {
                            layer.AddModel(new Model(modelShape,
                                                     new Vector3((float)x, (float)blockHeight / 2, (float)-z),
                                                     objAngle, (objScale + 100) * 0.01f));
                        }
                        else
                        {
                            Debug.LogWarning("Model \"" + modelName + "\" not found.");
                        }
                    }
                }

                // スキップ行
                for (; x < MaxSizeX; x++)
                {
                    stm.ReadLine();
                }
            }
        }        /* catch (Exception e) {
                  *     Debug.LogError(e.Message);
                  * }*/
    }
Пример #12
0
    void updateActions()
    {
        bool LMouseClicked = false, LMouseHeld = false, RMouseClicked = false, RMouseHeld = false;

        if (Input.GetMouseButtonDown(0))
        {
            LMouseClicked = true;
        }
        if (Input.GetMouseButton(0))
        {
            LMouseHeld = true;
        }
        if (Input.GetMouseButtonDown(1))
        {
            RMouseClicked = true;
        }
        if (Input.GetMouseButton(1))
        {
            RMouseHeld = true;
        }

        if (LMouseClicked)
        {
            if (Player.selectedShape == null)
            {
                if (Player.hoveringShape != null)
                {
                    ModelShape ms = Player.hoveringShape.GetComponent <ModelShape>();
                    if (ms != null)
                    {
                        Player.selectedShape = Player.hoveringShape;
                        ms.setSelected(true);
                    }
                }
            }
            else
            {
                if (hoveringShape && hoveringShape.GetComponent <ShapeHandle>())
                {
                    ShapeHandle handle = hoveringShape.GetComponent <ShapeHandle>();
                    if (handle.isSelected)
                    {
                        handle.isSelected = false;
                        handle.GetComponent <MeshRenderer>().material = handle.unselected;
                        if (handle == handle1)
                        {
                            handle1 = handle2;
                            handle2 = null;
                        }
                        else if (handle == handle2)
                        {
                            handle2 = null;
                        }
                    }
                    else
                    {
                        if (handle1 == null)
                        {
                            handle1 = handle;
                        }
                        else
                        {
                            if (handle2)
                            {
                                handle2.GetComponent <MeshRenderer>().material = handle.unselected;
                            }

                            handle2 = handle;
                        }
                        handle.GetComponent <MeshRenderer>().material = handle.selected;
                        handle.isSelected = true;
                    }
                }
                if (Player.hoveringShape == Player.selectedShape || Player.hoveringShape == null || Player.hoveringShape.GetComponent <ShapeHandle>() == null)
                {
                    if (Player.hoveringShape == null || hoveringShape.transform.parent == null || !hoveringShape.transform.parent.name.Equals("Axes"))
                    {
                        Player.selectedShape.GetComponent <ModelShape>().setSelected(false);
                        Player.selectedShape = null;
                    }
                }
            }
        }
        else
        {
            if (hoveringShape == null)
            {
                if (Player.lastHoveredShape != null)
                {
                    if (lastHoveredShape.GetComponent <ModelShape>() != null &&
                        lastHoveredShape.transform.Find("Cube").Find("OutlineHover") != null)
                    {
                        lastHoveredShape.transform.Find("Cube").Find("OutlineHover").gameObject.SetActive(false);
                    }

                    lastHoveredShape = null;
                }

                if (lastHoveredHandle)
                {
                    if (lastHoveredHandle.isSelected)
                    {
                        lastHoveredHandle.gameObject.GetComponent <MeshRenderer>().material = lastHoveredHandle.selected;
                    }
                    else
                    {
                        lastHoveredHandle.gameObject.GetComponent <MeshRenderer>().material = lastHoveredHandle.unselected;
                    }

                    lastHoveredHandle = null;
                }
            }
            else
            {
                if (Player.selectedShape == null)
                {
                    if (hoveringShape != null && hoveringShape.GetComponent <ModelShape>() != null)
                    {
                        hoveringShape.transform.Find("Cube").Find("OutlineHover").gameObject.SetActive(true);
                    }
                }
                else
                {
                    ShapeHandle handle = Player.hoveringShape.GetComponent <ShapeHandle>();
                    if (handle)
                    {
                        if (handle.isSelected)
                        {
                            hoveringShape.GetComponent <MeshRenderer>().material = handle.selectedHighlighted;
                        }
                        else
                        {
                            hoveringShape.GetComponent <MeshRenderer>().material = handle.highlighted;
                        }

                        lastHoveredHandle = handle;
                    }
                    else
                    {
                        if (lastHoveredHandle != null)
                        {
                            if (lastHoveredHandle.isSelected)
                            {
                                lastHoveredHandle.gameObject.GetComponent <MeshRenderer>().material = lastHoveredHandle.selected;
                            }
                            else
                            {
                                lastHoveredHandle.gameObject.GetComponent <MeshRenderer>().material = lastHoveredHandle.unselected;
                            }

                            lastHoveredHandle = null;
                        }
                    }
                }
            }
        }
    }
Пример #13
0
    // 読み込み
    public void Deserialize(XmlElement node)
    {
        if (node.HasAttribute("type"))
        {
            string typeName = node.GetAttribute("type");
            this.shape = ModelShape.Find(typeName);
            if (this.shape == null)
            {
                Debug.LogError("Unknown Model's type: " + typeName);
                return;
            }
        }
        else
        {
            Debug.LogError("Model's type element is not found.");
            return;
        }

        {
            Vector3 position = Vector3.zero;
            if (node.HasAttribute("x"))
            {
                float.TryParse(node.GetAttribute("x"), out position.x);
            }
            if (node.HasAttribute("y"))
            {
                float.TryParse(node.GetAttribute("y"), out position.y);
            }
            if (node.HasAttribute("z"))
            {
                float.TryParse(node.GetAttribute("z"), out position.z);
            }
            this.position = position;
        }
        {
            Vector3 offset = Vector3.zero;
            if (node.HasAttribute("offsetX"))
            {
                float.TryParse(node.GetAttribute("offsetX"), out offset.x);
            }
            if (node.HasAttribute("offsetY"))
            {
                float.TryParse(node.GetAttribute("offsetY"), out offset.y);
            }
            if (node.HasAttribute("offsetZ"))
            {
                float.TryParse(node.GetAttribute("offsetZ"), out offset.z);
            }
            this.offset = offset;
        }

        {
            int rotation = 0;
            if (node.HasAttribute("rotation"))
            {
                int.TryParse(node.GetAttribute("rotation"), out rotation);
            }
            this.rotation = rotation;
        }
        {
            float scale = 0;
            if (node.HasAttribute("scale"))
            {
                float.TryParse(node.GetAttribute("scale"), out scale);
            }
            this.scale = scale;
        }
    }