Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
ai.fluctio.fluctio-sim / EditorCore / Menu / CreateMenu.cs
Size: Mime:
using System.Runtime.CompilerServices;
using Fluctio.FluctioSim.Common.Configuration;
using Fluctio.FluctioSim.Core.Components.Base;
using Fluctio.FluctioSim.EditorCore.EditorGeneral;
using Fluctio.FluctioSim.EditorUtils.EditorGeneral;
using UnityEditor;
using UnityEngine;

[assembly: InternalsVisibleTo("Fluctio.FluctioSim.Core.Components")]
namespace Fluctio.FluctioSim.EditorCore.Menu
{
	internal static class CreateMenu
	{
		
		#region Constants
		
		private const string GameObjectPath = "GameObject/" + Config.EmojiName + "/";
		private const string TopMenuPath = Config.EmojiName + "/Create/";
		private const int GameObjectPriority = -9999;
		private const int TopMenuPriority = 0;
		
		#endregion
		
		#region Helper functions

		private static void RemoveObjectsIcons(GameObject gameObject)
		{
			foreach (var descendant in gameObject.GetDescendants(true))
			{
				EditorGUIUtility.SetIconForObject(descendant, null);
			}
		}
	
		private static GameObject InstantiatePrefab(params string[] pathComponents)
		{
			var prefab = EditorUtil.LoadAsset<GameObject>(Config.PrefabsFolderGuid, pathComponents);
			var instance = Object.Instantiate(prefab, Selection.activeTransform);
			instance.name = prefab.name;
			if (!GeneralSettings.AddGameObjectIcons)
			{
				RemoveObjectsIcons(instance);
			}
			Undo.RegisterCreatedObjectUndo(instance, $"Create {instance.name}");
			Selection.activeTransform = instance.transform;

			var editorComponents = instance.GetComponentsInChildren<EditorComponent>();
			foreach (var editorComponent in editorComponents)
			{
				editorComponent.InitializePrefab();
				editorComponent.OnSelfChanged();
			}
			
			return instance;
		}
		
		#endregion

		#region Menu items
		
		#region Primitives
		
		[MenuItem(GameObjectPath + "Primitives/Ball", false, GameObjectPriority + 10)]
		[MenuItem(TopMenuPath + "Primitives/Ball", false, TopMenuPriority + 10)]
		private static void CreateBall() => InstantiatePrefab("Primitives", "Ball", "Ball.prefab");

		[MenuItem(GameObjectPath + "Primitives/Box", false, GameObjectPriority + 15)]
		[MenuItem(TopMenuPath + "Primitives/Box", false, TopMenuPriority + 15)]
		private static void CreateBox() => InstantiatePrefab("Primitives", "Box", "Box.prefab");

		[MenuItem(GameObjectPath + "Primitives/Cylinder", false, GameObjectPriority + 20)]
		[MenuItem(TopMenuPath + "Primitives/Cylinder", false, TopMenuPriority + 20)]
		private static void CreateCylinder() => InstantiatePrefab("Primitives", "Cylinder", "Cylinder.prefab");

		[MenuItem(GameObjectPath + "Primitives/Capsule", false, GameObjectPriority + 25)]
		[MenuItem(TopMenuPath + "Primitives/Capsule", false, TopMenuPriority + 25)]
		private static void CreateCapsule() => InstantiatePrefab("Primitives", "Capsule", "Capsule.prefab");

		[MenuItem(GameObjectPath + "Primitives/Mesh", false, GameObjectPriority + 30)]
		[MenuItem(TopMenuPath + "Primitives/Mesh", false, TopMenuPriority + 30)]
		private static void CreateMesh() => InstantiatePrefab("Primitives", "MeshPrimitive", "Mesh.prefab");
		
		#endregion

		#region Ground

		[MenuItem(GameObjectPath + "Ground/Infinite Flat Floor", false, GameObjectPriority + 15)]
		[MenuItem(TopMenuPath + "Ground/Infinite Flat Floor", false, TopMenuPriority + 15)]
		private static void CreateFlatFloor() => InstantiatePrefab("Primitives", "Floor", "Floor.prefab");

		[MenuItem(GameObjectPath + "Ground/Box Floor", false, GameObjectPriority + 20)]
		[MenuItem(TopMenuPath + "Ground/Box Floor", false, TopMenuPriority + 20)]
		private static void CreateBoxFloor() => InstantiatePrefab("Parts", "BoxFloor", "BoxFloor.prefab");

		[MenuItem(GameObjectPath + "Ground/Perlin Noise", false, GameObjectPriority + 25)]
		[MenuItem(TopMenuPath + "Ground/Perlin Noise", false, TopMenuPriority + 25)]
		private static void CreatePerlinNoiseGround() => InstantiatePrefab("HeightField", "PerlinNoiseGround", "PerlinNoiseGround.prefab");

		[MenuItem(GameObjectPath + "Ground/Terrain Data", false, GameObjectPriority + 30)]
		[MenuItem(TopMenuPath + "Ground/Terrain Data", false, TopMenuPriority + 30)]
		private static void CreateTerrainDataGround() => InstantiatePrefab("HeightField", "TerrainDataGround", "TerrainDataGround.prefab");

		[MenuItem(GameObjectPath + "Ground/Texture Ground", false, GameObjectPriority + 35)]
		[MenuItem(TopMenuPath + "Ground/Texture Ground", false, TopMenuPriority + 35)]
		private static void CreateTextureGround() => InstantiatePrefab("HeightField", "TextureGround", "TextureGround.prefab");

		#endregion

		#region Parts
		
		[MenuItem(GameObjectPath + "Parts/Sliding Cart", false, GameObjectPriority + 20)]
		[MenuItem(TopMenuPath + "Parts/Sliding Cart", false, TopMenuPriority + 20)]
		private static void CreateSlidingCart() => InstantiatePrefab("Parts", "Cart", "Cart.prefab");
		
		[MenuItem(GameObjectPath + "Parts/Lever Arm", false, GameObjectPriority + 25)]
		[MenuItem(TopMenuPath + "Parts/Lever Arm", false, TopMenuPriority + 25)]
		private static void CreateLeverArm() => InstantiatePrefab("Parts", "LeverArm", "LeverArm.prefab");
		
		[MenuItem(GameObjectPath + "Parts/Wheel", false, GameObjectPriority + 30)]
		[MenuItem(TopMenuPath + "Parts/Wheel", false, TopMenuPriority + 30)]
		private static void CreateWheel() => InstantiatePrefab("Parts", "Wheel", "Axle.prefab");
		
		#endregion

		#region Agents
		
		[MenuItem(GameObjectPath + "Agents/Agent Template", false, GameObjectPriority + 25)]
		[MenuItem(TopMenuPath + "Agents/Agent Template", false, TopMenuPriority + 25)]
		private static void CreateAgentTemplate1() => InstantiatePrefab("MLGeneral", "AgentTemplate.prefab");
		
		[MenuItem(GameObjectPath + "Agents/Cart Pole", false, GameObjectPriority + 30)]
		[MenuItem(TopMenuPath + "Agents/Cart Pole", false, TopMenuPriority + 30)]
		private static void CreateCartPole() => InstantiatePrefab("Complex", "CartPole", "CartPoleAgent.prefab");
		
		[MenuItem(GameObjectPath + "Agents/Rotary Pendulum", false, GameObjectPriority + 35)]
		[MenuItem(TopMenuPath + "Agents/Rotary Pendulum", false, TopMenuPriority + 35)]
		private static void CreateRotaryPendulum() => InstantiatePrefab("Complex", "RotaryPendulum", "RotaryPendulumAgent.prefab");
		
		[MenuItem(GameObjectPath + "Agents/Rover", false, GameObjectPriority + 40)]
		[MenuItem(TopMenuPath + "Agents/Rover", false, TopMenuPriority + 40)]
		private static void CreateRover() => InstantiatePrefab("Complex", "Rover", "RoverAgent.prefab");
		
		#endregion

		#region ML General
		
		[MenuItem(GameObjectPath + "Machine Learning/Agent Template", false, GameObjectPriority + 30)]
		[MenuItem(TopMenuPath + "Machine Learning/Agent Template", false, TopMenuPriority + 30)]
		private static void CreateAgentTemplate2() => InstantiatePrefab("MLGeneral", "AgentTemplate.prefab");

		[MenuItem(GameObjectPath + "Machine Learning/Enable Component On Big Reward", false, GameObjectPriority + 35)]
		[MenuItem(TopMenuPath + "Machine Learning/Enable Component On Big Reward", false, TopMenuPriority + 35)]
		private static void CreateEnableComponentOnBigReward() => InstantiatePrefab("MLGeneral", "EnableComponentOnBigReward.prefab");

		[MenuItem(GameObjectPath + "Machine Learning/Rewards Logger", false, GameObjectPriority + 40)]
		[MenuItem(TopMenuPath + "Machine Learning/Rewards Logger", false, TopMenuPriority + 40)]
		private static void CreateLogRewards() => InstantiatePrefab("MLGeneral", "LogRewards.prefab");
		
		#endregion

		#region ML Rewards

		[MenuItem(GameObjectPath + "Rewards/Time Penalty", false, GameObjectPriority + 35)]
		[MenuItem(TopMenuPath + "Rewards/Time Penalty", false, TopMenuPriority + 35)]
		private static void CreateTimePenalty() => InstantiatePrefab("MLRewards", "TimePenalty.prefab");

		[MenuItem(GameObjectPath + "Rewards/Penalty For Distance", false, GameObjectPriority + 40)]
		[MenuItem(TopMenuPath + "Rewards/Penalty For Distance", false, TopMenuPriority + 40)]
		private static void CreatePenaltyForDistance() => InstantiatePrefab("MLRewards", "PenaltyForDistance.prefab");

		[MenuItem(GameObjectPath + "Rewards/Reward When Close", false, GameObjectPriority + 45)]
		[MenuItem(TopMenuPath + "Rewards/Reward When Close", false, TopMenuPriority + 45)]
		private static void CreateRewardWhenClose() => InstantiatePrefab("MLRewards", "RewardWhenClose.prefab");

		[MenuItem(GameObjectPath + "Rewards/End Episode When Close", false, GameObjectPriority + 50)]
		[MenuItem(TopMenuPath + "Rewards/End Episode When Close", false, TopMenuPriority + 50)]
		private static void CreateEndEpisodeWhenClose() => InstantiatePrefab("MLRewards", "EndEpisodeWhenClose.prefab");

		[MenuItem(GameObjectPath + "Rewards/Distance Change Reward", false, GameObjectPriority + 55)]
		[MenuItem(TopMenuPath + "Rewards/Distance Change Reward", false, TopMenuPriority + 55)]
		private static void CreateDistanceChangeReward() => InstantiatePrefab("MLRewards", "DistanceChangeReward.prefab");

		#endregion
		
		#endregion
		
	}
}