Beispiel #1
0
    public void Update()
    {
        bool visible = false;

        // マウスカーソルの処理
        Point point;
        bool  cursorEnabled = this.GetCursorPoint(out point);

        this.block = null;
        this.model = null;
        if (point.gameObject != null)
        {
            var layer = point.gameObject.GetComponent <EditLayer>();
            if (layer != null)
            {
                if (layer == EditManager.Instance.CurrentLayer)
                {
                    this.block = layer.GetBlock(point.position);
                }
            }
            else
            {
                this.model = EditManager.Instance.CurrentLayer.GetModel(point.gameObject);
            }
        }

        switch (EditManager.Instance.GetTool())
        {
        case EditManager.Tool.Block:
            if (cursorEnabled)
            {
                // 手前に立体カーソルを置く
                visible    = true;
                this.point = EditUtil.ResolvePosition(point.position +
                                                      new Vector3(point.normal.x, point.normal.y * 0.5f, point.normal.z));
                this.transform.position = this.point;
                this.transform.rotation = Quaternion.AngleAxis(
                    EditUtil.DirectionToAngle(this.blockDirection), Vector3.up);
                this.transform.localScale = Vector3.one;
            }
            break;

        case EditManager.Tool.Eraser:
        case EditManager.Tool.PointSelector:
            if (cursorEnabled)
            {
                // 立体カーソルを置く
                if (this.block != null)
                {
                    visible    = true;
                    this.point = point.position;
                    this.SetBlock();
                    this.transform.position   = point.position;
                    this.transform.rotation   = Quaternion.identity;
                    this.transform.localScale = Vector3.one;
                }
                else if (this.model != null)
                {
                    visible    = true;
                    this.point = point.position;
                    this.SetModelBound(this.model);
                    this.transform.position   = this.model.position;
                    this.transform.rotation   = Quaternion.identity;
                    this.transform.localScale = Vector3.one;
                }
            }
            break;

        case EditManager.Tool.Brush:
        case EditManager.Tool.Spuit:
            if (cursorEnabled && this.block != null)
            {
                this.point = point.position;
                // 面カーソルを置く
                visible             = true;
                this.panelDirection = EditUtil.VectorToDirection(point.normal);

                Mesh mesh = this.block.GetMesh(this.panelDirection);
                if (mesh != null)
                {
                    // 面が選択されている
                    this.objectSelected = false;
                    this.SetMesh(mesh);
                }
                else
                {
                    mesh = this.block.GetObjectMesh();
                    if (mesh != null)
                    {
                        // オブジェクトが選択されている
                        this.objectSelected = true;
                        this.SetMesh(mesh);
                    }
                    else
                    {
                        this.SetBlock();
                    }
                }

                Vector3 position = point.position + point.normal * 0.01f;
                this.transform.position = new Vector3(Mathf.Round(position.x), Mathf.Round(position.y * 2.0f) * 0.5f, Mathf.Round(position.z));
                this.transform.rotation = Quaternion.AngleAxis(
                    EditUtil.DirectionToAngle(this.block.direction) + 180.0f, Vector3.up);
                this.transform.localScale = Vector3.one;
            }
            break;

        case EditManager.Tool.Model:
            if (cursorEnabled)
            {
                // 手前に立体カーソルを置く
                visible    = true;
                this.point = EditUtil.ResolvePosition(point.position +
                                                      new Vector3(point.normal.x, point.normal.y * 0.5f, point.normal.z));
                this.transform.position = this.point;
                this.transform.rotation = Quaternion.AngleAxis(
                    EditUtil.DirectionToAngle(this.blockDirection), Vector3.up);
                this.transform.localScale = Vector3.one;
            }
            break;

        case EditManager.Tool.RoutePath:
        case EditManager.Tool.MetaInfo:
            if (cursorEnabled && this.block != null &&
                EditUtil.VectorToDirection(point.normal) == BlockDirection.Yplus
                )
            {
                this.point = point.position;
                visible    = true;
                // 面カーソルを置く
                this.SetPanel();
                Vector3 position = point.position + point.normal * 0.01f;
                this.transform.position = new Vector3(Mathf.Round(position.x),
                                                      Mathf.Round(position.y * 2.0f) * 0.5f + 0.25f,
                                                      Mathf.Round(position.z));
                this.panelDirection       = BlockDirection.Yplus;
                this.transform.rotation   = Quaternion.identity;
                this.transform.localScale = Vector3.one;
            }
            break;
        }
        this.visible = visible;
        this.guide.gameObject.SetActive(visible);
    }
Beispiel #2
0
    public void Update()
    {
        bool visible = false;

        // マウスカーソルの処理
        Vector3    point, normal;
        GameObject gameObject;
        bool       cursorEnabled = this.GetCursorPoint(out point, out normal, out gameObject);

        this.block = null;
        this.model = null;
        if (gameObject == EditManager.Instance.CurrentLayer.gameObject)
        {
            this.block = EditManager.Instance.CurrentLayer.GetBlock(point);
        }
        else if (gameObject != null)
        {
            this.model = EditManager.Instance.CurrentLayer.GetModel(gameObject);
        }

        switch (EditManager.Instance.GetTool())
        {
        case EditManager.Tool.Block:
            if (cursorEnabled)
            {
                // 手前に立体カーソルを置く
                point     += new Vector3(normal.x, normal.y * 0.5f, normal.z);
                visible    = true;
                this.point = point;
                this.transform.position = point;
                this.transform.rotation = Quaternion.AngleAxis(
                    EditUtil.DirectionToAngle(this.blockDirection), Vector3.up);
                this.transform.localScale = Vector3.one;
            }
            break;

        case EditManager.Tool.Eraser:
        case EditManager.Tool.PointSelector:
            if (cursorEnabled)
            {
                // 立体カーソルを置く
                if (this.block != null)
                {
                    visible    = true;
                    this.point = point;
                    this.SetBlock();
                    this.transform.position   = point;
                    this.transform.rotation   = Quaternion.identity;
                    this.transform.localScale = Vector3.one;
                }
                else if (this.model != null)
                {
                    visible    = true;
                    this.point = point;
                    this.SetModelBound(this.model);
                    this.transform.position   = this.model.position;
                    this.transform.rotation   = Quaternion.identity;
                    this.transform.localScale = Vector3.one;
                }
            }
            break;

        case EditManager.Tool.Brush:
        case EditManager.Tool.Spuit:
            if (cursorEnabled && this.block != null)
            {
                this.point = point;
                // 面カーソルを置く
                visible             = true;
                this.panelDirection = EditUtil.VectorToDirection(normal);
                var block = EditManager.Instance.CurrentLayer.GetBlock(point);
                if (block.GetMesh(this.panelDirection) != null)
                {
                    // 面のメッシュが存在していたら、面が選択されている
                    this.objectSelected = false;
                    this.SetPanel();
                    this.transform.position = point + new Vector3(normal.x * 0.5f, normal.y * 0.25f, normal.z * 0.5f);
                    switch (this.panelDirection)
                    {
                    case BlockDirection.Yplus:
                        this.transform.rotation   = Quaternion.identity;
                        this.transform.localScale = Vector3.one;
                        break;

                    case BlockDirection.Yminus:
                        this.transform.rotation   = Quaternion.Euler(180, 0, 0);
                        this.transform.localScale = Vector3.one;
                        break;

                    case BlockDirection.Zplus:
                        this.transform.rotation   = Quaternion.Euler(90, 180, 0);
                        this.transform.localScale = new Vector3(1.0f, 1.0f, 0.5f);
                        break;

                    case BlockDirection.Zminus:
                        this.transform.rotation   = Quaternion.Euler(90, 0, 0);
                        this.transform.localScale = new Vector3(1.0f, 1.0f, 0.5f);
                        break;

                    case BlockDirection.Xplus:
                        this.transform.rotation   = Quaternion.Euler(90, 90, 0);
                        this.transform.localScale = new Vector3(1.0f, 1.0f, 0.5f);
                        break;

                    case BlockDirection.Xminus:
                        this.transform.rotation   = Quaternion.Euler(90, 270, 0);
                        this.transform.localScale = new Vector3(1.0f, 1.0f, 0.5f);
                        break;
                    }
                }
                else
                {
                    // 面のメッシュが存在していないなら、オブジェクトが選択されている
                    this.objectSelected = true;
                    this.SetBlock();
                    this.transform.position   = point;
                    this.transform.rotation   = Quaternion.identity;
                    this.transform.localScale = Vector3.one;
                }
            }
            break;

        case EditManager.Tool.Model:
            if (cursorEnabled)
            {
                // ブロックの上に立体カーソルを置く
                point     += new Vector3(0.0f, 0.25f, 0.0f);
                visible    = true;
                this.point = point;
                this.transform.position   = point;
                this.transform.rotation   = Quaternion.identity;
                this.transform.localScale = Vector3.one;
            }
            break;

        case EditManager.Tool.RoutePath:
        case EditManager.Tool.MetaInfo:
            if (cursorEnabled && this.block != null &&
                EditUtil.VectorToDirection(normal) == BlockDirection.Yplus
                )
            {
                this.point = point;
                // 面カーソルを置く
                visible = true;
                this.transform.position   = point + new Vector3(normal.x * 0.5f, normal.y * 0.25f, normal.z * 0.5f);
                this.panelDirection       = BlockDirection.Yplus;
                this.transform.rotation   = Quaternion.identity;
                this.transform.localScale = Vector3.one;
            }
            break;
        }
        this.visible = visible;
        this.guide.gameObject.SetActive(visible);
    }
Beispiel #3
0
    // オブジェクトをクリック
    public void OnObjectClicked()
    {
        var selector = EditManager.Instance.Selector;
        var cursor   = EditManager.Instance.Cursor;

        switch (EditManager.Instance.GetTool())
        {
        case EditManager.Tool.Block:
            if (cursor.visible)
            {
                // 1つ手前にブロックを配置
                EditManager.Instance.AddBlock(cursor.point,
                                              EditManager.Instance.Cursor.blockDirection);
            }
            break;

        case EditManager.Tool.Eraser:
            // 選択されたオブジェクトを消す
            if (cursor.visible)
            {
                if (cursor.block != null)
                {
                    EditManager.Instance.RemoveBlock(cursor.point);
                }
                else if (cursor.model != null)
                {
                    EditManager.Instance.RemoveModel(cursor.model);
                }
            }
            break;

        case EditManager.Tool.Brush:
            if (cursor.visible)
            {
                // 対象のブロックを塗る(テクスチャ指定)
                var block = EditManager.Instance.CurrentLayer.GetBlock(cursor.point);
                if (block != null)
                {
                    EditManager.Instance.PaintBlock(block,
                                                    cursor.panelDirection, cursor.objectSelected,
                                                    TexturePalette.Instance.GetItem());
                }
            }
            break;

        case EditManager.Tool.Spuit:
            if (cursor.visible)
            {
                // 対象のブロックのテクスチャを取得
                var block = EditManager.Instance.CurrentLayer.GetBlock(cursor.point);
                if (block != null)
                {
                    TexturePalette.Instance.SetItem(block.GetTextureChip(cursor.panelDirection, cursor.objectSelected));
                }
            }
            break;

        case EditManager.Tool.PointSelector:
            // 選択モード
            if (cursor.visible)
            {
                // キャプチャ状態のオブジェクトを解放
                selector.ReleaseBlocks();

                // CtrlもShiftも押さずにクリックしたら選択解除
                if (!this.modifierControl && !this.modifierShift)
                {
                    selector.Clear();
                }

                if (this.modifierShift && selector.Count > 0)
                {
                    // Shift押しながら2つ目以降を選択した場合、範囲選択をする
                    selector.SelectRange(selector.LastPosition, cursor.point);
                }
                else if (cursor.model != null)
                {
                    if (selector.IsSelected(cursor.model))
                    {
                        selector.Remove(cursor.model);
                    }
                    else
                    {
                        selector.Add(cursor.model);
                    }
                }
                else
                {
                    // 通常の選択
                    if (selector.IsSelected(cursor.point))
                    {
                        selector.Remove(cursor.point);
                    }
                    else
                    {
                        selector.Add(cursor.point);
                    }
                }
            }
            else
            {
                // 何もないところをCtrlもShiftも押さずにクリックしたら選択解除
                if (!this.modifierControl && !this.modifierShift)
                {
                    selector.ReleaseBlocks();
                    selector.Clear();
                }
            }
            break;

        case EditManager.Tool.RoutePath:
            if (cursor.visible)
            {
                var routePath = EditManager.Instance.RoutePath;
                var block     = EditManager.Instance.CurrentLayer.GetBlock(cursor.point);
                if (routePath.isSelected)
                {
                    // パス確定
                    if (routePath.ContainsPath(routePath.selectedPosition, block.position))
                    {
                        // 存在していたら消す
                        EditManager.Instance.RemoveRoutePath(routePath.selectedPosition, block.position);
                        routePath.RemovePath(routePath.selectedPosition, block.position);
                    }
                    else if (routePath.CanAddPath(routePath.selectedPosition, block.position))
                    {
                        // 存在していなかったら追加
                        EditManager.Instance.AddRoutePath(routePath.selectedPosition, block.position);
                    }
                    else if (routePath.selectedPosition == block.position)
                    {
                        // 同じ位置の場合は侵入フラグをトグルする
                        EditManager.Instance.SetEnterable(block, !block.enterable);
                    }
                    routePath.isSelected = false;
                    EditManager.Instance.Selector.Clear();
                }
                else
                {
                    // パスの開始ブロックを選択
                    EditManager.Instance.Selector.Add(block.position);
                    routePath.selectedPosition = block.position;
                    routePath.isSelected       = true;
                }
            }
            break;

        case EditManager.Tool.Model:
            if (cursor.visible)
            {
                var foundModel = EditManager.Instance.CurrentLayer.GetModel(cursor.point);
                if (foundModel == null)
                {
                    // モデル配置
                    EditManager.Instance.AddModel(cursor.point,
                                                  (int)EditUtil.DirectionToAngle(EditManager.Instance.Cursor.blockDirection));
                }
            }
            break;

        case EditManager.Tool.MetaInfo:
            EditManager.Instance.Selector.Clear();
            EditManager.Instance.MetaInfo.gameObject.SetActive(false);
            if (cursor.visible)
            {
                var block = EditManager.Instance.CurrentLayer.GetBlock(cursor.point);
                if (block != null)
                {
                    // メタ情報を記入するブロックを選択
                    EditManager.Instance.Selector.Add(block.position);
                    // メタ情報記入のダイアログを表示
                    EditManager.Instance.MetaInfo.gameObject.SetActive(true);
                    EditManager.Instance.MetaInfo.SetBlock(block);
                }
            }
            break;
        }
    }