Add visual representation of equipped items

This commit is contained in:
excitedneon 2017-05-14 23:28:55 +03:00
parent 43059e57ca
commit 039a050647
7 changed files with 317 additions and 86 deletions

View File

@ -62,21 +62,6 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1067606113877164
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 4141975958961490}
m_Layer: 0
m_Name: Equipment Interface
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1073554920665706
GameObject:
m_ObjectHideFlags: 1
@ -365,6 +350,23 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1282435183566290
GameObject:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 4603884443367184}
- component: {fileID: 33816067446785734}
- component: {fileID: 23947590342960758}
m_Layer: 0
m_Name: Hat Mesh
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1292364954462330
GameObject:
m_ObjectHideFlags: 1
@ -429,6 +431,7 @@ GameObject:
- component: {fileID: 114575501420754388}
- component: {fileID: 114385213279389382}
- component: {fileID: 114702404122310282}
- component: {fileID: 114772626772950132}
m_Layer: 0
m_Name: PC
m_TagString: Untagged
@ -588,6 +591,23 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1455034129804424
GameObject:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 4949557329132524}
- component: {fileID: 33570510947136580}
- component: {fileID: 23795875440691066}
m_Layer: 0
m_Name: Left Hand
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1467080138821004
GameObject:
m_ObjectHideFlags: 1
@ -769,7 +789,7 @@ GameObject:
- component: {fileID: 33975615408091930}
- component: {fileID: 23193880740220832}
m_Layer: 0
m_Name: Hat Mesh
m_Name: Right Hand
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@ -1418,7 +1438,7 @@ Transform:
m_Children:
- {fileID: 4236387573765288}
m_Father: {fileID: 4883048021777868}
m_RootOrder: 3
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &4105190110964144
Transform:
@ -1487,19 +1507,6 @@ Transform:
m_Father: {fileID: 4145663281164610}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &4141975958961490
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1067606113877164}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4586682446228250}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &4145297277959534
Transform:
m_ObjectHideFlags: 1
@ -2035,7 +2042,6 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4400199165588268}
- {fileID: 4141975958961490}
- {fileID: 4883048021777868}
m_Father: {fileID: 0}
m_RootOrder: 0
@ -2054,6 +2060,19 @@ Transform:
m_Father: {fileID: 4783870784903044}
m_RootOrder: 13
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &4603884443367184
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1282435183566290}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0.125, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4883048021777868}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &4612469421790772
Transform:
m_ObjectHideFlags: 1
@ -2207,12 +2226,12 @@ Transform:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1593278606667730}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0.125, z: 0}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0.6, y: -0.30000007, z: 0.6}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4883048021777868}
m_RootOrder: 2
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &4783870784903044
Transform:
@ -2372,10 +2391,12 @@ Transform:
m_Children:
- {fileID: 4243620059187726}
- {fileID: 4126889091672100}
- {fileID: 4603884443367184}
- {fileID: 4949557329132524}
- {fileID: 4778775157160844}
- {fileID: 4099946104317490}
m_Father: {fileID: 4586682446228250}
m_RootOrder: 2
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &4885341820297518
Transform:
@ -2470,6 +2491,19 @@ Transform:
m_Father: {fileID: 4530114029127332}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &4949557329132524
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1455034129804424}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.6, y: -0.3, z: 0.6}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4883048021777868}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &4967445830105586
Transform:
m_ObjectHideFlags: 1
@ -3525,6 +3559,38 @@ MeshRenderer:
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!23 &23795875440691066
MeshRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1455034129804424}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_Materials:
- {fileID: 2100000, guid: cac55f0f5d2b94909899376ddfca7276, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!23 &23804466063309962
MeshRenderer:
m_ObjectHideFlags: 1
@ -3784,6 +3850,38 @@ MeshRenderer:
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!23 &23947590342960758
MeshRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1282435183566290}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_Materials:
- {fileID: 2100000, guid: cac55f0f5d2b94909899376ddfca7276, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!23 &23964641026033906
MeshRenderer:
m_ObjectHideFlags: 1
@ -4108,6 +4206,13 @@ MeshFilter:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1491104319836832}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!33 &33570510947136580
MeshFilter:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1455034129804424}
m_Mesh: {fileID: 0}
--- !u!33 &33585471952367662
MeshFilter:
m_ObjectHideFlags: 1
@ -4171,6 +4276,13 @@ MeshFilter:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1292364954462330}
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!33 &33816067446785734
MeshFilter:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1282435183566290}
m_Mesh: {fileID: 0}
--- !u!33 &33831674242328916
MeshFilter:
m_ObjectHideFlags: 1
@ -5105,6 +5217,26 @@ MonoBehaviour:
Axis: {x: 0, y: 1, z: 0}
RoundsPerMinute: 120
Spinning: 0
--- !u!114 &114772626772950132
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1297568499365208}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bd9edbba64bb2450dab508e94163b0f8, type: 3}
m_Name:
m_EditorClassIdentifier:
Inventory: {fileID: 114702404122310282}
UpdateFrequency: 15
Slots:
- Slot: 0
Mesh: {fileID: 33816067446785734}
- Slot: 1
Mesh: {fileID: 33975615408091930}
- Slot: 2
Mesh: {fileID: 33570510947136580}
--- !u!114 &114800660248371886
MonoBehaviour:
m_ObjectHideFlags: 1

View File

@ -634,48 +634,6 @@ CanvasRenderer:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 396674780}
--- !u!1001 &542383661
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 4586682446228250, guid: e8761b9491a974d1780e60dafbd372a2, type: 2}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4586682446228250, guid: e8761b9491a974d1780e60dafbd372a2, type: 2}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4586682446228250, guid: e8761b9491a974d1780e60dafbd372a2, type: 2}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4586682446228250, guid: e8761b9491a974d1780e60dafbd372a2, type: 2}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4586682446228250, guid: e8761b9491a974d1780e60dafbd372a2, type: 2}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4586682446228250, guid: e8761b9491a974d1780e60dafbd372a2, type: 2}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4586682446228250, guid: e8761b9491a974d1780e60dafbd372a2, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4586682446228250, guid: e8761b9491a974d1780e60dafbd372a2, type: 2}
propertyPath: m_RootOrder
value: 3
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: e8761b9491a974d1780e60dafbd372a2, type: 2}
m_IsPrefabParent: 0
--- !u!1 &564954320
GameObject:
m_ObjectHideFlags: 0
@ -885,6 +843,48 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 9d715320baa1f401ab0f46b603399dc3, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &662048545
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 4586682446228250, guid: e8761b9491a974d1780e60dafbd372a2, type: 2}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4586682446228250, guid: e8761b9491a974d1780e60dafbd372a2, type: 2}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4586682446228250, guid: e8761b9491a974d1780e60dafbd372a2, type: 2}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4586682446228250, guid: e8761b9491a974d1780e60dafbd372a2, type: 2}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4586682446228250, guid: e8761b9491a974d1780e60dafbd372a2, type: 2}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4586682446228250, guid: e8761b9491a974d1780e60dafbd372a2, type: 2}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4586682446228250, guid: e8761b9491a974d1780e60dafbd372a2, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4586682446228250, guid: e8761b9491a974d1780e60dafbd372a2, type: 2}
propertyPath: m_RootOrder
value: 3
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: e8761b9491a974d1780e60dafbd372a2, type: 2}
m_IsPrefabParent: 0
--- !u!1 &746314094
GameObject:
m_ObjectHideFlags: 0

View File

@ -0,0 +1,69 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cyber.Entities.SyncBases;
using Cyber.Util;
using Cyber.Items;
namespace Cyber.Controls {
/// <summary>
/// Interface that controls the visible equipment on the characters.
/// </summary>
public class EquipmentInterface : MonoBehaviour {
/// <summary>
/// Equipment mesh.
/// </summary>
[System.Serializable]
public struct EquipmentMesh {
/// <summary>
/// The slot enum of the item.
/// </summary>
public EquipSlot Slot;
/// <summary>
/// The in-world slot of the item.
/// </summary>
public MeshFilter Mesh;
}
/// <summary>
/// The inventory.
/// </summary>
public Inventory Inventory;
/// <summary>
/// How many times per second the visual equipment should be updated.
/// </summary>
public float UpdateFrequency = 1f;
/// <summary>
/// The slots where the equipped items go.
/// </summary>
public EquipmentMesh[] Slots;
private float LastUpdateTime = 0;
private void Update() {
if (Time.time - LastUpdateTime >= 1f / UpdateFrequency) {
Dictionary<EquipSlot, Item> Equips = Inventory.Equipped.GetEquippedDict();
// Empty all slots
for (int i = 0; i < Slots.Length; i++) {
Slots[i].Mesh.mesh = null;
}
// Equip all slots
foreach (EquipSlot Slot in Equips.Keys) {
for (int i = 0; i < Slots.Length; i++) {
if (Slots[i].Slot == Slot) {
Slots[i].Mesh.mesh = MeshDB.GetMesh(Equips[Slots[i].Slot].ModelID);
break;
}
}
}
LastUpdateTime = Time.time;
}
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: bd9edbba64bb2450dab508e94163b0f8
timeCreated: 1494789448
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -95,6 +95,7 @@ namespace Cyber.Controls {
private List<Transform> ItemGridCells;
private List<MeshFilter> ItemGridCellMeshes;
private int ItemGridSelectedIndex;
private Item SelectedItem = null;
private Color IconInventoryColor;
private Color IconStatusColor;
@ -136,6 +137,15 @@ namespace Cyber.Controls {
// Interacting with the item list
CurrentIndex = int.Parse(LookedAt.collider.name.Split(' ')[1]);
if (Input.GetButtonDown("Activate")) {
if (ItemGridSelectedIndex == CurrentIndex && SelectedItem != null) {
// Selected index was already this => equip (double-clicked)
Item Equipped = Inventory.Equipped.GetItem(SelectedItem.Slot);
if (Equipped != null && Equipped.ID == SelectedItem.ID) {
Inventory.Equipped.ClearSlot(SelectedItem.Slot);
} else {
Inventory.Equipped.SetSlot(SelectedItem.Slot, SelectedItem);
}
}
ItemGridSelectedIndex = CurrentIndex;
}
} else if (Mesh != null) {
@ -206,6 +216,9 @@ namespace Cyber.Controls {
}
if (ItemGridSelectedIndex == i) {
// Update the selected item
SelectedItem = Item;
// Set preview information
SetPreviewMesh(Mesh);
TextTextureProperties NameProps = ItemNameText.TextProperties;
@ -229,7 +242,6 @@ namespace Cyber.Controls {
Vector3.Lerp(ItemGridSelector.position,
ItemGridCells[i].position, 20f * Time.deltaTime);
}
//ItemGridSelector.LookAt(Camera.transform);
Vector3 NewRot = ItemGridSelector.localEulerAngles;
NewRot.z = 0;
ItemGridSelector.localEulerAngles = NewRot;

View File

@ -31,19 +31,26 @@ namespace Cyber.Items {
/// </summary>
public float Weight;
/// <summary>
/// The slot in which the item can be equipped to.
/// </summary>
public EquipSlot Slot;
/// <summary>
/// Creates an item. This should technically be only called by ItemDB, but it's public because of "reasons".
/// </summary>
/// <param name="id">ID of the item</param>
/// <param name="id">ID of the item.</param>
/// <param name="modelId">ModelID of the item, see ModelDB.</param>
/// <param name="name">The name if the item</param>
/// <param name="weight">The Weight of the item</param>
/// <param name="name">The name if the item.</param>
/// <param name="weight">The Weight of the item.</param>
/// <param name="slot">The equip slot of the item.</param>
/// <param name="description">The description of the item.</param>
public Item(int id, int modelId, string name, float weight, string description) {
public Item(int id, int modelId, string name, float weight, EquipSlot slot, string description) {
ID = id;
ModelID = modelId;
Name = name;
Weight = weight;
Slot = slot;
Description = description;
}
@ -52,8 +59,7 @@ namespace Cyber.Items {
/// </summary>
/// <returns></returns>
public Item Clone() {
return new Item(ID, ModelID, Name, Weight, Description);
return new Item(ID, ModelID, Name, Weight, Slot, Description);
}
}
}

View File

@ -19,8 +19,8 @@ namespace Cyber.Items {
/// Creates the ItemDB. Should not be externally called. See <see cref="Singleton"/>.
/// </summary>
public ItemDB() {
AddItem(new Item(Counter++, 0, "Very Long Item Name", 1.5f, "This item is a rare piece of the \"way too long of a name\" technology, invented by space goblins in ancient times."));
AddItem(new Item(Counter++, 1, "Outworldly spherical tube", .5f, "It's so spherical and smooth that it seems like it's not even from this world!"));
AddItem(new Item(Counter++, 0, "Very Long Item Name", 1.5f, EquipSlot.Hat, "This item is a rare piece of the \"way too long of a name\" technology, invented by space goblins in ancient times."));
AddItem(new Item(Counter++, 1, "Outworldly spherical tube", .5f, EquipSlot.RightHand, "It's so spherical and smooth that it seems like it's not even from this world!"));
}
/// <summary>