Added many other

This commit is contained in:
2026-08-06 18:56:32 +03:00
parent 9f2fd08ee5
commit d9d7ee49d2
2144 changed files with 1115424 additions and 1284 deletions
@@ -0,0 +1,147 @@
using Unity.Netcode;
using Unity.Netcode.Components;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;
public static class HandItemPrototypeSetup
{
private const string PlayerPrefabPath =
"Assets/CONTENT/Friendslop/Prefabs/NetworkPlayer.prefab";
private const string ItemPrefabFolder =
"Assets/CONTENT/Game/Prefabs/Items";
private const string ItemPrefabPath =
ItemPrefabFolder + "/TestCubeHandItem.prefab";
private const string FactoryScenePath = "Assets/CONTENT/Scenes/Factory.unity";
[MenuItem("Tools/FORT-BO/Setup Hand Item Prototype")]
public static void Setup()
{
if (EditorApplication.isPlayingOrWillChangePlaymode)
return;
EnsurePlayerHandSocket();
GameObject itemPrefab = EnsureTestItemPrefab();
EnsureFactoryInstance(itemPrefab);
AssetDatabase.SaveAssets();
}
private static void EnsurePlayerHandSocket()
{
GameObject root = PrefabUtility.LoadPrefabContents(PlayerPrefabPath);
try
{
PlayerHandController hand = root.GetComponent<PlayerHandController>();
if (hand == null)
hand = root.AddComponent<PlayerHandController>();
Transform socket = root.transform.Find("HandItemSocket");
if (socket == null)
{
var socketObject = new GameObject("HandItemSocket");
socket = socketObject.transform;
socket.SetParent(root.transform, false);
socket.localPosition = new Vector3(0.38f, 1.35f, 0.65f);
}
var serializedHand = new SerializedObject(hand);
serializedHand.FindProperty("itemSocket").objectReferenceValue = socket;
serializedHand.ApplyModifiedPropertiesWithoutUndo();
PrefabUtility.SaveAsPrefabAsset(root, PlayerPrefabPath);
}
finally
{
PrefabUtility.UnloadPrefabContents(root);
}
}
private static GameObject EnsureTestItemPrefab()
{
EnsureFolder("Assets/CONTENT/Game/Prefabs");
EnsureFolder(ItemPrefabFolder);
GameObject existing = AssetDatabase.LoadAssetAtPath<GameObject>(ItemPrefabPath);
if (existing != null)
return existing;
var root = new GameObject("TestCubeHandItem");
try
{
root.AddComponent<NetworkObject>();
root.AddComponent<NetworkTransform>();
Rigidbody body = root.AddComponent<Rigidbody>();
body.mass = 0.5f;
body.interpolation = RigidbodyInterpolation.Interpolate;
BoxCollider rootCollider = root.AddComponent<BoxCollider>();
rootCollider.size = Vector3.one * 0.35f;
NetworkTestCubeItem item = root.AddComponent<NetworkTestCubeItem>();
var serializedItem = new SerializedObject(item);
serializedItem.FindProperty("interactionLabel").stringValue = "Test Cube";
GameObject visual = GameObject.CreatePrimitive(PrimitiveType.Cube);
visual.name = "Visual";
Object.DestroyImmediate(visual.GetComponent<BoxCollider>());
visual.transform.SetParent(root.transform, false);
visual.transform.localScale = Vector3.one * 0.35f;
serializedItem.FindProperty("visual").objectReferenceValue = visual.transform;
serializedItem.ApplyModifiedPropertiesWithoutUndo();
return PrefabUtility.SaveAsPrefabAsset(root, ItemPrefabPath);
}
finally
{
Object.DestroyImmediate(root);
}
}
private static void EnsureFactoryInstance(GameObject itemPrefab)
{
if (itemPrefab == null)
return;
Scene scene = SceneManager.GetSceneByPath(FactoryScenePath);
bool openedBySetup = !scene.IsValid() || !scene.isLoaded;
if (openedBySetup)
scene = EditorSceneManager.OpenScene(FactoryScenePath, OpenSceneMode.Additive);
foreach (GameObject root in scene.GetRootGameObjects())
{
if (root.name == "TestCubeHandItem")
{
if (scene.isDirty)
EditorSceneManager.SaveScene(scene);
if (openedBySetup)
EditorSceneManager.CloseScene(scene, true);
return;
}
}
GameObject instance = (GameObject)PrefabUtility.InstantiatePrefab(itemPrefab, scene);
instance.name = "TestCubeHandItem";
instance.transform.position = new Vector3(2f, 1f, 2f);
EditorSceneManager.MarkSceneDirty(scene);
EditorSceneManager.SaveScene(scene);
if (openedBySetup)
EditorSceneManager.CloseScene(scene, true);
}
private static void EnsureFolder(string folderPath)
{
if (AssetDatabase.IsValidFolder(folderPath))
return;
int separator = folderPath.LastIndexOf('/');
string parent = folderPath[..separator];
string folderName = folderPath[(separator + 1)..];
EnsureFolder(parent);
AssetDatabase.CreateFolder(parent, folderName);
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d5e5a6d20559c47458e11f23d345823f