예제 #1
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);
        }
예제 #2
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);
        }