Beispiel #1
0
    void CmdRemoveComponent(int componentSlotIndex, ShipComponentType shipComponentType)
    {
        //Remove from array
        ShipComponentAsset[] componentArray = GetComponentArrayFromComponentType(shipComponentType);
        componentArray[componentSlotIndex] = null;

        //Try to get physical slots
        GameObject[] slots = GetSlotArrayFromComponentType(shipComponentType);
        //Null check
        if (slots == null)
        {
            return;
        }

        //Get the slot
        GameObject slot = slots[componentSlotIndex];

        //Null check
        if (slot == null)
        {
            return;
        }

        //Check whether the slot has any children (components) attached
        if (slot.transform.childCount == 0)
        {
            return;
        }

        //Get component and destroy it
        GameObject component = slot.transform.GetChild(0).gameObject;

        NetworkServer.Destroy(component);
    }
Beispiel #2
0
 //Function to get the component array relevant to the component type passed in to the function.
 public ShipComponentAsset[] GetComponentArrayFromComponentType(ShipComponentType type)
 {
     if (type == ShipComponentType.Small)
     {
         return(smallComponents);
     }
     else if (type == ShipComponentType.Medium)
     {
         return(mediumComponents);
     }
     else if (type == ShipComponentType.Large)
     {
         return(largeComponents);
     }
     else if (type == ShipComponentType.Expansion)
     {
         return(expansionComponents);
     }
     else if (type == ShipComponentType.Upgrade)
     {
         return(upgradeComponents);
     }
     else
     {
         return(null);
     }
 }
 public void InitProjectile(Vector2 velocity, GameObject parent, ShipComponentType target=ShipComponentType.HULL)
 {
     var rgdb2D = this.GetComponent<Rigidbody2D>();
     rgdb2D.velocity += velocity;
     this.ParentObject = parent;
     this.TargetType = target;
     this.gameObject.layer = LayerMask.NameToLayer(this.TargetType.ToString());
     this.GetComponent<SpriteRenderer>().sortingLayerName = this.TargetType.ToString();
 }
        public void InitProjectile(Vector2 velocity, GameObject parent, ShipComponentType target = ShipComponentType.HULL)
        {
            var rgdb2D = this.GetComponent <Rigidbody2D>();

            rgdb2D.velocity      += velocity;
            this.ParentObject     = parent;
            this.TargetType       = target;
            this.gameObject.layer = LayerMask.NameToLayer(this.TargetType.ToString());
            this.GetComponent <SpriteRenderer>().sortingLayerName = this.TargetType.ToString();
        }
Beispiel #5
0
 //Function to get the gameobject slot array from the component type
 public GameObject[] GetSlotArrayFromComponentType(ShipComponentType type)
 {
     if (type == ShipComponentType.Large)
     {
         return(largeComponentSlots);
     }
     else if (type == ShipComponentType.Expansion)
     {
         return(expansionComponentSlots);
     }
     else
     {
         return(null);
     }
 }
Beispiel #6
0
 public ShipComponent(ShipComponentType type, int maxHits)
 {
     this.type    = type;
     this.maxHits = maxHits;
 }