Newer
Older
Plot_On_Reality / Assets / Originals / Scripts / GraphManagement / RemoveGraph.cs
t-nagao on 1 Feb 2023 3 KB first
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class RemoveGraph : BackButton
{
    [SerializeField] GraphManager graphManager;
    [SerializeField] TextMeshPro graphKindText;
    [SerializeField] TextMeshPro graphFormulaText;
    [SerializeField] GameObject optionMenuScreen;

    private int index;
    private GraphData graphData;

    public void Initialize(GraphData data, int index)
    {
        graphData = data;
        this.index = index;
        graphKindText.text = graphKindStr(graphData.getGraphNum());
        graphFormulaText.text = getFormulaMessage(graphData);

    }

    public void pressedDecideButton()
    {
        graphManager.removeGraphData(index);
        base.anotherButtonAction();
    }

    private string graphKindStr(int num)
    {
        switch (num)
        {
            case 0:
                return "直線";
            case 1:
                return "平面";
            default:
                return "エラー";
        }
    }

    private string getFormulaMessage(GraphData data)
    {
        string str = "";
        if (data == null)
        {
            return str;
        }

        if (data.isDataFormulaInputted())
        {
            switch (data.getGraphNum())
            {
                case 0: //直線
                    Vector3 p = data.getLinePassingPoint();
                    Vector3 d = data.getLineDirection();
                    str = "点(" + p.x + " ," + p.y + " ," + p.z + ")を通る" +
                        "\nベクトル(" + d.x + " ," + d.y + " ," + d.z + ")に平行な直線"; ;

                    break;
                case 1: //平面
                    Vector4 c = data.getPlaneCoefficient();

                    str = c.x + "x ";
                    if (Mathf.Sign(c.y) == -1)
                    {
                        str += c.y + "y ";
                    }
                    else
                    {
                        str += "+" + c.y + "y ";
                    }

                    if (Mathf.Sign(c.z) == -1)
                    {
                        str += c.z + "z ";
                    }
                    else
                    {
                        str += "+" + c.z + "z ";
                    }

                    if (Mathf.Sign(c.w) == -1)
                    {
                        str += c.w + " = 0";
                    }
                    else
                    {
                        str += "+" + c.w + " = 0";
                    };
                    break;
                case 2:
                    str = "Error";
                    break;
            }

        }
        else
        {
            switch (data.getGraphNum())
            {
                case 0: //直線
                    str = "タッチして直線の式を入力";
                    break;
                case 1: //平面
                    str = "タッチして平面の式を入力";
                    break;
                case 2:
                    str = "対応していません。";
                    break;
            }

        }

        return str;

    }


}