Esempio n. 1
0
        /// <summary>
        /// Creates the material instance from the given material.
        /// </summary>
        /// <param name="materialItem">The material item to use as a base material.</param>
        public static void CreateMaterialInstance(BinaryAssetItem materialItem)
        {
            if (materialItem == null)
            {
                throw new ArgumentNullException();
            }

            var materialInstanceProxy = Editor.Instance.ContentDatabase.GetProxy <MaterialInstance>();

            Editor.Instance.Windows.ContentWin.NewItem(materialInstanceProxy, null, item => OnMaterialInstanceCreated(item, materialItem));
        }
Esempio n. 2
0
        private static void OnMaterialInstanceCreated(ContentItem item, BinaryAssetItem materialItem)
        {
            var assetItem        = (AssetItem)item;
            var materialInstance = FlaxEngine.Content.LoadAsync <MaterialInstance>(assetItem.ID);

            if (materialInstance == null || materialInstance.WaitForLoaded())
            {
                Editor.LogError("Failed to load created material instance.");
                return;
            }

            materialInstance.BaseMaterial = FlaxEngine.Content.LoadAsync <Material>(materialItem.ID);
            materialInstance.Save();
        }