コード例 #1
0
        public virtual object CreateInstance(Type NativeClass = null)
        {
            //If we have a parent script and a native class, instantiate the native class and apply all parent scripts.
            //If we have a Parent Script and No Native Class, walk up the chain until we find a Native Class (if no class, throw exception)
            //If we have No Parent Script and a Native Class, create the native class and apply this script.
            //If we have Neither Parent Script or Native Class, throw an exception.

            //Find the parent native class

            Type FoundNativeClass = FindNativeClass() ?? NativeClass;

            if (FoundNativeClass == null)
            {
                throw new MissingRequiredScriptFieldException(string.Format("{0} Has no {1} in any search path", ResourcePtr.ToString(), NativeClassName));
            }


            object o = Activator.CreateInstance(FoundNativeClass);

            if (o is IPostConstruct)
            {
                (o as IPostConstruct).PostConstruct();
            }
            ApplyToObject(o);

            return(o);
        }
コード例 #2
0
        public override object GetResource(ResourcePtr ptr, Stream stream)
        {
            using (TextReader Reader = new StreamReader(stream))
                using (JsonReader JReader = new JsonTextReader(Reader))
                {
                    MaterialScript ms = Activator.CreateInstance <MaterialScript>();
                    ms.JObject = JObject.Load(JReader);

                    //Validate that we have required shaders
                    if (ms.FragmentShader == null)
                    {
                        throw new WatertightLoadingFailureException(string.Format("Error loading material: {0}, missing $FragmentShader", ptr.ToString()));
                    }
                    if (ms.VertexShader == null)
                    {
                        throw new WatertightLoadingFailureException(string.Format("Error loading material: {0}, missing $VertexShader", ptr.ToString()));
                    }

                    Material Mat = IEngine.Instance.Renderer.MaterialFactory.Create(ms);

                    //Load the shaders
                    Mat._Shaders[Shader.Stage.Fragment] = GetShader(ms.FragmentShader, Shader.Stage.Fragment);
                    Mat._Shaders[Shader.Stage.Vertex]   = GetShader(ms.VertexShader, Shader.Stage.Vertex);

                    Mat.PostLoad();

                    return(Mat);
                }
        }