示例#1
0
        public void FindMissingNumberTest()
        {
            var list = new List <int> {
                1, 2, 3, 5, 6, 7
            };
            var result = Chapter05.FindMissingNumber(list, list.Count + 1);

            Assert.AreEqual(4, result);
        }
示例#2
0
    public override void OnInspectorGUI()
    {
        // base.OnInspectorGUI ();

        // Hide Script property
        serializedObject.Update();
        DrawPropertiesExcluding(serializedObject, new string[] { "m_Script" });
        serializedObject.ApplyModifiedProperties();

        Chapter05 obj = target as Chapter05;

        EditorGUI.BeginChangeCheck();

        EditorGUILayout.BeginVertical(GUI.skin.box);

        EditorGUILayout.LabelField(new GUIContent("Model Transform"));

        matrix.SetRow(0, RowVector4Field(matrix.GetRow(0)));
        matrix.SetRow(1, RowVector4Field(matrix.GetRow(1)));
        matrix.SetRow(2, RowVector4Field(matrix.GetRow(2)));
        matrix.SetRow(3, RowVector4Field(matrix.GetRow(3)));

        if (GUILayout.Button("Reset"))
        {
            matrix = Matrix4x4.identity;
        }

        if (GUILayout.Button("Apply"))
        {
            mf        = obj.cube.GetComponent <MeshFilter>();
            origVerts = mf.mesh.vertices;
            newVerts  = new Vector3[origVerts.Length];

            int i = 0;
            while (i < origVerts.Length)
            {
                newVerts[i] = matrix.MultiplyPoint3x4(origVerts[i]);
                i++;
            }

            mf.mesh.vertices = newVerts;
        }

        EditorGUILayout.EndVertical();

        EditorGUILayout.BeginVertical(GUI.skin.box);

        determinant3x3 = EditorGUILayout.FloatField("Determinant (3x3)", determinant3x3);
        determinant4x4 = EditorGUILayout.FloatField("Determinant (4x4)", determinant4x4);

        EditorGUILayout.EndVertical();

        EditorGUILayout.Space();

        EditorGUILayout.Space();

        EditorGUILayout.BeginVertical(GUI.skin.box);

        translation = EditorGUILayout.Vector3Field("Translation", translation);

        if (GUILayout.Button("Apply"))
        {
            Matrix4x4 m = Matrix4x4.identity;
            m.SetTRS(translation, Quaternion.identity, Vector3.one);
            matrix = m * matrix;
        }

        EditorGUILayout.EndVertical();

        EditorGUILayout.BeginVertical(GUI.skin.box);

        rotation = EditorGUILayout.Vector3Field("Rotation", rotation);

        if (GUILayout.Button("Apply"))
        {
            Matrix4x4 m = Matrix4x4.identity;
            m.SetTRS(Vector3.zero, Quaternion.Euler(rotation.x, rotation.y, rotation.z), Vector3.one);
            matrix = m * matrix;
        }

        EditorGUILayout.EndVertical();

        EditorGUILayout.BeginVertical(GUI.skin.box);

        scale = EditorGUILayout.Vector3Field("Scale", scale);

        if (GUILayout.Button("Apply"))
        {
            Matrix4x4 m = Matrix4x4.identity;
            m.SetTRS(Vector3.zero, Quaternion.identity, scale);
            matrix = m * matrix;
        }

        EditorGUILayout.EndVertical();

        EditorGUILayout.BeginVertical(GUI.skin.box);

        EditorGUILayout.LabelField(new GUIContent("Projection Transform"));

        if (GUILayout.Button("Perspective"))
        {
            Camera.main.orthographic = false;
        }

        if (GUILayout.Button("Orthographic"))
        {
            Camera.main.orthographic = true;
        }

        projectionMatrix.SetRow(0, RowVector4Field(projectionMatrix.GetRow(0)));
        projectionMatrix.SetRow(1, RowVector4Field(projectionMatrix.GetRow(1)));
        projectionMatrix.SetRow(2, RowVector4Field(projectionMatrix.GetRow(2)));
        projectionMatrix.SetRow(3, RowVector4Field(projectionMatrix.GetRow(3)));

        if (GUILayout.Button("Camera.main.projectionMatrix"))
        {
            string graphicsDeviceType = SystemInfo.graphicsDeviceType.ToString();
            Debug.Log(graphicsDeviceType);

            bool dx = graphicsDeviceType.IndexOf("Direct3D") == 0;

            int dxVersion = 11;
            if (dx)
            {
                System.Int32.TryParse(graphicsDeviceType.Substring("Direct3D".Length), out dxVersion);
                Debug.Log("Direct3D version: " + dxVersion);
            }

            Matrix4x4 pm = Camera.main.projectionMatrix;

            if (dx)
            {
                if (dxVersion < 11)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        pm [1, i] = -pm [1, i];
                    }

                    for (int i = 0; i < 4; i++)
                    {
                        pm [2, i] = pm [2, i] * 0.5f + pm [3, i] * 0.5f;
                    }
                }
                else
                {
                    for (int i = 0; i < 4; i++)
                    {
                        pm[1, i] = -pm[1, i];
                    }

                    for (int i = 0; i < 4; i++)
                    {
                        pm[2, i] = pm[2, i] * -0.5f + pm[3, i] * 0.5f;
                    }
                }
            }

            projectionMatrix = pm;

            Matrix4x4 gpuProjectionMatrix = GL.GetGPUProjectionMatrix(Camera.main.projectionMatrix, true);
            if (pm == gpuProjectionMatrix)
            {
                Debug.Log("Camera.main.projectionMatrix matches with GL.GetGPUProjectionMatrix");
            }
            else
            {
                Debug.LogWarning("Camera.main.projectionMatrix doesn't match with GL.GetGPUProjectionMatrix");
            }
        }

        if (GUILayout.Button("GL.GetGPUProjectionMatrix"))
        {
            projectionMatrix = GL.GetGPUProjectionMatrix(Camera.main.projectionMatrix, true);
        }

        if (GUILayout.Button("Reset"))
        {
            projectionMatrix = Matrix4x4.identity;
            Camera.main.ResetProjectionMatrix();
        }

        if (GUILayout.Button("Set"))
        {
            Camera.main.projectionMatrix = projectionMatrix;
        }

        EditorGUILayout.EndVertical();

        if (EditorGUI.EndChangeCheck())
        {
            determinant3x3 = getDeterminant3x3(matrix);
            determinant4x4 = getDeterminant4x4(matrix);

            Undo.RecordObject(target, "Chapter05EditorUndo");
            EditorUtility.SetDirty(target);
        }
    }
 public void Chapter05_FillFrame() => Chapter05.FillFrame(frame);