private void OnUpdate() { if (_queue.Count == 0 || (_task != null && _task.Enabled)) { return; } // TODO: add delay when processing the requests to reduce perf impact (eg. 0.2s before actual rendering) // Setup pipeline if (_atlases == null) { _atlases = new List <Atlas>(4); } if (_output == null) { _output = GPUDevice.Instance.CreateTexture("CameraCutMedia.Output"); var desc = GPUTextureDescription.New2D(Width, Height, PixelFormat.R8G8B8A8_UNorm); _output.Init(ref desc); } if (_task == null) { _task = Object.New <SceneRenderTask>(); _task.Output = _output; _task.Begin += OnBegin; _task.End += OnEnd; } // Kick off the rendering _task.Enabled = true; }
private void DoAdd() { // Restore script var parentActor = Object.Find <Actor>(ref _parentId); if (parentActor == null) { // Error Editor.LogWarning("Missing parent actor."); return; } _script = (Script)Object.New(_scriptType); if (_script == null) { // Error Editor.LogWarning("Cannot create script of type " + _scriptType); return; } Object.Internal_ChangeID(_script.unmanagedPtr, ref _scriptId); if (_scriptData != null) { FlaxEngine.Json.JsonSerializer.Deserialize(_script, _scriptData); } _script.Enabled = _enabled; parentActor.AddScript(_script); if (_orderInParent != -1) { _script.OrderInParent = _orderInParent; } if (_prefabObjectId != Guid.Empty) { Script.Internal_LinkPrefab(_script.unmanagedPtr, ref _prefabId, ref _prefabObjectId); } Editor.Instance.Scene.MarkSceneEdited(parentActor.Scene); }
/// <summary> /// Initializes Flax API. Called before everything else from native code. /// </summary> /// <param name="flags">The packed flags with small meta for the API.</param> /// <param name="platform">The runtime platform.</param> internal static void Init(int flags, PlatformType platform) { #if DEBUG Debug.Logger.LogHandler.LogWrite(LogType.Info, "Using FlaxAPI in Debug"); #else Debug.Logger.LogHandler.LogWrite(LogType.Info, "Using FlaxAPI in Release"); #endif Platform._is64Bit = (flags & 0x01) != 0; Platform._isEditor = (flags & 0x02) != 0; Platform._mainThreadId = Thread.CurrentThread.ManagedThreadId; Platform._platform = platform; AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; TaskScheduler.UnobservedTaskException += OnUnobservedTaskException; Globals.Init(); if (!Platform.IsEditor) { CreateGuiStyle(); } MainRenderTask.Instance = Object.New <MainRenderTask>(); }
private void OnUpdate() { if (_queue.Count == 0 || (_task != null && _task.Enabled)) { return; } // TODO: add delay when processing the requests to reduce perf impact (eg. 0.2s before actual rendering) // Setup pipeline if (_atlases == null) { _atlases = new List <Atlas>(4); } if (_output == null) { _output = RenderTarget.New(); _output.Init(PixelFormat.R8G8B8A8_UNorm, Width, Height); } if (_task == null) { _task = Object.New <SceneRenderTask>(); _task.Output = _output; _task.Begin += OnBegin; _task.End += OnEnd; } // Kick off the rendering _task.Enabled = true; }
/// <inheritdoc /> public override void OnInit() { // Create cache folder if (!Directory.Exists(_cacheFolder)) { Directory.CreateDirectory(_cacheFolder); } // Find atlases in a Editor cache directory var files = Directory.GetFiles(_cacheFolder, "cache_*.flax", SearchOption.TopDirectoryOnly); int atlases = 0; for (int i = 0; i < files.Length; i++) { // Load asset var asset = FlaxEngine.Content.LoadAsync(files[i]); if (asset == null) { continue; } // Validate type if (asset is PreviewsCache atlas) { // Cache atlas atlases++; _cache.Add(atlas); } else { // Skip asset Editor.LogWarning(string.Format("Asset \'{0}\' is inside Editor\'s private directory for Assets Thumbnails Cache. Please move it.", asset.Path)); } } Editor.Log(string.Format("Previews cache count: {0} (capacity for {1} icons)", atlases, atlases * PreviewsCache.AssetIconsPerAtlas)); // Prepare at least one atlas if (_cache.Count == 0) { GetValidAtlas(); } // Create render task but disabled for now _output = GPUDevice.Instance.CreateTexture("ThumbnailsOutput"); var desc = GPUTextureDescription.New2D(PreviewsCache.AssetIconSize, PreviewsCache.AssetIconSize, PreviewsCache.AssetIconsAtlasFormat); _output.Init(ref desc); _task = Object.New <RenderTask>(); _task.Order = 50; // Render this task later _task.Enabled = false; _task.Render += OnRender; }
/// <inheritdoc /> public object CreateInstance() { return(Object.New(TypeName)); }
/// <inheritdoc /> protected override DragDropEffect OnDragDropHeader(DragData data) { var result = DragDropEffect.None; Actor myActor = Actor; Actor newParent; int newOrder = -1; // Check if has no actor (only for Root Actor) if (myActor == null) { // Append to the last scene var scenes = Level.Scenes; if (scenes == null || scenes.Length == 0) { throw new InvalidOperationException("No scene loaded."); } newParent = scenes[scenes.Length - 1]; } else { newParent = myActor; // Use drag positioning to change target parent and index if (DragOverMode == DragItemPositioning.Above) { if (myActor.HasParent) { newParent = myActor.Parent; newOrder = myActor.OrderInParent; } } else if (DragOverMode == DragItemPositioning.Below) { if (myActor.HasParent) { newParent = myActor.Parent; newOrder = myActor.OrderInParent + 1; } } } if (newParent == null) { throw new InvalidOperationException("Missing parent actor."); } // Drag actors if (_dragActors != null && _dragActors.HasValidDrag) { bool worldPositionLock = Root.GetKey(KeyboardKeys.Control) == false; var singleObject = _dragActors.Objects.Count == 1; if (singleObject) { var targetActor = _dragActors.Objects[0].Actor; var customAction = targetActor.HasPrefabLink ? new ReparentAction(targetActor) : null; using (new UndoBlock(ActorNode.Root.Undo, targetActor, "Change actor parent", customAction)) { targetActor.SetParent(newParent, worldPositionLock); targetActor.OrderInParent = newOrder; } } else { var targetActors = _dragActors.Objects.ConvertAll(x => x.Actor); var customAction = targetActors.Any(x => x.HasPrefabLink) ? new ReparentAction(targetActors) : null; using (new UndoMultiBlock(ActorNode.Root.Undo, targetActors, "Change actors parent", customAction)) { for (int i = 0; i < targetActors.Count; i++) { var targetActor = targetActors[i]; targetActor.SetParent(newParent, worldPositionLock); targetActor.OrderInParent = newOrder; } } } result = DragDropEffect.Move; } // Drag assets else if (_dragAssets != null && _dragAssets.HasValidDrag) { for (int i = 0; i < _dragAssets.Objects.Count; i++) { var assetItem = _dragAssets.Objects[i]; if (assetItem.IsOfType <SkinnedModel>()) { // Create actor var model = FlaxEngine.Content.LoadAsync <SkinnedModel>(assetItem.ID); var actor = AnimatedModel.New(); actor.StaticFlags = Actor.StaticFlags; actor.Name = assetItem.ShortName; actor.SkinnedModel = model; actor.Transform = Actor.Transform; // Spawn ActorNode.Root.Spawn(actor, Actor); } else if (assetItem.IsOfType <Model>()) { // Create actor var model = FlaxEngine.Content.LoadAsync <Model>(assetItem.ID); var actor = StaticModel.New(); actor.StaticFlags = Actor.StaticFlags; actor.Name = assetItem.ShortName; actor.Model = model; actor.Transform = Actor.Transform; // Spawn ActorNode.Root.Spawn(actor, Actor); } else if (assetItem.IsOfType <CollisionData>()) { // Create actor var actor = MeshCollider.New(); actor.StaticFlags = Actor.StaticFlags; actor.Name = assetItem.ShortName; actor.CollisionData = FlaxEngine.Content.LoadAsync <CollisionData>(assetItem.ID); actor.Transform = Actor.Transform; // Spawn ActorNode.Root.Spawn(actor, Actor); } else if (assetItem.IsOfType <ParticleSystem>()) { // Create actor var actor = ParticleEffect.New(); actor.StaticFlags = Actor.StaticFlags; actor.Name = assetItem.ShortName; actor.ParticleSystem = FlaxEngine.Content.LoadAsync <ParticleSystem>(assetItem.ID); actor.Transform = Actor.Transform; // Spawn ActorNode.Root.Spawn(actor, Actor); } else if (assetItem.IsOfType <SceneAnimation>()) { // Create actor var actor = SceneAnimationPlayer.New(); actor.StaticFlags = Actor.StaticFlags; actor.Name = assetItem.ShortName; actor.Animation = FlaxEngine.Content.LoadAsync <SceneAnimation>(assetItem.ID); actor.Transform = Actor.Transform; // Spawn ActorNode.Root.Spawn(actor, Actor); } else if (assetItem.IsOfType <AudioClip>()) { // Create actor var actor = AudioSource.New(); actor.StaticFlags = Actor.StaticFlags; actor.Name = assetItem.ShortName; actor.Clip = FlaxEngine.Content.LoadAsync <AudioClip>(assetItem.ID); actor.Transform = Actor.Transform; // Spawn ActorNode.Root.Spawn(actor, Actor); break; } else if (assetItem.IsOfType <Prefab>()) { // Create prefab instance var prefab = FlaxEngine.Content.LoadAsync <Prefab>(assetItem.ID); var actor = PrefabManager.SpawnPrefab(prefab, null); actor.StaticFlags = Actor.StaticFlags; actor.Name = assetItem.ShortName; actor.Transform = Actor.Transform; // Spawn ActorNode.Root.Spawn(actor, Actor); } } result = DragDropEffect.Move; } // Drag actor type else if (_dragActorType != null && _dragActorType.HasValidDrag) { for (int i = 0; i < _dragActorType.Objects.Count; i++) { var item = _dragActorType.Objects[i]; // Create actor var actor = Object.New(item) as Actor; if (actor == null) { Editor.LogWarning("Failed to spawn actor of type " + item.FullName); continue; } actor.StaticFlags = Actor.StaticFlags; actor.Name = item.Name; actor.Transform = Actor.Transform; // Spawn ActorNode.Root.Spawn(actor, Actor); } result = DragDropEffect.Move; } // Clear cache _dragHandlers.OnDragDrop(null); // Check if scene has been modified if (result != DragDropEffect.None) { var node = SceneGraphFactory.FindNode(newParent.ID) as ActorNode; node?.TreeNode.Expand(); } return(result); }