Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
trantung998 committed Sep 28, 2017
1 parent 7645c56 commit 04277e1
Show file tree
Hide file tree
Showing 10 changed files with 297 additions and 4 deletions.
71 changes: 71 additions & 0 deletions Assets/Scripts/InventorySystem/ItemData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@

namespace Assets.Scripts.InventorySystem
{
public enum ItemType
{
None,
NormalItem,
ExpItem,
Resource,
}

public enum ItemClass
{
None,
Weapon,
Head,
Chest,
Legs,
Accessorie,
Hand
}

[Serializable]
public class ItemData
{
Expand All @@ -17,6 +36,37 @@ public class ItemData
private string name;
[SerializeField]
private uint itemStar;
[SerializeField]
private bool isStackable;

[SerializeField] private bool hideInventory;

[SerializeField] private ItemType itemType;
[SerializeField] private ItemClass itemClass;

public ItemType ItemType
{
get { return itemType; }
set { itemType = value; }
}

public ItemClass ItemClass
{
get { return itemClass; }
set { itemClass = value; }
}

public bool HideInventory
{
get { return hideInventory; }
set { hideInventory = value; }
}

public bool IsStackable
{
get { return isStackable; }
set { isStackable = value; }
}

public List<Attribute> Attributes
{
Expand All @@ -42,4 +92,25 @@ public uint ItemStar
set { itemStar = value; }
}
}

[Serializable]
public class ItemVisual
{
[SerializeField]
private uint itemDataId;

[SerializeField] private Sprite itemSprite;

public uint ItemDataId
{
get { return itemDataId; }
set { itemDataId = value; }
}

public Sprite ItemSprite
{
get { return itemSprite; }
set { itemSprite = value; }
}
}
}
8 changes: 7 additions & 1 deletion Assets/Scripts/InventorySystem/ItemDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ namespace Assets.Scripts.InventorySystem
public class ItemDatabase : ScriptableObject
{
[SerializeField] private List<ItemData> itemDataList;
[SerializeField] private List<ItemVisual> itemVisualList;

public List<ItemData> ItemDataList
{
get { return (List<ItemData>)Utilities.DeepClone(itemDataList); }
get { return (List<ItemData>) Utilities.DeepClone(itemDataList); }
}

public List<ItemVisual> ItemVisualList
{
get { return itemVisualList; }
}
}
}
22 changes: 21 additions & 1 deletion Assets/Scripts/InventorySystem/ItemManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,30 @@ namespace Assets.Scripts.InventorySystem
public class ItemManager : MonoBehaviour
{
private ItemDatabase itemDatabase;
private UserItemManager userItemManager;

Dictionary<uint, Sprite> itemVisualDic = new Dictionary<uint, Sprite>();
Dictionary<uint, ItemData> itemDataDic = new Dictionary<uint, ItemData>();
void Start()
{
itemDatabase = Resources.Load("Data/ItemData/Item Visuals") as ItemDatabase;
userItemManager = new UserItemManager();
}

private void InitData()
{
//item visual
itemVisualDic = itemDatabase.ItemVisualList.Distinct().ToDictionary(x=>x.ItemDataId, x=>x.ItemSprite);
itemDataDic = itemDatabase.ItemDataList.Distinct().ToDictionary(x=>x.ItemDataId, x=>x);
}

public ItemData GetItemRawData(uint itemId)
{
if (itemDataDic.ContainsKey(itemId)) return itemDataDic[itemId];
return null;
}

public void AddItem(int itemId, int value = 1)
public void AddItem(uint itemId, int value = 1)
{

}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/InventorySystem/UserItemData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Assets.Scripts.InventorySystem
{
public class UserItemManager
{
private string uItemDataFile = "u_item.data";
private string uItemDataFile = "/u_item.data";
private UserItemDataFile userData;

public UserItemDataFile UserData
Expand Down
9 changes: 9 additions & 0 deletions Assets/Scripts/Singleton.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions Assets/Scripts/Singleton/PersistentSingleton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using UnityEngine;

namespace InventorySystem.Tools
{
/// <summary>
/// Persistent singleton.
/// </summary>
public class PersistentSingleton<T> : MonoBehaviour where T : Component
{
protected static T _instance;
protected bool _enabled;

/// <summary>
/// Singleton design pattern
/// </summary>
/// <value>The instance.</value>
public static T Instance
{
get
{
if (_instance == null)
{
_instance = FindObjectOfType<T>();
if (_instance == null)
{
GameObject obj = new GameObject();
_instance = obj.AddComponent<T>();
}
}
return _instance;
}
}

/// <summary>
/// On awake, we check if there's already a copy of the object in the scene. If there's one, we destroy it.
/// </summary>
protected virtual void Awake()
{
if (!Application.isPlaying)
{
return;
}

if (_instance == null)
{
//If I am the first instance, make me the Singleton
_instance = this as T;
DontDestroyOnLoad(transform.gameObject);
_enabled = true;
}
else
{
//If a Singleton already exists and you find
//another reference in scene, destroy it!
if (this != _instance)
{
Destroy(this.gameObject);
}
}
}
}
}
12 changes: 12 additions & 0 deletions Assets/Scripts/Singleton/PersistentSingleton.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 93 additions & 0 deletions InventorySystem.CSharp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.20506</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{89C10793-54C2-8094-B12A-CB38A05F3246}</ProjectGuid>
<OutputType>Library</OutputType>
<AssemblyName>Assembly-CSharp</AssemblyName>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkProfile>Unity Subset v3.5</TargetFrameworkProfile>
<CompilerResponseFile>
</CompilerResponseFile>
<UnityProjectType>Game:1</UnityProjectType>
<UnityBuildTarget>StandaloneWindows64:19</UnityBuildTarget>
<UnityVersion>2017.1.1f1</UnityVersion>
<RootNamespace>
</RootNamespace>
<LangVersion Condition=" '$(VisualStudioVersion)' != '10.0' ">4</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>false</Optimize>
<OutputPath>Temp\UnityVS_bin\Debug\</OutputPath>
<IntermediateOutputPath>Temp\UnityVS_obj\Debug\</IntermediateOutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DefineConstants>DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_1_1;UNITY_2017_1;UNITY_2017;PLATFORM_ARCH_64;UNITY_64;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_GENERICS;ENABLE_PVR_GI;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_RUNTIME_NAVMESH_BUILDING;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_DIRECTOR;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_COLLAB_SOFTLOCKS;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_USE_WEBREQUEST;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_WEBSOCKET_CLIENT;ENABLE_DIRECTOR_AUDIO;ENABLE_TIMELINE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;ENABLE_NATIVE_ARRAY;ENABLE_SPRITE_MASKING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;ENABLE_MONO_BDWGC;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_VIDEO;ENABLE_RMGUI;ENABLE_CUSTOM_RENDER_TEXTURE;ENABLE_STYLE_SHEETS;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;NET_2_0_SUBSET;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;ENABLE_NATIVE_ARRAY_CHECKS;UNITY_TEAM_LICENSE;ENABLE_VSTU</DefineConstants>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>false</Optimize>
<OutputPath>Temp\UnityVS_bin\Release\</OutputPath>
<IntermediateOutputPath>Temp\UnityVS_obj\Release\</IntermediateOutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DefineConstants>TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_1_1;UNITY_2017_1;UNITY_2017;PLATFORM_ARCH_64;UNITY_64;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_GENERICS;ENABLE_PVR_GI;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_RUNTIME_NAVMESH_BUILDING;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_DIRECTOR;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_COLLAB_SOFTLOCKS;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_USE_WEBREQUEST;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_WEBSOCKET_CLIENT;ENABLE_DIRECTOR_AUDIO;ENABLE_TIMELINE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;ENABLE_NATIVE_ARRAY;ENABLE_SPRITE_MASKING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;ENABLE_MONO_BDWGC;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_VIDEO;ENABLE_RMGUI;ENABLE_CUSTOM_RENDER_TEXTURE;ENABLE_STYLE_SHEETS;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;NET_2_0_SUBSET;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;ENABLE_NATIVE_ARRAY_CHECKS;UNITY_TEAM_LICENSE;ENABLE_VSTU</DefineConstants>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.XML" />
<Reference Include="System.Core" />
<Reference Include="Boo.Lang" />
<Reference Include="UnityScript.Lang" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="UnityEditor">
<HintPath>Library\UnityAssemblies\UnityEditor.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>Library\UnityAssemblies\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>Library\UnityAssemblies\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.Networking">
<HintPath>Library\UnityAssemblies\UnityEngine.Networking.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TestRunner">
<HintPath>Library\UnityAssemblies\UnityEngine.TestRunner.dll</HintPath>
</Reference>
<Reference Include="nunit.framework">
<HintPath>Library\UnityAssemblies\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.Timeline">
<HintPath>Library\UnityAssemblies\UnityEngine.Timeline.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.Analytics">
<HintPath>Library\UnityAssemblies\UnityEngine.Analytics.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.HoloLens">
<HintPath>Library\UnityAssemblies\UnityEngine.HoloLens.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Assets\Scripts\FileHelper.cs" />
<Compile Include="Assets\Scripts\InventorySystem\Attribute.cs" />
<Compile Include="Assets\Scripts\InventorySystem\ItemData.cs" />
<Compile Include="Assets\Scripts\InventorySystem\ItemDatabase.cs" />
<Compile Include="Assets\Scripts\InventorySystem\ItemManager.cs" />
<Compile Include="Assets\Scripts\InventorySystem\UserItemData.cs" />
<Compile Include="Assets\Scripts\InventorySystem\Utilities.cs" />
<Compile Include="Assets\Scripts\Singleton\PersistentSingleton.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\SyntaxTree\UnityVS\2015\UnityVS.CSharp.targets" />
</Project>
20 changes: 20 additions & 0 deletions InventorySystem.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2015
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InventorySystem.CSharp", "InventorySystem.CSharp.csproj", "{89C10793-54C2-8094-B12A-CB38A05F3246}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{89C10793-54C2-8094-B12A-CB38A05F3246}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{89C10793-54C2-8094-B12A-CB38A05F3246}.Debug|Any CPU.Build.0 = Debug|Any CPU
{89C10793-54C2-8094-B12A-CB38A05F3246}.Release|Any CPU.ActiveCfg = Release|Any CPU
{89C10793-54C2-8094-B12A-CB38A05F3246}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
m_EditorVersion: 2017.1.0f3
m_EditorVersion: 2017.1.1f1

0 comments on commit 04277e1

Please sign in to comment.