Ejemplo n.º 1
0
                public void MarkSceneEdited(SceneModule sceneModule)
                {
                    var spline = Object.Find <Spline>(ref SplineId);

                    sceneModule.MarkSceneEdited(spline.Scene);
                    OnSplineEdited(spline);
                }
Ejemplo n.º 2
0
        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);
        }
        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(obj.unmanagedPtr, ref _prefabId, ref prefabObjId);
                }
                else if (obj is Script)
                {
                    Script.Internal_LinkPrefab(obj.unmanagedPtr, ref _prefabId, ref prefabObjId);
                }
            }

            Editor.Instance.Scene.MarkSceneEdited(actor.Scene);
            Editor.Instance.Windows.PropertiesWin.Presenter.BuildLayout();
        }
        private void DoBreak()
        {
            var actor = Object.Find <Actor>(ref _actorId);

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

            if (_prefabObjectIds == null)
            {
                _prefabObjectIds = new Dictionary <Guid, Guid>(1024);
            }
            else
            {
                _prefabObjectIds.Clear();
            }
            CollectIds(actor);

            _prefabId = actor.PrefabID;

            actor.BreakPrefabLink();

            Editor.Instance.Scene.MarkSceneEdited(actor.Scene);
            Editor.Instance.Windows.PropertiesWin.Presenter.BuildLayout();
        }
Ejemplo n.º 5
0
            /// <inheritdoc />
            public void Do()
            {
                var terrain = Object.Find <FlaxEngine.Terrain>(ref _terrainId);

                if (terrain == null)
                {
                    Editor.LogError("Missing terrain actor.");
                    return;
                }

                terrain.GetPatchBounds(terrain.GetPatchIndex(ref _patchCoord), out var patchBounds);
                terrain.RemovePatch(ref _patchCoord);
                OnPatchEdit(terrain, ref patchBounds);
            }
Ejemplo n.º 6
0
            private void Set(ref Guid id)
            {
                var terrain = Object.Find <FlaxEngine.Terrain>(ref _terrainId);

                if (terrain == null)
                {
                    Editor.LogError("Missing terrain actor.");
                    return;
                }

                terrain.SetChunkOverrideMaterial(ref _patchCoord, ref _chunkCoord, FlaxEngine.Content.LoadAsync <MaterialBase>(ref id));

                Editor.Instance.Scene.MarkSceneEdited(terrain.Scene);
            }
Ejemplo n.º 7
0
            /// <inheritdoc />
            public void Undo()
            {
                var terrain = Object.Find <FlaxEngine.Terrain>(ref _terrainId);

                if (terrain == null)
                {
                    Editor.LogError("Missing terrain actor.");
                    return;
                }

                terrain.RemovePatch(ref _patchCoord);

                Editor.Instance.Scene.MarkSceneEdited(terrain.Scene);
            }
Ejemplo n.º 8
0
            /// <inheritdoc />
            public void Undo()
            {
                var terrain = Object.Find <FlaxEngine.Terrain>(ref _terrainId);

                if (terrain == null)
                {
                    Editor.LogError("Missing terrain actor.");
                    return;
                }

                terrain.AddPatch(ref _patchCoord);
                TerrainTools.DeserializePatch(terrain, ref _patchCoord, _data);

                _editor.Scene.MarkSceneEdited(terrain.Scene);
            }
Ejemplo n.º 9
0
            /// <inheritdoc />
            public void Undo()
            {
                var terrain = Object.Find <FlaxEngine.Terrain>(ref _terrainId);

                if (terrain == null)
                {
                    Editor.LogError("Missing terrain actor.");
                    return;
                }

                terrain.AddPatch(ref _patchCoord);
                TerrainTools.DeserializePatch(terrain, ref _patchCoord, _data);
                terrain.GetPatchBounds(terrain.GetPatchIndex(ref _patchCoord), out var patchBounds);
                OnPatchEdit(terrain, ref patchBounds);
            }
Ejemplo n.º 10
0
        private void DoRemove()
        {
            // Remove script (it could be removed by sth else, just check it)
            var script = Object.Find <Script>(ref _scriptId);

            if (!script)
            {
                Editor.LogWarning("Missing script.");
                return;
            }
            if (script.Actor)
            {
                Editor.Instance.Scene.MarkSceneEdited(script.Scene);
            }
            Object.Destroy(ref script);
        }
Ejemplo n.º 11
0
            public static SceneGraphNode Create(StateData state)
            {
                var data   = JsonSerializer.Deserialize <Data>(state.State);
                var spline = Object.Find <Spline>(ref data.Spline);

                spline.InsertSplineLocalPoint(data.Index, data.Keyframe.Time, data.Keyframe.Value, false);
                spline.SetSplineKeyframe(data.Index, data.Keyframe);
                var splineNode = (SplineNode)SceneGraphFactory.FindNode(data.Spline);

                if (splineNode == null)
                {
                    return(null);
                }
                splineNode.OnUpdate();
                OnSplineEdited(spline);
                return(splineNode.ActorChildNodes[data.Index]);
            }
Ejemplo n.º 12
0
        internal unsafe void CopyFrom(CollisionData *data)
        {
            _impulse   = data->Impulse;
            _velocityA = data->VelocityA;
            _velocityB = data->VelocityB;
            _colliderA = Object.Find <Collider>(ref data->ColliderA);
            _colliderB = Object.Find <Collider>(ref data->ColliderB);

            Assert.AreEqual(data->ContactsCount, _contacts.Length);

            ContactPointData *ptr = &data->Contacts0;

            for (int i = 0; i < data->ContactsCount; i++)
            {
                _contacts[i] = new ContactPoint(ref ptr[i], ref data->ColliderA, ref data->ColliderB);
            }
        }
Ejemplo n.º 13
0
            /// <inheritdoc />
            public void Do()
            {
                var terrain = Object.Find <FlaxEngine.Terrain>(ref _terrainId);

                if (terrain == null)
                {
                    Editor.LogError("Missing terrain actor.");
                    return;
                }

                terrain.AddPatch(ref _patchCoord);
                if (TerrainTools.InitializePatch(terrain, ref _patchCoord))
                {
                    Editor.LogError("Failed to initialize terrain patch.");
                }
                terrain.GetPatchBounds(terrain.GetPatchIndex(ref _patchCoord), out var patchBounds);
                OnPatchEdit(terrain, ref patchBounds);
            }
Ejemplo n.º 14
0
            /// <inheritdoc />
            public void Do()
            {
                var terrain = Object.Find <FlaxEngine.Terrain>(ref _terrainId);

                if (terrain == null)
                {
                    Editor.LogError("Missing terrain actor.");
                    return;
                }

                terrain.AddPatch(ref _patchCoord);
                if (TerrainTools.InitializePatch(terrain, ref _patchCoord))
                {
                    Editor.LogError("Failed to initialize terrain patch.");
                }

                Editor.Instance.Scene.MarkSceneEdited(terrain.Scene);
            }
Ejemplo n.º 15
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]);
         }
     }
 }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
0
            private void Set(Guid oldRootId, Guid newRootId)
            {
                var oldRoot = Object.Find <Actor>(ref oldRootId);
                var newRoot = Object.Find <Actor>(ref newRootId);

                _window.Graph.MainActor = null;
                if (SceneGraphFactory.Nodes.TryGetValue(oldRootId, out var oldRootNode))
                {
                    oldRootNode.Dispose();
                }
                if (SceneGraphFactory.Nodes.TryGetValue(newRootId, out var newRootNode))
                {
                    newRootNode.Dispose();
                }

                newRoot.Parent = null;
                oldRoot.Parent = newRoot;

                _window.Graph.MainActor   = newRoot;
                _window.Viewport.Instance = newRoot;
            }
Ejemplo n.º 18
0
                public void Undo()
                {
                    var spline = Object.Find <Spline>(ref SplineId);

                    spline.RemoveSplinePoint(Index);
                }
Ejemplo n.º 19
0
        /// <summary>
        /// Collect loaded scenes data.
        /// </summary>
        public void GatherSceneData()
        {
            if (HasData)
            {
                throw new InvalidOperationException("DuplicateScenes has already gathered scene data.");
            }

            Editor.Log("Collecting scene data");

            // Get loaded scenes
            var scenes      = SceneManager.Scenes;
            int scenesCount = scenes.Length;

            if (scenesCount == 0)
            {
                throw new InvalidOperationException("Cannot gather scene data. No scene loaded.");
            }
            var sceneIds = scenes.ToList().ConvertAll(x => x.ID);

            // Serialize scenes
            _scenesData.Capacity = scenesCount;
            for (int i = 0; i < scenesCount; i++)
            {
                var scene = scenes[i];
                var data  = new SceneData
                {
                    IsDirty = Editor.Instance.Scene.IsEdited(scene),
                    Bytes   = SceneManager.SaveSceneToBytes(scene),
                };
                _scenesData.Add(data);
            }

            // Delete old scenes
            if (SceneManager.UnloadAllScenes())
            {
                throw new FlaxException("Failed to unload scenes.");
            }
            FlaxEngine.Scripting.FlushRemovedObjects();

            // Ensure that old scenes has been unregistered
            {
                var noScenes = SceneManager.Scenes;
                if (noScenes != null && noScenes.Length != 0 && sceneIds.TrueForAll(x => Object.Find <Object>(ref x) == null))
                {
                    throw new FlaxException("Failed to unregister scene objects.");
                }
            }

            Editor.Log(string.Format("Gathered {0} scene(s)!", scenesCount));
        }
Ejemplo n.º 20
0
                public void Do()
                {
                    var spline = Object.Find <Spline>(ref SplineId);

                    spline.InsertSplineLocalPoint(Index, Time, Value);
                }