Initial commit
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19552a1e2e8fe244c99238f38355f7ae
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,142 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
public class BlockDataCreatorEditor : EditorWindow
|
||||
{
|
||||
private GameObject prefab;
|
||||
private string saveFolder = "Assets/Resources/BlocksData/Final";
|
||||
|
||||
[MenuItem("Tools/Block Data Creator")]
|
||||
public static void ShowWindow() =>
|
||||
GetWindow<BlockDataCreatorEditor>("Block Data Creator");
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
GUILayout.Label("Block Data Creator", EditorStyles.boldLabel);
|
||||
EditorGUILayout.Space();
|
||||
|
||||
prefab = (GameObject)EditorGUILayout.ObjectField("Block Prefab", prefab, typeof(GameObject), false);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
GUILayout.Label("Save Paths", EditorStyles.boldLabel);
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
saveFolder = EditorGUILayout.TextField("BlockData Folder", saveFolder);
|
||||
if (GUILayout.Button("Browse", GUILayout.Width(60)))
|
||||
saveFolder = BrowseFolder(saveFolder);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
GUI.enabled = prefab != null;
|
||||
if (GUILayout.Button("Create BlockData"))
|
||||
CreateBlockData();
|
||||
GUI.enabled = true;
|
||||
|
||||
if (prefab == null)
|
||||
EditorGUILayout.HelpBox("Assign a prefab to get started.", MessageType.Info);
|
||||
}
|
||||
|
||||
public void CreateBlockData()
|
||||
{
|
||||
EnsureFolderExists(saveFolder);
|
||||
|
||||
// ── 1. Create BlockData ───────────────────────────────────────────────
|
||||
BlockData blockData = ScriptableObject.CreateInstance<BlockData>();
|
||||
blockData.blockName = prefab.name;
|
||||
blockData.blockPrefab = prefab;
|
||||
|
||||
string assetPath = AssetDatabase.GenerateUniqueAssetPath(
|
||||
$"{saveFolder}/{prefab.name}_BlockData.asset");
|
||||
AssetDatabase.CreateAsset(blockData, assetPath);
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
// ── 2. Assign BlockData back to the Block component on the prefab ─────
|
||||
Block block = prefab.GetComponent<Block>();
|
||||
if (block != null)
|
||||
{
|
||||
SerializedObject so = new SerializedObject(block);
|
||||
SerializedProperty prop = so.FindProperty("BlockData");
|
||||
if (prop != null)
|
||||
{
|
||||
prop.objectReferenceValue = blockData;
|
||||
so.ApplyModifiedProperties();
|
||||
PrefabUtility.SavePrefabAsset(prefab);
|
||||
Debug.Log($"[BlockDataCreator] BlockData assigned to {prefab.name}.");
|
||||
}
|
||||
else
|
||||
Debug.LogWarning("[BlockDataCreator] 'BlockData' field not found on Block component.");
|
||||
}
|
||||
else
|
||||
Debug.LogWarning($"[BlockDataCreator] No Block component on {prefab.name}.");
|
||||
|
||||
// ── 3. Ping the new asset ─────────────────────────────────────────────
|
||||
EditorUtility.FocusProjectWindow();
|
||||
Selection.activeObject = blockData;
|
||||
EditorGUIUtility.PingObject(blockData);
|
||||
Debug.Log($"[BlockDataCreator] Created: {assetPath}");
|
||||
}
|
||||
|
||||
public BlockData CreateBlockData(GameObject Prefab)
|
||||
{
|
||||
EnsureFolderExists(saveFolder);
|
||||
|
||||
// ── 1. Create BlockData ───────────────────────────────────────────────
|
||||
BlockData blockData = ScriptableObject.CreateInstance<BlockData>();
|
||||
blockData.blockName = Prefab.name;
|
||||
blockData.blockPrefab = Prefab;
|
||||
|
||||
string assetPath = AssetDatabase.GenerateUniqueAssetPath(
|
||||
$"{saveFolder}/{Prefab.name}_BlockData.asset");
|
||||
AssetDatabase.CreateAsset(blockData, assetPath);
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
// ── 2. Assign BlockData back to the Block component on the prefab ─────
|
||||
Block block = Prefab.GetComponent<Block>();
|
||||
if (block != null)
|
||||
{
|
||||
SerializedObject so = new SerializedObject(block);
|
||||
SerializedProperty prop = so.FindProperty("BlockData");
|
||||
if (prop != null)
|
||||
{
|
||||
prop.objectReferenceValue = blockData;
|
||||
so.ApplyModifiedProperties();
|
||||
PrefabUtility.SavePrefabAsset(Prefab);
|
||||
Debug.Log($"[BlockDataCreator] BlockData assigned to {Prefab.name}.");
|
||||
}
|
||||
else
|
||||
Debug.LogWarning("[BlockDataCreator] 'BlockData' field not found on Block component.");
|
||||
}
|
||||
else
|
||||
Debug.LogWarning($"[BlockDataCreator] No Block component on {Prefab.name}.");
|
||||
|
||||
// ── 3. Ping the new asset ─────────────────────────────────────────────
|
||||
EditorUtility.FocusProjectWindow();
|
||||
Selection.activeObject = blockData;
|
||||
EditorGUIUtility.PingObject(blockData);
|
||||
Debug.Log($"[BlockDataCreator] Created: {assetPath}");
|
||||
|
||||
// ── 4. Return the Block Data ──────────────────────────────────────────
|
||||
return blockData;
|
||||
}
|
||||
|
||||
private string BrowseFolder(string current)
|
||||
{
|
||||
string abs = EditorUtility.OpenFolderPanel("Select Folder", current, "");
|
||||
if (string.IsNullOrEmpty(abs)) return current;
|
||||
if (abs.StartsWith(Application.dataPath))
|
||||
return "Assets" + abs.Substring(Application.dataPath.Length);
|
||||
Debug.LogWarning("[BlockDataCreator] Folder must be inside Assets.");
|
||||
return current;
|
||||
}
|
||||
|
||||
private void EnsureFolderExists(string path)
|
||||
{
|
||||
if (AssetDatabase.IsValidFolder(path)) return;
|
||||
string parent = Path.GetDirectoryName(path).Replace("\\", "/");
|
||||
EnsureFolderExists(parent);
|
||||
AssetDatabase.CreateFolder(parent, Path.GetFileName(path));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67e48e5b7a08bb3479888fe7c8bdc644
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,55 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
|
||||
public class BlockDataIconLinker : AssetPostprocessor
|
||||
{
|
||||
// Fires after any assets are imported
|
||||
static void OnPostprocessAllAssets(
|
||||
string[] importedAssets,
|
||||
string[] deletedAssets,
|
||||
string[] movedAssets,
|
||||
string[] movedFromAssetPaths)
|
||||
{
|
||||
foreach (string assetPath in importedAssets)
|
||||
{
|
||||
// Only care about Texture2D PNGs
|
||||
if (!assetPath.EndsWith(".png", System.StringComparison.OrdinalIgnoreCase))
|
||||
continue;
|
||||
|
||||
Texture2D texture = AssetDatabase.LoadAssetAtPath<Texture2D>(assetPath);
|
||||
if (texture == null) continue;
|
||||
|
||||
// Try to find a matching BlockData for this texture
|
||||
TryLinkToBlockData(texture, assetPath);
|
||||
}
|
||||
}
|
||||
|
||||
private static void TryLinkToBlockData(Texture2D texture, string texturePath)
|
||||
{
|
||||
string textureName = Path.GetFileNameWithoutExtension(texturePath);
|
||||
|
||||
// Find all BlockData assets in the project
|
||||
string[] guids = AssetDatabase.FindAssets("t:BlockData");
|
||||
foreach (string guid in guids)
|
||||
{
|
||||
string blockDataPath = AssetDatabase.GUIDToAssetPath(guid);
|
||||
BlockData blockData = AssetDatabase.LoadAssetAtPath<BlockData>(blockDataPath);
|
||||
|
||||
if (blockData == null || blockData.blockPrefab == null) continue;
|
||||
|
||||
// Match by checking if the texture name contains the prefab name
|
||||
// Handles prefixes/suffixes like "Icon_zPin", "Icon_zPin_v2", etc.
|
||||
if (!textureName.Contains(blockData.blockPrefab.name)) continue;
|
||||
|
||||
// Skip if already assigned to avoid unnecessary reimports
|
||||
if (blockData.icon == texture || blockData.icon != null) continue;
|
||||
|
||||
blockData.icon = texture;
|
||||
EditorUtility.SetDirty(blockData);
|
||||
AssetDatabase.SaveAssetIfDirty(blockData);
|
||||
|
||||
Debug.Log($"[BlockDataIconLinker] Linked '{texturePath}' → '{blockDataPath}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e135bd5a5f097741b1772c8f5fd8b9e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,51 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public enum PlaneAxis
|
||||
{
|
||||
XZ = 0,
|
||||
XY = 1,
|
||||
YZ = 2
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class PlaneSelection
|
||||
{
|
||||
public PlaneAxis planeAxis;
|
||||
public GameObject WorldGrid;
|
||||
}
|
||||
|
||||
public class PlaneSelector : MonoBehaviour
|
||||
{
|
||||
public TMP_Dropdown planeAxisDropDown;
|
||||
|
||||
public PlaneSelection[] PlaneAxis;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
planeAxisDropDown.onValueChanged.AddListener(OnPlaneAxisChanged);
|
||||
UpdatePlaneVisibility();
|
||||
}
|
||||
|
||||
private void OnPlaneAxisChanged(int index)
|
||||
{
|
||||
UpdatePlaneVisibility();
|
||||
}
|
||||
|
||||
private void UpdatePlaneVisibility()
|
||||
{
|
||||
foreach (var plane in PlaneAxis)
|
||||
{
|
||||
if (plane.planeAxis == (PlaneAxis)planeAxisDropDown.value)
|
||||
{
|
||||
plane.WorldGrid.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
plane.WorldGrid.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 70c9ce54d0b332b4abe8b68218428d08
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "Scripts.Editor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f",
|
||||
"GUID:0f8d877125e73cc40a31b031c2e5fe60"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33db7b02ee883714bad5e572b698bdb7
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cfe9faaa56b81844a437d9850a85c8f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 7a786d380a7823b4d9a0511ba886548f, type: 3}
|
||||
m_Name: Connector Prefab Settings
|
||||
m_EditorClassIdentifier:
|
||||
MainComponents:
|
||||
GrabInteractable: {fileID: 11500000, guid: d9a466110b129074db957157c7ec5b2f, type: 3}
|
||||
MechanicalBlock: {fileID: 11500000, guid: c4a1be166f8c7184ab860f9a010f5764, type: 3}
|
||||
AttachableBlock: {fileID: 11500000, guid: 6f653344f2c17b64fb6a4073754cb555, type: 3}
|
||||
SocketContainer: {fileID: 11500000, guid: aa5c0234b0ff887468bde7ca9dbbf542, type: 3}
|
||||
PlacementValidator: {fileID: 11500000, guid: 8245c6e3d94e025439b7ccced75276db,
|
||||
type: 3}
|
||||
SocketPoint: {fileID: 11500000, guid: 7d04d85508b5c414d82419db222f9936, type: 3}
|
||||
ContainerInit: {fileID: 11500000, guid: b628454e932ec7e47be99c98c50c21d2, type: 3}
|
||||
BlockSettings:
|
||||
grabInteractable:
|
||||
Test:
|
||||
mechanicalBlock:
|
||||
Test:
|
||||
attachableBlock:
|
||||
Type: 1
|
||||
socketContainer:
|
||||
Test:
|
||||
validator:
|
||||
CollisionLayerMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 64
|
||||
socketPoint:
|
||||
SocketRadius: 0.3
|
||||
MiscellaneousSettings:
|
||||
BlockLayer:
|
||||
serializedVersion: 2
|
||||
m_Bits: 64
|
||||
categoryData: {fileID: 11400000, guid: 5a2a0a71bcd471d468b7bcacbbc8176a, type: 2}
|
||||
SavePath: Assets/_Project/Prefabs/Final Prefabs/Connectors
|
||||
Name: Connector
|
||||
IteratedNumbering: 1
|
||||
Suffix: _v
|
||||
OverwriteExisting: 0
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38c572c2bd6d37d47b52e39734d17138
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 7a786d380a7823b4d9a0511ba886548f, type: 3}
|
||||
m_Name: Joint Prefab Settings
|
||||
m_EditorClassIdentifier:
|
||||
MainComponents:
|
||||
GrabInteractable: {fileID: 11500000, guid: d9a466110b129074db957157c7ec5b2f, type: 3}
|
||||
MechanicalBlock: {fileID: 11500000, guid: c4a1be166f8c7184ab860f9a010f5764, type: 3}
|
||||
AttachableBlock: {fileID: 11500000, guid: 6f653344f2c17b64fb6a4073754cb555, type: 3}
|
||||
SocketContainer: {fileID: 11500000, guid: aa5c0234b0ff887468bde7ca9dbbf542, type: 3}
|
||||
PlacementValidator: {fileID: 11500000, guid: 8245c6e3d94e025439b7ccced75276db,
|
||||
type: 3}
|
||||
SocketPoint: {fileID: 11500000, guid: 7d04d85508b5c414d82419db222f9936, type: 3}
|
||||
ContainerInit: {fileID: 11500000, guid: b628454e932ec7e47be99c98c50c21d2, type: 3}
|
||||
BlockSettings:
|
||||
grabInteractable:
|
||||
Test:
|
||||
mechanicalBlock:
|
||||
Test:
|
||||
attachableBlock:
|
||||
Type: 0
|
||||
socketContainer:
|
||||
Test:
|
||||
validator:
|
||||
CollisionLayerMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 64
|
||||
socketPoint:
|
||||
SocketRadius: 0
|
||||
MiscellaneousSettings:
|
||||
BlockLayer:
|
||||
serializedVersion: 2
|
||||
m_Bits: 64
|
||||
categoryData: {fileID: 11400000, guid: ffda9eca5fbd46e4badbaf708cf51b66, type: 2}
|
||||
SavePath: Assets/_Project/Prefabs/Final Prefabs/Joints
|
||||
Name: Joint
|
||||
IteratedNumbering: 1
|
||||
Suffix: _v
|
||||
OverwriteExisting: 0
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2de43eefeedfd8a4eb9ba0e9d8b1ef93
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 7a786d380a7823b4d9a0511ba886548f, type: 3}
|
||||
m_Name: Link Prefab Settings
|
||||
m_EditorClassIdentifier:
|
||||
MainComponents:
|
||||
GrabInteractable: {fileID: 11500000, guid: d9a466110b129074db957157c7ec5b2f, type: 3}
|
||||
MechanicalBlock: {fileID: 11500000, guid: c4a1be166f8c7184ab860f9a010f5764, type: 3}
|
||||
AttachableBlock: {fileID: 11500000, guid: 6f653344f2c17b64fb6a4073754cb555, type: 3}
|
||||
SocketContainer: {fileID: 11500000, guid: aa5c0234b0ff887468bde7ca9dbbf542, type: 3}
|
||||
PlacementValidator: {fileID: 11500000, guid: 8245c6e3d94e025439b7ccced75276db,
|
||||
type: 3}
|
||||
SocketPoint: {fileID: 11500000, guid: 7d04d85508b5c414d82419db222f9936, type: 3}
|
||||
ContainerInit: {fileID: 11500000, guid: b628454e932ec7e47be99c98c50c21d2, type: 3}
|
||||
BlockSettings:
|
||||
grabInteractable:
|
||||
Test:
|
||||
mechanicalBlock:
|
||||
Test:
|
||||
attachableBlock:
|
||||
Type: 1
|
||||
socketContainer:
|
||||
Test:
|
||||
validator:
|
||||
CollisionLayerMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 64
|
||||
socketPoint:
|
||||
SocketRadius: 0.3
|
||||
MiscellaneousSettings:
|
||||
BlockLayer:
|
||||
serializedVersion: 2
|
||||
m_Bits: 64
|
||||
categoryData: {fileID: 11400000, guid: 86480ee67e6364b4fa1f9a1a496e5b4c, type: 2}
|
||||
SavePath: Assets/_Project/Prefabs/Final Prefabs/Links
|
||||
Name: Link
|
||||
IteratedNumbering: 1
|
||||
Suffix: _v
|
||||
OverwriteExisting: 0
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94270647119ef4240866cec766f99b11
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,112 @@
|
||||
using NaughtyAttributes;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public class mainComponent
|
||||
{
|
||||
[Header("Input the scripts for the components as intstructed by their name")]
|
||||
[Tooltip("Input the Grab Interactable script here")] public MonoScript GrabInteractable;
|
||||
[Tooltip("Input the Mechanical Block script here")] public MonoScript MechanicalBlock;
|
||||
[Tooltip("Input the Attachable Block script here")] public MonoScript AttachableBlock;
|
||||
[Tooltip("Input the Socket Container script here")] public MonoScript SocketContainer;
|
||||
[Tooltip("Input the Placement Validator script here")] public MonoScript PlacementValidator;
|
||||
[Tooltip("Input the Socket Point script here")] public MonoScript SocketPoint;
|
||||
[Tooltip("Input the Block Container Init script here")] public MonoScript ContainerInit;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class blockSettings
|
||||
{
|
||||
[System.Serializable]
|
||||
public class GrabInteractableSettings
|
||||
{
|
||||
[Header("WIP")]
|
||||
public string Test;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class MechanicalBlockSettings
|
||||
{
|
||||
[Header("WIP")]
|
||||
public string Test;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class AttachableBlockSettings
|
||||
{
|
||||
public BlockType Type;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class SocketContainerSettings
|
||||
{
|
||||
[Header("WIP")]
|
||||
public string Test;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class ValidatorSettings
|
||||
{
|
||||
public LayerMask CollisionLayerMask;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class SocketPointSettings
|
||||
{
|
||||
public float SocketRadius;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class MiscSettings
|
||||
{
|
||||
public LayerMask BlockLayer;
|
||||
}
|
||||
|
||||
public GrabInteractableSettings grabInteractable;
|
||||
public MechanicalBlockSettings mechanicalBlock;
|
||||
public AttachableBlockSettings attachableBlock;
|
||||
public SocketContainerSettings socketContainer;
|
||||
public ValidatorSettings validator;
|
||||
public SocketPointSettings socketPoint;
|
||||
public MiscSettings MiscellaneousSettings;
|
||||
}
|
||||
|
||||
[CreateAssetMenu(fileName = "BlockPrefabSettings", menuName = "Youssef Tools/Prefab Creator Settings")]
|
||||
public class PrefabCreatorSettings : ScriptableObject
|
||||
{
|
||||
public mainComponent MainComponents;
|
||||
|
||||
public blockSettings BlockSettings;
|
||||
|
||||
public CategoryData categoryData;
|
||||
|
||||
[Header("-- Save Settings --")]
|
||||
[ContextMenuItem("Browse Folder", "Browse")]
|
||||
public string SavePath = "Assets/_Project/Prefabs";
|
||||
public string Name = "Block";
|
||||
public bool IteratedNumbering = false;
|
||||
public string Suffix = " vX";
|
||||
|
||||
[Header("-- Behavior [Leave if unsure] --")]
|
||||
public bool OverwriteExisting = false;
|
||||
|
||||
private void Browse()
|
||||
{
|
||||
string path = EditorUtility.OpenFolderPanel("Select Save Folder", "Assets", "");
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
if (path.StartsWith(Application.dataPath))
|
||||
{
|
||||
SavePath = "Assets" + path.Substring(Application.dataPath.Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("Please select a folder inside the Assets directory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a786d380a7823b4d9a0511ba886548f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,242 @@
|
||||
using Codice.CM.SEIDInfo;
|
||||
using IconsCreationTool.Editor.Core;
|
||||
using JetBrains.Annotations;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Unity.EditorCoroutines.Editor;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using static UnityEditor.Experimental.GraphView.GraphView;
|
||||
using static UnityEngine.GraphicsBuffer;
|
||||
|
||||
public class PrefabCreatorTool
|
||||
{
|
||||
static BlockDataCreatorEditor BDCE = new BlockDataCreatorEditor();
|
||||
static IconsCreator IC = new IconsCreator();
|
||||
|
||||
[MenuItem("Youssef Tools/Create Prefab", false, 0)]
|
||||
static void CreatePrefab()
|
||||
{
|
||||
string SavedPath = EditorPrefs.GetString("YoussefTool_SettingsPath", "");
|
||||
if (string.IsNullOrEmpty(SavedPath))
|
||||
{
|
||||
Debug.Log("Couldn't find settings script. Please add it via the setup window");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Found settings scriptable object");
|
||||
}
|
||||
PrefabCreatorSettings Settings = AssetDatabase.LoadAssetAtPath<PrefabCreatorSettings>(SavedPath);
|
||||
if (Settings == null)
|
||||
{
|
||||
Debug.LogError("The assigned settings file was deleted or moved. Please reassign in the Settings Manager.");
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject[] selectedObjects = Selection.gameObjects;
|
||||
int count = selectedObjects.Length;
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
Debug.LogError("Please select a GameObject in the hierarchy first");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
float progress = (float)i / count;
|
||||
EditorUtility.DisplayProgressBar("Creating Prefabs", $"Processing {selectedObjects[i].name}...", progress);
|
||||
|
||||
GameObject instObj = Object.Instantiate(selectedObjects[i]);
|
||||
Undo.RegisterCreatedObjectUndo(instObj, "Create Prefab");
|
||||
|
||||
CreateStart(instObj, Settings);
|
||||
}
|
||||
|
||||
EditorUtility.ClearProgressBar();
|
||||
}
|
||||
|
||||
|
||||
// Logic (ngl Youssef cooked here)
|
||||
public static void CreateStart(GameObject Target, PrefabCreatorSettings Settings)
|
||||
{
|
||||
|
||||
if (Target.transform.childCount == 0)
|
||||
{
|
||||
Debug.LogError("Please setup the target object by supplying it with the spheres as children");
|
||||
return;
|
||||
}
|
||||
|
||||
// Main mesh part
|
||||
var MC = Settings.MainComponents;
|
||||
|
||||
if (MC.GrabInteractable != null)
|
||||
{
|
||||
var scriptType = MC.GrabInteractable.GetClass();
|
||||
if (scriptType == null || !typeof(GrabInteractable).IsAssignableFrom(scriptType))
|
||||
Debug.LogError("The Grab Interactable script is incorrect or does not inherit from GrabInteractable");
|
||||
else
|
||||
{
|
||||
var gInteract = Target.AddComponent(scriptType);
|
||||
}
|
||||
}
|
||||
|
||||
if (MC.MechanicalBlock != null)
|
||||
{
|
||||
var scriptType = MC.MechanicalBlock.GetClass();
|
||||
if (scriptType == null || !typeof(Block).IsAssignableFrom(scriptType))
|
||||
Debug.LogError("The Block script is incorrect!");
|
||||
else
|
||||
{
|
||||
var mBlock = Target.AddComponent(scriptType);
|
||||
}
|
||||
}
|
||||
|
||||
if (MC.AttachableBlock != null)
|
||||
{
|
||||
var scriptType = MC.AttachableBlock.GetClass();
|
||||
if (scriptType == null || !typeof(AttachableBlock).IsAssignableFrom(scriptType))
|
||||
Debug.LogError("The Attachable Block script is incorrect!");
|
||||
else
|
||||
{
|
||||
Target.AddComponent(scriptType);
|
||||
BlockType layerM = Settings.BlockSettings.attachableBlock.Type;
|
||||
Target.GetComponent<AttachableBlock>().SetBlockType(layerM);
|
||||
}
|
||||
}
|
||||
|
||||
if (MC.SocketContainer != null)
|
||||
{
|
||||
var scriptType = MC.SocketContainer.GetClass();
|
||||
if (scriptType == null || !typeof(SocketContainer).IsAssignableFrom(scriptType))
|
||||
Debug.LogError("The Socket Container script is incorrect!");
|
||||
else
|
||||
{
|
||||
var sContain = Target.AddComponent(scriptType);
|
||||
}
|
||||
}
|
||||
|
||||
if (MC.PlacementValidator != null)
|
||||
{
|
||||
var scriptType = MC.PlacementValidator.GetClass();
|
||||
if (scriptType == null || !typeof(IValidator).IsAssignableFrom(scriptType))
|
||||
Debug.LogError("The Validator script is incorrect!");
|
||||
else
|
||||
{
|
||||
var pValidate = Target.AddComponent(scriptType);
|
||||
LayerMask Coll = Settings.BlockSettings.validator.CollisionLayerMask;
|
||||
Target.GetComponent<IValidator>().SetLayerMask(Coll);
|
||||
}
|
||||
}
|
||||
|
||||
if (MC.ContainerInit != null)
|
||||
{
|
||||
var scriptType = MC.ContainerInit.GetClass();
|
||||
if (scriptType == null || !typeof(BlockContainerInit).IsAssignableFrom(scriptType))
|
||||
Debug.LogError("The Block Container Init script is incorrect");
|
||||
else
|
||||
{
|
||||
var cInit = Target.AddComponent(scriptType);
|
||||
}
|
||||
}
|
||||
|
||||
Rigidbody RB = Target.AddComponent<Rigidbody>();
|
||||
MeshCollider MeshC = Target.AddComponent<MeshCollider>();
|
||||
|
||||
MeshC.convex = false;
|
||||
RB.isKinematic = true;
|
||||
RB.useGravity = false;
|
||||
|
||||
Target.transform.localEulerAngles = new Vector3(0, 0, 0);
|
||||
|
||||
var Tlayer = Settings.BlockSettings.MiscellaneousSettings.BlockLayer;
|
||||
|
||||
// Children part
|
||||
Transform[] Children = Target.GetComponentsInChildren<Transform>().Where(x => x != Target.transform).ToArray();
|
||||
|
||||
if (Children.Length < 0)
|
||||
Debug.Log($"No children exist for object {Target.name}, please make sure the object has children or add sockets manually");
|
||||
|
||||
else
|
||||
{
|
||||
foreach (Transform t in Children)
|
||||
{
|
||||
Object.DestroyImmediate(t.GetComponent<MeshRenderer>());
|
||||
if (MC.SocketPoint != null)
|
||||
{
|
||||
var scriptType = MC.SocketPoint.GetClass();
|
||||
if (scriptType == null || !typeof(SocketPoint).IsAssignableFrom(scriptType))
|
||||
Debug.LogError("The Socket Point script is incorrect!");
|
||||
else
|
||||
{
|
||||
t.gameObject.AddComponent(scriptType);
|
||||
var sPoint = t.gameObject.GetComponent<SocketPoint>();
|
||||
sPoint.SetSocketRadius(Settings.BlockSettings.socketPoint.SocketRadius);
|
||||
}
|
||||
}
|
||||
Rigidbody rb = t.AddComponent<Rigidbody>();
|
||||
CapsuleCollider sc = t.AddComponent<CapsuleCollider>();
|
||||
|
||||
rb.isKinematic = true;
|
||||
rb.useGravity = false;
|
||||
sc.isTrigger = true;
|
||||
t.localPosition = new Vector3(t.localPosition.x, t.localPosition.y / 2, t.localPosition.z);
|
||||
t.localScale = new Vector3(0.006f, 0.006f, 0.006f);
|
||||
}
|
||||
}
|
||||
|
||||
if (!Directory.Exists(Settings.SavePath))
|
||||
{
|
||||
Directory.CreateDirectory(Settings.SavePath);
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
string fileName = Settings.Name + Settings.Suffix;
|
||||
string localPath = $"{Settings.SavePath}/{fileName}.prefab";
|
||||
|
||||
if (Settings.IteratedNumbering || !Settings.OverwriteExisting)
|
||||
{
|
||||
localPath = AssetDatabase.GenerateUniqueAssetPath(localPath);
|
||||
}
|
||||
|
||||
bool success;
|
||||
GameObject prefabAsset = PrefabUtility.SaveAsPrefabAsset(Target, localPath, out success);
|
||||
|
||||
if (success)
|
||||
{
|
||||
Debug.Log($"Success! Prefab created at: {localPath}");
|
||||
EditorGUIUtility.PingObject(prefabAsset);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Prefab failed to save. Check the Save Path in Settings.");
|
||||
}
|
||||
var BD = BDCE.CreateBlockData(prefabAsset);
|
||||
prefabAsset.GetComponent<MechanicalBlock>().SetBlockData(BD);
|
||||
if (Settings.categoryData)
|
||||
{
|
||||
var Category = Settings.categoryData;
|
||||
BD.associatedCategory = Category;
|
||||
Category.blocks.Add(BD);
|
||||
}
|
||||
|
||||
List<Object> list = new List<Object>();
|
||||
list.Add(prefabAsset);
|
||||
|
||||
IconBackgroundData IBD = new IconBackgroundData(IconBackground.None, Color.white, Texture2D.whiteTexture);
|
||||
IconsCreatorData ICD = new IconsCreatorData(1024, 0, null, null, IBD, list, true);
|
||||
IC.SetData(ICD);
|
||||
IC.CreateIcon();
|
||||
|
||||
PrefabUtility.RecordPrefabInstancePropertyModifications(prefabAsset);
|
||||
EditorUtility.SetDirty(prefabAsset);
|
||||
AssetDatabase.SaveAssetIfDirty(prefabAsset);
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
Object.DestroyImmediate(Target);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 147dedb329e334b4e8f14903b5a67d1e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
public class PrefabSettingsWindow : EditorWindow
|
||||
{
|
||||
public PrefabCreatorSettings CurrentSettings;
|
||||
|
||||
[MenuItem("Youssef Tools/Prefab Creator Setup")]
|
||||
public static void ShowWindow() => GetWindow<PrefabSettingsWindow>("Setup Window");
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
string SavedPath = EditorPrefs.GetString("YoussefTool_SettingsPath", "");
|
||||
if (!string.IsNullOrEmpty(SavedPath))
|
||||
{
|
||||
CurrentSettings = AssetDatabase.LoadAssetAtPath<PrefabCreatorSettings>(SavedPath);
|
||||
}
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
GUILayout.Label("Active Tool Settings", EditorStyles.boldLabel);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
CurrentSettings = (PrefabCreatorSettings)EditorGUILayout.ObjectField(
|
||||
"Prefab Creator Settings", CurrentSettings, typeof(PrefabCreatorSettings), false);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
string path = AssetDatabase.GetAssetPath(CurrentSettings);
|
||||
EditorPrefs.SetString("YoussefTool_SettingsPath", path);
|
||||
}
|
||||
|
||||
if (CurrentSettings != null)
|
||||
Editor.CreateEditor(CurrentSettings).OnInspectorGUI();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81bb800f6ea1d69459bb074210dd283a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,61 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
public static class Setup
|
||||
{
|
||||
[MenuItem("Tools/Setup/CreateFolderStructure")]
|
||||
public static void CreateDefaultFolders()
|
||||
{
|
||||
Folders.CreateDefault("_Project", "Animations" , "Art" , "Audio" , "Data", "Prefabs" , "Scenes" , "Scripts");
|
||||
|
||||
Folders.CreateDefault("_Project/Art", "UI" , "Texture" , "Materials" , "Models");
|
||||
|
||||
Folders.CreateDefault("_Project/Scenes", "GameScenes" , "TestLabs");
|
||||
|
||||
Folders.CreateDefault("_Project/Audio", "BackgroundMusic", "SFX");
|
||||
|
||||
Folders.CreateDefault("_Project/Scripts", "Shaders" , "Code");
|
||||
|
||||
Folders.CreateDefault("_Project/Prefabs", "XR Prefabs", "System Prefabs" , "Partical Prefabs");
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
|
||||
[MenuItem("Tools/Setup/ImportAssets")]
|
||||
public static void ImportAssets()
|
||||
{
|
||||
Assets.ImportAsset("DOTween HOTween v2.unitypackage" , "Demigiant/Editor ExtensionsAnimation");
|
||||
Assets.ImportAsset("Colored Hierarchy Headers.unitypackage", "Baedrick/Editor ExtensionsUtilities");
|
||||
Assets.ImportAsset("CGHierarchyIcons.unitypackage", "Franco Rosatto/Editor ExtensionsUtilities");
|
||||
Assets.ImportAsset("Folder.Icons.v0.1.2.unitypackage", "WooshiiDev");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
static class Folders
|
||||
{
|
||||
public static void CreateDefault(string root, params string[] folders)
|
||||
{
|
||||
var fullpath = Path.Combine(Application.dataPath, root);
|
||||
foreach (var folder in folders)
|
||||
{
|
||||
var path = Path.Combine(fullpath , folder);
|
||||
if(!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Assets
|
||||
{
|
||||
public static void ImportAsset(string asset , string subfolder, string folder = "C:/Users/hussi/AppData/Roaming/Unity/Asset Store-5.x")
|
||||
{
|
||||
AssetDatabase.ImportPackage(Path.Combine(folder, subfolder, asset), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aba1aadf96359c3459698607d6d75832
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user