예제 #1
0
        private void DoLink()
        {
            if (_prefabObjectIds == null)
            {
                throw new FlaxException("Cannot link prefab. Missing objects Ids mapping.");
            }

            var actor = Object.Find <Actor>(ref _actorId);

            if (actor == null)
            {
                throw new FlaxException("Cannot link prefab. Missing actor.");
            }

            // Restore cached links
            foreach (var e in _prefabObjectIds)
            {
                var objId       = e.Key;
                var prefabObjId = e.Value;

                var obj = Object.Find <Object>(ref objId);
                if (obj is Actor)
                {
                    Actor.Internal_LinkPrefab(Object.GetUnmanagedPtr(obj), ref _prefabId, ref prefabObjId);
                }
                else if (obj is Script)
                {
                    Script.Internal_LinkPrefab(Object.GetUnmanagedPtr(obj), ref _prefabId, ref prefabObjId);
                }
            }

            Editor.Instance.Scene.MarkSceneEdited(actor.Scene);
            Editor.Instance.Windows.PropertiesWin.Presenter.BuildLayout();
        }
예제 #2
0
        /// <inheritdoc />
        public override bool GetBoxDebuggerTooltip(Box box, out string text)
        {
            if (Editor.Instance.Simulation.IsDuringBreakpointHang)
            {
                // Find any local variable from the current scope that matches this box
                var state = Windows.Assets.VisualScriptWindow.GetLocals();
                if (state.Locals != null)
                {
                    for (int i = 0; i < state.Locals.Length; i++)
                    {
                        ref var local = ref state.Locals[i];
                        if (local.BoxId == box.ID && local.NodeId == box.ParentNode.ID)
                        {
                            text = $"{local.Value ?? string.Empty} ({local.ValueTypeName})";
                            return(true);
                        }
                    }
                }

                // Evaluate the value using the Visual Scripting backend
                if (box.CurrentType != typeof(void))
                {
                    var local = new Editor.VisualScriptLocal
                    {
                        NodeId = box.ParentNode.ID,
                        BoxId  = box.ID,
                    };
                    var script = ((Windows.Assets.VisualScriptWindow)box.Surface.Owner).Asset;
                    if (Editor.Internal_EvaluateVisualScriptLocal(Object.GetUnmanagedPtr(script), ref local))
                    {
                        text = $"{local.Value ?? string.Empty} ({local.ValueTypeName})";
                        return(true);
                    }
                }
            }
예제 #3
0
        public static void DrawText(Font font, string text, Rectangle layoutRect, Color color, TextAlignment horizontalAlignment = TextAlignment.Near, TextAlignment verticalAlignment = TextAlignment.Near, TextWrapping textWrapping = TextWrapping.NoWrap, float baseLinesGapScale = 1.0f, float scale = 1.0f)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            Internal_DrawText(Object.GetUnmanagedPtr(font), text, ref layoutRect, ref color, horizontalAlignment, verticalAlignment, textWrapping, baseLinesGapScale, scale);
#endif
        }
예제 #4
0
        public static void DrawSpritePoint(Sprite sprite, Rectangle rect, Color color)
        {
#if UNIT_TEST_COMPILANT
			throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            Internal_DrawSpritePoint(Object.GetUnmanagedPtr(sprite.Atlas), sprite.Index, ref rect, ref color);
#endif
        }
예제 #5
0
        public static Actor SpawnPrefab(Prefab prefab, Actor parent)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            return(Internal_SpawnPrefab(Object.GetUnmanagedPtr(prefab), Object.GetUnmanagedPtr(parent)));
#endif
        }
예제 #6
0
        public static void DrawTexture(SpriteAtlas t, Rectangle rect, Color color, bool withAlpha = false)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            Internal_DrawTexture2(Object.GetUnmanagedPtr(t), ref rect, ref color, withAlpha);
#endif
        }
예제 #7
0
        public static bool TryGetPatchCoordToAdd(Terrain terrain, Ray ray, out Int2 patchCoord)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            return(Internal_TryGetPatchCoordToAdd(Object.GetUnmanagedPtr(terrain), ref ray, out patchCoord));
#endif
        }
예제 #8
0
        public static bool ExportTerrain(Terrain terrain, string outputFolder)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            return(Internal_ExportTerrain(Object.GetUnmanagedPtr(terrain), outputFolder));
#endif
        }
예제 #9
0
        public static void DeserializePatch(Terrain terrain, ref Int2 patchCoord, string value)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            Internal_DeserializePatch(Object.GetUnmanagedPtr(terrain), ref patchCoord, value);
#endif
        }
예제 #10
0
        public static bool Intersects(Foliage foliage, Ray ray, out float distance, out Vector3 normal, out int instanceIndex)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            return(Internal_Intersects(Object.GetUnmanagedPtr(foliage), ref ray, out distance, out normal, out instanceIndex));
#endif
        }
예제 #11
0
        public static string BrowseFolderDialog(Window parent, string initialDirectory, string title)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            return(Internal_BrowseFolderDialog(Object.GetUnmanagedPtr(parent), initialDirectory, title));
#endif
        }
예제 #12
0
        public static bool GenerateTerrain(Terrain terrain, ref Int2 numberOfPatches, Texture heightmap, float heightmapScale, Texture splatmap1, Texture splatmap2)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            return(Internal_GenerateTerrain(Object.GetUnmanagedPtr(terrain), ref numberOfPatches, Object.GetUnmanagedPtr(heightmap), heightmapScale, Object.GetUnmanagedPtr(splatmap1), Object.GetUnmanagedPtr(splatmap2)));
#endif
        }
예제 #13
0
        public static bool RayCastChunk(Terrain terrain, Ray ray, out float resultHitDistance, out Int2 resultPatchCoord, out Int2 resultChunkCoord, float maxDistance = float.MaxValue)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            return(Internal_RayCastChunk(Object.GetUnmanagedPtr(terrain), ref ray, out resultHitDistance, out resultPatchCoord, out resultChunkCoord, maxDistance));
#endif
        }
예제 #14
0
        public static IntPtr GetSplatMapData(Terrain terrain, ref Int2 patchCoord, int index)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            return(Internal_GetSplatMapData(Object.GetUnmanagedPtr(terrain), ref patchCoord, index));
#endif
        }
예제 #15
0
        public static bool ModifySplatMap(Terrain terrain, ref Int2 patchCoord, int index, IntPtr samples, ref Int2 offset, ref Int2 size)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            return(Internal_ModifySplatMap(Object.GetUnmanagedPtr(terrain), ref patchCoord, index, samples, ref offset, ref size));
#endif
        }
예제 #16
0
        public static bool InitializePatch(Terrain terrain, ref Int2 patchCoord)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            return(Internal_InitializePatch(Object.GetUnmanagedPtr(terrain), ref patchCoord));
#endif
        }
예제 #17
0
        public static void Paint(Foliage foliage, int[] foliageTypesIndices, Vector3 brushPosition, float brushRadius, bool additive)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            Internal_Paint(Object.GetUnmanagedPtr(foliage), foliageTypesIndices, ref brushPosition, brushRadius, additive);
#endif
        }
예제 #18
0
        public static DialogResult Show(Window parent, string text, string caption, Buttons buttons, Icon icon)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            return(Internal_Show(Object.GetUnmanagedPtr(parent), text, caption, buttons, icon));
#endif
        }
예제 #19
0
        /// <inheritdoc />
        public void Log(LogType logType, Object context, string message)
        {
#if DEBUG
            string stackTrace = Environment.StackTrace;
#else
            string stackTrace = string.Empty;
#endif
            Internal_Log(logType, message, Object.GetUnmanagedPtr(context), stackTrace);

            SendLog?.Invoke(logType, message, context, stackTrace);
        }
예제 #20
0
        /// <inheritdoc />
        public void Log(LogType logType, Object context, string message)
        {
            if (message == null)
            {
                return;
            }
#if BUILD_RELEASE
            string stackTrace = null;
#else
            string stackTrace = Environment.StackTrace;
#endif
            Internal_Log(logType, message, Object.GetUnmanagedPtr(context), stackTrace);
            SendLog?.Invoke(logType, message, context, stackTrace);
        }
예제 #21
0
        public static void DrawText(Font font, MaterialBase customMaterial, string text, Rectangle layoutRect, Color color, TextAlignment horizontalAlignment = TextAlignment.Near, TextAlignment verticalAlignment = TextAlignment.Near, TextWrapping textWrapping = TextWrapping.NoWrap, float baseLinesGapScale = 1.0f, float scale = 1.0f)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            TextLayoutOptions layout;
            layout.Bounds = layoutRect;
            layout.HorizontalAlignment = horizontalAlignment;
            layout.VerticalAlignment = verticalAlignment;
            layout.TextWrapping = textWrapping;
            layout.Scale = scale;
            layout.BaseLinesGapScale = baseLinesGapScale;
            Internal_DrawText2(Object.GetUnmanagedPtr(font), Object.GetUnmanagedPtr(customMaterial), text, ref color, ref layout);
#endif
        }
예제 #22
0
        public static void Draw(FlaxEngine.Rendering.RenderTask task, Actor[] selectedActors)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            // Get unmanaged pointers
            IntPtr[] actors = null;
            if (selectedActors != null && selectedActors.Length > 0)
            {
                actors = new IntPtr[selectedActors.Length];
                for (int i = 0; i < selectedActors.Length; i++)
                {
                    actors[i] = Object.GetUnmanagedPtr(selectedActors[i]);
                }
            }

            Internal_Draw(Object.GetUnmanagedPtr(task), actors, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, false);
#endif
        }
예제 #23
0
 /// <inheritdoc />
 public void Undo()
 {
     // Restore links
     for (int i = 0; i < _actorsCount; i++)
     {
         var actor = Object.Find <Actor>(ref _ids[i]);
         if (actor != null && _prefabIds[i] != Guid.Empty)
         {
             Actor.Internal_LinkPrefab(Object.GetUnmanagedPtr(actor), ref _prefabIds[i], ref _prefabObjectIds[i]);
         }
     }
     for (int i = _actorsCount; i < _ids.Length; i++)
     {
         var script = Object.Find <Script>(ref _ids[i]);
         if (script != null && _prefabIds[i] != Guid.Empty)
         {
             Script.Internal_LinkPrefab(Object.GetUnmanagedPtr(script), ref _prefabIds[i], ref _prefabObjectIds[i]);
         }
     }
 }
예제 #24
0
        private void DoAdd()
        {
            // Restore script
            var parentActor = Object.Find <Actor>(ref _parentId);

            if (parentActor == null)
            {
                Editor.LogWarning("Missing parent actor.");
                return;
            }
            var type = TypeUtils.GetType(_scriptTypeName);

            if (!type)
            {
                Editor.LogWarning("Cannot find script type " + _scriptTypeName);
                return;
            }
            var script = type.CreateInstance() as Script;

            if (script == null)
            {
                Editor.LogWarning("Cannot create script of type " + _scriptTypeName);
                return;
            }
            Object.Internal_ChangeID(Object.GetUnmanagedPtr(script), ref _scriptId);
            if (_scriptData != null)
            {
                FlaxEngine.Json.JsonSerializer.Deserialize(script, _scriptData);
            }
            script.Enabled = _enabled;
            script.Parent  = parentActor;
            if (_orderInParent != -1)
            {
                script.OrderInParent = _orderInParent;
            }
            if (_prefabObjectId != Guid.Empty)
            {
                SceneObject.Internal_LinkPrefab(Object.GetUnmanagedPtr(script), ref _prefabId, ref _prefabObjectId);
            }
            Editor.Instance.Scene.MarkSceneEdited(parentActor.Scene);
        }
예제 #25
0
        /// <summary>
        /// Adds the draw call (single terrain chunk drawing).
        /// </summary>
        /// <param name="terrain">The terrain to render. Cannot be null.</param>
        /// <param name="patchCoord">The terrain patch coordinates.</param>
        /// <param name="chunkCoord">The terrain chunk coordinates.</param>
        /// <param name="material">The material to apply during rendering. Cannot be null.</param>
        /// <param name="lodIndex">The geometry Level Of Detail index.</param>
        public void AddDrawCall(Terrain terrain, ref Int2 patchCoord, ref Int2 chunkCoord, MaterialBase material, int lodIndex = -1)
        {
            if (terrain == null)
            {
                throw new ArgumentNullException(nameof(terrain));
            }
            if (material == null)
            {
                throw new ArgumentNullException(nameof(material));
            }

            var drawCall = new RenderTask.DrawCall
            {
                Type     = RenderTask.DrawCall.Types.TerrainChunk,
                Flags    = StaticFlags.None,
                LodIndex = lodIndex,
                Index0   = patchCoord,
                Index1   = chunkCoord,
                Object   = terrain.unmanagedPtr,
                Material = Object.GetUnmanagedPtr(material),
            };

            _drawCalls.Add(drawCall);
        }
예제 #26
0
        /// <summary>
        /// Adds the draw call (single mesh drawing).
        /// </summary>
        /// <param name="mesh">The mesh to render. Cannot be null.</param>
        /// <param name="material">The material to apply during rendering. Cannot be null.</param>
        /// <param name="world">The world matrix used to transform mesh geometry during rendering. Use <see cref="Matrix.Identity"/> to render mesh 'as is'.</param>
        /// <param name="flags">The static flags. Used to describe type of the geometry.</param>
        /// <param name="receiveDecals">True if rendered geometry can receive decals, otherwise false.</param>
        public void AddDrawCall(Mesh mesh, MaterialBase material, ref Matrix world, StaticFlags flags = StaticFlags.None, bool receiveDecals = true)
        {
            if (mesh == null)
            {
                throw new ArgumentNullException(nameof(mesh));
            }
            if (material == null)
            {
                throw new ArgumentNullException(nameof(material));
            }

            var drawCall = new RenderTask.DrawCall
            {
                Type     = RenderTask.DrawCall.Types.Mesh,
                Flags    = flags,
                LodIndex = mesh._lodIndex,
                Index0   = new Int2(mesh._meshIndex, receiveDecals ? 1 : 0),
                Object   = Object.GetUnmanagedPtr(mesh.ParentModel),
                Material = Object.GetUnmanagedPtr(material),
                World    = world
            };

            _drawCalls.Add(drawCall);
        }
예제 #27
0
        /// <summary>
        /// Draws postFx material to the render target.
        /// </summary>
        /// <param name="material">The material to render. It must be a post fx material.</param>
        /// <param name="output">The output texture. Must be valid and created.</param>
        /// <param name="input">The input texture. It's optional.</param>
        /// <param name="sceneRenderTask">Render task to use it's view description and the render buffers.</param>
        public void DrawPostFxMaterial(MaterialBase material, GPUTexture output, GPUTexture input, SceneRenderTask sceneRenderTask)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            Internal_DrawPostFxMaterial1(unmanagedPtr, GetUnmanagedPtr(material), GetUnmanagedPtr(output), GetUnmanagedPtr(input), ref sceneRenderTask.View, Object.GetUnmanagedPtr(sceneRenderTask.Buffers));
#endif
        }
예제 #28
0
        public static void Draw(FlaxEngine.Rendering.RenderTask task, IntPtr[] selectedActors, FlaxEngine.Rendering.RenderTarget target = null, FlaxEngine.Rendering.GPUContext context = null, FlaxEngine.Rendering.RenderTarget depthBuffer = null, bool enableDepthTest = false)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            Internal_Draw(Object.GetUnmanagedPtr(task), selectedActors, Object.GetUnmanagedPtr(target), Object.GetUnmanagedPtr(context), Object.GetUnmanagedPtr(depthBuffer), enableDepthTest);
#endif
        }
예제 #29
0
        /// <inheritdoc />
        public void LogException(Exception exception, Object context)
        {
            Internal_LogException(exception, Object.GetUnmanagedPtr(context));

            SendExceptionLog?.Invoke(exception, context);
        }
예제 #30
0
        /// <summary>
        /// Executes the draw calls.
        /// </summary>
        /// <param name="context">The GPU command context.</param>
        /// <param name="task">The render task.</param>
        /// <param name="output">The output texture.</param>
        /// <param name="outputDepth">The output depth texture.</param>
        /// <param name="pass">The rendering pass mode.</param>
        public void ExecuteDrawCalls(GPUContext context, RenderTask task, GPUTexture output, GPUTexture outputDepth, DrawPass pass)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            GPUContext.Internal_ExecuteDrawCalls(context.unmanagedPtr, task.unmanagedPtr, output.unmanagedPtr, Object.GetUnmanagedPtr(outputDepth), DrawCalls, pass);
        }