Exemplo n.º 1
0
    public void NotifyPartDestroyed(ShipPart part)
    {
        parts.Remove(part);
        parts = parts.Where(p => p != null).ToList(); // HACK! Don't know why I need this. Single cockpit throws errors otherwise
        cameraManager.AddScreenShake(1.5f);

        Thrusters thruster = part.GetComponent <Thrusters>();

        if (thruster != null)
        {
            thrusters.Remove(thruster);
        }

        ProjectileWeapon weapon = part.GetComponent <ProjectileWeapon>();

        if (weapon != null)
        {
            weapons.Remove(weapon);
        }

        if (part.partName == "Cockpit")
        {
            // Inverse for loop because each death will modify parts with the callback
            Debug.LogFormat("Killing remaining {0} parts", parts.Count);
            for (int i = parts.Count - 1; i >= 0; i--)
            {
                // TODO: It would be really cool if we could show each part blowing up in succession
                parts[i].TakeDamage(parts[i].maxHealth);
            }
            Destroy(gameObject);
        }
    }
Exemplo n.º 2
0
 public AttachPoint(Vector3 position,ShipPart myParent, string name)
 {
     GameObject attachPoint = (GameObject)Instantiate(Resources.Load("attachPoint"));
     attachPoint.transform.position = position;
     attachPoint.transform.localScale =
         new Vector3(myParent.GetComponent<BoxCollider>().size.x / 1.5f,myParent.GetComponent<BoxCollider>().size.x / 1.5f,myParent.GetComponent<BoxCollider>().size.x / 1.5f);
     attachPoint.transform.parent = myParent.transform;
     myName = name;
     attachPoint.name = "attachPoint(" + myName + ")";
 }
Exemplo n.º 3
0
    void SelectShipPart()
    {
        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit, 100000.0f))
        {
            if (_selectedPart != null)
            {
                foreach (Renderer rend in _selectedPart.GetAllMeshRenderers())
                {
                    foreach (var mat in rend.materials)
                    {
                        mat.EnableKeyword("_EMISSION");
                        mat.SetColor("_EmissionColor", Color.black);
                    }
                }
                _selectedPart.isSelected = false;
            }
            var newPart = hit.transform.GetComponent <ShipPart>();
            if (_selectedPart != newPart)
            {
                _selectedPart            = newPart;
                _selectedPart.isSelected = true;
                foreach (Renderer rend in _selectedPart.GetAllMeshRenderers())
                {
                    foreach (var mat in rend.materials)
                    {
                        mat.EnableKeyword("_EMISSION");
                        mat.SetColor("_EmissionColor", Color.cyan);
                    }
                }
                partText.text = _selectedPart.name;
                var shipPart = _selectedPart.GetComponent <ShipPart>();
                statusText.text = "Status: " + _selectedPart.GetComponent <ShipPart>().GetPartStatus;
                panel.SetActive(true);
                if (shipPart.GetPartStatus == PartStatus.OK)
                {
                    fixButton.SetActive(false);
                    panel.GetComponent <RectTransform>().sizeDelta = new Vector2(300, 200);
                }
                else
                {
                    fixButton.SetActive(true);
                    panel.GetComponent <RectTransform>().sizeDelta = new Vector2(300, 300);
                }
            }
            else
            {
                UnselectShipPart();
            }

            Debug.Log("You selected the " + hit.transform.name); // ensure you picked right object
        }
    }
Exemplo n.º 4
0
    public AttachPoint(Vector3 position, ShipPart myParent, string name)
    {
        GameObject attachPoint = (GameObject)Instantiate(Resources.Load("attachPoint"));

        attachPoint.transform.position   = position;
        attachPoint.transform.localScale =
            new Vector3(myParent.GetComponent <BoxCollider>().size.x / 1.5f, myParent.GetComponent <BoxCollider>().size.x / 1.5f, myParent.GetComponent <BoxCollider>().size.x / 1.5f);
        attachPoint.transform.parent = myParent.transform;
        myName           = name;
        attachPoint.name = "attachPoint(" + myName + ")";
    }
Exemplo n.º 5
0
    // Top screen
    private void SetupSelectedPartUI(int buttonIndex)
    {
        List <string> invKeys = inventory.Keys.ToList();

        invKeys.Sort();
        if (invKeys.Count == 0)
        {
            return;
        }
        selectedPart   = shipFactory.GetPrefabByNameAndMark(invKeys[partScrollIndex + buttonIndex]).GetComponent <ShipPart>();
        SP_title.text  = selectedPart.partName;
        SP_mark.text   = "MK " + selectedPart.mark;
        SP_place.text  = "Inventory: " + inventory[invKeys[partScrollIndex + buttonIndex]];
        SP_icon.sprite = selectedPart.GetComponent <SpriteRenderer>().sprite;
        if (selectedPart.partName == "Thrusters")
        {
            SP_icon.sprite = thrusterButtonSprite;
        }
        foreach (RectTransform button in partSelectButtons)
        {
            button.GetComponent <Image>().color = Color.white;
        }
        partSelectButtons[buttonIndex].GetComponent <Image>().color = selectedPartColor;
    }
Exemplo n.º 6
0
    public IEnumerator Loader()
    {
        if (savedSpaceShip.shipName != "")
        {
            savedSpaceShip.partIndex = PlayerPrefsX.GetIntArray(savedSpaceShip.shipName + ".savedSpaceShip.partIndex");
            myAPoints     = PlayerPrefsX.GetIntArray(savedSpaceShip.shipName + ".myAPoints");
            targetAPoints = PlayerPrefsX.GetIntArray(savedSpaceShip.shipName + ".targetAPoints");

            int[] serialID = new int[savedSpaceShip.partIndex.Length];
            thisPartAttachPoint  = null;
            otherPartAttachPoint = null;
            thisParts            = new ShipPart[savedSpaceShip.partIndex.Length];
            otherParts           = new ShipPart[savedSpaceShip.partIndex.Length];

            ShipPart thisPart  = null;
            ShipPart otherPart = null;
            int      value;

            for (int i = 0; i < savedSpaceShip.partIndex.Length; i++)
            {
                thisPart = (ShipPart)Instantiate(partInstantiator.GetComponent <PartInstantiator>().partList[savedSpaceShip.partIndex[i]], (Vector2)(Camera.main.transform.position), Quaternion.Euler(-90, 180, 0));
                int.TryParse(thisPart.name, out value);
                thisPart.name = (i + 100 + value).ToString();
                int.TryParse(thisPart.name, out value);
                serialID [i]  = value;
                otherPart     = GameObject.Find(serialID[thisPart.attachedToIndex].ToString()).GetComponent <ShipPart>();
                thisParts[i]  = thisPart;
                otherParts[i] = otherPart;

                if (i == 0)
                {
                    loadedShip = thisPart.gameObject;
                }

                shipScaleVertical += thisPart.GetComponent <BoxCollider>().size.y;
            }

            yield return(new WaitForEndOfFrame());

            for (int i = 0; i < myAPoints.Length; i++)
            {
                Transform[] children = thisParts[i + 1].GetComponentsInChildren <Transform>();

                foreach (Transform child in children)
                {
                    if ((child.name == "attachPoint(up)" && myAPoints[i] == 1) || (child.name == "attachPoint(down)" && myAPoints[i] == 2))
                    {
                        thisPartAttachPoint = child.GetComponent <AttachPoint>();
                    }
                }

                children = otherParts[i + 1].GetComponentsInChildren <Transform>();
                foreach (Transform child in children)
                {
                    if ((child.name == "attachPoint(up)" && targetAPoints[i] == 1) || (child.name == "attachPoint(down)" && targetAPoints[i] == 2))
                    {
                        otherPartAttachPoint = child.GetComponent <AttachPoint>();
                    }
                }

                thisPartAttachPoint.otherAttachPoint = otherPartAttachPoint;
                thisPartAttachPoint.Attach();
            }
        }
        else
        {
            Debug.Log("Load failed.");
        }
    }