Ejemplo n.º 1
0
 public void OnUndo()
 {
     myTarget = (target as Distort);
     if (myTarget.updateIntEditor)
     {
         myTarget.UpdateDistort();
     }
 }
Ejemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            //Get all the distortions
            System.Collections.Generic.List <DistortData> distort = myTarget.distort;

            Undo.RecordObject(target, "Changing distortion");

            myTarget.calculation = (Distort.Calculate)EditorGUILayout.EnumPopup(new GUIContent("Calculate", "Do calculations in local or global position."), myTarget.calculation);

            GUILayout.Toggle(false, new GUIContent("Calculate in GPU (Ony in the Full Version)", "Only in the full version."));

            if (myTarget.calculateInGPU)
            {
                myTarget.distortShader = EditorGUILayout.ObjectField("Shader", myTarget.distortShader, typeof(ComputeShader), false) as ComputeShader;
            }

            //Debug options
            myTarget.showPreviewWindow = GUILayout.Toggle(myTarget.showPreviewWindow, new GUIContent("Show Preview Window", "Show the preview window in the editor."));
            myTarget.showMeshInEditor  = GUILayout.Toggle(myTarget.showMeshInEditor, new GUIContent("Show Mesh in Editor", "Show a mesh preview in the editor window."));
            myTarget.showDebugLines    = GUILayout.Toggle(myTarget.showDebugLines, new GUIContent("Show Debug Lines", "Show lines in the editor to help to see the distort effects."));


            if (myTarget.showDebugLines)
            {
                myTarget.debugLinesDistance = EditorGUILayout.Slider(new GUIContent("Debug line distance", "Distance from the line between the center and the borders of the mesh"), myTarget.debugLinesDistance, 0, 1);
            }


            //Save the distorted mesh as a file
            if (GUILayout.Button(new GUIContent("Save Mesh as File", "Save a file of the mesh in the asset folder.")))
            {
                SaveMesh();
            }



            reList.DoLayoutList();

            //Set the distortion boxes
            if (distort != null)
            {
                for (int i = 0; i < distort.Count; i++)
                {
                    distort[i].showInEditor = EditorGUILayout.Foldout(distort[i].showInEditor, (i + 1) + ": " + distort[i].name, true);


                    if (distort[i].showInEditor)
                    {
                        EditorGUILayout.BeginVertical("box");
                        distort[i].enabled = EditorGUILayout.Toggle("Enabled", distort[i].enabled);
                        distort[i].calculateInWorldSpace = EditorGUILayout.Toggle(new GUIContent("World Space", "Calculate the distorion in world or local space"), distort[i].calculateInWorldSpace);
                        distort[i].isPingPong            = EditorGUILayout.Toggle(new GUIContent("Use PingPong", "Repeat the distorion forever in a pingpong manner"), distort[i].isPingPong);

                        distort[i].animationSpeed = EditorGUILayout.FloatField(new GUIContent("Animation Mult.", "Speed up or down the animation speed of this distortion"), distort[i].animationSpeed);
                        distort[i].type           = (Distort.Type)EditorGUILayout.EnumPopup("Type", distort[i].type);

                        distort[i].force = EditorGUILayout.FloatField(new GUIContent("Force", "How much force this distortion will have"), distort[i].force);
                        distort[i].movementDisplacement = EditorGUILayout.FloatField(new GUIContent("Force Displacement", "Displace the distortion force, mostly used for animation"), distort[i].movementDisplacement);


                        distort[i].tile = EditorGUILayout.Vector3Field(new GUIContent("Tile: ", "How much times the distortion will repeat between bounds"), distort[i].tile);

                        EditorGUILayout.BeginVertical("box");

                        EditorGUILayout.LabelField(new GUIContent("Displaced Force:", "Calculated WITH the Force Displacement value."));
                        distort[i].displacedForceXY = EditorGUILayout.CurveField(new GUIContent("X by Y", "Displace the X axis by the Y position"), distort[i].displacedForceXY);
                        distort[i].displacedForceXZ = EditorGUILayout.CurveField(new GUIContent("X by Z", "Displace the X axis by the Z position"), distort[i].displacedForceXZ);

                        EditorGUILayout.Space();

                        distort[i].displacedForceYX = EditorGUILayout.CurveField(new GUIContent("Y by X", "Displace the Y axis by the X position"), distort[i].displacedForceYX);
                        distort[i].displacedForceYZ = EditorGUILayout.CurveField(new GUIContent("Y by Z", "Displace the Y axis by the Z position"), distort[i].displacedForceYZ);

                        EditorGUILayout.Space();

                        distort[i].displacedForceZX = EditorGUILayout.CurveField(new GUIContent("Z by X", "Displace the Z axis by the X position"), distort[i].displacedForceZX);
                        distort[i].displacedForceZY = EditorGUILayout.CurveField(new GUIContent("Z by Y", "Displace the Z axis by the Y position"), distort[i].displacedForceZY);



                        EditorGUILayout.Space();


                        EditorGUILayout.LabelField(new GUIContent("Static force:", "Calculated WITHOUT the Force Displacement value."));
                        distort[i].staticForceX = EditorGUILayout.CurveField(new GUIContent("X", "Displacement in the X axis"), distort[i].staticForceX);
                        distort[i].staticForceY = EditorGUILayout.CurveField(new GUIContent("Y", "Displacement in the Y axis"), distort[i].staticForceY);
                        distort[i].staticForceZ = EditorGUILayout.CurveField(new GUIContent("Z", "Displacement in the Z axis"), distort[i].staticForceZ);
                        EditorGUILayout.EndVertical();

                        //Button to remove the distortion
                        if (GUILayout.Button("Delete this distortion."))
                        {
                            if (EditorUtility.DisplayDialog("Delete Distortion", "Do you really want to remove this distortion?", "Remove", "Cancel"))
                            {
                                myTarget.RemoveDistort(i);
                            }
                        }

                        EditorGUILayout.EndVertical();
                    }
                }
            }

            EditorGUILayout.Space();

            //Button to add a new distortion
            if (GUILayout.Button("Add New Distortion"))
            {
                if (target != null)
                {
                    myTarget.AddDistortion();
                }
            }



            if (GUI.changed)
            {
                if (myTarget.updateIntEditor)
                {
                    myTarget.EditParameters();
                    myTarget.UpdateDistort();
                }
                EditorUtility.SetDirty(target);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Calculate a animation in a determined frame
        /// </summary>
        /// <param name="displaceOffset">Time in animation</param>
        /// <param name="delta">Delta time since last animation update</param>
        void Animation(float displaceOffset, float delta)
        {
            //Call setup if needed
            if (distort == null)
            {
                Setup();
            }

            ///For each distortion in the GameObject update the movementDisplacement, this will make the object animate
            for (int i = 0; i < distort.distort.Count; i++)
            {
                //Animation type constant
                if (type == Type.constant)
                {
                    if (animate == Animate.displacement)
                    {
                        float disp = constantSpeed * delta * distort.distort[i].animationSpeed;
                        distort.distort[i].movementDisplacement += disp;
                    }
                    else
                    {
                        distort.distort[i].force += constantSpeed * delta * distort.distort[i].animationSpeed;
                    }
                }
                //Animation type pingpong
                else if (type == Type.pingpong)
                {
                    if (animate == Animate.displacement)
                    {
                        float disp = Mathf.Lerp(minValue, maxValue, Mathf.PingPong(displaceOffset * constantSpeed * distort.distort[i].animationSpeed, 1));
                        distort.distort[i].movementDisplacement = disp;
                    }
                    else
                    {
                        distort.distort[i].force = Mathf.Lerp(minValue, maxValue, Mathf.PingPong(displaceOffset * constantSpeed * distort.distort[i].animationSpeed, 1));
                    }
                }
                //Animation type sin
                else if (type == Type.sin)
                {
                    if (animate == Animate.displacement)
                    {
                        float disp = Mathf.Lerp(minValue, maxValue, (Mathf.Sin(displaceOffset * constantSpeed * distort.distort[i].animationSpeed) + 1) * 0.5f);
                        distort.distort[i].movementDisplacement = disp;
                    }
                    else
                    {
                        distort.distort[i].force = Mathf.Lerp(minValue, maxValue, (Mathf.Sin(displaceOffset * constantSpeed * distort.distort[i].animationSpeed) + 1) * 0.5f);
                    }
                }
                else if (type == Type.curve)
                {
                    if (animate == Animate.displacement)
                    {
                        float disp = curveType.Evaluate(displaceOffset * constantSpeed * distort.distort[i].animationSpeed);
                        distort.distort[i].movementDisplacement = disp;
                    }
                    else
                    {
                        distort.distort[i].force = curveType.Evaluate(displaceOffset * constantSpeed * distort.distort[i].animationSpeed);
                    }
                }
            }
            //Update the mesh vertices position.
            distort.UpdateDistort();
        }