Exemplo n.º 1
0
        //!!!!
        //static void LoadContext_ProcessNotCompiledComponentItems( Metadata.LoadContext context, out bool changed )
        //{
        //	changed = false;

        //	var items = context.GetNotCompiledItems();
        //	if( items.Count != 0 )
        //	{
        //		//creation stage
        //		foreach( var item in items )
        //		{
        //			//try create component
        //			if( item.component == null && item.parent != null && item.parent.component != null )
        //			{
        //				//!!!!
        //				xx xx;
        //				//if( componentBlock.Data == "_Dev\\Import3D\\ColladaTest2.dae:Originals\\Materials\\ColladaTestStoneStatic" )
        //				//	Log.Warning( "dfgdfg" );

        //				xx xx;

        //				bool readyOnly = xx;

        //				Metadata.TypeInfo type = MetadataManager.GetType( item.textBlock.Data );

        //				xx xx;//загружен тип должен быть

        //				if( type == null )
        //				{
        //					xx xx;

        //					//!!!!
        //					Log.Fatal( "impl" );
        //				}

        //				xx xx;//а также проверять на loaded. клонироваться же


        //				item.component = (Component)type.InvokeInstance( null );
        //				item.component.providedTypeAllow = false;

        //				//!!!!!!так?
        //				item.parent.component.AddComponent( item.component );

        //				//!!!!
        //				//string error3;
        //				//if( !component._LoadHierarchy( context, componentBlock, out error3 ) )
        //				//{
        //				//	//!!!!
        //				//	Log.Fatal( "impl" );

        //				//	//!!!!!?
        //				//	//RemoveComponent
        //				//	//component = null;
        //				//}

        //				changed = true;
        //			}
        //		}

        //		//if changed on creation stage then reply creation stage
        //		if( changed )
        //			return;

        //		//loading properties stage
        //		{
        //			xx xx;

        //		}

        //		xx xx;

        //		xx xx;
        //		//changed = true;
        //	}
        //}

        //static void LoadContext_ProcessComponentItemsRecursive( Metadata.LoadContext.ComponentItem componentItem )
        //{
        //}

        //public static bool LoadComponentFromTextBlock( Component component, Metadata.LoadContext overrideContextObject, TextBlock block, string loadedFromFile, out string error )
        //{
        //	xx xx;

        //	xx xx;

        //	loadedFromFile = VirtualPathUtils.NormalizePath( loadedFromFile );

        //	Metadata.LoadContext context = overrideContextObject;
        //	if( context == null )
        //		context = new Metadata.LoadContext();
        //	context.virtualFileName = loadedFromFile;

        //	error = "";

        //	if( block.Children.Count != 1 )
        //	{
        //		//!!!!
        //		Log.Fatal( "impl" );
        //	}

        //	TextBlock componentBlock = block.Children[ 0 ];
        //	if( componentBlock.Name != ".component" )
        //	{
        //		//!!!!
        //		Log.Fatal( "impl" );
        //	}

        //	if( string.IsNullOrEmpty( componentBlock.Data ) )
        //	{
        //		//!!!!
        //		Log.Fatal( "impl" );
        //	}

        //	//get type
        //	Metadata.TypeInfo type = MetadataManager.GetType( componentBlock.Data );
        //	if( type == null )
        //	{
        //		//!!!!
        //		Log.Fatal( "impl" );
        //	}

        //	xx xx;
        //	//create instance
        //	var component = (Component)type.InvokeInstance( null );

        //	//create context, init tree structure of components
        //	context.rootComponentItem = new Metadata.LoadContext.ComponentItem();
        //	context.rootComponentItem.textBlock = componentBlock;
        //	LoadContext_InitComponentItemsRecursive( context, context.rootComponentItem );

        //	//processing
        //	context.rootComponentItem.component = component;
        //	LoadContext_ProcessComponentItems( context );

        //	if( !context.rootComponentItem.loaded )
        //	{
        //		//!!!!
        //		Log.Fatal( "impl" );
        //	}

        //	return true;
        //}

        public static Component LoadComponentFromTextBlock(Metadata.LoadContext overrideContextObject, TextBlock block, string loadedFromFile,
                                                           Resource.Instance createdByResource, bool?componentSetEnabled, bool componentCreateHierarchyController, out string error)
        {
            loadedFromFile = VirtualPathUtility.NormalizePath(loadedFromFile);

            Metadata.LoadContext context = overrideContextObject;
            if (context == null)
            {
                context = new Metadata.LoadContext();
            }
            context.virtualFileName = loadedFromFile;

            error = "";

            if (block.Children.Count != 1)
            {
                error = "Invalid format. block.Children.Count != 1";
                return(null);
            }

            TextBlock componentBlock = block.Children[0];

            if (componentBlock.Name != ".component")
            {
                error = "Invalid format. componentBlock.Name != \".component\"";
                return(null);
            }

            if (string.IsNullOrEmpty(componentBlock.Data))
            {
                error = "Invalid format. string.IsNullOrEmpty( componentBlock.Data )";
                return(null);
            }

            //get type
            Metadata.TypeInfo type = MetadataManager.GetType(componentBlock.Data);
            if (type == null)
            {
                error = $"Type with name \'{componentBlock.Data}\' is not exists.";
                return(null);
            }

            //create instance
            var component = (Component)type.InvokeInstance(null);

            //set ResultObject for resource
            if (createdByResource != null)
            {
                createdByResource.ResultObject = component;
            }

            //create hierarchy controller. disabled at creation.
            if (componentCreateHierarchyController)
            {
                ComponentUtility.CreateHierarchyControllerForRootComponent(component, createdByResource, false);                  //, true );
            }
            //create context, init tree structure of components
            context.rootComponentItem           = new Metadata.LoadContext.ComponentItem();
            context.rootComponentItem.textBlock = componentBlock;

            if (!LoadContext_InitComponentItemsRecursive(context, context.rootComponentItem, out error))
            {
                component?.Dispose();
                return(null);
            }

            //processing
            context.rootComponentItem.component = component;
            if (!LoadContext_ProcessComponentItems(context, out error))
            {
                component?.Dispose();
                return(null);
            }

            if (!context.rootComponentItem.loaded)
            {
                error = "Root component is not loaded.";
                component?.Dispose();
                return(null);
            }

            //set Enabled
            if (componentSetEnabled != null)
            {
                component.Enabled = componentSetEnabled.Value;
            }
            //enable hierarchy controller
            if (component.HierarchyController != null)
            {
                component.HierarchyController.HierarchyEnabled = true;
            }

            return(component);
        }
Exemplo n.º 2
0
        //!!!!!
        //public static Resource Create( string name, bool makeUniqueName, Type resourceClass, object[] constructorParams = null )
        //{
        //	if( constructorParams == null )
        //		constructorParams = new object[ 0 ];

        //	Resource res;

        //	lock( lockObject )
        //	{
        //		if( makeUniqueName )
        //		{
        //			//!!!!так? первый без цифры?

        //			if( GetByName( name ) != null )
        //			{
        //				string newName = name;
        //				do
        //				{
        //					newName = uniqueNameGenerator.Get( name );
        //				}
        //				while( GetByName( newName ) != null );

        //				name = newName;
        //			}
        //		}
        //		else
        //		{
        //			if( GetByName( name ) != null )
        //				Log.Fatal( "ResourceManager: Create: GetByName( name ) != null. Resource name: \"{0}\".", name );
        //		}

        //		ConstructorInfo constructor = ReflectionUtils.GetSuitableConstructor( resourceClass, constructorParams, true );
        //		res = (Resource)constructor.Invoke( constructorParams );
        //		res.name = name;

        //		//add to the list
        //		resources.Add( GetKey( name ), res );

        //		//object result = null;
        //		//if( typeof( Resource ).IsAssignableFrom( resourceClass ) )
        //		//{
        //		//	ConstructorInfo constructor = GetSuitableConstructor( resourceClass, constructorParams );
        //		//	ins = (Resource)constructor.Invoke( constructorParams );

        //		//	ins.name = name;
        //		//	AddInstance( ins );

        //		//	result = ins;
        //		//}
        //		//else
        //		//{
        //		//	ins = new Resource();

        //		//	ins.name = name;
        //		//	AddInstance( ins );

        //		//	ConstructorInfo constructor = GetSuitableConstructor( resourceClass, constructorParams );
        //		//	ins.ResultObject = constructor.Invoke( constructorParams );
        //		//}

        //		//ins.status = Resource.StatusEnum.Ready;

        //		//ins.OnCreate_SameThread();
        //		//if( i.OnCreateEnd() )
        //		//	i.status = ResourceInstance.ResourceStatus.Ready;
        //		//else
        //		//	i.status = ResourceInstance.ResourceStatus.Error;
        //	}

        //	return res;
        //}

        //!!!!!?
        //public static T Create<T>( string name, bool makeUniqueName, object[] constructorParams = null ) where T : Resource
        //{
        //	return (T)Create( name, makeUniqueName, typeof( T ), constructorParams );
        //}

        //!!!!!везде повтыкать где как юзается loadInBackground

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        static void LoadTaskFunction(object data)
        {
            Resource.Instance ins = (Resource.Instance)data;
            ins.PerformLoad();
        }
Exemplo n.º 3
0
        public static void CreateHierarchyControllerForRootComponent(Component rootComponent, Resource.Instance createdByResource,
                                                                     bool hierarchyEnabled)
        {
            if (rootComponent.HierarchyController != null)
            {
                Log.Fatal("ComponentManager: CreateHierarchyControllerForRootComponent: rootComponent.HierarchyController != null.");
            }
            if (rootComponent.Parent != null)
            {
                Log.Fatal("ComponentManager: CreateHierarchyControllerForRootComponent: rootComponent.Parent != null.");
            }

            var controller = new ComponentHierarchyController();

            controller.rootComponent          = rootComponent;
            controller.createdByResource      = createdByResource;
            rootComponent.hierarchyController = controller;

            controller.HierarchyEnabled = hierarchyEnabled;
        }