/// <inheritdoc />
        public IEnumerator Load(IAssetRequest <T> assetRequest)
        {
            FARLogger.Assert(assetRequest.Url != null, "Request url cannot be null");
            assetRequest.State = Progress.InProgress;

            // make sure bundle is loaded
            if (BundleLoader.NeedsReload)
            {
                yield return(BundleLoader.Load());
            }

            // check for errors
            if (BundleLoader.State == Progress.Error)
            {
                FARLogger.ErrorFormat("Could not load asset bundle {0} for request {1}",
                                      BundleLoader.Url,
                                      assetRequest.Url);
                assetRequest.State = Progress.Error;
                assetRequest.OnError();
                yield break;
            }

            if (!BundleLoader.TryGetAsset(assetRequest.Url, out T asset))
            {
                FARLogger.ErrorFormat("Could not find asset {0} in bundle {1}", assetRequest.Url, BundleLoader.Url);
                assetRequest.State = Progress.Error;
                assetRequest.OnError();
                yield break;
            }

            assetRequest.State = Progress.Completed;
            assetRequest.OnLoad(asset);
        }
        /// <summary>
        /// Add a component to a GameObject. Note that this function must be run from the main thread since it accesses Unity methods
        /// </summary>
        /// <param name="type">type of the component</param>
        /// <param name="parent">optional parent gameobject, if not provided will create new one</param>
        /// <param name="persistant">whether this component should not be destroyed on load</param>
        /// <returns>the created component</returns>
        public static Component Create(Type type, Transform parent = null, bool persistant = false)
        {
            FARLogger.Assert(typeof(Component).IsBaseOf(type),
                             $"Invalid type given: {type.ToString()}, expected Component");

            GameObject go        = parent == null ? new GameObject() : parent.gameObject;
            Component  component = go.AddComponent(type);

            if (persistant)
            {
                Object.DontDestroyOnLoad(component);
            }

            return(component);
        }
Exemple #3
0
 // since this is POD struct, use pointer casting for quick indexed access
 public unsafe double this[int index]
 {
     get
     {
         FARLogger.Assert(index < 7, "Index out of bounds");
         fixed(ProjectedArea *areas = &this)
         {
             return(((double *)areas)[index]);
         }
     }
     set
     {
         FARLogger.Assert(index < 7, "Index out of bounds");
         fixed(ProjectedArea *areas = &this)
         {
             ((double *)areas)[index] = value;
         }
     }
 }
Exemple #4
0
        private object FindOrMakeInstance()
        {
            // handle static classes
            if (ValueType.IsStatic())
            {
                return(null);
            }
            object instance = ReflectionUtils.FindInstance(ValueType);

            if (instance != null)
            {
                return(instance);
            }
            FARLogger.TraceFormat("Instance of {0} was not provided and could not find one. Creating one", ValueType);
            instance = ReflectionUtils.CreateInstance(ValueType);

            FARLogger.Assert(instance != null, "Could not create instance");

            return(instance);
        }
 private static void CheckStatus()
 {
     FARLogger.Assert(Thread != null, "Calling main thread task before initialization");
 }