Exemplo n.º 1
0
    void importSettingsFromExistingManager()
    {
        RealisticWaterPhysicsManager = null;
        RealisticWaterPhysicsManager = GameObject.Find("RealisticWaterPhysicsManager") as GameObject;

        if (RealisticWaterPhysicsManager != null)
        {
            if (RealisticWaterPhysicsManager.GetComponent <RealisticWaterPhysicsManager>() != null)
            {
                RealisticWaterPhysicsManager RWPM = RealisticWaterPhysicsManager.GetComponent <RealisticWaterPhysicsManager>();
                selectedOceanLiquidsMaterial = RWPM.selectedOceanLiquidsMaterial;
                useExternalWaterLevel        = RWPM.useExternalWaterLevel;
                waterObject            = RWPM.waterLevelObject;
                useAirDensity          = RWPM.useAirDensity;
                selectedGasesMaterial  = RWPM.selectedGasesMaterial;
                maxAirLevel            = RWPM.maxAirLevel;
                waterLevel             = RWPM.waterLevel;
                currentUseCeto         = RWPM.useCeto;
                currentUseAquas        = RWPM.useAquas;
                currentUseDW           = RWPM.useDW;
                currentUsePlayWayWater = RWPM.usePW;
            }
            else
            {
                Debug.LogError("RealisticWaterPhysicsManager is missing its RealisticWaterPhysicsManager script!");
                lastErrorLog = "RealisticWaterPhysicsManager is missing its RealisticWaterPhysicsManager script!";
                //Disable All controlls!
                OverWriteDisableWindow = true;
            }
        }
    }
Exemplo n.º 2
0
    public static float getGasesMaterialValue(GasesMaterialList _GasesMaterialList)
    {
        switch (_GasesMaterialList)
        {
        case GasesMaterialList.Acetylene: return(1.0921f);

        case GasesMaterialList.Air: return(1.2051f);

        case GasesMaterialList.Ammonia: return(0.7171f);

        case GasesMaterialList.Argon: return(1.6611f);

        case GasesMaterialList.Benzene: return(3.486f);

        case GasesMaterialList.BlastFurnaceGas: return(1.2502f);

        case GasesMaterialList.Butane: return(2.4891f);

        case GasesMaterialList.CarbonDioxide: return(1.8421f);

        case GasesMaterialList.Chlorine: return(2.9941f);

        case GasesMaterialList.Hydrogen: return(0.08992f);

        case GasesMaterialList.HydrogenSulfide: return(1.4341f);

        case GasesMaterialList.HydrogenChloride: return(1.5281f);

        case GasesMaterialList.Methane: return(0.6681f);

        case GasesMaterialList.NaturalGas: return(0.92f);

        case GasesMaterialList.NitricOxide: return(1.2491f);

        case GasesMaterialList.Nitrogen: return(1.1651f);

        case GasesMaterialList.Oxygen: return(1.3311f);

        case GasesMaterialList.Propane: return(1.8821f);

        case GasesMaterialList.SulfurDioxide: return(2.2791f);

        case GasesMaterialList.WaterVapor: return(0.804f);

        case GasesMaterialList.Helium: return(0.179f);

        case GasesMaterialList.TungstenHexafluoride: return(12.4f);

        default: return(0.0f); break;
        }
    }
Exemplo n.º 3
0
    void importSettingsFromSelectedGameObject()
    {
        clearTestResults();

        if (SelectedObject.GetComponent <RealisticBuoyancy>() == true)
        {
            RealisticBuoyancy BuoyancyScript = SelectedObject.GetComponent <RealisticBuoyancy>();

            slicesPerAxis           = BuoyancyScript.slicesPerAxis;
            isConcave               = BuoyancyScript.isConcave;
            voxelsLimit             = BuoyancyScript.voxelsLimit;
            percentageSolid         = BuoyancyScript.percentageSolid;
            SelectedMaterialType    = BuoyancyScript.SelectedMaterialType;
            selectedGasesMaterial   = BuoyancyScript.selectedGasesMaterial;
            selectedLiquidsMaterial = BuoyancyScript.selectedLiquidsMaterial;
            selectedSolidsMaterial  = BuoyancyScript.selectedSolidsMaterial;

            if (BuoyancyScript.SelectedMaterialType != MaterialTypes.Solid)
            {
                ShowAdvancedInfo = true;
            }

            if (slicesPerAxis == 1)
            {
                selectedFloatingQuality = FloatingQuality.ExtremeLow;
            }
            if (slicesPerAxis == 2)
            {
                selectedFloatingQuality = FloatingQuality.Low;
            }
            if (slicesPerAxis == 4)
            {
                selectedFloatingQuality = FloatingQuality.Medium;
            }

            if (slicesPerAxis == 6)
            {
                selectedFloatingQuality = FloatingQuality.High;
            }

            if (slicesPerAxis == 8)
            {
                selectedFloatingQuality = FloatingQuality.ExtremeHigh;
            }
        }
        else
        {
            //Cant find settings to import.
            //Nothing wrong with that!
        }
    }
Exemplo n.º 4
0
 /// <summary>
 /// Set the Material gas type
 /// </summary>
 public void setSubType(GasesMaterialList _MaterialSubTypes)
 {
     selectedGasesMaterial = _MaterialSubTypes;
 }
Exemplo n.º 5
0
 public static void Setup(float _waterDensity, float _waterLevel, bool _ExternalWater, bool _useCeto, bool _useDW, bool _useAquas, bool _usePW, GasesMaterialList _SelectedGasesMaterial, float _airLevel, float _waterTemp, float _airTemp)
 {
     waterDensity  = _waterDensity;
     waterLevel    = _waterLevel;
     ExternalWater = _ExternalWater;
     airLevel      = _airLevel;
     airDensity    = PhysicsMaterialsList.getGasesMaterialValue(_SelectedGasesMaterial);
     airTemp       = _airTemp;
     waterTemp     = _waterTemp;
     //Support
     useCeto  = _useCeto;
     useDW    = _useDW;
     useAquas = _useAquas;
     usePW    = _usePW;
 }
Exemplo n.º 6
0
    void OnGUI()
    {
        //To fix the crapy static stuff and missing Start void :/
        if (firstStart == false)
        {
            firstStart = true;
            importSettingsFromExistingManager();

            if (SelectedObject != null)
            {
                importSettingsFromSelectedGameObject();
            }
        }

        //To keep everything updated!
        NoneGUIElementsUpdate();

        if (OverWriteDisableWindow == false)        // If this value = true there is something wrong!
        {
            if (ShowAdvancedInfo == true)
            {
                if (GUILayout.Button("Hide advanced options/info"))
                {
                    ShowAdvancedInfo = false;;
                    hideManagerGameObject();
                }
            }
            else
            {
                if (GUILayout.Button("Show advanced options/info"))
                {
                    ShowAdvancedInfo = true;
                    showManagerGameObject();
                }
            }

            if (textureLogo == null)
            {
                textureLogo = (Texture2D)EditorGUIUtility.Load("Assets/RealisticPhysics/RealisticWaterPhysics/Resources/icon0.png");
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.Label(textureLogo);
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            toolbarInt = GUILayout.Toolbar(toolbarInt, toolbarStrings);

            EditorGUILayout.BeginHorizontal();
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(450), GUILayout.Height(300));
        }

        EditorGUILayout.HelpBox("Waring log: " + lastErrorLog, MessageType.Info, true); //Desplay the last error log, warning!

        if (OverWriteDisableWindow == false)                                            // If this value = true there is something wrong!
        {
            EditorGUILayout.Space();
            if (showSetupOptions == true)
            {
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Water settings:");
                selectedOceanLiquidsMaterial = (LiquidsMaterialList)EditorGUILayout.EnumPopup("Water Classification:", selectedOceanLiquidsMaterial);

                if (ShowAdvancedInfo)
                {
                    EditorGUILayout.LabelField("Density of the water:" + CalculatedWaterDensity);
                }
                EditorGUILayout.Space();

                if (waterObject != null)
                {
                    waterLevel = waterObject.transform.position.y;
                }

                if (currentUseCeto == false && currentUseDW == false && currentUseAquas == false && currentUsePlayWayWater == false)
                {
                    if (waterObject == null)
                    {
                        waterLevel = EditorGUILayout.FloatField("Water Level:", waterLevel);
                    }
                    if (ShowAdvancedInfo)
                    {
                        if (waterObject == null)
                        {
                            EditorGUILayout.LabelField("Or");
                        }
                        if (waterObject = EditorGUILayout.ObjectField("Water GameObject: ", waterObject, typeof(GameObject), true) as GameObject)
                        {
                            waterLevel = waterObject.transform.position.y;
                            EditorGUILayout.BeginHorizontal();
                            EditorGUILayout.LabelField("");
                            EditorGUILayout.LabelField("Water level: " + waterLevel.ToString());
                            EditorGUILayout.EndHorizontal();
                        }
                        EditorGUILayout.LabelField("Or");
                        useExternalWaterLevel = EditorGUILayout.Toggle("Use external water level", useExternalWaterLevel);                         // Allows you to make something yourself ;)
                    }
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Air settings:");
                useAirDensity = EditorGUILayout.Toggle("Use air density", useAirDensity);
                if (useAirDensity == true)
                {
                    maxAirLevel = EditorGUILayout.FloatField("Max air Level:", maxAirLevel);
                    if (ShowAdvancedInfo)
                    {
                        selectedAirGasesMaterial = (GasesMaterialList)EditorGUILayout.EnumPopup("Air type: ", selectedAirGasesMaterial);
                        airDensity = PhysicsMaterialsList.getGasesMaterialValue(selectedAirGasesMaterial);
                        EditorGUILayout.LabelField("Density of the air:" + CalculatedAirDensity);                         // work in progress!
                    }
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Support settings:");

                //Again for support
                                #if CETO
                currentUseCeto = EditorGUILayout.Toggle("Enable Ceto support", currentUseCeto);
                                #endif

                                #if DW
                currentUseDW = EditorGUILayout.Toggle("Enable Dynamic Water support", currentUseDW);
                                #endif

                                #if AQUAS
                currentUseAquas = EditorGUILayout.Toggle("Enable Aquas support", currentUseAquas);
                                #endif
                //Aquas needs a water level to work with, so leave that at them, just let the users select the aqaus water object
                if (currentUseAquas == true)
                {
                    if (AquaswaterObject = EditorGUILayout.ObjectField("AQUAS water object: ", AquaswaterObject, typeof(GameObject), true) as GameObject)
                    {
                        waterLevel = AquaswaterObject.transform.position.y;
                    }
                    if (AquaswaterObject != null)
                    {
                        waterLevel = AquaswaterObject.transform.position.y;
                    }
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("");
                    EditorGUILayout.LabelField("Water level: " + waterLevel.ToString());
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.Space();
                }


                                #if PW
                currentUsePlayWayWater = EditorGUILayout.Toggle("Enable PlayWay Water support", currentUsePlayWayWater);
                                #endif

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Read the Manual for more info.");
                //get some room!
                EditorGUILayout.Space();
                EditorGUILayout.Space();
                EditorGUILayout.Space();
            }

            if (showGameobjectSetupOptions == true)
            {
                if (selectionGameObjects.Count > 0)
                {
                    EditorGUILayout.LabelField("All Gameobjects below will get the same settings!");
                    SelectedObject = selectionGameObjects[0];

                    for (int i = 0; i < selectionGameObjects.Count; i++)
                    {
                        selectionGameObjects[i] = EditorGUILayout.ObjectField("GameObject " + i.ToString() + ": ", selectionGameObjects[i], typeof(GameObject), true) as GameObject;
                    }
                }
                else
                {
                    EditorGUILayout.LabelField("Select a gameOject in the Hierarchy");
                    SelectedObject = null;
                }


                if (SelectedObject != null)
                {
                    //Check if there is a mesh filter else report it to the user and clear the selection!
                    if (SelectedObject.GetComponent <MeshFilter>() == true && SelectedObject.GetComponent <MeshFilter>() != null)
                    {
                        lastErrorLog = "";
                        if (didImport == false)
                        {
                            importSettingsFromSelectedGameObject();
                            OldSelectedObject = SelectedObject;
                            didImport         = true;
                        }
                        else if (OldSelectedObject != SelectedObject)
                        {
                            didImport = false;
                        }
                    }
                    else
                    {
                        //So there is no Mesh filter on this object!
                        //We can still use it we just got to use somthing else for volume... collider?
                        if (SelectedObject.GetComponent <Collider>() == true)
                        {
                            lastErrorLog = "Can't find MeshFilter, using collider!";
                            if (didImport == false)
                            {
                                importSettingsFromSelectedGameObject();
                                OldSelectedObject = SelectedObject;
                                didImport         = true;
                            }
                            else if (OldSelectedObject != SelectedObject)
                            {
                                didImport = false;
                            }
                        }
                        else
                        {
                            //Also no collider....
                            lastErrorLog = "There is no MeshFilter or Collider on this object!";
                        }
                    }



                    EditorGUILayout.Space();

                    if (ShowAdvancedInfo == true)
                    {
                        EditorGUILayout.LabelField("Gameobject settings:");
                        slicesPerAxis = EditorGUILayout.IntField("Slices Per Axis", slicesPerAxis);
                        if (slicesPerAxis < 1)
                        {
                            slicesPerAxis = 1;
                        }
                        else if (slicesPerAxis > 8)
                        {
                            slicesPerAxis = 8;
                        }
                        isConcave   = EditorGUILayout.Toggle("GameObject is concave", isConcave);                       // has its issues!
                        voxelsLimit = EditorGUILayout.IntField("Voxels limit", voxelsLimit);
                        if (slicesPerAxis < 1)
                        {
                            slicesPerAxis = 1;
                        }
                        else if (slicesPerAxis > 64)
                        {
                            slicesPerAxis = 64;
                        }
                    }
                    else
                    {
                        selectedFloatingQuality = (FloatingQuality)EditorGUILayout.EnumPopup("Floating Quality:", selectedFloatingQuality);
                        if (selectedFloatingQuality == FloatingQuality.ExtremeLow)
                        {
                            slicesPerAxis = 1;
                            voxelsLimit   = 2;
                        }
                        if (selectedFloatingQuality == FloatingQuality.Low)
                        {
                            slicesPerAxis = 2;
                            voxelsLimit   = 4;
                        }
                        if (selectedFloatingQuality == FloatingQuality.Medium)
                        {
                            slicesPerAxis = 4;
                            voxelsLimit   = 8;
                        }
                        if (selectedFloatingQuality == FloatingQuality.High)
                        {
                            slicesPerAxis = 6;
                            voxelsLimit   = 12;
                        }
                        if (selectedFloatingQuality == FloatingQuality.ExtremeHigh)
                        {
                            slicesPerAxis = 8;
                            voxelsLimit   = 16;
                        }
                    }

                    if (ShowAdvancedInfo == true)
                    {
                        SelectedMaterialType = (MaterialTypes)EditorGUILayout.EnumPopup("Material type:", SelectedMaterialType);
                    }
                    else
                    {
                        //Back to basic solids only!
                        SelectedMaterialType = MaterialTypes.Solid;
                    }
                    if (SelectedMaterialType == MaterialTypes.Solid)
                    {
                        selectedSolidsMaterial = (SolidsMaterialList)EditorGUILayout.EnumPopup("Solid Material:", selectedSolidsMaterial);
                    }
                    else if (SelectedMaterialType == MaterialTypes.Liquids)
                    {
                        selectedLiquidsMaterial = (LiquidsMaterialList)EditorGUILayout.EnumPopup("Liquid Material:", selectedLiquidsMaterial);
                    }
                    else
                    {
                        selectedGasesMaterial = (GasesMaterialList)EditorGUILayout.EnumPopup("Gas Material:", selectedGasesMaterial);
                    }


                    percentageSolid = EditorGUILayout.IntField("Percentage Solid:", percentageSolid);
                    if (percentageSolid < 0)
                    {
                        percentageSolid = 0;
                    }
                    else if (percentageSolid > 100)
                    {
                        percentageSolid = 100;
                    }
                    EditorGUILayout.Space();

                    if (GUILayout.Button("Calculate test results"))
                    {
                        calculateResults();                         //Update the results.
                    }

                    if (DidTest == true)
                    {
                        if (ShowAdvancedInfo)
                        {
                            testResultsString = "Test result of the object:" + System.Environment.NewLine + System.Environment.NewLine +
                                                "Calculated mass: " + CalculatedMass + System.Environment.NewLine +
                                                "Calculated volume: " + CalculatedVolume + System.Environment.NewLine +
                                                "Calculated density: " + CalculatedDensity + System.Environment.NewLine +
                                                "Float in water: " + ((CalculatedWillFloatInWater == true) ? "Yes" : "No").ToString() + System.Environment.NewLine +
                                                "Float in Air: " + ((CalculatedWillFloatInAir == true) ? "Yes" : "No").ToString();
                        }
                        else
                        {
                            //Will it float or not?!
                            testResultsString = "Test result of the object:" + System.Environment.NewLine + System.Environment.NewLine +
                                                "Float in water: " + ((CalculatedWillFloatInWater == true) ? "Yes" : "No").ToString() + System.Environment.NewLine +
                                                "Float in Air: " + ((CalculatedWillFloatInAir == true) ? "Yes" : "No").ToString();
                        }
                    }
                    else
                    {
                        testResultsString = "No test results yet!";
                    }

                    EditorGUILayout.HelpBox(testResultsString, MessageType.Info, true);

                    //Button
                    if (SelectedObject != null)
                    {
                        if (SelectedObject.GetComponent <RealisticBuoyancy>())
                        {
                            if (GUILayout.Button("Update gameobject script"))
                            {
                                if (selectionGameObjects != null && selectionGameObjects.Count > 0)
                                {
                                    foreach (var Selectedgameobject in selectionGameObjects)
                                    {
                                        createObjectScript(Selectedgameobject);
                                    }
                                }
                                else
                                {
                                    createObjectScript(SelectedObject);                                      // Update the script on the selected object.
                                }
                            }
                        }
                        else
                        {
                            if (GUILayout.Button("Create gameobject script"))
                            {
                                if (selectionGameObjects != null && selectionGameObjects.Count > 0)
                                {
                                    foreach (var Selectedgameobject in selectionGameObjects)
                                    {
                                        createObjectScript(Selectedgameobject);
                                    }
                                }
                                else
                                {
                                    createObjectScript(SelectedObject);                                      // Update the script on the selected object.
                                }
                            }
                        }
                    }
                    else                     //double check to make sure there is indeed a gamobject selected!
                    {
                        if (GUILayout.Button("First select a gameobject."))
                        {
                            //Still show the button but its does nothing :P
                        }
                    }
                }

                EditorGUILayout.Space();

                if (SelectedObject != null)
                {
                    if (ScriptSavedAfterTest == true)
                    {
                        stateInfo = "Changes have been saved!";
                    }
                    else
                    {
                        stateInfo = "Changes have NOT been saved!";
                    }
                    EditorGUILayout.HelpBox(stateInfo, MessageType.Info, true);
                }
            }
            EditorGUILayout.EndScrollView();

            EditorGUILayout.EndHorizontal();
        }
    }