Exemplo n.º 1
0
        public static double SmoothDamp(double current, double target, ref double currentVelocity, double smoothTime, double maxSpeed, double deltaTime)
        {
            smoothTime = Mathd.Max(0.0001d, smoothTime);
            double num1 = 2d / smoothTime;
            double num2 = num1 * deltaTime;
            double num3 = (1.0d / (1.0d + num2 + 0.479999989271164d * num2 * num2 + 0.234999999403954d * num2 * num2 * num2));
            double num4 = current - target;
            double num5 = target;
            double max  = maxSpeed * smoothTime;
            double num6 = Mathd.Clamp(num4, -max, max);

            target = current - num6;
            double num7 = (currentVelocity + num1 * num6) * deltaTime;

            currentVelocity = (currentVelocity - num1 * num7) * num3;
            double num8 = target + (num6 + num7) * num3;

            if (num5 - current > 0.0 == num8 > num5)
            {
                num8            = num5;
                currentVelocity = (num8 - num5) / deltaTime;
            }
            return(num8);
        }
Exemplo n.º 2
0
        public static Vector3Double SmoothDamp(Vector3Double current, Vector3Double target, ref Vector3Double currentVelocity, double smoothTime, double maxSpeed, double deltaTime)
        {
            smoothTime = Mathd.Max(0.0001d, smoothTime);
            double        num1      = 2d / smoothTime;
            double        num2      = num1 * deltaTime;
            double        num3      = (1.0d / (1.0d + num2 + 0.479999989271164d * num2 * num2 + 0.234999999403954d * num2 * num2 * num2));
            Vector3Double vector    = current - target;
            Vector3Double vector3_1 = target;
            double        maxLength = maxSpeed * smoothTime;
            Vector3Double vector3_2 = Vector3Double.ClampMagnitude(vector, maxLength);

            target = current - vector3_2;
            Vector3Double vector3_3 = (currentVelocity + num1 * vector3_2) * deltaTime;

            currentVelocity = (currentVelocity - num1 * vector3_3) * num3;
            Vector3Double vector3_4 = target + (vector3_2 + vector3_3) * num3;

            if (Vector3Double.Dot(vector3_1 - current, vector3_4 - vector3_1) > 0.0)
            {
                vector3_4       = vector3_1;
                currentVelocity = (vector3_4 - vector3_1) / deltaTime;
            }
            return(vector3_4);
        }
Exemplo n.º 3
0
 public static bool Approximately(double a, double b)
 {
     return(Mathd.Abs(b - a) < Mathd.Max(1E-06d * Mathd.Max(Mathd.Abs(a), Mathd.Abs(b)), 1.121039E-44d));
 }
Exemplo n.º 4
0
 public static Vector3Double Max(Vector3Double lhs, Vector3Double rhs)
 {
     return(new Vector3Double(Mathd.Max(lhs.x, rhs.x), Mathd.Max(lhs.y, rhs.y), Mathd.Max(lhs.z, rhs.z)));
 }
Exemplo n.º 5
0
        /// <summary>
        /// Draws the data fields for each operation
        /// </summary>
        /// <param name="op"></param>
        public static void DrawOperationFields(GaiaOperation op, EditorUtils editorUtils, GaiaSessionManager sessionManager, bool helpEnabled, int currentIndex)
        {
            //shared default fields first
            //op.m_isActive = m_editorUtils.Toggle("Active", op.m_isActive, helpEnabled);
            bool currentGUIState = GUI.enabled;

            GUI.enabled      = op.m_isActive;
            op.m_description = editorUtils.TextField("Description", op.m_description, helpEnabled);
            editorUtils.LabelField("DateTime", new GUIContent(op.m_operationDateTime), helpEnabled);
            EditorGUI.indentLevel++;
            op.m_terrainsFoldedOut = editorUtils.Foldout(op.m_terrainsFoldedOut, "AffectedTerrains", helpEnabled);

            if (op.m_terrainsFoldedOut)
            {
                foreach (string name in op.m_affectedTerrainNames)
                {
                    EditorGUILayout.LabelField(name);
                }
            }
            EditorGUI.indentLevel--;

            //type specific fields, switch by op type to draw additional fields suitable for the op type

            switch (op.m_operationType)
            {
            case GaiaOperation.OperationType.CreateWorld:
                editorUtils.LabelField("xTiles", new GUIContent(op.WorldCreationSettings.m_xTiles.ToString()), helpEnabled);
                editorUtils.LabelField("zTiles", new GUIContent(op.WorldCreationSettings.m_zTiles.ToString()), helpEnabled);
                editorUtils.LabelField("TileSize", new GUIContent(op.WorldCreationSettings.m_tileSize.ToString()), helpEnabled);
                break;

            case GaiaOperation.OperationType.Spawn:
                editorUtils.LabelField("NumberOfSpawners", new GUIContent(op.SpawnOperationSettings.m_spawnerSettingsList.Count.ToString()), helpEnabled);
                float size = (float)Mathd.Max(op.SpawnOperationSettings.m_spawnArea.size.x, op.SpawnOperationSettings.m_spawnArea.size.z);
                editorUtils.LabelField("SpawnSize", new GUIContent(size.ToString()), helpEnabled);
                break;
            }
            GUI.enabled = currentGUIState;
            //Button controls
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(20);
            if (editorUtils.Button("Delete"))
            {
                if (EditorUtility.DisplayDialog(editorUtils.GetTextValue("PopupDeleteTitle"), editorUtils.GetTextValue("PopupDeleteText"), editorUtils.GetTextValue("OK"), editorUtils.GetTextValue("Cancel")))
                {
                    try
                    {
                        if (!String.IsNullOrEmpty(op.scriptableObjectAssetGUID))
                        {
                            AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(op.scriptableObjectAssetGUID));
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.LogError("Error while deleting one of the operation data files: " + ex.Message + " Stack Trace:" + ex.StackTrace);
                    }

                    sessionManager.RemoveOperation(currentIndex);
                    EditorGUIUtility.ExitGUI();
                }
            }
            GUI.enabled = op.m_isActive;
            if (editorUtils.Button("Play"))
            {
                if (EditorUtility.DisplayDialog(editorUtils.GetTextValue("PopupPlayTitle"), editorUtils.GetTextValue("PopupPlayText"), editorUtils.GetTextValue("OK"), editorUtils.GetTextValue("Cancel")))
                {
                    GaiaSessionManager.ExecuteOperation(op);
                    //Destroy all temporary tools used while executing
                    //not if it is a spawn operation since that is asynchronous
                    if (op.m_operationType != GaiaOperation.OperationType.Spawn)
                    {
                        GaiaSessionManager.DestroyTempSessionTools();
                    }
                }
            }
            GUI.enabled = currentGUIState;
            //EditorGUILayout.EndHorizontal();
            //EditorGUILayout.BeginHorizontal();
            //GUILayout.Space(20);
            if (editorUtils.Button("ViewData"))
            {
                switch (op.m_operationType)
                {
                case GaiaOperation.OperationType.CreateWorld:
                    Selection.activeObject = op.WorldCreationSettings;
                    break;

                case GaiaOperation.OperationType.Stamp:
                    Selection.activeObject = op.StamperSettings;
                    break;

                case GaiaOperation.OperationType.Spawn:
                    Selection.activeObject = op.SpawnOperationSettings;
                    break;

                case GaiaOperation.OperationType.FlattenTerrain:
                    Selection.activeObject = op.FlattenOperationSettings;
                    break;

                case GaiaOperation.OperationType.StampUndo:
                    Selection.activeObject = op.UndoRedoOperationSettings;
                    break;

                case GaiaOperation.OperationType.StampRedo:
                    Selection.activeObject = op.UndoRedoOperationSettings;
                    break;

                case GaiaOperation.OperationType.ClearSpawns:
                    Selection.activeObject = op.ClearOperationSettings;
                    break;

                case GaiaOperation.OperationType.RemoveNonBiomeResources:
                    Selection.activeObject = op.RemoveNonBiomeResourcesSettings;
                    break;

                case GaiaOperation.OperationType.MaskMapExport:
                    Selection.activeObject = op.ExportMaskMapOperationSettings;
                    break;
                }

                EditorGUIUtility.PingObject(Selection.activeObject);
            }
            switch (op.m_operationType)
            {
            case GaiaOperation.OperationType.Stamp:
                if (editorUtils.Button("PreviewInStamper"))
                {
                    Stamper stamper = GaiaSessionManager.GetOrCreateSessionStamper();
                    stamper.LoadSettings(op.StamperSettings);
#if GAIA_PRO_PRESENT
                    if (GaiaUtils.HasDynamicLoadedTerrains())
                    {
                        //We got placeholders, activate terrain loading
                        stamper.m_loadTerrainMode = LoadMode.EditorSelected;
                    }
#endif
                    Selection.activeObject = stamper.gameObject;
                }

                break;

            case GaiaOperation.OperationType.Spawn:
                if (editorUtils.Button("PreviewInSpawner"))
                {
                    BiomeController bmc         = null;
                    List <Spawner>  spawnerList = null;
                    Selection.activeObject = GaiaSessionManager.GetOrCreateSessionSpawners(op.SpawnOperationSettings, ref bmc, ref spawnerList);
                }

                break;

            case GaiaOperation.OperationType.MaskMapExport:
#if GAIA_PRO_PRESENT
                if (editorUtils.Button("PreviewInExport"))
                {
                    MaskMapExport mme = null;
                    Selection.activeObject = GaiaSessionManager.GetOrCreateMaskMapExporter(op.ExportMaskMapOperationSettings.m_maskMapExportSettings, ref mme);
                }
#endif
                break;
            }

            EditorGUILayout.EndHorizontal();
        }