Пример #1
0
    public override void OnInspectorGUI()
    {
        this.serializedObject.Update();
        myScript = (BattleboxManager)target;

        DrawDefaultInspector();


//        EditorGUILayout.Space();
//        EditorGUILayout.Space();
//        if (GUILayout.Button("从文件载入格子数据"))
//        {
//            myScript.InitFromFile();
//        }

        EditorGUILayout.Space();
        EditorGUILayout.Space();
        if (GUILayout.Button(IsSceneEditing ? $"结束编辑(G)" : "开始编辑(G)"))
        {
            ChangeEditStatus(!IsSceneEditing);
        }

        EditorGUILayout.Space();
        EditorGUILayout.Space();
        if (GUILayout.Button("初始化格子数据(慎用)"))
        {
            myScript.CreateDataset();
        }
    }
Пример #2
0
    private void EditBlocks()
    {
        //            var sceneCamera = SceneView.lastActiveSceneView.camera;
        //            var pixelPos = Event.current.mousePosition;
        //            var v3 = new Vector3(pixelPos.x, pixelPos.y, 0.0f);
        //            var ray = sceneCamera.ScreenPointToRay(v3);
        Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, 10000, 1 << LayerMask.NameToLayer("Ground")))
        {
            if (myScript.m_Dataset == null)
            {
                myScript.CreateDataset();
            }

            Debug.Log($"选中了坐标点:{hit.point.x}:{hit.point.z}");

            var pos    = myScript.m_Dataset.GetXYIndex(hit.point.x, hit.point.z);
            var xindex = (int)pos.X;
            var yindex = (int)pos.Y;
            if (myScript.Exist(xindex, yindex))
            {
                Debug.Log($"编辑格子状态,{xindex}:{yindex}");
                myScript.ChangeValid(xindex, yindex);
                myScript.SaveToFile();
            }
            else
            {
                Debug.Log($"没有选中格子,{pos.X}:{pos.Y}");
            }
        }
    }