Пример #1
0
    public bool [ , ] GetSkippedSlots(OSItem except)
    {
        bool [ , ] skip = new bool [width, height];

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                OSSlot slot = inventory.GetSlot(x, y);

                if (slot == null || slot.hidden || (slot.item != null && slot.item == except))
                {
                    continue;
                }

                for (int sx = 0; sx < slot.scale.x; sx++)
                {
                    for (int sy = 0; sy < slot.scale.y; sy++)
                    {
                        if ((sx == 0 && sy == 0) || x + sx >= width || y + sy >= height)
                        {
                            continue;
                        }
                        else
                        {
                            skip [x + sx, y + sy] = true;
                        }
                    }
                }
            }
        }

        return(skip);
    }
Пример #2
0
    public OSSlot(int x, int y, string path)
    {
        GameObject go = (GameObject)Resources.Load(path);

        this.x    = x;
        this.y    = y;
        this.item = go.GetComponent <OSItem> ();
    }
Пример #3
0
    public void DecreaseItem(OSItem item)
    {
        OSSlot slot = GetSlot(item);

        if (slot != null)
        {
            DecreaseSlot(slot);
        }
    }
Пример #4
0
    public void AdoptValues(OSItem item)
    {
        this.ammunition.value = item.ammunition.value;

        for (int i = 0; i < item.attributes.Length; i++)
        {
            this.attributes[i].value = item.attributes[i].value;
        }
    }
Пример #5
0
 public void RemoveItem(OSItem item)
 {
     for (int i = 0; i < slots.Count; i++)
     {
         if (slots[i].item == item)
         {
             slots.RemoveAt(i);
         }
     }
 }
Пример #6
0
    public OSSlot GetSlot(OSItem item)
    {
        for (int i = 0; i < slots.Count; i++)
        {
            if (slots[i] != null && slots[i].item.prefabPath == item.prefabPath)
            {
                return(slots[i]);
            }
        }

        return(null);
    }
Пример #7
0
    // Get data
    public int GetItemIndex(OSItem item)
    {
        for (int i = 0; i < slots.Count; i++)
        {
            if (slots[i].item == item)
            {
                return(i);
            }
        }

        return(-1);
    }
Пример #8
0
    public bool IsEquipped(OSItem item)
    {
        for (int i = 0; i < slots.Count; i++)
        {
            if (slots[i] != null && slots[i].item == item && slots[i].equipped)
            {
                return(true);
            }
        }

        return(false);
    }
Пример #9
0
    public void Update()
    {
        if (!item)
        {
            item = this.GetComponent <OSItem> ();
            return;
        }

        if (!bullet)
        {
            bullet = item.ammunition.projectile;
        }

        if (fireTimer > 0)
        {
            fireTimer -= Time.deltaTime;
        }

        if (flashTimer > 0)
        {
            flashTimer -= Time.deltaTime;
        }

        if (muzzleFlash)
        {
            if (flashTimer > 0 && !muzzleFlash.activeSelf)
            {
                muzzleFlash.SetActive(true);

                if (muzzleFlash.particleSystem)
                {
                    muzzleFlash.particleSystem.Play();
                }
            }
            else if (flashTimer <= 0 && muzzleFlash.activeSelf)
            {
                muzzleFlash.SetActive(false);
            }
        }

        if (projectileTypeThreshold > 0)
        {
            if (Time.timeScale >= projectileTypeThreshold)
            {
                projectileType = OSProjectileType.Raycast;
            }
            else if (bullet)
            {
                projectileType = OSProjectileType.Prefab;
            }
        }
    }
Пример #10
0
    public void Update()
    {
        if (!item)
        {
            item = this.GetComponent <OSItem> ();
            return;
        }

        if (fireTimer > 0)
        {
            fireTimer -= Time.deltaTime;
        }
    }
Пример #11
0
    public bool AddItemFromScene(OSItem sceneItem)
    {
        if (!sceneItem)
        {
            return(false);
        }

        GameObject go = (GameObject)Resources.Load(sceneItem.prefabPath);

        sceneItem.gameObject.SendMessage("OnPickUp", SendMessageOptions.DontRequireReceiver);
        Destroy(sceneItem.gameObject);

        return(AddItem(go.GetComponent <OSItem> ()));
    }
Пример #12
0
    public void SetEquipped(OSItem item, bool isEquipped)
    {
        for (int i = 0; i < slots.Count; i++)
        {
            if (slots[i] != null && slots[i].item == item)
            {
                slots[i].equipped = isEquipped;

                if (eventHandler)
                {
                    eventHandler.SendMessage("OnEquipItem", slots[i].item, SendMessageOptions.DontRequireReceiver);
                }

                break;
            }
        }
    }
Пример #13
0
	public bool CheckSlot ( int x, int y, OSItem item ) {
		if ( x < 0 || y < 0 ) {
			return false;
		}
		
		bool [ , ] skip = GetSkippedSlots ( item );
		
		for ( int sx = 0; sx < item.slotSize.x; sx++ ) {
			for ( int sy = 0; sy < item.slotSize.y; sy++ ) {
				OSSlot slot = inventory.GetSlot ( x + sx, y + sy );

				if ( ( x + sx < skip.GetLength(0) && y + sy < skip.GetLength(1) && skip [ x + sx, y + sy ] ) || ( slot != null && !slot.hidden && slot.item != null && slot.item != item ) || x + sx >= width || y + sy >= height ) {
					return false;
				}
			}
		}

		return true;
	}
Пример #14
0
    public bool AddItem(OSItem item)
    {
        if (!item)
        {
            return(false);
        }

        item.definitions = this.definitions;

        // Check if similar item is already in the inventory
        for (int i = 0; i < slots.Count; i++)
        {
            if (slots[i].item.id == item.id)
            {
                if (item.stackable)
                {
                    slots[i].quantity++;

                    // TODO: Find a way to store ammunition information *not* in the OSItem prefab itself
                    //} else if ( item.ammunition.enabled ) {
                    //	slots[i].item.ChangeAmmunition ( item.ammunition.value );

                    return(true);
                }
            }
        }

        // If not, search for available slots
        OSPoint availableCell = new OSPoint(-1, -1);

        availableCell = grid.GetAvailableCell(item);

        if (OSPoint.IsNullOrNegative(availableCell))
        {
            return(false);
        }
        else
        {
            slots.Add(new OSSlot(availableCell.x, availableCell.y, item));
            return(true);
        }
    }
Пример #15
0
    // Get/set items
    public void SpawnSlot(OSSlot slot, Transform parent, Vector3 position)
    {
        if (!slot.item)
        {
            return;
        }

        for (int i = 0; i < slot.quantity; i++)
        {
            GameObject go      = (GameObject)Instantiate(Resources.Load(slot.item.prefabPath));
            Vector3    scale   = go.transform.localScale;
            OSItem     oldItem = slot.item;
            OSItem     newItem = go.GetComponent <OSItem> ();

            newItem.AdoptValues(oldItem);

            go.transform.parent     = parent;
            go.transform.position   = position;
            go.transform.localScale = scale;
        }
    }
Пример #16
0
	public bool [ , ] GetSkippedSlots ( OSItem except ) { 
		bool [ , ] skip = new bool [ width, height ];

		for ( int x = 0; x < width; x++ ) {
			for ( int y = 0; y < height; y++ ) {
				OSSlot slot = inventory.GetSlot ( x, y );

				if ( slot == null || slot.hidden || ( slot.item != null && slot.item == except ) ) { continue; }
				
				for ( int sx = 0; sx < slot.scale.x; sx++ ) {
					for ( int sy = 0; sy < slot.scale.y; sy++ ) {
						if ( ( sx == 0 && sy == 0 ) || x + sx >= width || y + sy >= height ) {
							continue;
						} else {
							skip [ x + sx, y + sy ] = true;
						}
					}
				}
			}
		}

		return skip;
	}
Пример #17
0
    public OSPoint GetAvailableCell(OSItem item)
    {
        bool [ , ] skip = GetSkippedSlots();

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                bool    cancel = false;
                OSPoint point  = new OSPoint(x, y);

                for (int sx = 0; sx < item.slotSize.x; sx++)
                {
                    for (int sy = 0; sy < item.slotSize.y; sy++)
                    {
                        OSSlot slot = inventory.GetSlot(x + sx, y + sy);

                        if (slot != null && !slot.hidden && slot.item != null || x + sx >= width || y + sy >= height || skip [x + sx, y + sy])
                        {
                            cancel = true;
                        }
                    }
                }

                if (cancel)
                {
                    continue;
                }
                else
                {
                    return(point);
                }
            }
        }

        return(null);
    }
Пример #18
0
    public bool CheckSlot(int x, int y, OSItem item)
    {
        if (x < 0 || y < 0)
        {
            return(false);
        }

        bool [ , ] skip = GetSkippedSlots(item);

        for (int sx = 0; sx < item.slotSize.x; sx++)
        {
            for (int sy = 0; sy < item.slotSize.y; sy++)
            {
                OSSlot slot = inventory.GetSlot(x + sx, y + sy);

                if ((x + sx < skip.GetLength(0) && y + sy < skip.GetLength(1) && skip [x + sx, y + sy]) || (slot != null && !slot.hidden && slot.item != null && slot.item != item) || x + sx >= width || y + sy >= height)
                {
                    return(false);
                }
            }
        }

        return(true);
    }
Пример #19
0
	public void SetEquipped ( OSItem item, bool isEquipped ) {
		for ( int i = 0; i < slots.Count; i++ ) {
			if ( slots[i] != null && slots[i].item == item ) {
				slots[i].equipped = isEquipped;
				
				if ( eventHandler ) {
					eventHandler.SendMessage ( "OnEquipItem", slots[i].item, SendMessageOptions.DontRequireReceiver );
				}
				
				break;
			}
		}
	}
Пример #20
0
	public void SetEquipped ( OSItem item ) {
		SetEquipped ( item, true );
	}
Пример #21
0
	public bool IsEquipped ( OSItem item ) {
		for ( int i = 0; i < slots.Count; i++ ) {
			if ( slots[i] != null && slots[i].item == item && slots[i].equipped ) {
				return true;
			}
		}

		return false;
	}
Пример #22
0
	public static OSItem ConvertFromScene ( OSItem item ) {
		return (OSItem) Resources.Load ( item.prefabPath );
	}
Пример #23
0
 public OSSlot(int x, int y, OSItem item)
 {
     this.x    = x;
     this.y    = y;
     this.item = item;
 }
Пример #24
0
	public bool AddItemFromScene ( OSItem sceneItem ) {
		if ( !sceneItem ) { return false; }
		
		GameObject go = (GameObject) Resources.Load ( sceneItem.prefabPath );

		sceneItem.gameObject.SendMessage ( "OnPickUp", SendMessageOptions.DontRequireReceiver );
		Destroy ( sceneItem.gameObject );

		return AddItem ( go.GetComponent< OSItem > () );
	}
Пример #25
0
	public void DecreaseItem ( OSItem item ) {
		OSSlot slot = GetSlot ( item );

		if ( slot != null ) {
			DecreaseSlot ( slot );
		}
	}
    public override void OnInspectorGUI()
    {
        OSInventory inventory = (OSInventory)target;

        inventory.definitions = (OSDefinitions)EditorGUILayout.ObjectField("Definitions", inventory.definitions, typeof(OSDefinitions), false);

        if (!inventory.definitions)
        {
            GUI.color = Color.red;
            EditorGUILayout.LabelField("You need to link an OSDefinitions prefab with this inventory", EditorStyles.boldLabel);
            GUI.color = Color.white;
            return;
        }

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("Currency amounts", EditorStyles.boldLabel);

        for (int i = 0; i < inventory.definitions.currencies.Length; i++)
        {
            OSCurrency def = inventory.definitions.currencies[i];

            EditorGUILayout.BeginHorizontal();

            inventory.CheckCurrency(i);

            int oldAmount = inventory.GetCurrencyAmount(def.name);
            int newAmount = EditorGUILayout.IntField(def.name, oldAmount);

            if (oldAmount != newAmount)
            {
                inventory.SetCurrencyAmount(def.name, newAmount);
            }

            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.Space();

        Event evt = Event.current;

        inventory.grid.inventory = inventory;

        // Grid
        OSSlot slot         = null;
        int    slotSize     = 60;
        bool   mouseDown    = evt.type == EventType.MouseDown;
        bool   keyLeft      = evt.type == EventType.KeyDown && evt.keyCode == KeyCode.LeftArrow;
        bool   keyRight     = evt.type == EventType.KeyDown && evt.keyCode == KeyCode.RightArrow;
        bool   keyUp        = evt.type == EventType.KeyDown && evt.keyCode == KeyCode.UpArrow;
        bool   keyDown      = evt.type == EventType.KeyDown && evt.keyCode == KeyCode.DownArrow;
        bool   keyTab       = evt.type == EventType.KeyDown && evt.keyCode == KeyCode.Tab;
        bool   keyBackspace = evt.type == EventType.KeyDown && evt.keyCode == KeyCode.Backspace;

        EditorGUILayout.BeginHorizontal();

        GUILayout.Space(34);
        inventory.grid.width = EditorGUILayout.IntField(inventory.grid.width, GUILayout.Width(30));

        EditorGUILayout.EndHorizontal();

        GUILayout.Space(4);

        EditorGUILayout.BeginHorizontal();

        inventory.grid.height = EditorGUILayout.IntField(inventory.grid.height, GUILayout.Width(30));

        Rect rect = EditorGUILayout.GetControlRect(GUILayout.Width(slotSize * inventory.grid.width), GUILayout.Height(slotSize * inventory.grid.height));
        int  xPos = (int)rect.x;
        int  yPos = (int)rect.y;

        bool [ , ] skip = inventory.grid.GetSkippedSlots();

        if (mouseDown && !rect.Contains(evt.mousePosition))
        {
            selected = null;
        }


        for (int x = 0; x < inventory.grid.width; x++)
        {
            for (int y = 0; y < inventory.grid.height; y++)
            {
                if (skip [x, y] == true)
                {
                    continue;
                }
                else
                {
                    Texture2D tex = null;
                    OSItem    item;
                    Rect      slotRect;
                    slot = inventory.GetSlot(x, y);

                    xPos = (int)rect.x + x * slotSize;
                    yPos = (int)rect.y + y * slotSize;

                    if (slot != null && slot.item && !slot.hidden)
                    {
                        item     = slot.item;
                        tex      = item.preview;
                        slotRect = new Rect(xPos, yPos, slotSize * slot.scale.x, slotSize * slot.scale.y);

                        if (slot == selected)
                        {
                            GUI.backgroundColor = Color.green;
                            GUI.SetNextControlName("Selected");
                        }

                        GUI.Box(slotRect, "");
                        GUI.backgroundColor = Color.white;

                        if (tex)
                        {
                            GUI.DrawTexture(slotRect, tex);
                        }

                        if (slot.quantity > 1)
                        {
                            GUI.Label(new Rect(xPos + 4, yPos + slot.scale.y * slotSize - 20, slot.scale.x * slotSize, 20), slot.quantity.ToString());
                        }

                        if (slotRect.Contains(evt.mousePosition) && mouseDown)
                        {
                            selected = slot;
                        }
                    }
                    else
                    {
                        slotRect = new Rect(xPos, yPos, slotSize, slotSize);

                        if (slotRect.Contains(evt.mousePosition) && mouseDown)
                        {
                            selected = null;
                        }

                        GUI.Box(slotRect, "");
                    }
                }
            }
        }

        EditorGUILayout.BeginVertical();

        if (selected != null && selected.item)
        {
            EditorGUILayout.LabelField(selected.item.id, EditorStyles.boldLabel);
            EditorGUILayout.LabelField(selected.item.description);

            EditorGUILayout.Space();

            foreach (OSAttribute attribute in selected.item.attributes)
            {
                EditorGUILayout.BeginHorizontal();

                EditorGUILayout.LabelField(attribute.name + ":", GUILayout.Width(80));
                EditorGUILayout.LabelField(attribute.value + " " + attribute.suffix, GUILayout.Width(80));

                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("[ " + selected.item.category + " : " + selected.item.subcategory + " ]");
        }

        EditorGUILayout.EndVertical();

        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();

        OSItem addItem = null;

        addItem = (OSItem)EditorGUILayout.ObjectField("Add item", addItem, typeof(OSItem), true);

        if (addItem)
        {
            inventory.AddItem(addItem);
        }

        GUI.backgroundColor = Color.red;
        if (GUILayout.Button("Clear inventory"))
        {
            inventory.slots.Clear();
        }
        GUI.backgroundColor = Color.white;

        // ^ Move slot
        if (selected != null && selected.item)
        {
            if (keyLeft)
            {
                inventory.grid.Move(selected, selected.x - 1, selected.y);
                evt.Use();
            }
            else if (keyRight)
            {
                inventory.grid.Move(selected, selected.x + 1, selected.y);
                evt.Use();
            }
            else if (keyDown)
            {
                inventory.grid.Move(selected, selected.x, selected.y + 1);
                evt.Use();
            }
            else if (keyUp)
            {
                inventory.grid.Move(selected, selected.x, selected.y - 1);
                evt.Use();
            }
            else if (keyBackspace)
            {
                inventory.RemoveItem(selected.item);
                evt.Use();
            }
        }

        if (keyTab)
        {
            evt.Use();

            if (selected != null && selected.item)
            {
                int i = inventory.GetItemIndex(selected.item);

                if (i < inventory.slots.Count - 1)
                {
                    i++;
                }
                else
                {
                    i = 0;
                }

                selected = inventory.slots[i];
            }
            else if (inventory.slots.Count > 0)
            {
                selected = inventory.slots[0];
            }

            GUI.FocusControl("Selected");
        }

        Repaint();

        if (GUI.changed)
        {
            SavePrefab(target);
        }
    }
Пример #27
0
	public void Update () {
		if ( !item ) {
			item = this.GetComponent< OSItem > ();
			return;
		}

		if ( fireTimer > 0 ) {
			fireTimer -= Time.deltaTime;
		}
	}	
Пример #28
0
 // Quick info
 public void SetQuickItem(OSItem item, int key)
 {
     quickSlots.Insert(key, GetItemIndex(item));
 }
Пример #29
0
    public override void OnInspectorGUI()
    {
        OSItem item = (OSItem)target;

        // Meta
        EditorGUILayout.LabelField("Id", EditorStyles.boldLabel);
        item.id          = EditorGUILayout.TextField("Name", item.id);
        item.description = EditorGUILayout.TextField("Description", item.description);
        item.definitions = (OSDefinitions)EditorGUILayout.ObjectField("Definitions", item.definitions, typeof(OSDefinitions), false);

        if (!item.definitions)
        {
            GUI.color = Color.red;
            EditorGUILayout.LabelField("You need to link an OSDefinitions prefab with this item", EditorStyles.boldLabel);
            GUI.color = Color.white;
        }
        else
        {
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Resource", EditorStyles.boldLabel);

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.TextField("Path", item.prefabPath);

            if (!item.gameObject.activeInHierarchy)
            {
                GUI.backgroundColor = Color.green;
                if (GUILayout.Button("Update", GUILayout.Width(60)))
                {
                    string path = AssetDatabase.GetAssetPath(item.gameObject);
                    if (path.Contains("Assets/Resources/"))
                    {
                        path = path.Replace("Assets/Resources/", "");
                        path = path.Replace(".prefab", "");

                        item.prefabPath = path;

                        resourceWarning = false;
                    }
                    else
                    {
                        resourceWarning = true;
                    }
                }
                GUI.backgroundColor = Color.white;
            }

            EditorGUILayout.EndHorizontal();

            if (resourceWarning)
            {
                item.prefabPath = "";
                GUI.color       = Color.red;
                EditorGUILayout.LabelField("Object not in /Resources folder!", EditorStyles.boldLabel);
                GUI.color = Color.white;
            }

            // Category
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Category", EditorStyles.boldLabel);

            item.catIndex = EditorGUILayout.Popup("Category", item.catIndex, item.definitions.GetCategoryStrings());

            if (item.subcatIndex >= item.definitions.categories [item.catIndex].subcategories.Length)
            {
                item.subcatIndex = 0;
            }

            item.subcatIndex = EditorGUILayout.Popup("Subcategory", item.subcatIndex, item.definitions.categories [item.catIndex].subcategories);

            // Slot
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Slot properties", EditorStyles.boldLabel);
            item.stackable = EditorGUILayout.Toggle("Stackable", item.stackable);
            item.canDrop   = EditorGUILayout.Toggle("Can drop", item.canDrop);

            item.slotSize.x = EditorGUILayout.IntField("Width", item.slotSize.x);
            item.slotSize.y = EditorGUILayout.IntField("Height", item.slotSize.y);

            if (item.slotSize.x < 1)
            {
                item.slotSize.x = 1;
            }
            if (item.slotSize.y < 1)
            {
                item.slotSize.y = 1;
            }

            // Attributes
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Attributes", EditorStyles.boldLabel);
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.BeginVertical();

            for (int i = 0; i < item.attributes.Length; i++)
            {
                EditorGUILayout.BeginHorizontal();

                GUI.backgroundColor = Color.red;
                if (GUILayout.Button("x", GUILayout.Width(28), GUILayout.Height(14)))
                {
                    List <OSAttribute> tmpAttr = new List <OSAttribute> (item.attributes);

                    tmpAttr.RemoveAt(i);

                    item.attributes = tmpAttr.ToArray();
                    return;
                }
                GUI.backgroundColor = Color.white;

                item.attributes[i].definitions = item.definitions;
                item.attributes[i].index       = EditorGUILayout.Popup(item.attributes[i].index, item.definitions.GetAttributeStrings());
                item.attributes[i].value       = EditorGUILayout.FloatField(item.attributes[i].value);
                EditorGUILayout.LabelField(item.attributes[i].suffix, GUILayout.Width(80));

                EditorGUILayout.EndHorizontal();
            }

            GUI.backgroundColor = Color.green;
            if (GUILayout.Button("+", GUILayout.Width(28), GUILayout.Height(14)))
            {
                List <OSAttribute> tmpAttr = new List <OSAttribute> (item.attributes);

                tmpAttr.Add(new OSAttribute(item.definitions));

                item.attributes = tmpAttr.ToArray();
            }
            GUI.backgroundColor = Color.white;

            EditorGUILayout.EndVertical();

            EditorGUILayout.EndHorizontal();

            // Sounds
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Sounds", EditorStyles.boldLabel);
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.BeginVertical();

            for (int i = 0; i < item.sounds.Length; i++)
            {
                EditorGUILayout.BeginHorizontal();

                GUI.backgroundColor = Color.red;
                if (GUILayout.Button("x", GUILayout.Width(28), GUILayout.Height(14)))
                {
                    List <AudioClip> tmpSound = new List <AudioClip> (item.sounds);

                    tmpSound.RemoveAt(i);

                    item.sounds = tmpSound.ToArray();
                    return;
                }
                GUI.backgroundColor = Color.white;

                item.sounds[i] = (AudioClip)EditorGUILayout.ObjectField(item.sounds[i], typeof(AudioClip), false);

                EditorGUILayout.EndHorizontal();
            }

            GUI.backgroundColor = Color.green;
            if (GUILayout.Button("+", GUILayout.Width(28), GUILayout.Height(14)))
            {
                List <AudioClip> tmpSound = new List <AudioClip> (item.sounds);

                tmpSound.Add(null);

                item.sounds = tmpSound.ToArray();
            }
            GUI.backgroundColor = Color.white;

            EditorGUILayout.EndVertical();

            EditorGUILayout.EndHorizontal();

            // Ammunition
            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Ammunition", EditorStyles.boldLabel, GUILayout.Width(80));
            item.ammunition.enabled = EditorGUILayout.Toggle(item.ammunition.enabled);
            EditorGUILayout.EndHorizontal();

            if (item.ammunition.enabled)
            {
                item.ammunition.index  = EditorGUILayout.Popup("Type", item.ammunition.index, item.definitions.GetAmmunitionStrings());
                item.ammunition.value  = EditorGUILayout.IntField("Amount", item.ammunition.value);
                item.ammunition.max    = EditorGUILayout.IntField("Maximum", item.ammunition.max);
                item.ammunition.spread = EditorGUILayout.IntField("Spread", item.ammunition.spread);
                item.ammunition.item   = item;
            }

            // Textures
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Textures", EditorStyles.boldLabel);

            item.thumbnail = (Texture2D)EditorGUILayout.ObjectField("Thumbnail", item.thumbnail as Object, typeof(Texture2D), false);
            item.preview   = (Texture2D)EditorGUILayout.ObjectField("Preview", item.preview as Object, typeof(Texture2D), false);

            if (GUI.changed)
            {
                OSInventoryInspector.SavePrefab(target);
            }
        }
    }
Пример #30
0
	public OSAmmunitionAmount ( OSItem item ) {
		this.item = item;
	}
Пример #31
0
 public OSAmmunitionAmount(OSItem item)
 {
     this.item = item;
 }
Пример #32
0
	// Quick info
	public void SetQuickItem ( OSItem item, int key ) {
		quickSlots.Insert ( key, GetItemIndex ( item ) );
	}
Пример #33
0
	public void Update () {
		if ( !item ) {
			item = this.GetComponent< OSItem > ();
			return;
		}

		if ( !bullet ) {
			bullet = item.ammunition.projectile;
		}

		if ( fireTimer > 0 ) {
			fireTimer -= Time.deltaTime;
		}

		if ( flashTimer > 0 ) {
			flashTimer -= Time.deltaTime;
		}

		if ( muzzleFlash ) {
			if ( flashTimer > 0 && !muzzleFlash.activeSelf ) {
				muzzleFlash.SetActive ( true );

				if ( muzzleFlash.particleSystem ) {
					muzzleFlash.particleSystem.Play ();
				}
			
			} else if ( flashTimer <= 0 && muzzleFlash.activeSelf ) {
				muzzleFlash.SetActive ( false );

			}
		}

		if ( projectileTypeThreshold > 0 ) {
			if ( Time.timeScale >= projectileTypeThreshold ) {
				projectileType = OSProjectileType.Raycast;
			
			} else if ( bullet ) {
				projectileType = OSProjectileType.Prefab;
			
			}
		}
	}	
Пример #34
0
	// Get data
	public int GetItemIndex ( OSItem item ) {
		for ( int i = 0; i < slots.Count; i++ ) {
			if ( slots[i].item == item ) {
				return i;
			}
		}
		
		return -1;
	}
Пример #35
0
 public void SetEquipped(OSItem item)
 {
     SetEquipped(item, true);
 }
Пример #36
0
	public void RemoveItem ( OSItem item ) {
		for ( int i = 0; i < slots.Count; i++ ) {
			if ( slots[i].item == item ) {
				slots.RemoveAt ( i );
			}
		}
	}
Пример #37
0
	public OSSlot ( int x, int y, string path ) {
		GameObject go = (GameObject) Resources.Load ( path );
		this.x = x;
		this.y = y;
		this.item = go.GetComponent< OSItem > ();
	}	
Пример #38
0
	public bool AddItem ( OSItem item ) {
		if ( !item ) { return false; }
	
		item.definitions = this.definitions;
	
		// Check if similar item is already in the inventory
		for ( int i = 0; i < slots.Count; i++ ) {
			if ( slots[i].item.id == item.id ) {
			       	if ( item.stackable ) {
					slots[i].quantity++;
				
				// TODO: Find a way to store ammunition information *not* in the OSItem prefab itself
				//} else if ( item.ammunition.enabled ) {
				//	slots[i].item.ChangeAmmunition ( item.ammunition.value );
				
					return true;
				}
			}
		}
		
		// If not, search for available slots
		OSPoint availableCell = new OSPoint ( -1, -1 );

		availableCell = grid.GetAvailableCell ( item );
		
		if ( OSPoint.IsNullOrNegative ( availableCell ) ) {
			return false;

		} else {
			slots.Add ( new OSSlot ( availableCell.x, availableCell.y, item ) );
			return true;

		}

	}
Пример #39
0
	public OSSlot ( int x, int y, OSItem item ) {
		this.x = x;
		this.y = y;
		this.item = item;
	}
Пример #40
0
	public OSSlot GetSlot ( OSItem item ) {
		for ( int i = 0; i < slots.Count; i++ ) {
			if ( slots[i] != null && slots[i].item.prefabPath == item.prefabPath ) {
				return slots[i];
			}
		}

		return null;
	}
Пример #41
0
	public void AdoptValues ( OSItem item ) {
		this.ammunition.value = item.ammunition.value;

		for ( int i = 0; i < item.attributes.Length; i++ ) {
			this.attributes[i].value = item.attributes[i].value;
		}
	}
Пример #42
0
	public OSPoint GetAvailableCell ( OSItem item ) {
		bool [ , ] skip = GetSkippedSlots ();

		for ( int y = 0; y < height; y++ ) {
			for ( int x = 0; x < width; x++ ) {
				bool cancel = false;
				OSPoint point = new OSPoint ( x, y );

				for ( int sx = 0; sx < item.slotSize.x; sx++ ) {
					for ( int sy = 0; sy < item.slotSize.y; sy++ ) {
						OSSlot slot = inventory.GetSlot ( x + sx, y + sy );

						if ( slot != null && !slot.hidden && slot.item != null || x + sx >= width || y + sy >= height || skip [ x + sx, y + sy ] ) {
							cancel = true;
						}
					}
				}
				
				if ( cancel ) {
					continue;

				} else {
					return point;

				}
			}
		}

		return null;
	}
Пример #43
0
 public static OSItem ConvertFromScene(OSItem item)
 {
     return((OSItem)Resources.Load(item.prefabPath));
 }