Esempio n. 1
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!
        }
    }
Esempio n. 2
0
    public static float getSolidMaterialValue(SolidsMaterialList _SolidsMaterialList)
    {
        switch (_SolidsMaterialList)
        {
        case SolidsMaterialList.Aerographite: return(0.2f);

        case SolidsMaterialList.MetallicMicrolattice: return(0.9f);

        case SolidsMaterialList.Aerogel: return(1.0f);

        case SolidsMaterialList.Styrofoam: return(75f);

        case SolidsMaterialList.Cork: return(240f);

        case SolidsMaterialList.Pine: return(373f);

        case SolidsMaterialList.Lithium: return(535f);

        case SolidsMaterialList.Wood: return(700f);

        case SolidsMaterialList.Oak: return(710f);

        case SolidsMaterialList.Potassium: return(860f);

        case SolidsMaterialList.Sodium: return(970f);

        case SolidsMaterialList.Ice: return(916.7f);

        case SolidsMaterialList.Nylon: return(1150f);

        case SolidsMaterialList.Plastics: return(1175f);

        case SolidsMaterialList.Magnesium: return(1740f);

        case SolidsMaterialList.Beryllium: return(1850f);

        case SolidsMaterialList.Glycerol: return(1261f);

        case SolidsMaterialList.Concrete: return(2000f);

        case SolidsMaterialList.Silicon: return(2330f);

        case SolidsMaterialList.Aluminium: return(2700f);

        case SolidsMaterialList.Diiodomethane: return(3325f);

        case SolidsMaterialList.Diamond: return(3500f);

        case SolidsMaterialList.Titanium: return(4540f);

        case SolidsMaterialList.Selenium: return(4800f);

        case SolidsMaterialList.Vanadium: return(6100f);

        case SolidsMaterialList.Antimony: return(6690f);

        case SolidsMaterialList.Zinc: return(7000f);

        case SolidsMaterialList.Chromium: return(7200f);

        case SolidsMaterialList.Tin: return(7310f);

        case SolidsMaterialList.Manganese: return(7325f);

        case SolidsMaterialList.Iron: return(7870f);

        case SolidsMaterialList.Steel: return(8050f);

        case SolidsMaterialList.Niobium: return(8570f);

        case SolidsMaterialList.Brass: return(8600f);

        case SolidsMaterialList.Cadmium: return(8650f);

        case SolidsMaterialList.Cobalt: return(8900f);

        case SolidsMaterialList.Nickel: return(8900f);

        case SolidsMaterialList.Copper: return(8940f);

        case SolidsMaterialList.Bismuth: return(9750f);

        case SolidsMaterialList.Molybdenum: return(10220f);

        case SolidsMaterialList.Silver: return(10500f);

        case SolidsMaterialList.Lead: return(11340f);

        case SolidsMaterialList.Thorium: return(11700f);

        case SolidsMaterialList.Rhodium: return(12410f);

        case SolidsMaterialList.Tantalum: return(16600f);

        case SolidsMaterialList.Uranium: return(18800f);

        case SolidsMaterialList.Tungsten: return(19300f);

        case SolidsMaterialList.Gold: return(19320f);

        case SolidsMaterialList.Plutonium: return(19840f);

        case SolidsMaterialList.Platinum: return(21450f);

        case SolidsMaterialList.Iridium: return(22420f);

        case SolidsMaterialList.Osmium: return(22570);

        case SolidsMaterialList.Dama: return(1450);

        case SolidsMaterialList.Human: return(970f);        // yes we even got human on the menu!

        default: return(0.0f); break;
        }
    }
Esempio n. 3
0
 /// <summary>
 /// Set the Material solid sub type
 /// </summary>
 public void setSubType(SolidsMaterialList _MaterialSubTypes)
 {
     selectedSolidsMaterial = _MaterialSubTypes;
 }
Esempio n. 4
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();
        }
    }