예제 #1
0
    public Hull(HullData hd)
    {
        _name        = hd.name;
        _description = hd.description;

        _weaponSlots  = hd.weaponSlots;
        _utilitySlots = hd.utilitySlots;

        _hullpoints        = hd.hitpoints;
        _baseMovementSpeed = hd.movementSpeed;
        _baseRotationSpeed = hd.rotationSpeed;

        _gasStorage   = hd.gasStorage;
        _oreStorage   = hd.oreStorage;
        _fuelStorage  = hd.fuelStorage;
        _goodsStorage = hd.goodsStorage;

        _maintenanceCosts = hd.maintenanceCosts;

        _size = hd.size;

        _model        = hd.model;
        _destroyedVFX = hd.destroyedVFX;
        _icon         = hd.icon;
    }
예제 #2
0
        private static void GenerateAsset(GameObject selectedObject, Mesh srcMesh)
        {
            if (!AssetDatabase.IsValidFolder("Assets/Physics Hulls"))
            {
                AssetDatabase.CreateFolder("Assets", "Physics Hulls");
            }

            string path = "Assets/Physics Hulls/";

            // Find suitable asset names
            string paintAssetName, hullAssetName;

            CreateAssetPaths(path, selectedObject.name, out paintAssetName, out hullAssetName);

            // Painting asset
            PaintingData painting = ScriptableObject.CreateInstance <PaintingData>();

            painting.sourceMesh = srcMesh;
            AssetDatabase.CreateAsset(painting, paintAssetName);

            // Mesh asset
            HullData hulls = ScriptableObject.CreateInstance <HullData>();

            AssetDatabase.CreateAsset(hulls, hullAssetName);

            // Connect the painting data to the hull data

            painting.hullData = hulls;

            // Get the hull painter (or create one if it doesn't exist)

            HullPainter selectedPainter = selectedObject.GetComponent <HullPainter>();

            if (selectedPainter == null)
            {
                selectedPainter = selectedObject.AddComponent <HullPainter>();
            }

            // Point the painter at the asset data

            selectedPainter.paintingData = painting;
            selectedPainter.hullData     = hulls;

            // Start with a single empty hull
            selectedPainter.paintingData.AddHull(HullType.ConvexHull, null, false);

            EditorUtility.SetDirty(painting);
            EditorUtility.SetDirty(hulls);

            // Ping the painting asset in the ui (can only ping one object at once, so do the more important one)
            EditorGUIUtility.PingObject(painting);

            EditorWindow.GetWindow(typeof(HullPainterWindow));
        }
예제 #3
0
    void UpdateHullStats()
    {
        //if(saver.activePart == "Hull")
        HullData data = SaveBot.CurrentPresetData.hull;

        title.text = data.partName;
        stats.text = "Integrity = " + data.maxIntegrity +
                     "\nEnergy = " + data.maxEnergy +
                     "\nMass = " + data.mass +
                     "\nPairs = " + data.maxPairs;
        if (data.size != 1)
        {
            stats.text += "\nSize = " + data.size + "x";
        }
    }
예제 #4
0
        public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0, float signalStrength = 1.0f)
        {
            base.ReceiveSignal(stepsTaken, signal, connection, source, sender, power, signalStrength);

            if (source == null || source.CurrentHull == null)
            {
                return;
            }

            Hull sourceHull = source.CurrentHull;

            if (!hullDatas.TryGetValue(sourceHull, out HullData hullData))
            {
                hullData = new HullData();
                hullDatas.Add(sourceHull, hullData);
            }

            if (hullData.Distort)
            {
                return;
            }

            switch (connection.Name)
            {
            case "water_data_in":
                //cheating a bit because water detectors don't actually send the water level
                if (source.GetComponent <WaterDetector>() == null)
                {
                    hullData.Water = Rand.Range(0.0f, 1.0f);
                }
                else
                {
                    hullData.Water = Math.Min(sourceHull.WaterVolume / sourceHull.Volume, 1.0f);
                }
                break;

            case "oxygen_data_in":
                float oxy;

                if (!float.TryParse(signal, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out oxy))
                {
                    oxy = Rand.Range(0.0f, 100.0f);
                }

                hullData.Oxygen = oxy;
                break;
            }
        }
    public GameObject HUD;  //Set by spawner

    void Awake()
    {
        if (GetComponentInParent <PhotonView>().isMine)
        {
            enabled = true;

            if (staticHull == null)
            {
                staticHull = this;
            }
            else if (staticHull != this)
            {
                Debug.LogError("You have 2 active hulls!");
            }

            data      = SaveBot.CurrentPresetData.hull;
            integrity = data.maxIntegrity;
            energy    = data.maxEnergy;
        }
    }
예제 #6
0
        private void DrawHUDBack(SpriteBatch spriteBatch, GUICustomComponent container)
        {
            hullInfoFrame.Visible = false;
            if (item.Submarine == null || !hasPower)
            {
                foreach (Hull hull in Hull.hullList)
                {
                    var hullFrame = submarineContainer.Children.First().FindChild(hull);
                    if (hullFrame == null)
                    {
                        continue;
                    }

                    hullFrame.Color = Color.DarkCyan * 0.3f;
                    hullFrame.Children.First().Color = Color.DarkCyan * 0.3f;
                }
            }

            float scale = 1.0f;
            HashSet <Submarine> subs = new HashSet <Submarine>();

            foreach (Hull hull in Hull.hullList)
            {
                if (hull.Submarine == null)
                {
                    continue;
                }
                var hullFrame = submarineContainer.Children.First().FindChild(hull);
                if (hullFrame == null)
                {
                    continue;
                }

                hullDatas.TryGetValue(hull, out HullData hullData);
                if (hullData == null)
                {
                    hullData = new HullData();
                    hullDatas.Add(hull, hullData);
                }

                if (hullData.Distort)
                {
                    hullFrame.Children.First().Color = Color.Lerp(Color.Black, Color.DarkGray * 0.5f, Rand.Range(0.0f, 1.0f));
                    hullFrame.Color = Color.DarkGray * 0.5f;
                    continue;
                }

                subs.Add(hull.Submarine);
                scale = Math.Min(
                    hullFrame.Parent.Rect.Width / (float)hull.Submarine.Borders.Width,
                    hullFrame.Parent.Rect.Height / (float)hull.Submarine.Borders.Height);

                Color borderColor = Color.DarkCyan;

                float?gapOpenSum = 0.0f;
                if (ShowHullIntegrity)
                {
                    gapOpenSum  = hull.ConnectedGaps.Where(g => !g.IsRoomToRoom).Sum(g => g.Open);
                    borderColor = Color.Lerp(Color.DarkCyan, Color.Red, Math.Min((float)gapOpenSum, 1.0f));
                }

                float?oxygenAmount = null;
                if (!RequireOxygenDetectors || hullData?.Oxygen != null)
                {
                    oxygenAmount = RequireOxygenDetectors ? hullData.Oxygen : hull.OxygenPercentage;
                    GUI.DrawRectangle(spriteBatch, hullFrame.Rect, Color.Lerp(Color.Red * 0.5f, Color.Green * 0.3f, (float)oxygenAmount / 100.0f), true);
                }

                float?waterAmount = null;
                if (!RequireWaterDetectors || hullData.Water != null)
                {
                    waterAmount = RequireWaterDetectors ? hullData.Water : Math.Min(hull.WaterVolume / hull.Volume, 1.0f);
                    if (hullFrame.Rect.Height * waterAmount > 3.0f)
                    {
                        Rectangle waterRect = new Rectangle(
                            hullFrame.Rect.X, (int)(hullFrame.Rect.Y + hullFrame.Rect.Height * (1.0f - waterAmount)),
                            hullFrame.Rect.Width, (int)(hullFrame.Rect.Height * waterAmount));

                        waterRect.Inflate(-3, -3);

                        GUI.DrawRectangle(spriteBatch, waterRect, new Color(85, 136, 147), true);
                        GUI.DrawLine(spriteBatch, new Vector2(waterRect.X, waterRect.Y), new Vector2(waterRect.Right, waterRect.Y), Color.LightBlue);
                    }
                }

                if (GUI.MouseOn == hullFrame || hullFrame.IsParentOf(GUI.MouseOn))
                {
                    hullInfoFrame.RectTransform.ScreenSpaceOffset = hullFrame.Rect.Center;

                    hullInfoFrame.Visible = true;
                    hullNameText.Text     = hull.RoomName;

                    hullBreachText.Text      = gapOpenSum > 0.1f ? TextManager.Get("MiniMapHullBreach") : "";
                    hullBreachText.TextColor = Color.Red;

                    hullAirQualityText.Text = oxygenAmount == null?TextManager.Get("MiniMapAirQualityUnavailable") : TextManager.Get("MiniMapAirQuality") + ": " + (int)oxygenAmount + " %";

                    hullAirQualityText.TextColor = oxygenAmount == null ? Color.Red : Color.Lerp(Color.Red, Color.LightGreen, (float)oxygenAmount / 100.0f);

                    hullWaterText.Text = waterAmount == null?TextManager.Get("MiniMapWaterLevelUnavailable") : TextManager.Get("MiniMapWaterLevel") + ": " + (int)(waterAmount * 100.0f) + " %";

                    hullWaterText.TextColor = waterAmount == null ? Color.Red : Color.Lerp(Color.LightGreen, Color.Red, (float)waterAmount);

                    borderColor = Color.Lerp(borderColor, Color.White, 0.5f);
                    hullFrame.Children.First().Color = Color.White;
                }
                else
                {
                    hullFrame.Children.First().Color = Color.DarkCyan * 0.8f;
                }
                hullFrame.Color = borderColor;
            }

            foreach (Submarine sub in subs)
            {
                if (sub.HullVertices == null)
                {
                    continue;
                }

                Rectangle worldBorders = sub.GetDockedBorders();
                worldBorders.Location += sub.WorldPosition.ToPoint();

                scale = Math.Min(
                    submarineContainer.Rect.Width / (float)worldBorders.Width,
                    submarineContainer.Rect.Height / (float)worldBorders.Height) * 0.9f;

                float   displayScale = ConvertUnits.ToDisplayUnits(scale);
                Vector2 offset       = ConvertUnits.ToSimUnits(sub.WorldPosition - new Vector2(worldBorders.Center.X, worldBorders.Y - worldBorders.Height / 2));
                Vector2 center       = container.Rect.Center.ToVector2();

                for (int i = 0; i < sub.HullVertices.Count; i++)
                {
                    Vector2 start = (sub.HullVertices[i] + offset) * displayScale;
                    start.Y = -start.Y;
                    Vector2 end = (sub.HullVertices[(i + 1) % sub.HullVertices.Count] + offset) * displayScale;
                    end.Y = -end.Y;
                    GUI.DrawLine(spriteBatch, center + start, center + end, Color.DarkCyan * Rand.Range(0.3f, 0.35f), width: 10);
                }
            }
        }
예제 #7
0
        public override void ReceiveSignal(Signal signal, Connection connection)
        {
            Item source = signal.source;

            if (source == null || source.CurrentHull == null)
            {
                return;
            }

            Hull sourceHull = source.CurrentHull;

            if (!hullDatas.TryGetValue(sourceHull, out HullData hullData))
            {
                hullData = new HullData();
                hullDatas.Add(sourceHull, hullData);
            }

            if (hullData.Distort)
            {
                return;
            }

            switch (connection.Name)
            {
            case "water_data_in":
                //cheating a bit because water detectors don't actually send the water level
                float waterAmount;
                if (source.GetComponent <WaterDetector>() == null)
                {
                    waterAmount = Rand.Range(0.0f, 1.0f);
                }
                else
                {
                    waterAmount = Math.Min(sourceHull.WaterVolume / sourceHull.Volume, 1.0f);
                }
                hullData.ReceivedWaterAmount = waterAmount;
                foreach (var linked in sourceHull.linkedTo)
                {
                    if (!(linked is Hull linkedHull))
                    {
                        continue;
                    }
                    if (!hullDatas.TryGetValue(linkedHull, out HullData linkedHullData))
                    {
                        linkedHullData = new HullData();
                        hullDatas.Add(linkedHull, linkedHullData);
                    }
                    linkedHullData.ReceivedWaterAmount = waterAmount;
                }
                break;

            case "oxygen_data_in":
                if (!float.TryParse(signal.value, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out float oxy))
                {
                    oxy = Rand.Range(0.0f, 100.0f);
                }
                hullData.ReceivedOxygenAmount = oxy;
                foreach (var linked in sourceHull.linkedTo)
                {
                    if (!(linked is Hull linkedHull))
                    {
                        continue;
                    }
                    if (!hullDatas.TryGetValue(linkedHull, out HullData linkedHullData))
                    {
                        linkedHullData = new HullData();
                        hullDatas.Add(linkedHull, linkedHullData);
                    }
                    linkedHullData.ReceivedOxygenAmount = oxy;
                }
                break;
            }
        }
예제 #8
0
        private void GenerateColliders()
        {
            HullPainter currentHullPainter = sceneManipulator.GetCurrentHullPainter();

            if (currentHullPainter == null)
            {
                return;
            }

            Undo.RegisterCompleteObjectUndo(currentHullPainter.gameObject, "Generate Colliders");

            // Fetch the data assets

            PaintingData paintingData = currentHullPainter.paintingData;
            HullData     hullData     = currentHullPainter.hullData;

            string hullAssetPath = AssetDatabase.GetAssetPath(hullData);

            // Create / update the hull meshes

            foreach (Hull hull in paintingData.hulls)
            {
                paintingData.GenerateCollisionMesh(hull, sceneManipulator.GetTargetVertices(), sceneManipulator.GetTargetTriangles());
            }

            // Sync the in-memory hull meshes with the asset meshes in hullAssetPath

            List <Mesh> existingMeshes = GetAllMeshesInAsset(hullAssetPath);

            foreach (Mesh existing in existingMeshes)
            {
                if (!paintingData.ContainsMesh(existing))
                {
                    GameObject.DestroyImmediate(existing, true);
                }
            }

            foreach (Hull hull in paintingData.hulls)
            {
                if (hull.collisionMesh != null)
                {
                    if (!existingMeshes.Contains(hull.collisionMesh))
                    {
                        AssetDatabase.AddObjectToAsset(hull.collisionMesh, hullAssetPath);
                    }
                }
                if (hull.faceCollisionMesh != null)
                {
                    if (existingMeshes.Contains(hull.faceCollisionMesh))
                    {
                        AssetDatabase.AddObjectToAsset(hull.faceCollisionMesh, hullAssetPath);
                    }
                }
            }

            EditorUtility.SetDirty(hullData);

            AssetDatabase.SaveAssets();

            // Add collider components to the target object

            currentHullPainter.CreateColliderComponents();
        }
    public void ChangePart(string partName)
    {
//		Debug.Log ("Part changed to " + partName);
        pathName = "Part Database/" + partType.ToString() + "s/" + partName;

        partTitle.text = partName;
        if (partDisplay != null)
        {
            Destroy(partDisplay);
        }

        if (partType == PartTypes.Hull)
        {
            hData = Resources.Load <HullData> (pathName);
            if (hData == null)
            {
                Debug.LogError("No data found for " + partName);
            }

            //get all variables and add to statPanel
            partDisplay = Instantiate(hData.partVisuals);
            partDisplay.transform.SetParent(displayParent, false);

            partStats.text = "Integrity = " + hData.maxIntegrity +
                             "\nEnergy = " + hData.maxEnergy +
                             "\nMass = " + hData.mass +
                             "\nPairs = " + hData.maxPairs;
        }
        else if (partType == PartTypes.Weapon)
        {
            wData = Resources.Load <WeaponData> (pathName);
            if (wData == null)
            {
                Debug.LogError("No data found for " + partName);
            }

            //get all variables and add to statPanel
            partDisplay = Instantiate(wData.partVisuals);
            partDisplay.transform.SetParent(displayParent, false);

            partStats.text = "Integrity = " + wData.integrityMultiplier * 100 +
                             "%\nDamage = " + wData.damage +
                             "\nRate of Fire = " + wData.RoF +
                             "\nRange = " + wData.range;
            if (wData.force > 0)
            {
                partStats.text += "\nForce = " + wData.force;
            }
            if (wData.projectileSpeed > 0)
            {
                partStats.text += "\nProjectile Speed = " + wData.projectileSpeed;
            }
        }
        else if (partType == PartTypes.Movement)
        {
            mData = Resources.Load <MovementData> (pathName);
            if (mData == null)
            {
                Debug.LogError("No data found for " + partName);
            }

            //get all variables and add to statPanel
            partDisplay = Instantiate(mData.partVisuals);
            partDisplay.transform.SetParent(displayParent, false);

            string capacityText;
            if (mData.capacity > 0)
            {
                capacityText = mData.capacity.ToString();
            }
            else
            {
                capacityText = "Infinte";
            }
            partStats.text = "Integrity = " + mData.integrityMultiplier * 100 +
                             "%\nCapacity = " + capacityText +
                             "\nPower = " + mData.power +
                             "\nJump = " + mData.jumpPower +
                             "\nMax Speed = " + mData.maxSpeed.z;
        }
        else if (partType == PartTypes.Gadget)
        {
            gData = Resources.Load <GadgetData> (pathName);
            if (gData == null)
            {
                Debug.LogError("No data found for " + partName);
            }

            //get all variables and add to statPanel
            partStats.text = "TEST";
        }
    }