Пример #1
0
        public static MyObjectBuilder_ToolbarItem ObjectBuilderFromDefinition(MyDefinitionBase defBase)
        {
            if (defBase is MyPhysicalItemDefinition)
            {
                MyObjectBuilder_ToolbarItemWeapon weaponData = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_ToolbarItemWeapon>();
                weaponData.DefinitionId = defBase.Id;
                return weaponData;
            }
            else if (defBase is MyCubeBlockDefinition)
            {
                MyCubeBlockDefinition blockDef = defBase as MyCubeBlockDefinition;
                MyObjectBuilder_ToolbarItemCubeBlock cubeData = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_ToolbarItemCubeBlock>();
                cubeData.DefinitionId = defBase.Id;
                return cubeData;
            }
            else if (defBase is MyAnimationDefinition)
            {
                var animData = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_ToolbarItemAnimation>();
                animData.DefinitionId = defBase.Id;
                return animData;
            }
            else if (defBase is MyVoxelHandDefinition)
            {
                var vhData = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_ToolbarItemVoxelHand>();
                vhData.DefinitionId = defBase.Id;
                return vhData;
            }
            else if (defBase is MyPrefabThrowerDefinition)
            {
                var ptData = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_ToolbarItemPrefabThrower>();
                ptData.DefinitionId = defBase.Id;
                return ptData;
            }
            else if (defBase is MyBotDefinition)
            {
                var bdData = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_ToolbarItemBot>();
                bdData.DefinitionId = defBase.Id;
                return bdData;
            }
            else if (defBase is MyAiCommandDefinition)
            {
                var acData = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_ToolbarItemAiCommand>();
                acData.DefinitionId = defBase.Id;
                return acData;
            }
            else if (defBase.Id.TypeId == typeof(MyObjectBuilder_RopeDefinition))
            {
                var ob = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_ToolbarItemRope>();
                ob.DefinitionId = defBase.Id;
                return ob;
            }
			else if (defBase is MyAreaMarkerDefinition)
			{
				var acData = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_ToolbarItemAreaMarker>();
				acData.DefinitionId = defBase.Id;
				return acData;
			}
            return new MyObjectBuilder_ToolbarItemEmpty();
        }
 private string sorter(MyDefinitionBase def)
 {
     var physDef = def as MyPhysicalItemDefinition;
     if (physDef != null)
         return physDef.DisplayNameText;
     return null;
 }