Skip to content

Commit

Permalink
Stable
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodCatGames committed May 22, 2020
0 parents commit 82f9f03
Show file tree
Hide file tree
Showing 749 changed files with 49,749 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Unity
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/Assets/AssetStoreTools*
sysinfo.txt
*.pidb.meta

Logs
[Ii]gnore/
*[Ii]gnore.*

# VS/Rider/MD/Consulo
ExportedObj/
.consulo/
.idea/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*


# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

# dev package
/Packages/*
!/Packages/com.goodcat.un-inventory/

ProjectSettings

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
*.csproj

old.gitignore
8 changes: 8 additions & 0 deletions Editor.meta

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

18 changes: 18 additions & 0 deletions Editor/EntityPrefabCreator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using JetBrains.Annotations;
using UnityEditor;
using UnInventory.Core.Manager;
using UnInventory.Editor.Extensions;

namespace UnInventory.Editor
{
public class EntityPrefabCreator
{
[MenuItem("Assets/Create/UnInventory/Prefabs/Entity Standard")]
[UsedImplicitly]
private static void Init()
{
var slotPrefabStandard = InventoryManager.Get().BindPrefabs.EntityPrefabStandard;
CopyPrefabToActiveFolder.Copy(slotPrefabStandard, "Entity");
}
}
}
11 changes: 11 additions & 0 deletions Editor/EntityPrefabCreator.cs.meta

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

8 changes: 8 additions & 0 deletions Editor/Extensions.meta

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

18 changes: 18 additions & 0 deletions Editor/Extensions/CopyPrefabToActiveFolder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using UnityEditor;
using UnityEngine;

namespace UnInventory.Editor.Extensions
{
public static class CopyPrefabToActiveFolder
{
public static bool Copy(GameObject prefab, string namePrefabCopy)
{
var pathFrom = AssetDatabase.GetAssetPath(prefab.GetInstanceID());
var pathActiveFolder = AssetDatabase.GetAssetPath(Selection.activeObject);
var pathToTemplate = $"{pathActiveFolder}/{namePrefabCopy}.prefab";
var pathTo = AssetDatabase.GenerateUniqueAssetPath(pathToTemplate);
var success = AssetDatabase.CopyAsset(pathFrom, pathTo);
return success;
}
}
}
11 changes: 11 additions & 0 deletions Editor/Extensions/CopyPrefabToActiveFolder.cs.meta

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

112 changes: 112 additions & 0 deletions Editor/InventoryCreator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System;
using UnInventory.Core.Manager;
using UnInventory.Core.MVC.Model.Data;
using UnInventory.Core.MVC.View.Components;
using UnInventory.Core.MVC.View.Components.Slot;
using UnInventory.Standard.MVC.View.Components;
using UnityEngine;
using UnityEngine.UI;
using Object = UnityEngine.Object;

namespace UnInventory.Editor
{
public class InventoryCreator
{
public GameObject CreateInventory(PresetInventory preset)
{
var canvasInventory = CreateCanvasInventory(preset.NameInventory);
var rootInventory = CreateRootInventory(preset, canvasInventory);

// Data
var dataInventory = new DataInventory(preset.NameInventory, preset.TypeInventory);
var inventoryComponent = rootInventory.GetComponent<InventoryComponent>();
inventoryComponent.Init(dataInventory);

// Slots
CreateSlots(preset, rootInventory);

return canvasInventory;
}

private void CreateSlots(PresetInventory preset, GameObject root)
{
for (var row = 1; row <= preset.NumberRows; row++)
{
for (var column = 1; column <= preset.NumberColumns; column++)
{
var slot = Object.Instantiate(preset.SlotPrefab, root.transform);
slot.name = GetSlotName(column, row);

if (preset.TypeInventory == DataInventory.TypeInventoryEnum.FreeSlots)
{
PrepareFreeSlot(slot, preset, column, row);
}

// ISlotRootComponent
var slotComponent = (ISlotRootComponent) slot.AddComponent(preset.TypeSlotRootComponent);
if (slotComponent == null)
{
throw new Exception($"Cant Add ISlotRootComponent component to slot: {slot}!");
}

slotComponent.Data.Column = column;
slotComponent.Data.Row = row;

// SlotInputComponent
if (preset.TypeSlotInputComponent != null)
{
slot.AddComponent(preset.TypeSlotInputComponent);
}

// SlotDebugComponent
slot.AddComponent<SlotDebugComponent>();
}
}
}

private void PrepareFreeSlot(GameObject slot, PresetInventory preset, int column, int row)
{
slot.transform.localPosition = new Vector2(preset.CellSize.x * (column - 1), preset.CellSize.y * (row - 1));
slot.transform.localScale = new Vector3(1, 1, 1);
slot.transform.GetComponent<RectTransform>().sizeDelta = preset.CellSize;
}

private string GetSlotName(int column, int row)
{
return "Slot_" + column + "_" + row;
}

private GameObject CreateRootInventory(PresetInventory preset, GameObject canvasInventory)
{
var root = new GameObject(preset.NameInventory);
root.transform.SetParent(canvasInventory.transform);
root.transform.localPosition = Vector3.zero;
root.transform.localScale = new Vector3(1, 1, 1);

root.AddComponent<InventoryComponent>();

root.AddComponent<CanvasRenderer>();
var rectTransform = root.AddComponent<RectTransform>();
rectTransform.sizeDelta = new Vector2Int(preset.CellSize.x * preset.NumberColumns, preset.CellSize.y * preset.NumberRows);

if (preset.TypeInventory != DataInventory.TypeInventoryEnum.FreeSlots)
{
var grid = root.AddComponent<GridLayoutGroup>();
grid.cellSize = preset.CellSize;
}
return root;
}

private GameObject CreateCanvasInventory(string nameInventory)
{
var canvasRoot = InventoryManagerCreator.GetCanvasInventoryManager();
var canvasInventory = new GameObject(GetNameCanvasInventory(nameInventory), typeof(Canvas), typeof(GraphicRaycaster));
canvasInventory.transform.SetParent(canvasRoot.transform);
canvasInventory.transform.localPosition = Vector3.zero;
canvasInventory.transform.localScale = new Vector3(1, 1, 1);
return canvasInventory;
}

private static string GetNameCanvasInventory(string nameInventory) => nameInventory+"Canvas";
}
}
11 changes: 11 additions & 0 deletions Editor/InventoryCreator.cs.meta

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

116 changes: 116 additions & 0 deletions Editor/InventoryCreatorWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using System;
using JetBrains.Annotations;
using UnInventory.Core.Manager;
using UnInventory.Core.MVC.Controller;
using UnInventory.Core.MVC.Model.Data;
using UnInventory.Core.MVC.View.Components.Slot;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace UnInventory.Editor
{
public class InventoryCreatorWindow : EditorWindow
{
[MenuItem("GameObject/UnInventory/Inventory Creator")]
[UsedImplicitly]
private static void Init()
{
var window = (InventoryCreatorWindow)GetWindow(typeof(InventoryCreatorWindow), true, "Inventory Creator");
window.InitInstance();
window.Show();
}

// Inventory
private readonly InventoryCreator _inventoryCreator = new InventoryCreator();
private readonly PresetInventory _presetInventory = new PresetInventory();

// gui
private readonly PopupSelectionType<ISlotRootComponent> _popupSelectionTypeSlotDataComponent
= new PopupSelectionType<ISlotRootComponent>("SlotDataComponent: ");

private readonly PopupSelectionType<SlotInputComponent> _popupSelectionTypeSlotInputComponent
= new PopupSelectionType<SlotInputComponent>("SlotInputComponent: ", true);

private bool _selectionComponentsGroup = true;

public void InitInstance()
{
_presetInventory.SlotPrefab = InventoryManager.Get().BindPrefabs.SlotPrefabStandard;
}

[UsedImplicitly]
private void OnGUI()
{
InventorySectionOnGui();
EditorGUILayout.Separator();

SlotSectionOnGui();
EditorGUILayout.Separator();

if (GUILayout.Button("Create Inventory "))
{
_presetInventory.TypeSlotRootComponent = _popupSelectionTypeSlotDataComponent.Selected;
_presetInventory.TypeSlotInputComponent = _popupSelectionTypeSlotInputComponent.Selected;
var canvasInventory = _inventoryCreator.CreateInventory(_presetInventory);
Selection.activeGameObject = canvasInventory;
EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
}
}

private void InventorySectionOnGui()
{
GUILayout.Label("Inventory: ", EditorStyles.boldLabel);
EditorGUILayout.BeginVertical();
_presetInventory.NameInventory = EditorGUILayout.TextField("Name: ", _presetInventory.NameInventory);
_presetInventory.TypeInventory = (DataInventory.TypeInventoryEnum)EditorGUILayout.EnumPopup("Type: ", _presetInventory.TypeInventory);

var inventoryTypeDescription = GetDescriptionTypeInventory(_presetInventory.TypeInventory);
GUILayout.TextArea(inventoryTypeDescription, GUI.skin.box);

_presetInventory.CellSize = EditorGUILayout.Vector2IntField("Cell dimensions: ", _presetInventory.CellSize);

_presetInventory.NumberColumns = EditorGUILayout.IntField("Columns", _presetInventory.NumberColumns);
_presetInventory.NumberRows = EditorGUILayout.IntField("Rows", _presetInventory.NumberRows);

EditorGUILayout.EndVertical();
}

private void SlotSectionOnGui()
{
GUILayout.Label("Slot: ", EditorStyles.boldLabel);
_presetInventory.SlotPrefab = (GameObject)EditorGUILayout.ObjectField("Slot prefab", _presetInventory.SlotPrefab, typeof(GameObject), false);

_selectionComponentsGroup = EditorGUILayout.BeginFoldoutHeaderGroup(_selectionComponentsGroup, "Add components: ");

// SlotData (Required)
if (_selectionComponentsGroup)
{
_popupSelectionTypeSlotDataComponent.OnGuiPopup();
_popupSelectionTypeSlotInputComponent.OnGuiPopup();
}

EditorGUILayout.EndFoldoutHeaderGroup();
}

private string GetDescriptionTypeInventory(DataInventory.TypeInventoryEnum typeInventory)
{
switch (typeInventory)
{
case DataInventory.TypeInventoryEnum.FreeSlots:
return
"Slots are not interconnected, you can freely move and resize them. The behavior of multislot entities is similar to Grid.";
case DataInventory.TypeInventoryEnum.Grid:
return
"Slots are connected in one grid. Multislot entities occupy one slot (migrated from another inventory will be placed in one slot)";
case DataInventory.TypeInventoryEnum.GridSupportMultislotEntity:
return
"Slots are connected in one grid. Multislot entities occupy several slots.";
default:
throw new ArgumentOutOfRangeException(nameof(typeInventory), typeInventory, null);
}
}

}
}
Loading

0 comments on commit 82f9f03

Please sign in to comment.